// JavaScript Document

var g_TopMenudir = 1;
var g_TopMenuwidth = 144;

var g_menuColor = "#FFFFFF";
var g_fontColorOff	= "#000000";
var g_menuBorderColor = "#CCCCCC";
var g_PrimaryColor	= "#FF9900";

var g_BrowserWidth	= window.innerWidth;
var g_hasLayers	= (document.layers);
var g_hasAll	= (document.all);
var g_hasGetElement = (document.getElementById);
var undefined;

var IE40 = (navigator.appVersion.indexOf("MSIE 4.0") >= 0);
var IE45 = (navigator.appVersion.indexOf("MSIE 4.5") >= 0);

var NS7 = ((navigator.userAgent.indexOf("Netscape/7") >= 0) || (navigator.userAgent.indexOf("Safari") >= 0));
var NS6 = (!g_hasAll && g_hasGetElement); 

function doJump(strURL) {
	document.location.href=strURL;
}


function doJump1(strURL) {
	if (strURL.search(/^javascript|window.open/i) == 0) {
		val = explode(strURL,"|");
		eval(val[1]);
	} else {
		document.location.href=strURL;
	}
}


function explode(inputstring, separator) {
	inputstring = new String(inputstring);
	separators = new String(separator);

	fixedExplode = new Array(1);
	currentElement = "";
	count = 0;

	for(x=0; x < inputstring.length; x++) {
		mychar = inputstring.charAt(x);
		if(separators.indexOf(mychar) != -1) {
			fixedExplode[count] = currentElement;
			count++;
			currentElement = ""; 
		}
		else { currentElement += mychar; }
	}
	fixedExplode[count] = currentElement;
	return fixedExplode;
}


function outputMenusNow()
{
document.write("<DIV id='topNav' align='left' style='z-index:1;position:relative; width:"+g_TopMenuwidth+"px; height:"+g_TopMenuheight+"px; top:0; left:0;'>")
writeMenuItems()
document.write("</DIV>")

if (g_hasAll)	centerDiv();
else if (g_hasGetElement) centerNS6();
}

function showDDNav(itemId) { 
var obj;
if (g_hasGetElement) obj = document.getElementById(itemId);
else obj = document.all[itemId]; 
if (obj) {
if(obj.style.visibility == 'hidden') obj.style.visibility = 'visible';
}
}

function hideDDNav(itemId) {
var obj;
if (g_hasGetElement) obj = document.getElementById(itemId);
else obj = document.all[itemId];
if (obj) {
if(obj.style.visibility == 'visible')	obj.style.visibility = 'hidden';
}
}

function writeDiv(menuID, left, divTop, tdID, width, dir) {
var divID = "menu" + menuID;
var menuData = eval("menuData" + menuID);
if (menuData == null) return 0;

var divLeft = 144;

divTop = parseInt(divTop);
var mousey = " onMouseover=\"showDDNav('"+ divID + "');\" onMouseout=\"hideDDNav('" + divID + "');\" ";
cl = "dropDownContainer";

if (g_hasGetElement) {
if (NS6) {
objDiv = "<div class=\""+cl+"\" id=\"" + divID + "\" style=\"left: " + divLeft + "; width: " + (width+2) + "; visibility:hidden; top: " + divTop + "; z-index:2; \" " + mousey + " >";
} else {
objDiv = "<div class=\""+cl+"\" id=\"" + divID + "\" style=\"left: " + divLeft + "; top: " + divTop + "; visibility: hidden; z-index:2;\" " + mousey + " >";
}
} else if (g_hasAll) {
objDiv = "<div class=\""+cl+"\" id=\"" + divID + "\" style=\"left: " + divLeft + ";visibility: hidden;top: " + divTop + "; z-index:2; \" " + mousey + " >";
}

var leftText = (g_hasAll) ? "" : "left:1;";

for (y = 0; y < menuData.length / 4; y++) {
var strItem = menuData[(y * 4)+1];
var strUrl = menuData[(y * 4)];
var strsub	= menuData[(y * 4) + 3];
var strId	= menuData[(y * 4) + 2];
var strsubwidth	= 144;
var strsubdir	= "r";
var strItemTip = strItem.replace("'","\\'");

if (strUrl.search(/^javascript:/i) == -1)	strUrl = "doJump('" + strUrl + "')"
if (strUrl.search(/^javascript|window.open/i) == 0) { strUrl="doJump1('" + strUrl + "')";}

if (g_hasAll || NS6) 
item_cl = "dhtmlNav"; 
item_cl1 = "dhtmlNav1";

if(strsub!=0) {
objDiv += "<div id=\"x" + tdID + "\" style=\"z-index:3; width:" + width + ";" + leftText + "\" onMouseover='showsub("+strId+");this.className=\""+item_cl1+"\"' onMouseout='hidesub("+strId+");this.className=\""+item_cl+"\"' class=\""+item_cl+"\" onClick=\""+strUrl+"\">";
objDiv +="&nbsp;<img src=img/arrow.gif>&nbsp;&nbsp;"+ strItem;
objDiv += "</div>"; 
mdivTop = parseInt((17*y));
objDiv += writesubDiv(strId, 144, strsub, strsubwidth,strsubdir,mdivTop);
}
else objDiv += "<div id=\"x" + tdID + "\" style=\"z-index:3; width:" + width + ";" + leftText + "\" onMouseover='this.className=\""+item_cl1+"\"' onMouseout='this.className=\""+item_cl+"\"' class=\""+item_cl+"\" onClick=\""+strUrl+"\">&nbsp;&nbsp;&nbsp;"+ strItem +"</div>"; 
tdID = tdID + 1;
}
objDiv += "</div>";
document.write(objDiv);
return tdID;
}


function writesubDiv(menuID, left, tdID, width, dir,divTop) {
var divID = "menu" + menuID;
var menuData = eval("menuData" + menuID);
if (menuData == null) return 0;
var divLeft = 144;

var mousey = " onMouseover=\"showDDNav('"+ divID + "');\" onMouseout=\"hideDDNav('" + divID + "');\" ";

cl = "dropDownContainer"; 
item_cl = "dhtmlNav"; 
item_cl1 = "dhtmlNav";

if (g_hasGetElement) {
if (NS6) {
objDiv = "<div class=\""+cl+"\" id=\"" + divID + "\" style=\"left: " + divLeft + "; width: " + (width+2) + "; visibility:hidden; top: " + divTop + "; z-index:4; \" " + mousey + " >";
} else {
objDiv = "<div class=\""+cl+"\" id=\"" + divID + "\" style=\"left: " + divLeft + ";visibility: hidden;top: " + divTop + "; z-index:4; \" " + mousey + " >";
}
} else if (g_hasAll) {
objDiv = "<div class=\""+cl+"\" id=\"" + divID + "\" style=\"left: " + divLeft + ";visibility: hidden;top: " + divTop + "; z-index:4; \" " + mousey + " >";
}

var leftText = (g_hasAll) ? "" : "left:1;";

for (z = 0; z < menuData.length / 4; z++) {
var strItem = menuData[(z * 4)+1];
var strUrl = menuData[(z * 4)];
var strsub	= menuData[(z * 4) + 3];
var strId	= menuData[(z * 4) + 2];
var strsubwidth	= 144;
var strsubdir	= "r";
var strItemTip = strItem.replace("'","\\'");

if (strUrl.search(/^javascript:/i) == -1)	strUrl = "doJump('" + strUrl + "')"
if (strUrl.search(/^javascript|window.open/i) == 0) { strUrl="doJump1('" + strUrl + "')";}

if (g_hasAll || NS6) 
item_cl = "dhtmlNav"; 
item_cl1 = "dhtmlNav1";
if(strsub!=0) { 
objDiv += "<div id=\"x" + tdID + "\" style=\"z-index:5; width:" + width + ";" + leftText + "\" onMouseover='showsub("+strId+");this.className=\""+item_cl1+"\"' onMouseout='hidesub("+strId+");this.className=\""+item_cl+"\"' class=\""+item_cl+"\" onClick=\""+strUrl+"\">";
objDiv +="&nbsp;<img src=img/arrow.gif>&nbsp;&nbsp;"+ strItem;
objDiv += "</div>";
oldz = z;
mdivTop = parseInt((17*z));
objDiv += writesubDiv(strId, 144, strsub, strsubwidth,strsubdir,mdivTop);
z = oldz;
}
else objDiv += "<div id=\"x" + tdID + "\" style=\"z-index:5; width:" + width + ";" + leftText + "\" onMouseover='this.className=\""+item_cl1+"\";' onMouseout='this.className=\""+item_cl+"\"' class=\""+item_cl+"\" onClick=\""+strUrl+"\">&nbsp;&nbsp;&nbsp;"+ strItem +"&nbsp;</div>"; 
tdID = tdID + 1;
}
objDiv += "</div>";
return objDiv;
}

function showsub(m) {
mm = "menu"+m;
showDDNav(mm);
}

function hidesub(m) {
mm = "menu"+m;
hideDDNav(mm);
}

function writeMenuItem(menuIndex){
var menuDataIdx = menuIndex*4;
var menuName = "menu" + mainMenuData[menuDataIdx+2];

var item_cl = "mainNav"; 
var item_cl1 = "mainNav1";

var href	= mainMenuData[menuDataIdx];
var title	= mainMenuData[menuDataIdx+1];

if (href.search(/^javascript:/i) == -1)	strUrl = "doJump('" + href + "')"
if (href.search(/^javascript|window.open/i) == 0) { strUrl="doJump1('" + href + "')";}


//var mousey = " onClick=\"doJump('" + href + "')\" onMouseover=\"this.className='"+item_cl1+"';showDDNav('"+ menuName+ "');\" onMouseout=\"this.className='"+item_cl+"';hideDDNav('"+ menuName+ "');\"";
var mousey = " onClick=\"" + strUrl + "\" onMouseover=\"this.className='"+item_cl1+"';showDDNav('"+ menuName+ "');\" onMouseout=\"this.className='"+item_cl+"';hideDDNav('"+ menuName+ "');\"";

var str = "";

if (NS6 || NS7) str += "<div "+ mousey + " name='img" + menuName + "' style='z-index:1;width:144px;height:17px;' class=\""+item_cl+"\">";
else str += "<div "+ mousey + " name='img" + menuName + "' style='z-index:1;width:144px;height:18px;' class=\""+item_cl+"\">";
if (mainMenuData[menuDataIdx+3]==1) {
	str += "&nbsp;<img src=img/arrow.gif>";
}
else str += "&nbsp;&nbsp;";
str += "&nbsp;&nbsp;"+title;

str += "</div>";

document.write(str);
}

function writeMenuItems() 
{
if (g_hasGetElement || g_hasAll) initMenus();
for (var i = 0; i < g_TopMenuCount; i++)	{ writeMenuItem(i); }
}

function initMenus() { 
var mtop = 0;
if(g_TopMenudir==1) mtop = 0;
var tdID = 0;
var offset = 0;

for (var y = 0; y < g_TopMenuCount; y++) { 
var left = 144;
var width = 144;
var dir = 'r';
var menuID = mainMenuData[y * 4 + 2];
var submn = mainMenuData[y * 4 + 3];

if (g_hasGetElement || g_hasAll) {
if(submn==1) tdID = writeDiv(menuID, left, mtop, tdID, width, dir);
} 

if(g_TopMenudir==1) mtop = mtop + 18;
offset++;
}
}

function centerDiv() {
var elGlobalNav = document.all["globalNav"];
if (elGlobalNav == null) return;

var browserWidth = document.body.clientWidth;
var globalNavWidth = elGlobalNav.offsetWidth;

if (document.parentWindow.frameElement != null)
browserWidth -=16;

var leftMarg = (browserWidth-globalNavWidth) / 2;
if (leftMarg < 5) leftMarg = 5;
elGlobalNav.style.pixelLeft = leftMarg;
elGlobalNav.style.visibility = "visible";
}

function centerNS6() {
var elGlobalNav = document.getElementById("globalNav");
if (elGlobalNav == null) return;

elGlobalNav.style.left = getLeftPos();
elGlobalNav.style.visibility = "visible";
}


function getLeftPos() {
var browserWidth = window.innerWidth;
var subNavWidth = 759;
if (g_BrowserWidth > browserWidth) {
subNavWidth = subNavWidth - 15;
}
var subNavLeft= (browserWidth - subNavWidth) / 2;
subNavLeft = Math.round(subNavLeft);

// quirky offset for gecko
if (NS6 || NS7) {
subNavLeft -= 8;
if (subNavLeft < 5) subNavLeft = 5;
} else {
if (subNavLeft < 15) subNavLeft = 15;
}
return subNavLeft;
}
