// The following are set each time a menu pops up, i.e. the current menus boundaries.
var iMenuTop;		// The top boundary where a menu should disappear.
var iMenuRight;	// The right boundary where a menu should disappear.
var iMenuBottom;	// The bottom boundary where a menu should disappear.
var iMenuLeft;		// The left boundary where a menu should disappear.

var oMenuUp;		// The current menu that is being displayed.
var isIE = false;
var isNav = false;
var isMozilla = false;
var isOpera = false;

if(document.all)	// If IE DOM
{
	isIE = true;
}
else if(document.layers)	// If this is Navigator DOM
{
	document.captureEvents(Event.MOUSEMOVE);
	isNav = true;
}
else if(document.getElementById)	// If Mozilla DOM
{
	isMozilla = true;
}


//alert("IE: " + isIE + "\nNav: " + isNav + "\nMozilla: " + isMozilla);
document.onmousemove = FindMouse;
//window.onload = LoadPage;	// Stop the execution of the rest of the script until the page fully loads.

function ShowMenu(menuName)
{

	MENU_TOP_OFFSET = 35;

	if(isIE)
		ManageForms("hidden");
	
	if(oMenuUp)
		Hide(oMenuUp);
	
	oMenu = document.getElementById(menuName + "Menu");
	oMenuCell = document.getElementById(menuName + "Src");
	// alert(menuName + "\n" + oMenu + "\n" + oMenuCell);
	if( ! oMenu || ! oMenuCell )
	{
		oMenu = document.all[menuName + "Src"];
		oMenuCell = document.all[menuName + "Cell"];
		if( ! oMenu || ! oMenuCell )
			return;
	}
	
	iMenuTop = DL_GetElementTop(oMenuCell);
	MENU_TOP_OFFSET = parseInt(oMenuCell.offsetHeight);
	iMenuLeft = DL_GetElementLeft(oMenuCell);
	iMenuBottom = iMenuTop + parseInt(oMenu.offsetHeight) + MENU_TOP_OFFSET;
	iMenuRight = iMenuLeft + parseInt(oMenuCell.offsetWidth);
	oMenu.style.width = iMenuRight - iMenuLeft; // + "px";
	oMenu.style.top = (iMenuTop + MENU_TOP_OFFSET) + "px"; // iMenuTop + oMenuCell.offsetHeight + 1;
	oMenu.style.left =  iMenuLeft+ "px"; // iMenuLeft;
	//alert(oMenu.style.width);
	//iMenuLeft = parseInt(oMenu.style.left);
	//iMenuTop = parseInt(oMenu.style.top) - 30;
	oMenu.style.visibility = "visible";
	oMenuUp = oMenu;
}

function ManageForms(sVisibility)
{
	iCounter = 1;
	while(document.forms[iCounter]){
		oForm = document.forms[iCounter];
		// If we're hiding all the forms on the page,

		iI = 0;

		while(oForm.elements[iI]){
			oEle = oForm.elements[iI];
			if(oEle.type == "select-one" || oEle.type == "checkbox"){
				oEle.style.visibility = sVisibility;
			}
			
			iI++;
		}

		iCounter++;
	}
}

function FindMouse(e)
{

	var mouseX;
	var mouseY;						

	// Use clientX for IE because that uses the cursor's absolute position on the page.
	
	if(! isMozilla || isOpera)
	{
		if(event)
		{
			mouseX = event.clientX 
			mouseY = event.clientY 
		}

	} 
	else 
	{
		mouseX = e.pageX;
		mouseY = e.pageY;
	}

	/*
	var strStatus = "X: ";
	strStatus += mouseX;
	strStatus += "     Y: ";
	strStatus += mouseY;
	strStatus += "     top: " + iMenuTop + "   left: " + iMenuLeft + "   bottom: " + iMenuBottom + "   right: " + iMenuRight;
	window.status = strStatus;
	*/

	if(mouseX < iMenuLeft || mouseX > iMenuRight || mouseY < iMenuTop || mouseY > iMenuBottom){
		Hide();
	}

	if(! oMenuUp && (isIE || isOpera) )
		ManageForms("visible");
}	

function Hide()
{
	if(! oMenuUp)
		return;

	oMenuUp.style.visibility = "hidden";
	oMenuUp = "";
}

function LoadPage(e)
{
	return;
}

function HideForm(oForm)
{
	if(oForm)
	{
		for(iCounter = 0; oForm.elements[iCounter]; ++iCounter)
		{
			oEle = oForm.elements[iCounter];
			oEle.style.visibility = "hidden";
		}
	}
}

function ShowForm(form)
{
	if(form)
	{
		for(i = 0; form.elements[i]; ++i)
		{
			ele = form.elements[i];
			ele.style.visibility = "visible";
		}
	}
}

function CellProperties(oCell)
{
	var sVar;
	var sVal;
	var sProps = oCell.id + "\n";
	for (sVar in oCell){
		sVal = eval( "oCell." + sVar);
		if( parseInt(sVal) > 0 ){
			sProps += "[" + sVar + ": " + eval("oCell." + sVar) + "]\n ";
		}
	}

	for( sVar in oCell.style ){
		sVal = eval( "oCell.style." + sVar );
		if( parseInt(sVal) > 0 ){
			sProps += "[style." + sVar + ": " + parseInt(sVal) + "]\n";
		}
	}
	return sProps;
}

function ObjProps(oObj)
{

	var sVar;
	var sVal;
	var sProps = "";	//oObj.id + "\n";
	for (sVar in oObj){
		sProps += "[" + sVar + "] ";
		//sProps += "[" + sVar + ": " + eval("oObj." + sVar) + "]\n ";
	}
	return sProps;

}

/**
* The following two functions were taken from DHTML diner
* (http://www.webreference.com/dhtml/diner/).  
* The web pages they were taken from don't mention anything about permissions, licenses, etc.
*/
function DL_GetElementLeft(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is <TT>null</TT> or is <TT>0</TT>)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE

   var nLeftPos = eElement.offsetLeft;       // initialize var to store calculations
   var eParElement = eElement.offsetParent;  // identify first offset parent element

   while (eParElement != null)
   {                                         // move up through element hierarchy

      if(DL_bIE)                             // if browser is IE, then...
      {
         if( (eParElement.tagName != "TABLE") && (eParElement.tagName != "BODY") )
         {                                   // if parent is not a table or the body, then...
            nLeftPos += eParElement.clientLeft; // append cell border width to calcs
         }
      }
      else                                   // if browser is Gecko, then...
      {
         if(eParElement.tagName == "TABLE")  // if parent is a table, then...
         {                                   // get its border as a number
            var nParBorder = parseInt(eParElement.border);
            if(isNaN(nParBorder))            // if no valid border attribute, then...
            {                                // check the table's frame attribute
               var nParFrame = eParElement.getAttribute('frame');
               if(nParFrame != null)         // if frame has ANY value, then...
               {
                  nLeftPos += 1;             // append one pixel to counter
               }
            }
            else if(nParBorder > 0)          // if a border width is specified, then...
            {
               nLeftPos += nParBorder;       // append the border width to counter
            }
         }
      }
      nLeftPos += eParElement.offsetLeft;    // append left offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nLeftPos;                          // return the number calculated
}

function DL_GetElementTop(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is <TT>null</TT> or is <TT>0</TT>)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE

   var nTopPos = eElement.offsetTop;         // initialize var to store calculations
   var eParElement = eElement.offsetParent;  // identify first offset parent element

   while (eParElement != null)
   {                                         // move up through element hierarchy
      if(DL_bIE)                             // if browser is IE, then...
      {
         if( (eParElement.tagName != "TABLE") && (eParElement.tagName != "BODY") )
         {                                   // if parent a table cell, then...
            nTopPos += eParElement.clientTop; // append cell border width to calcs
         }
      }
      else                                   // if browser is Gecko, then...
      {
         if(eParElement.tagName == "TABLE")  // if parent is a table, then...
         {                                   // get its border as a number
            var nParBorder = parseInt(eParElement.border);
            if(isNaN(nParBorder))            // if no valid border attribute, then...
            {                                // check the table's frame attribute
               var nParFrame = eParElement.getAttribute('frame');
               if(nParFrame != null)         // if frame has ANY value, then...
               {
                  nTopPos += 1;              // append one pixel to counter
               }
            }
            else if(nParBorder > 0)          // if a border width is specified, then...
            {
               nTopPos += nParBorder;        // append the border width to counter
            }
         }
      }

      nTopPos += eParElement.offsetTop;      // append top offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nTopPos;                           // return the number calculated
}
