var menuObj = new Array();
var subMenuObj = new Array();

//Browser Type var:
var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;

//If not NS4. It should be IE or NS6+
isIE5 =!isNS4;

function moveDivs(layerObj, inObj){
	layerObj.top  = inObj;
} 

function moveTopDivs(layerObj, inObjTop, inObjLeft){
	layerObj.top  = inObjTop;
	layerObj.left  = inObjLeft;
} 

function getDim(el){
	for (var lx=0,ly=0;el!=null;
		lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
	return {x:lx,y:ly}
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	var k;
	y=19;
	isNS4 = (document.layers) ? true : false;
	isIE4 = (document.all && !document.getElementById) ? true : false;
	isIE5 = (document.all && document.getElementById) ? true : false;
	isNS6 = (!document.all && document.getElementById) ? true : false;
	for (i=0, k=1; i<(args.length-3); i+=3, k+=1) {
    	if ((obj=MM_findObj(args[i]))!=null) { 
			v=args[i+2];
			var s=args[i].substring(5);
			if (obj.style) { obj=obj.style; }
			if (v=='show') {
				if (!document.layers) {   // all others
					if (isNS6) {
//						w = window.innerWidth;
						eval('moveTopDivs(document.getElementById("Layer'+s+'").style, 173, document.images["menu_'+s+'"].x)');
					}else {
						eval('moveTopDivs(document.all["Layer'+s+'"].style, 173, getDim(document.images.menu_'+s+').x)');
					}
				}else {  //NN4
					eval('moveTopDivs(document.layers["Layer'+s+'"], 173, document.images["menu_'+s+'"].x)');
				}		
			}
			v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
			obj.visibility=v; 
		}
	}
}

function getLocationPath() {
	return './';
}

function getImagePath() {
	return getLocationPath() + '../images/';
}

function addMenu(index, caption, url, offPic, onPic, width, hasChild)
{
	menuObj[index] = new Object();
	menuObj[index].caption = caption;
	menuObj[index].url = getLocationPath() + url;
	menuObj[index].onPic = getImagePath() + 'menu/' + onPic;
	menuObj[index].offPic = getImagePath() + 'menu/' + offPic;
	menuObj[index].width = width;
	menuObj[index].hasChild = hasChild;
}

function addSubMenu(menuIndex, subMenuIndex, caption, url) {
	var subMenu = new Object();
	subMenu.id = menuIndex;
	subMenu.subID = subMenuIndex;
	subMenu.caption = caption;
	subMenu.url = url;

	subMenuObj.push(subMenu);
}

function processUrl(url) {
	if (url.indexOf('http://') == 0)
		return url + '" target="_blank';
	else
		return getLocationPath() + url;
}

function getNavigationMenu() {
	var str = '';
	str += '<div align="center">';
	for (var i=0; i<menuObj.length; i++) {
		var outAction = '';
		var overAction = '';

		if (menuObj[i].hasChild == "Y") {
			outAction = "onMouseOut=\"MM_showHideLayers(\'Layer"+i+"\',\'\',\'hide\',0);MM_swapImgRestore();\"";
			overAction = " onMouseOver=\"MM_showHideLayers(\'Layer"+i+"\',\'\',\'show\',0);MM_swapImage('menu_"+i+"', '', '"+menuObj[i].onPic+"',1);\" ";
		} else {
			outAction = "onMouseOut=\"MM_swapImgRestore();\"";
			overAction = " onMouseOver=\"MM_swapImage('menu_"+i+"', '', '"+menuObj[i].onPic+"',1);\" ";
		}

		if (i > 0)
			str += '<img src="'+getImagePath()+'spacer.gif" width="20" height="1" />';

		if (menuObj[i].hasChild == 'Y') {
			str += '<img '+outAction+' '+overAction+' name="menu_'+i+'" id="menu_'+i+'" src="'+menuObj[i].offPic+'" title="'+menuObj[i].caption+'" alt="'+menuObj[i].caption+'" border="0"  height="32" cursor="pointer" cursor="hand" />';
		} else {
			str += '<a href="'+processUrl(menuObj[i].url)+'" '+outAction+' '+overAction+'>';
			str += '<img name="menu_'+i+'" id="menu_'+i+'" src="'+menuObj[i].offPic+'" title="'+menuObj[i].caption+'" alt="'+menuObj[i].caption+'" border="0"  height="32" />';
			str += '</a>';
		}
	}

	str += '</div>';

	document.writeln(str);
}

function getSubMenus() {
	var str = '';

	for (var i=0; i<menuObj.length; i++) {
		str = '';

		if (menuObj[i].hasChild == 'Y') {
			if (!document.all && document.getElementById)
				var leftt = eval('document.images["menu_'+i+'"].x');
			else
				var leftt = eval('getDim(document.images.menu_'+i+').x');

			str += '<div id="Layer'+i+'" style="position:absolute; z-index:1; left:'+leftt+'px; top:173px; width:158; visibility:hidden" onMouseOver="MM_swapImage(\'menu_'+i+'\',\'\', \''+menuObj[i].onPic+'\',1); MM_showHideLayers(\'Layer'+i+'\',\'\',\'show\',0)" onMouseOut="MM_swapImgRestore();MM_showHideLayers(\'Layer'+i+'\',\'\',\'hide\',0)">';

			str += '<table border="1" cellpadding="2" cellspacing="0" borderColor="#D0E7C6">';

			for (var j=0; j<subMenuObj.length; j++) {
				if (subMenuObj[j].id == i)
					str += '<tr><td bgColor="#0762A9" class="submenu"><a href="'+processUrl(subMenuObj[j].url)+'">'+subMenuObj[j].caption+'</a></td></tr>';
			}

			str += "</table>";
			str += '</div>';

			document.writeln(str);
		}
	}
}

function SwitchLang(lang) {

var gopath;
	if (top.location.href.indexOf("#") != -1) {
		locationx = top.location.href.substring(0, top.location.href.indexOf("#"));
	} else {
		locationx = top.location.href;
	}
	if (lang == 'eng') {
		if (locationx.indexOf("/eng/") == -1) {
			if (locationx.indexOf("/sch/") != -1) {
				gopath = top.location.replace(locationx.replace("/sch/","/eng/"));
			} else if (locationx.indexOf("/tch/") != -1) {
				gopath = top.location.replace(locationx.replace("/tch/","/eng/"));
			}
		}
	} else if (lang == 'sch') {
		if (locationx.indexOf("/sch/") == -1) {
			if (locationx.indexOf("/eng/") != -1) {
				gopath = top.location.replace(locationx.replace("/eng/","/sch/"));
			} else if (locationx.indexOf("/tch/") != -1) {
				gopath = top.location.replace(locationx.replace("/tch/","/sch/"));
			}
		}
	} else if (lang == 'tch') {
		if (locationx.indexOf("/tch/") == -1) {
			if (locationx.indexOf("/eng/") != -1) {
		 		gopath = top.location.replace(locationx.replace("/eng/","/tch/"));
			} else if (locationx.indexOf("/sch/") != -1) {
		 		gopath = top.location.replace(locationx.replace("/sch/","/tch/"));
			}
		}
	}
	
}

