
// Determine browser type (Netscape 6 or IE 5.5).

	var isIE5 = (navigator.userAgent.indexOf("MSIE 5.5") > 0) ? 1 : 0;
	var isNS6 = (navigator.userAgent.indexOf("Gecko")    > 0) ? 1 : 0;

// Global variable for tracking the currently active button.

	var activeButton = null;
	var ActiveChildMenu = null;
	
	var bool_MenuShowing = false

// Depressed button style values.

	var depressedBackgroundColor = "#FFFFFF";
	var depressedColor           = "#FF0000";
	var depressedNWBorderColor   = "#FFFFFF";
	var depressedSEBorderColor   = "#FFFFFF";

// Capture mouse clicks on the page so any active button can be deactivated.

	if (isIE5)
		document.onmousedown = pageMousedown;
	if (isNS6)
		document.addEventListener("mousedown", pageMousedown, true);
		//alert("netCrap")


	function pageMousedown(event) {
	
		var className;

	 // If the object clicked on was not a menu button or item, close any active menu.

		if (isIE5)
			className = window.event.srcElement.className;
		if (isNS6)
			className = (event.target.className ?
			event.target.className : event.target.parentNode.className);

		if (className != "menuButton" && className != "menuItem" && activeButton)
			resetButton(activeButton);
						
	}//End Function
	
	function resetButtonTest() {
		//This function is called from another page to hide the menu.
		// need to test to see if the menu is showing before you try to hide it...
		
			var className;

	 // If the object clicked on was not a menu button or item, close any active menu.

		if (isIE5)
			className = window.event.srcElement.className;
		if (isNS6)
			className = (event.target.className ?
			event.target.className : event.target.parentNode.className);
		
		if (className != "") { 
			if (className != "menuButton" && className != "menuItem" && activeButton)
				resetButton(activeButton);
		}//end if

	
	}// end function
	

	function MenuSelection(){
	//Closes the menu after a valid choice is picked
		resetButton(activeButton);
	}//end function


	function buttonClick(button, menuName) {

		button.blur(); // ... Don't think I need

		if (!button.menu)// Associate the named menu to this button if not already done.
			button.menu = document.getElementById(menuName);

		// Reset the currently active button, if any.

		if (activeButton&& activeButton != button)
			resetButton(activeButton);

		// Toggle the button's state.

		if (button.isDepressed)
			resetButton(button);
		else
			depressButton(button);
    
		return false;
	}//End Function


	function ShowChild(MenuItem, ChildID){// This Function will show the Child Menu
		
		if (!MenuItem.menu)// Associate the named menu to this button if not already done.
			MenuItem.menu = document.getElementById(ChildID);
		
		//depressButton(MenuItem, ChildID); //show the Child Menu
				
		// Save current style values so they can be restored later. Only needs to be done once.

		button = MenuItem
		
		if (!MenuItem.oldBackgroundColor) { //Will not need with better style diffinition...
			MenuItem.oldBackgroundColor   = MenuItem.style.backgroundColor;
			MenuItem.oldColor             = MenuItem.style.color;
    		MenuItem.oldBorderTopColor    = MenuItem.style.borderTopColor;
			MenuItem.oldBorderRightColor  = MenuItem.style.borderRightColor;
			MenuItem.oldBorderBottomColor = MenuItem.style.borderBottomColor;
			MenuItem.oldBorderLeftColor   = MenuItem.style.borderLeftColor;
			MenuItem.oldPosition = MenuItem.style.position;
			MenuItem.oldLeft     = MenuItem.style.left;
			MenuItem.oldTop      = MenuItem.style.top;
		}//End If

  // Change Menu Item to Hightlight Future use, might change to highlight... Style

	//Allow the Hyper link to work anywhere, not just on the text
		if (isIE5 && !MenuItem.menu.firstChild.style.width)
			MenuItem.menu.firstChild.style.width = MenuItem.menu.offsetWidth + "px";
			
		//Position the Child Menu next to and Under the Parent Menu
		
		x = getPageOffsetLeft(MenuItem) + MenuItem.offsetWidth;
		y = getPageOffsetTop(MenuItem);
		
		//alert (document.body.clientWidth)
		  
		//window.alert (x + MenuItem.offsetWidth)
		//window.alert (document.body.clientWidth)

		if (x + MenuItem.offsetWidth > document.body.clientWidth){
		MenuItem.menu.style.left = x - MenuItem.offsetWidth - MenuItem.menu.offsetWidth + "px";
		}
		else{
		MenuItem.menu.style.left = x + "px";}
		
		MenuItem.menu.style.top  = y + "px";
		MenuItem.menu.style.visibility = "visible";

		ActiveChildMenu = ChildID
		
		return false;

	}//ShowChild end function
	

	function HideChild(ChildID){
		if (ActiveChildMenu && ActiveChildMenu != ChildID)
			document.getElementById(ActiveChildMenu).style.visibility = "hidden";
	}//End HideChild Function
	

	function buttonMouseover(button, menuName) {// If any other button menu is active, deactivate it and activate this one.
		if (activeButton && activeButton != button) {
			resetButton(activeButton);
			
			if (menuName)
				buttonClick(button, menuName);
		}//end if
	}//end function


	function depressButton(button) {

		// Save current style values so they can be restored later. Only needs to be done once.

		if (!button.oldBackgroundColor) {
			button.oldBackgroundColor   = button.style.backgroundColor;
			button.oldColor             = button.style.color;
			button.oldBorderTopColor    = button.style.borderTopColor;
			button.oldBorderRightColor  = button.style.borderRightColor;
			button.oldBorderBottomColor = button.style.borderBottomColor;
			button.oldBorderLeftColor   = button.style.borderLeftColor;
			button.oldPosition = button.style.position;
			button.oldLeft     = button.style.left;
			button.oldTop      = button.style.top;
		}//end if

		// Change style value to make the button looks like it's depressed.

		button.style.backgroundColor   = depressedBackgroundColor;
		button.style.color             = depressedColor;
		button.style.boarderstyle      = 'inset';
		button.style.borderTopColor    = depressedNWBorderColor;
		button.style.borderRightColor  = depressedSEBorderColor;
		button.style.borderBottomColor = depressedSEBorderColor;
		button.style.borderLeftColor   = depressedNWBorderColor;
		button.style.position = "relative";
		button.style.left     = "1px";
		button.style.top      = "1px";
	
		// For IE, force first menu item to the width of the parent menu, this
		// causes mouseovers work for all items even when cursor is not over the
		// link text.

		if (isIE5 && !button.menu.firstChild.style.width)
			button.menu.firstChild.style.width = button.menu.offsetWidth +"px";
			
		x = getPageOffsetLeft(button);
		y = getPageOffsetTop(button) + button.offsetHeight; // Put the SubMenu Under the Title Bar
		
		button.menu.style.left = x + "px";
		button.menu.style.top  = y -1 + "px";
		button.menu.style.visibility = "visible";

		// Set button state and let the world know which button is active.

		button.isDepressed = true;
		activeButton = button;
		
		bool_MenuShowing = true;
		
		
	}//End Function

	function resetButton(button) { //Reset the Title Bar

		// Restore the button's style settings.

		button.style.backgroundColor = button.oldBackgroundColor;
		button.style.borderBottomColor = button.oldBorderBottomColor;
		button.style.borderRightColor = button.oldBorderRightColor;
		button.style.borderTopColor = button.oldBorderTopColor;
		button.style.borderLeftColor = button.oldBorderLeftColor;
		button.style.color = button.oldColor;
		button.style.left = button.oldLeft
		button.style.position = button.oldPosition;
		button.style.top = button.oldTop;

		if (button.menu)// Hide The Title Bar's Sub Menu
			button.menu.style.visibility = "hidden";
  
		var i = 0; //do a loop to hide all menus *** numberofmenus is set from the server in local java
		for (i;i < numberofmenus ;i ++) {
			document.getElementById('Menu'+i).style.visibility = "hidden";
		}//end for

		// Set button state and clear active menu global.
			button.isDepressed = false;
			activeButton = null;
	
		bool_MenuShowing = false
	
	}//end function


	function getPageOffsetLeft(el) {// Return the true x coordinate of an element relative to the page.
	
		return el.offsetLeft + (el.offsetParent ? getPageOffsetLeft(el.offsetParent) : 0);
	}//end function

	function getPageOffsetTop(el) {
		
		return el.offsetTop + (el.offsetParent ? getPageOffsetTop(el.offsetParent) : 0);
	}//end function
