// Decide browser version
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;
var mac = false;

if (navigator.appVersion.indexOf('Mac') != -1)
	mac = true;

if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
		ie5 = true;
	}
	if (ns6) {
		ns6 = false;
	}
}

var md=750;
var ti=-1;
var oTd=new Object;
oTd=null;

function doMenu(td){
	clearTimeout(ti);
	if(document.thisForm)
		document.thisForm.style.visibility="hidden";
	if(document.thisForm2)
		document.thisForm2.style.visibility="hidden";
	var i;
	var sT="";
	var tda=new Array();
	tda=td.id.split("_");
	if(oTd!=null){
		var tdo=new Array();
		tdo=oTd.id.split("_");
		for(i=1;i<tdo.length;i++){
			sT+="_"+tdo[i];
			if(tdo[i]!=tda[i]){
				if(document.getElementById("tbl"+sT)!=null)
					document.getElementById("tbl"+sT).style.visibility="hidden";
			}
		}
	}
	oTd=td;
	sT="tbl";
	for(i=1;i<tda.length;i++)
		sT+="_"+tda[i];
	if(document.getElementById(sT)!=null)
		document.getElementById(sT).style.visibility="visible";

}

function clearMenu(){
	if(document.thisForm)
		document.thisForm.style.visibility="visible";
	if(document.thisForm2)
		document.thisForm2.style.visibility="visible";
	if(oTd!=null){
		var tdo=new Array();
		tdo=oTd.id.split("_");
		var sT="";
		for(var i=1;i<tdo.length;i++){
			sT+="_"+tdo[i];
			if(document.getElementById("tbl"+sT)!=null)
				document.getElementById("tbl"+sT).style.visibility="hidden";
		}
		oTd=null;
	}
}

function runMenu(strURL){
	location.href=strURL;
}

function getoffsetTop(itemID) {
	itemRef=document.getElementById(itemID);
	var iHeight=0;
	while (itemRef.tagName!="BODY")
	{
		iHeight+=itemRef.offsetTop;
		itemRef=itemRef.offsetParent;
	}
	iHeight=(ie5)?iHeight:iHeight;
	return  iHeight;
}

var tt="";
var sT="";
var pT=new Array();
var tA=new Array();

function getCoord(st){
	tA=st.split("_");
	if(tA.length>2){
		tA=tA.slice(0,-1);
		tt=tA.join("_");
		return (getoffsetTop("shim"+st)+0)+"px;left:"+
			(document.getElementById("tbl"+tt).offsetLeft+document.getElementById("td"+st).offsetWidth+0)+"px\">";
	}
	return (document.getElementById("mainmenu").offsetTop+document.getElementById("td"+st).offsetHeight+2)+"px;left:"+
		  (document.getElementById("mainmenu").offsetLeft+document.getElementById("td"+st).offsetLeft+0)+"px\">";
}


// write the main menu table
var sH="<table class=\"menu\" id=\"mainmenu\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\"><tr>";
var p=0;
var j=0;
while(eval("typeof(td_"+ ++j +")!=\"undefined\"")){
	sH+="<td id=\"td_"+j+"\" Class=MainNavMenu ALIGN=\"CENTER\" VALIGN=\"MIDDLE\" NOWRAP HEIGHT=\"31\" onmouseover=\"doMenu(this); this.className='MainNavMenuOn'\" onmouseout=\"ti=setTimeout('clearMenu()',md); this.className='MainNavMenu'\"";
	sH+=(eval("typeof(url_"+j+")!=\"undefined\""))?" onclick=\"runMenu('"+eval("url_"+j)+"')\">":">";
	sH+=eval("td_"+j)+"</td>";
	if (eval("typeof(td_"+j+"_1)!=\"undefined\""))
		pT[p++]="_"+j;
}
sH+="</tr></table>";
document.write(sH);


// write the sub-menu table
for(var q=0;typeof(pT[q])!="undefined";q++){
	sT=pT[q];
	sH="";
	j=0;
	sH+="<table class=\"submenu\" id=\"tbl"+sT+"\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" style=\"top:"+getCoord(sT);
	sH+="</td></tr>";
	while (eval("typeof(td"+sT+"_"+ ++j +")!=\"undefined\"")){
		sH+="<tr><td id=\"td"+sT+"_"+j+"\" Class=SubNavMenu onmouseover=\"doMenu(this); this.className='SubNavMenuOn'\" onmouseout=\"ti=setTimeout('clearMenu()',md); this.className='SubNavMenu'\"";
		sH+=(eval("typeof(url"+sT+"_"+j+")!=\"undefined\""))?" onclick=\"runMenu('"+eval("url"+sT+"_"+j)+"')\">&nbsp;&nbsp;":">";
		sH+=eval("td"+sT+"_"+j)+"&nbsp;&nbsp;</td></tr>";
		if (eval("typeof(td"+sT+"_"+j+"_1)!=\"undefined\""))
			pT[p++]=sT+"_"+j;
	}
	//sH+="<tr><td STYLE=\"padding: 0px\"><TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\"><TR><TD WIDTH=\"10\"><IMG SRC=\"images/menu_bottom_left.gif\" WIDTH=10 HEIGHT=10 BORDER=0></TD><TD WIDTH=100% BGCOLOR=\"#B3C1D4\"><IMG SRC=\"images/shim.gif\" WIDTH=100% HEIGHT=1 BORDER=0></TD><TD WIDTH=\"10\"><IMG SRC=\"images/menu_bottom_right.gif\" WIDTH=10 HEIGHT=10 BORDER=0></TD></TR></TABLE></td></tr></table>";
	sH+="</table>";
	document.write(sH);
}

function showMenu() {
	document.getElementById("mainmenu").style.visibility="visible";
}

function hideMenu() {
	document.getElementById("mainmenu").style.visibility="hidden";
}

document.getElementById("mainmenu").style.visibility="visible";

