var objTimeoutArray = new Array()

function hidePopup(strName)
{
	if ( document.getElementById(strName) )
	{   
		document.getElementById(strName).style.visibility = "hidden";
   }
}

function clearPopups(strName)
{
	//strName = the name of any popup to keep open
	var intCurrentIndex = -1;
	
	if ( typeof(strName) == "string" )
	{
	   if ( strName.length != 0 )
	   {
			intCurrentIndex = parseInt(strName.charAt(strName.length - 1),10);
		}
	}				

	for ( var i = 1; i <= objTimeoutArray.length-1; i++ )
	{
		if ( i != intCurrentIndex )
		   hidePopup('menu' + i);
	}
	
}

function displayPopup(strParent, strPopupName, strPosition)
{
   var objToolTip;
   var objParent;
   var intLeft;
   var intTop;
   
   //strParent = the id of the <TD> tag for this menu item
	//strPopupName = the name of the menu to display
	//strPosition = the position relative to the parent tage that you would 
	//				like the pop up to appear at. Possible values are:
	//				left	- popup will appear to the left
	//				right	- popup will appear to the right
	//				above	- popup will appear above
	//				below	- popup will appear below
	//
				
	//Clear all OTHER popups
	clearPopups();
					
	//Take ownership of current window if it is open
	killHide(strPopupName);			
				
	//Get current element for positioning purposes
	if ( document.getElementById )
	{			
	   //get the parent tag object	
		objParent = document.getElementById(strParent);
		intLeft = findAbsoluteX(objParent);
		intTop = findAbsoluteY(objParent);
					
		//Get the popup object
		objToolTip = document.getElementById(strPopupName);
					
		//Hide the popup. This is a toggle.
		if ( objToolTip.style.visibility == "visible" )
		{
		   //hidePopup(strPopupName);
      }
      else
      {
			//position the popup appropriately
         intTop = parseInt(intTop + objParent.offsetHeight + 5);
         if ( intTop < 5 )
            intTop = 5;

         if ( intLeft < 20 )
            intLeft = 20;

         objToolTip.style.top = intTop + 'px';
         objToolTip.style.left = intLeft + 'px';
         objToolTip.style.visibility = "visible";
      }
   }
}

function displayNestedPopup(strParent,strPopupName,strPosition)
{
   var objToolTip;
   var objParent;
   var intLeft;
   var intTop;
				
	//strParent = the id of the <TD> tag for this menu item
	//strPopupName = the name of the menu to display
	//strPosition = the position relative to the parent tage that you would 
	//				like the pop up to appear at. Possible values are:
	//				left	- popup will appear to the left
	//				right	- popup will appear to the right
	//				above	- popup will appear above
	//				below	- popup will appear below
	//

	//Take ownership of current window if it is open
	killHide(strPopupName);

	//Get current element for positioning purposes
	if ( document.getElementById )
	{				
	   //get the parent tag object	
		objParent = document.getElementById(strParent);
		intLeft = findAbsoluteX(objParent);
		intTop = findAbsoluteY(objParent);
					
		//Get the popup object
		objToolTip = document.getElementById(strPopupName);
					
		//Hide the popup. This is a toggle.
		if ( objToolTip.style.visibility == "visible" )
		{
		   //hidePopup(strPopupName);
      }
      else
      {
		   //position the popup appropriately
         //intTop = parseInt(intTop + objParent.offsetHeight + 5) + 'px';
         if ( intTop < 5 )
            intTop = 5;

         if ( intLeft < 20 )
            intLeft = 20;

         objToolTip.style.top = intTop + 'px';
         objToolTip.style.left = (intLeft + objParent.offsetWidth) + 'px';
         objToolTip.style.visibility = "visible";
      }
   }
}
			    
function delayHidePopup(strName,intDelay)
{	
   var intIndex;
				
	if ( strName.length != 0 )
	{
	   intIndex = parseInt(strName.charAt(strName.length - 1),10);
	}
	else
	{
	   intIndex=0;
	}
				
	//Save timeout ID
	objTimeoutArray[intIndex] = setTimeout("hidePopup('"+strName+"')",intDelay);
}
			
function killHide(strName)
{			
	var intIndex=0;
				
	if ( strName.length != 0 )
	{
	   intIndex = parseInt(strName.charAt(strName.length - 1),10);
	}			
	clearTimeout (objTimeoutArray[intIndex]);
	objTimeoutArray[intIndex]==0;
}
			    
function findAbsoluteX(objSource)
{
   var lngX = 0;
   				
	do
	{
	   lngX += objSource.offsetLeft;
		objSource = objSource.offsetParent;
	}
	while ( objSource );
								
	return lngX;
}

function findAbsoluteY(objSource)
{
	var lngY = 0;

	do
	{
		lngY += objSource.offsetTop;
		objSource = objSource.offsetParent;
	}
	while ( objSource );
								
	return lngY;
}

function hover(intOnOff, objElement)
{
	if ( intOnOff )
	{
		objElement.className="selectedMenuItem";
   }
	else
	{
	   objElement.className="menuItem";
	}
}

function goTo(strString)
{
	window.location = strString;
}				
				
function debugPrint(strString)
{
	var objDebug = document.getElementById("debug");				
	var objDate = new Date()
				
	if ( objDebug.innerHTML.lastIndexOf('*') > 200 )
	{
		objDebug.innerHTML = objDebug.innerHTML.slice(objDebug.innerHTML.lastIndexOf('*') - 200,objDebug.innerHTML.lastIndexOf('*') + 5);
	}
				
	objDebug.innerHTML = objDebug.innerHTML + objDate.getTime() + " - " + strString + "*<br>";
				
}			