var ML_HTML_RE = /</g;

function EnforceCol(el) {
	if (el.length) {
		return el;
	} else {
		var ar = new Array();
		ar[0] = el;
		return ar;
	}	
}

function TranslateAll(shallow) {	
	if (LANG.length < 2) return;
	//process all elements with "FR='something' attribute
	//var mls = document.getElementsByTagName("SPAN"); //LABEL hides undescore from links, unfortunately...
	var mls = document.all("ml");
	if (mls != null) {
		mls = EnforceCol(mls);
		var e = new Enumerator(mls); 
		for (; !e.atEnd(); e.moveNext()) {
			var el = e.item();
			var s = GetMLString(el);
			if (s != null) {
				if (ML_HTML_RE.test(s)) {
					el.innerHtml = s;
				} else {
					el.innerText = s;
				}	
			}	
			if (el.title) {
				var t = GetMLTitle(el);
				if (t) {
					el.title = t;
				} else {
					el.title = s;
				}
			}		
		}
	}	
	var e = null;
	var mls = null;
	var mls = document.getElementsByTagName("INPUT");
	var e = new Enumerator(mls); 
	for (; !e.atEnd(); e.moveNext()) {
		var el = e.item();
		var s = GetMLString(el);
		if (s != null) {
			el.value = s;
			if (el.title) el.title = s;
		}
		if (el.title) {
			var t = GetMLTitle(el);
			if (t) {
				el.title = t;
			} else {
				if (s != null) el.title = s;
			}
		}
	}
	
	var langSel = document.all("Lang");
	if (langSel) {
		var opts = langSel.options;
		var lng = (LANG == "EN" || LANG == "") ? "" : "_" + LANG.toLowerCase();
		for (var i=0; i<opts.length; i++) {
			if (opts[i].value == lng) {
				langSel.selectedIndex = i;
				break;
			}
		}
	}
	
	return; //infinite loop - each page is calling this proc! :TODO:
	if (shallow == true) return;
	
	var frs = parent.frames;
	if (frs) {
		for (var i=0; i<frs.length; i++) {
			var fra = frs[i];
			alert(fra.name + ": " + fra.LANG);
			if (fra.LANG) {
				fra.LANG = LANG;
				fra.TranslateAll(true);
			}
		}
	}
}	


function GetMLString(el) {
	return eval("el." + LANG);
}

function GetMLTitle(el) {
	return eval("el." + LANG + "T");
}

function MLString(text, ar) {
	if (ar == null) return text;
	var N = ar.length;
	var  key = LANG + "=";
	for (var i=0; i<N; i++) {
		var s = ar[i];
		if (s.substring(0,3) == key) {
				return s.substring(3);
		}
	}
	return text;
}

var hideLangSel = null;
function ExpandLanguageSelector() {
	var sel = document.frmLang.Lang;
	sel.focus();
	//sel.setActive();
	if (divLang.style.position == 'absolute') return;
	divLang.style.position = 'absolute';
	divLang.oldHeight = divLang.style.height;
	divLang.style.height = '70px';
	divLang.style.left = event.clientX + 8;
	divLang.style.top = 1;
	//divLang.style.top = event.clientX + 8;
	divLang.style.overflow = 'auto'; 
	sel.size = 3; 
	hideLangSel = window.setTimeout("CollapseLanguageSelector()", 3000);
}

function CollapseLanguageSelector() {
	if (hideLangSel) window.clearTimeout(hideLangSel);
	divLang.style.position = 'relative';
	if (divLang.oldHeight) divLang.style.height = divLang.oldHeight;
	divLang.style.overflow = 'hidden';
	divLang.style.left = "";
	divLang.style.top = "";
	document.frmLang.Lang.size = 1; 
}

window.setTimeout("TranslateAll()", 1); //make async call

