//		JavaScript Document
//		The following two functions are not being used, but may be helpful in the future in working through browser differences,
//		particularly how they handle the offsetLeft and offsetTop properties.
function findPosX(obj)
{
       var curleft = 0;
     if (obj.offsetParent)
       {
                while (obj.offsetParent)
               {
                        curleft += obj.offsetLeft
                      obj = obj.offsetParent;
              }
        }
        else if (obj.x)
              curleft += obj.x;
      return curleft;
}

function findPosY(obj)
{
      var curtop = 0;
     if (obj.offsetParent)
       {
                while (obj.offsetParent)
               {
                        curtop += obj.offsetTop
                      obj = obj.offsetParent;
              }
        }
        else if (obj.y)
              curtop += obj.y;
      return curtop;
}
//		end of comment


function hideSelectBoxes() {
	var all_selects = document.getElementsByTagName("select");
	for (i=0; i < all_selects.length; i++) {
		all_selects[i].style.visibility = "hidden";
	}
}

function showSelectBoxes() {
	var all_selects = document.getElementsByTagName("select");
	for (i=0; i < all_selects.length; i++) {
		all_selects[i].style.visibility = "visible";
	}
}




//		This function finds and hides all the pulldown menus - identifying them first by tag type (div), then by class name (pulldown)
function hidePulldowns()
{
	for (i=0;i<document.getElementsByTagName("div").length; i++)
	{
		if (document.getElementsByTagName("div").item(i).className == "pulldown")
		{
        	document.getElementsByTagName("div").item(i).style.display = "none";
    	}
    }
}

//		This function finds and hides all the submenus - identifying them first by tag type (div), then by class name (submenu)
function hideSubmenus()
{
	for (i=0;i<document.getElementsByTagName("div").length; i++)
	{
		if (document.getElementsByTagName("div").item(i).className == "submenu")
		{
		document.getElementsByTagName("div").item(i).style.display = "none";
    	}
    }
	
	for (i=0;i<document.getElementsByTagName("div").length; i++)
	{
		if (document.getElementsByTagName("div").item(i).className == "pulldown")
		{
        	document.getElementsByTagName("div").item(i).style.display = "none";
    	}
    }
}

//		This function finds all tab elements with a "selected" class name and deselects them 
function deselectTabs()
{
	for (i=0;i<document.getElementsByTagName("a").length; i++)
		{
			  if (document.getElementsByTagName("a").item(i).className == "tabselected")
			  {
                    document.getElementsByTagName("a").item(i).className = "tab";
              }
        }
		
		for (i=0;i<document.getElementsByTagName("div").length; i++)
		{
			  if (document.getElementsByTagName("div").item(i).className == "tabwrapperselected")
			  {
                    document.getElementsByTagName("div").item(i).className = "tabwrapper";
              }
        }
}


//		This function resets the page tabs to their initial state 
function restoreTab(OriginalTab)
{
	var OriginalTabWrapper = "TabWrapper" + OriginalTab;
	var OriginalTab = "Tab" + OriginalTab;

	
//		First deselect all tabs
	deselectTabs();

//		Then restore the original one (for subpages only)
	if (OriginalTab != 'none' && isObject(OriginalTab) ) {
		document.getElementById(OriginalTabWrapper).className = 'tabwrapperselected';
		document.getElementById(OriginalTab).className = 'tabselected';
	}
}

//		This variable needs to be initialized here in order for the timer functions to work properly
var TimerToggle = null;


function posMenu(HoverGroup)
{
	var HoverTabWrapper = "TabWrapper" + HoverGroup;
	var HoverTab = "Tab" + HoverGroup;
	var Pulldown = "Submenu" + HoverGroup;
   
	var TabPosX = document.getElementById(HoverTabWrapper).offsetLeft;
	var TabPosY = document.getElementById(HoverTabWrapper).offsetTop;
     
//  	Get position coordinates of tab and show them *Used only for testing purposes
//		document.getElementById("TextBox").innerHTML = "Left:" + TabPosX + ", Top:" + TabPosY;

//		Clear any outstanding timers *this is necessary because multiple instances of timers will slow the browser to a halt
	stopTimer();

//		Hide all submenus
	hideSubmenus();

//		Finds all tabs with class of "selected" and makes them look normal
//		then it gives class "selected" to the tab being moused over
	deselectTabs();

//		Give the hovered tab a class of "selected"
	document.getElementById(HoverTabWrapper).className = 'tabwrapperselected';
	document.getElementById(HoverTab).className = 'tabselected';

//		Now show the pulldown that is selected
	document.getElementById(Pulldown).style.display = "";
      
//		Position the pulldown to match the tab position
	document.getElementById(Pulldown).style.left = TabPosX + "px";
	document.getElementById(Pulldown).style.top = TabPosY + "px";
	
	// hide select boxes
	hideSelectBoxes();
}

//		This function is meant to be used with an onMouseOver event handler. When you mouseOver a tab,
//		it highlights that tab and brings up it's submenu.
function toggleMenu(HoverGroup)
{
	var HoverTabWrapper = "TabWrapper" + HoverGroup;
	var HoverTab = "Tab" + HoverGroup;
	var HoverSubmenu = "Submenu" + HoverGroup;
   
//		Clear any outstanding timers *this is necessary because multiple instances of timers will slow the browser to a halt
	stopTimer();

//		Hide all submenus
	hideSubmenus();

//		Finds all tabs with class of "selected" and makes them look normal
//		then it gives class "selected" to the tab being moused over
	deselectTabs();

//		Give the hovered tab a class of "selected"
	document.getElementById(HoverTabWrapper).className = 'tabwrapperselected';
	document.getElementById(HoverTab).className = 'tabselected';

//		And show the submenu that goes with it
	document.getElementById(HoverSubmenu).style.display = "";

}


//		This is a timer function. It calls other functions after half a second (500 milliseconds). It calls:
//		hideSubmenus - which hides all the submenus except for the original one
//		restoreTab - which sets deselects all tabs and selects the original one
function timedRestoreMenu(OriginalTab)
{

	TimerToggle = setTimeout('hideSubmenus(); showSelectBoxes(); restoreTab(\''+OriginalTab+'\');', 500);
//	TimerToggle = setTimeout('hideSubmenus();', 500);

}

//		This function stops the timedHideMenu function by clearing the timer
function stopTimer()
{
	TimerToggle = clearTimeout(TimerToggle);
}