// MPC 9/08/2004
//	Task: 2573
//	Description: This Javascript is used to show and hide the menus defined by /assets/include/menus.inc for most common browsers.
//	The following functions are called from the /assets/include/leftnav.inc when mouse events occur.
//	It is currently limited to a maximum of three levels of depth.

var displayTime = 0;
var lastMenu = 0;
var layerTimer;
var opac = 0;
var curMenu = 0;

//browser detection
var browserType

if (document.all) { browserType = "IE" } //ie
else if (document.getElementById){ browserType = "NS6" } //ns6: mozilla, firefox
else if (document.layers) { browserType = "NS4" } //ns4


function showMenu(sltMenu, which, x, y, index, z) {
	var strResolution = getResolution();
	//opera Netscape 6 Netscape 4x Mozilla 
	if (window.innerWidth || window.innerHeight){ 
	docwidth = window.innerWidth; 
	docheight = window.innerHeight; 
	} 
	//IE Mozilla 
	if (document.body.clientWidth || document.body.clientHeight){ 
	docwidth = document.body.clientWidth; 
	docheight = document.body.clientHeight; 
	} 

	if(strResolution == 'c') {
	   if (index == 1) {
	      x = ((docwidth/2) - (729/2));
	   }
	   if (index == 2) {
	      x = (((docwidth/2) - (729/2)) + 145)
	   }
	   if (index == 21) {
	      x = (((docwidth/2) - (729/2)) + 315)
	   }
	   if (index == 22) {
	      x = (((docwidth/2) - (729/2)) + 315)
	   }
	   if (index == 3) {
	      x = (((docwidth/2) - (729/2)) + 290)
	   }
	   if (index == 35) {
	      x = (((docwidth/2) - (729/2)) + 460)
	   }
	   if (index == 4) {
	      x = (((docwidth/2) - (729/2)) + 435)
	   }
	   if (index == 46) {
	      x = (((docwidth/2) - (729/2)) + 265)
	   }
	   if (index == 47) {
	      x = (((docwidth/2) - (729/2)) + 265)
	   }
	   if (index == 8) {
	      x = (((docwidth/2) - (729/2)) + 265)
	   }
	} 
	
	var tweakXposition = 0;
	var tweakYposition = 0;
	displayTime = 0;
	opac = 0;
	
	curMenu = sltMenu;
	
	if((document.getElementById(sltMenu).style.visibility == 'visible')  && (sltMenu == lastMenu)) {
		clearTimeout(layerTimer);
		return;
	}
	
	// hide menus that do not need to be shown before displaying the new menu
	// Note: do not hide any menus if the current selected menu (sltmenu) is equivalent to the last selected menu 
	// or if it is a menu on the third level
	//if(sltMenu != lastMenu && lastMenu != 0 && sltMenu != "menu1a" && sltMenu != "menu4a") {
    if(sltMenu != lastMenu && lastMenu != 0 && sltMenu != "menu2a" && sltMenu != "menu2b" && sltMenu != "menu3e" && sltMenu != "menu4f" && sltMenu != "menu4g" && sltMenu != "menu8c") {
		eval("document.getElementById('" + lastMenu + "').style.visibility ='hidden'");

		//hide 2nd level menus that link to a 3rd level menu
		//eval("document.getElementById('menu1').style.visibility ='hidden'");
	}
	//get position of the originating anchor tag in order to solidify the positioning menus for non-IE browsers.
	if(which != 0) {
		varcoords = getAnchorPosition(z);
		
		//add minor positional tweak for non-IE browser
		//if(browserType != "IE") {
		//	tweakXposition = 2;
		//}
		if(z == 'a2') {
		   tweakXposition = 245;
		   if(sltMenu == 'menu2a') {
		      tweakXposition = 330;
		   }
		   if(sltMenu == 'menu2b') {
		      tweakXposition = 330;
			  tweakYposition = 65;
		   }
		}
		if(z == 'a3') {
		   tweakXposition = 290;
		   if(sltMenu == 'menu3e') {
		      tweakXposition = 475;
			  tweakYposition = 145;
		   }
		}
		if(z == 'a4') {
		   tweakXposition = 435;
		   if(sltMenu == 'menu4f') {
		      tweakXposition = 250;
			  tweakYposition = 170;
		   }
		   if(sltMenu == 'menu4g') {
		      tweakXposition = 250;
			  tweakYposition = 195;
		   }
		}
		document.getElementById(curMenu).style.left = varcoords.x + tweakXposition;
	    document.getElementById(curMenu).style.top = varcoords.y + 35;
		if(sltMenu == 'menu2b') {
		   document.getElementById(curMenu).style.top = varcoords.y + tweakYposition;
		}
		if(sltMenu == 'menu3e') {
		   document.getElementById(curMenu).style.top = varcoords.y + tweakYposition;
		}
		if(sltMenu == 'menu4f') {
		   document.getElementById(curMenu).style.top = varcoords.y + tweakYposition;
		}
		if(sltMenu == 'menu4g') {
		   document.getElementById(curMenu).style.top = varcoords.y + tweakYposition;
		}
		//eval("document.getElementById('" + sltMenu + "').style.left = varcoords.x + 180 + tweakXposition");
		//eval("document.getElementById('" + sltMenu + "').style.top = varcoords.y - 1");	
	} else {
		varcoords = 0;
		document.getElementById(curMenu).style.left = x;
	    document.getElementById(curMenu).style.top = y;
	}	
	// display new menu
	//document.getElementById(curMenu).style.left = x;
	//document.getElementById(curMenu).style.top = y;
	document.getElementById(curMenu).style.visibility = 'visible';
	//eval("document.getElementById('" + curMenu + "').style.left = x");
	//eval("document.getElementById('" + curMenu + "').style.top = y");
	//eval("document.getElementById('" + curMenu + "').style.visibility = 'visible'");
	//fadeIn();
	
	lastMenu = sltMenu;			// store the current selected menu so that we can hide it later
	clearTimeout(layerTimer);	// reset the timer since we want the current menu to be displayed for the full specified time
	
	return;
}

function hideMenu() {

		if(displayTime < 1) { // This code causes 1 increment of the below 500 ms to occur before hidding anything
			displayTime++;
		}
		else { // hide all menus
			eval("document.getElementById('menu1').style.visibility ='hidden'");	
			eval("document.getElementById('menu2').style.visibility ='hidden'");
			eval("document.getElementById('menu2a').style.visibility ='hidden'");
			eval("document.getElementById('menu2b').style.visibility ='hidden'");
			eval("document.getElementById('menu3').style.visibility ='hidden'");
			eval("document.getElementById('menu3e').style.visibility ='hidden'");
			eval("document.getElementById('menu4').style.visibility ='hidden'");
			eval("document.getElementById('menu4f').style.visibility ='hidden'");		
			eval("document.getElementById('menu4g').style.visibility ='hidden'");
			displayTime = 0;
			opac = 0;
		}
		layerTimer=setTimeout("hideMenu()", 200); // call hideMenu again after 500 ms have gone by
}

function hideMenu2() {

		if(displayTime < 1) { // This code causes 1 increment of the below 500 ms to occur before hidding anything
			displayTime++;
		}
		else { // hide all menus
			eval("document.getElementById('menu5').style.visibility ='hidden'");	
			eval("document.getElementById('menu6').style.visibility ='hidden'");
			eval("document.getElementById('menu8').style.visibility ='hidden'");
			eval("document.getElementById('menu8c').style.visibility ='hidden'");
			displayTime = 0;
			opac = 0;
		}
		layerTimer=setTimeout("hideMenu2()", 200); // call hideMenu again after 500 ms have gone by
}

function resetTimer() {
	displayTime = 0;
	clearTimeout(layerTimer);
}

// adds fade in effect to the displaying of the div tag
function fadeIn() {
	eval("document.getElementById('" + curMenu + "').style.visibility = 'visible'");
	//if(opac < 96){
	//	opac+=32;
	//	eval("document.getElementById('" + curMenu + "').style.filter='alpha(opacity = " + opac + ")'");
	//	setTimeout('fadeIn()', 1);
	//}
}

function getResolution() {
   var iWidth, iHeight, sRes
   if(window.innerWidth != null) {
   	  iWidth = window.innerWidth;
   	  iHeight = window.innerHeight; 
   } 
   else if(document.body.clientWidth != null) {
      iWidth = document.body.clientWidth;
      iHeight = document.body.clientHeight;
   } else {
      iWidth = 640;
   }
   if(iWidth < 800) 
      {sRes = "a"}		
   else if(iWidth == 800)
   	  {sRes = "b"}		
   else if(iWidth > 800)
   	  {sRes = "c"}		
   else {sRes = "z"}
   return (sRes)
}

function findPosX(evt,obj) {
	var varBrowser;
	varBrowser = getBrowser();
	var curleft = 0;
	if (varBrowser.indexOf("ie")>=0)  {
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) 
		curleft += obj.x;
	} else {
	curleft = evt.pageX;
	}
	return curleft;
}

function findPosY(evt,obj) {
	var varBrowser;
	varBrowser = getBrowser();
	var curtop = 0;
	if (varBrowser.indexOf("ie")>=0)  {
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	} else {
	curtop = evt.pageY;
	curtop = (curtop - 25);
	}
	return curtop;
}

function getBrowser() {
   var vBrowser=navigator.appName;			
   var vVersion=navigator.appVersion;
   var sBrowser;
   if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("6")>=0)
      {sBrowser="ie5";} 	// Microsoft Internet Explorer 5.x
   else if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("5")>=0)
   	  {sBrowser="ie5";} 	// Microsoft Internet Explorer 5.x
   else if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("4")>=0)
   	  {sBrowser="ie4";}		// Microsoft Internet Explorer 4.x
   else if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("3")>=0)
   	  {sBrowser="ie3";}	// Microsoft Internet Explorer 3.x
   else if (vBrowser.indexOf("Netscape")>=0 && vVersion.indexOf("7")>=0)
   	  {sBrowser="ns7";}	// Netscape Navigator 7.x
   else if (vBrowser.indexOf("Netscape")>=0 && vVersion.indexOf("6")>=0)
   	  {sBrowser="ns6";}	// Netscape Navigator 6.x
   else if (vBrowser.indexOf("Netscape")>=0 && vVersion.indexOf("4")>=0)
   	  {sBrowser="ns4";}	// Netscape Navigator 4.x
   else if (vBrowser.indexOf("Netscape")>=0 && vVersion.indexOf("3")>=0)
   	  {sBrowser="ns3";}	// Netscape Navigator 3.x
   else
      {sBrowser="other";}	// All Others 	
   return(sBrowser);
}

/* 
DESCRIPTION: These functions find the position of an <A> tag in a document,
so other elements can be positioned relative to it.

COMPATABILITY: Netscape 4.x,6.x,Mozilla, IE 5.x,6.x on Windows. Some small
positioning errors - usually with Window positioning - occur on the 
Macintosh platform.

FUNCTIONS:
getAnchorPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor. Position is relative to the PAGE.

getAnchorWindowPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor, relative to the WHOLE SCREEN.

NOTES:

1) For popping up separate browser windows, use getAnchorWindowPosition. 
   Otherwise, use getAnchorPosition

2) Your anchor tag MUST contain both NAME and ID attributes which are the 
   same. For example:
   <A NAME="test" ID="test"> </A>

3) There must be at least a space between <A> </A> for IE5.5 to see the 
   anchor tag correctly. Do not do <A></A> with no space.
*/ 

// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}
