// JavaScript Document
/*

* Common Functions

*/



function OnSelectDropDown(dropdownname)

{

	var dropdown = document.getElementById(dropdownname);

	

	window.location = dropdown.options[dropdown.selectedIndex].value;

}



/*

getOffsetLeft

Return the absolute left dimension of the object in the current 

*/

function getOffsetLeft(objThis)

{

	var objOffsetParent = objThis.offsetParent;

	if (objOffsetParent)

	{

		return objThis.offsetLeft + getOffsetLeft(objOffsetParent);

	}

	else

	{

		return 0;

	}

}



function getMenuBarOffsetRight(objThis)

{

	var objParent = objThis.parentElement;

	if (objParent)

	{

		if (objParent.id == "nav")

		{

			return getOffsetLeft(objParent) + objParent.offsetWidth - 1;

		}

		else

		{

			return getMenuBarOffsetRight(objParent);

		}

	}

	else

	{

		return 0;

	}

}



function getOffsetTop(objThis)

{

	var objOffsetParent = objThis.offsetParent;

	if (objOffsetParent)

	{

		return objThis.offsetTop + getOffsetTop(objOffsetParent);

	}

	else

	{

		return 0;

	}

}

var currentMenu = null;
var navmenu = null; // added by LM

var currentPath = new String(document.URL);

currentPath = currentPath.substring(currentPath.indexOf("/", currentPath.indexOf("//") + 2), currentPath.length);



if (!document.getElementById)

{

	document.getElementById = function() { return null; }

}



function initializeMenu(actuatorNum, actuatorPath)

{
	
	var mainmenu = document.getElementById("subnav_" + actuatorNum);
	
	var navmenu = document.getElementById("nav_" + actuatorNum); // added by LM
	
	var actuator = document.getElementById("navlink_" + actuatorNum);

	var actuatorTab = document.getElementById("nav_" + actuatorNum);

	var blocker = document.getElementById("menuBlocker");


	if (actuator != null)

	{

		// Check if we need to highlight this tab

		if (actuatorTab != null)

		{

			var isCurrentTab;

			

			if (actuatorPath == "/")

			{


				isCurrentTab = (currentPath.indexOf("/",1) < 0);

			}

			else if (actuatorPath.length > 1)

			{

				isCurrentTab = (currentPath.indexOf(actuatorPath) == 0);

			}

			

			if (isCurrentTab)

			{

				if (actuatorTab.className != '')

				{

					actuatorTab.className = actuatorTab.className + ' NavItemActive';

				}

				else

				{

					actuatorTab.className = "NavItemActive";

				}

			}

		}



		// Actuator Mouseover Event

		actuator.onmouseover = function()

		{
			
			if (currentMenu == null)

			{
				
				if (mainmenu != null)

				{
				
					this.showMenu();

				}

			}

			if (currentMenu)

			{

				currentMenu.style.visibility = "hidden";


				

				if (blocker)

				{

					blocker.style.visibility = "hidden";

				}

				

				if (mainmenu != null)

				{

					this.showMenu();

				}

			}

		}



		// Main Menu-related functions		

		if (mainmenu != null)

		{			

			mainmenu.onmouseover = function()

			{

				if (currentMenu == null)

				{

					this.showagainMenu();

				}

				if (currentMenu)

				{

					currentMenu.style.visibility = "hidden";

					this.showagainMenu();

				}

			}
			
			// added by LM
			navmenu.onmouseout = function()
			{

				if (currentMenu == null)

				{

					currentMenu.hideMenu();

				}

				if (currentMenu)

				{

					currentMenu.style.visibility = "visible";

					currentMenu.hideMenu();
					currentmenu = null; // added by L Mendoza
				}
	

			}
			

			mainmenu.onmouseout = function()

			{

				if (currentMenu == null)

				{

					this.hideMenu();


				}

				if (currentMenu)

				{

					currentMenu.style.visibility = "visible";

					this.hideMenu();
					currentmenu = null; // added by L Mendoza
				}
	

			}
			
			actuator.showMenu = function()

			{

				var myLeft = getOffsetLeft(this);

				var myTop = getOffsetTop(this);

				var barRight = getMenuBarOffsetRight(this);

				

				if (((myLeft + mainmenu.offsetWidth) > barRight) && (barRight > 0))

				{

					myLeft = barRight - mainmenu.offsetWidth + 1;

				}

				

				mainmenu.style.left = myLeft + "px";

				mainmenu.style.top = (myTop + this.offsetHeight) + "px";

				if (blocker)

				{

					blocker.style.top = (myTop + this.offsetHeight) + "px";

					blocker.style.left = myLeft + "px";

					blocker.style.width = mainmenu.offsetWidth + "px";

					blocker.style.height = mainmenu.offsetHeight + "px";

					blocker.style.zIndex = "100"; /* was 99 */

					blocker.style.visibility = "visible"; 

				}

				mainmenu.style.visibility = "visible"; 

				mainmenu.style.zIndex = "100";
				currentMenu = mainmenu;

			}

			

			mainmenu.showMenu = function()

			{

				actuator.showMenu();

			}



			mainmenu.showagainMenu = function()

			{

				mainmenu.style.visibility = "visible";

				if (blocker)

				{

					blocker.style.visibility = "visible";

				}
				currentMenu = mainmenu;

			}

			

			mainmenu.hideMenu = function()

			{

				mainmenu.style.visibility = "hidden";

				if (blocker)

				{

					blocker.style.visibility = "hidden";

				}
				currentMenu = mainmenu;
			}

		}

	}

}

