//*********************************************************************************
//   MenuScripts - By Salvador Valencia
//   This may be used and changed freely as long as this msg is intact! 
//*********************************************************************************
//------------------------------
//Scripts for the event handling 
//of the dropdown menus
//------------------------------

//Set local values for the current browser
//========================================
arrayMenu = new Array();
oldMenuLevel = 0;
newMenuLevel = 0;

if (document.layers){
   visible = 'show';
   hidden = 'hide';
}
else if (document.all){
   visible = 'visible';
   hidden = 'hidden'; 
}

//FUNCTION: HideMenu
//==================
function HideMenu(menu){
   var aMenu;

   if (document.layers) {
      aMenu = document.layers[menu];
   }else if (document.all) {
      aMenu = document.all(menu).style;
   }
   if (aMenu.visibility == visible) {
      aMenu.visibility = hidden;
   }
}

//FUNCTION: ShowMenu
//==================
function ShowMenu(newMenu){
   
	 newMenuLevel = GetMenuLevel(newMenu);
   
   if ( newMenuLevel == 0 ){
      ShowMenuBlock(newMenu);
   }
	 else if ( newMenuLevel > oldMenuLevel ){
			ShowMenuBlock(newMenu);	 
	 }
	 else{      
      ClearSubMenus(newMenuLevel);
      ShowMenuBlock(newMenu);	 
	 }   
	 oldMenuLevel = newMenuLevel;
}

//FUNCTION: ShowMenuBlock
//=======================
function ShowMenuBlock(menuName){
   var itemCount;
   var aMenu;
   var itemFound = false;

   for (itemCount = 0; itemCount < arrayMenu.length && !itemFound; itemCount++){
      if ( menuName == arrayMenu[itemCount] ){
         aMenu = document.all(menuName).style;
         aMenu.visibility = visible;
         itemFound = true;  
      }
   }
}

//FUNCTION: ClearSubMenus
//=======================
function ClearSubMenus(startLevel){
   var itemCount;
   var aMenu;
   var menuName;
   var menuLevel;   
   
   for (itemCount = 0; itemCount < arrayMenu.length; itemCount++){
      menuName = arrayMenu[itemCount];      
      menuLevel = GetMenuLevel( menuName );
      //alert("menuName = " + menuName + " menuLevel = " + menuLevel + " startLevel= " + startLevel);
      if ( menuLevel >= startLevel ){
         aMenu = document.all(menuName).style;
         aMenu.visibility = hidden;   
      }
   }
}

//FUNCTION: CollapseAll
//=====================
function CollapseAll()
{
   ClearSubMenus(0);
   oldMenuLevel = 0;
}

//FUNCTION: MenuScan
//==================
function MenuScan(){
   var menuCount = 0;
   var itemCount;

   tmpCollection = document.all.tags("DIV");
   for (itemCount = 0; itemCount < tmpCollection.length; itemCount++){
      itemName = tmpCollection(itemCount).id;      
      if ( itemName.substr(0,5) == "MenuL" ){
         arrayMenu[menuCount] = itemName;
         menuCount++;
      }
   }   
}

//FUNCTION: GetMenuLevel
//======================
function GetMenuLevel(menuName){
   var strLevel;
   var levelValue;   

   strLevel = menuName.substr(5,1);	 
   levelValue = parseInt(strLevel, 10);	 
	 if ( isNaN(levelValue) ){
	    levelValue = 0;
	 }
   return levelValue;
}


