
//	ClientMenu.js	
//	The following script provides a drop down submenu for a horizontal menu.


 
//	Usage: 
//		Each submenu (dropdown menu) on the page is created in a table
//		with a separate <td> for each item
//		eg.  
//			<table class='table_nav_drop' id=HContainerMenu>
//				<tr>
//					<td><a href='Container.aspx' class='table_nav_drop_a'>Container&nbsp;Order:&nbsp;Once</a></td>
//					<td><a href='ContainerSched.aspx' class='table_nav_drop_a'>Container&nbsp;Order:&nbsp;Schedule</a></td>
//					<td><a href='Containers.aspx' class='table_nav_drop_a'>View&nbsp;Container&nbsp;Order&nbsp;List</a></td>
//				</tr>
//			</table>
//
//	In the anchor tag where the mouseover event will cause the drop down
//		menu to appear (actuator), specify an ID that can be referenced
//		later.
//		eg. id=PickUp
//
//	In the javacsript window.onload function, call HinitializeMenu()
//		passing it the submenu ID as the first parameter, and the
//		actuator ID as the second parameter for each submenu. 
//		eg.
//			HinitializeMenu("HPickupMenu", "Pickup")
//
//	The Hinitialize functions can be pulled out of the window.onload function
//		and called to provide drop down menu only when required.
//
//	Once initilized, the actuator can be disabled by passing the actuator ID
//		for the HideMe function.
//
//	For positioning, the script uses getPos() to obtain the position of
//		top left corner of the TD cell in which the actuator anchor tag
//		is located. The positioning can be varied by adding offsets to
//		either PosTD.x or PosTD.y
//	To allow menu to resize to caption, add "&nbsp;" where there is space between the words

var HcurrentMenu = null;
var LeftOffset = -10;
var TopOffset = 15;

function MakeDropDowns_old() {
	var menflag = document.getElementById("MenuFlag");
	if (menflag.value == "Approved") {
		HinitializeMenu("HContainerMenu", "Containers");
		HinitializeMenu("HQuoteMenu", "Quotes");
		HinitializeMenu("HPickupMenu", "Pickup");
	}
}

if (!document.getElementById) {
    document.getElementById = function() { 
		return null; 
	}
}

function HinitializeMenu(HmenuId, HactuatorId) {
	var Hactuator = document.getElementById(HactuatorId);
	var Hmenu = document.getElementById(HmenuId);

	if (Hmenu == null || Hactuator == null) {
		return;
	}

	Hactuator.onmouseover = function() {
		if (HcurrentMenu) {
			try {
				HcurrentMenu.style.visibility = "hidden";
			}
			catch(theException) {
				return false;
			}
		}
		this.HshowMenu();
	}

	Hactuator.onmouseout = function() {
		try	 {
			HcurrentMenu.style.visibility = "hidden";
		}			
		catch(theException)	{
			return;				
		}
	}

	Hactuator.HshowMenu = function() {
		objTrigger = this.id;
		var PosTD = getPos(this);
		var thisCentre = Math.floor(PosTD.x +  this.clientWidth/2);
		if (thisCentre + Math.ceil(document.getElementById(HmenuId).clientWidth/2) > document.body.clientWidth) {
			Hmenu.style.left = document.body.clientWidth - document.getElementById(HmenuId).clientWidth - 5 + "px";
		} else {
			Hmenu.style.left = thisCentre - Math.floor(document.getElementById(HmenuId).clientWidth/2) + "px";
		}
		Hmenu.style.top = PosTD.y + TopOffset + "px";				
		Hmenu.style.visibility = "visible";
		HcurrentMenu = Hmenu;	
   	}	

   	Hmenu.onmouseover = function() {
		Hmenu.style.visibility = "visible";
		document.getElementById(objTrigger).className += "_static";
	}

	Hmenu.onmouseout = function() {
		Hmenu.style.visibility = "hidden";
		document.getElementById(objTrigger).className = document.getElementById(objTrigger).className.substring(0, document.getElementById(objTrigger).className.indexOf('_static'));
		HcurrentMenu = null;
	}
}
    
//Get the position of the container of the Anchor Tag Actuator. 
//For this example it is the TD tag	

function getPos(el) {
	for (var lx = 0, ly = 0; el != null;
		lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
	return {x:lx, y:ly}	
}

function HideMe(HactuatorId) {
	var HActuator = document.getElementById(HactuatorId);
	HActuator.onmouseover = null;			
}

