// Function chooses which div is open when a button is clicked.  All others close.

function selectDiv(DivName)
{

  if (DivName == '') return;

  var x = 1;
  var menu = "tab";
  var tab = "admintab";
  var divtab;
  var current = document.getElementById(DivName).style.display.valueOf();
  for (x=1;x<=maxtabs;x++)
    {
       divtab = tab + x;
	   menutab = menu + x;
	   //alert(divtab);
	   //alert(current);
	   if (current == "none" || current == "" || current == "undefined")
	     {

		    
			if (DivName == divtab)
			  {
			    document.getElementById(DivName).style.display = "block";
			    document.getElementById(DivName).style.height = contentheight[x] + "px";
				document.getElementById('nav_link' + x.toString()).style.opacity = "1.0";
				document.getElementById('nav_link' + x.toString()).style.filter='alpha(opacity=100)'; 
				document.getElementById('submenu' + x.toString()).style.display = "block";
				
			    //document.getElementById(menutab).style.backgroundColor = bgcolor;
                document.getElementById('default_home').style.display = "none";
				document.getElementById('default_home').style.height = "0px";
			  }
		    else
			  {
			    document.getElementById(divtab).style.display = "none";
			    document.getElementById(divtab).style.height = "0px";
				document.getElementById('submenu' + x.toString()).style.display = "none";				
				//document.getElementById(menutab).style.backgroundColor = defbgcolor;
				document.getElementById('nav_link' + x.toString()).style.opacity = "0.60";
				document.getElementById('nav_link' + x.toString()).style.filter='alpha(opacity=60)'; 
		
			  }
		 }
	   else
	     {
			if (DivName == divtab)
			  {
			    document.getElementById(DivName).style.display = "none";
   			    document.getElementById(DivName).style.height = "0px";
				document.getElementById('submenu' + x.toString()).style.display = "none";				
                //document.getElementById(menutab).style.backgroundColor = defbgcolor;
				document.getElementById('nav_link' + x.toString()).style.opacity = "0.60";
				document.getElementById('nav_link' + x.toString()).style.filter='alpha(opacity=60)'; 
			  }
		    else
			  {
			    var hometab = tab + "1";
			    document.getElementById(hometab).style.display = "block";
                document.getElementById(hometab).style.height = contentheight[1] + "px";
				document.getElementById('submenu' + x.toString()).style.display = "block";				
				//document.getElementById(menutab).style.backgroundColor = bgcolor;
                document.getElementById('default_home').style.display = "none";
				document.getElementById('default_home').style.height = "0px";
				document.getElementById('nav_link' + x.toString()).style.opacity = "1.0";
				document.getElementById('nav_link' + x.toString()).style.filter='alpha(opacity=100)'; 
			  }
		   
		 
		 
		 }
		 
	    

    }

}


function expandNav(position)
  {
    
    var x = 1;
    for (x = 1; x <= maxtabs; x++)
      {
	    var divId = "nav_link" + x.toString();
		var divIdOver = "nav_link_over" + x.toString();
		var getsub = "submenu" + x.toString();
		
		tab = document.getElementById(divId);
		tabover = document.getElementById(divIdOver);
        subdiv = document.getElementById(getsub);
	  	if (x != 1)
		  {
			tab.style.marginLeft = '10px';
		  }
		if (x == position)
		  {
		    //alert(getsub);
	        tabover.style.display = "block";
			//tabover.style.marginLeft = "20px";
	        tab.style.display = "none";	
			//subdiv.style.display = "block";
			//alert(isSet(subnavtimer[x]));
			if (!isSet(subnavtimer[x]) && subnavexpand[x]) expandSubNav(x); 
		  }

		 
	  }
    
  
  
  }


function shrinkNav(position)
  {
    var tabname = "tab" + position;
    var x;
    for (x = 1; x <= maxtabs; x++)
      {
	    var divId = "nav_link" + x.toString();
		var divIdOver = "nav_link_over" + x.toString();
		tab = document.getElementById(divId);
		tabover = document.getElementById(divIdOver);
        submenu = document.getElementById('submenu' + x.toString());		
	    //submenu.style.display = "none";
	  	if (x != 1)
		  {
			tab.style.marginLeft = '30px';
		  }
		if (x == position)
		  {
	        tab.style.display = "block";
	        tabover.style.display = "none";
			submenu.style.height = "0px";
			subnavheight[position] = 0;
		    if (isSet(subnavtimer[position]))
		      {
		        clearInterval(subnavtimer[position]);
                delete subnavtimer[position];
    		  }			
	        submenu.style.display = "none";		
		  }
	  }
  
  
  }
  
function expandSubNav(position)
  {
    var y;
    for (y = 1; y <= maxtabs; y++)
	  {
		//alert('subnavtimer= ' + subnavtimer[y] + ' pos= ' + position);
        if (!isSet(subnavtimer[y]) && position == y)
		  {
		    //alert('setting timer ' + y);
			currsubnav = y;
    		var submenuname = "submenu" + currsubnav;
            var subheight = subnavheight[currsubnav] + "px";			
			snav = document.getElementById(submenuname);
			//alert('height= ' + subheight + ' menu= ' + submenuname);
			snav.style.height = subheight;
			snav.style.display = "block";
			subnavtimer[y] = setInterval(addSubNav, speed);
		  
		  }
		if (isSet(subnavtimer[y]) && position != y)
		  {
		    clearInterval(subnavtimer[y]);
            delete subnavtimer[y];
		  }
  
	  }
  }
  
  
function addSubNav()
  {
  	if (subnavheight[currsubnav] >= maxsubheight[currsubnav])
	  {
	    subnavheight[currsubnav] = maxsubheight[currsubnav];
		clearInterval(subnavtimer[currsubnav]);
		delete subnavtimer[currsubnav];
	  }
    else 
	  {
	    subnavheight[currsubnav] += subnavstep;	    
	  
	  }

		var submenuname = "submenu" + currsubnav;
        var subheight = subnavheight[currsubnav] + "px";
		//var j = confirm(submenuname + '  ' + subheight);
		//if (!j) clearInterval(subnavtimer[currsubnav]);
		  
		sdiv = document.getElementById(submenuname);
		sdiv.style.height = subheight;
  }

function openSubNavOption(option, position)
  {
    shrinkNav(position);
    //alert(lastdivopen + ", " + option);
    if (option == lastdivopen)
	  {
	    //alert("equal!");
  		//divopen = document.getElementById(option);
		//divopen.style.display = "none";
		//divopen.style.height = "0px";
		//defaultopen = document.getElementById("default_home");
		//defaultopen.style.display = "block";
		//defaultopen.style.height = "100%";
		//lastdivopen = "default_home";
	  }
	else
	  {
	    //alert("not equal!");
	    oldopen = document.getElementById(lastdivopen);
		oldopen.style.display = "none";
		oldopen.style.height = "0px";
		divopen = document.getElementById(option);
	    divopen.style.display = "block";
		divopen.style.height = "100%";
		lastdivopen = option;
	  }
	var dheight = getDocHeight();
	//alert(dheight);
    setBodyHeight("main", dheight );
    setBodyHeight("left_panel", dheight);
    setBodyHeight("right_panel", dheight);
  
  
  }

function setDefaultHome()
  {
	  	divopen = document.getElementById(lastdivopen);
		divopen.style.display = "none";
		divopen.style.height = "0px";
		defaultopen = document.getElementById("default_home");
		defaultopen.style.display = "block";
		defaultopen.style.height = "100%";
		lastdivopen = "default_home";
	
  }

function openCategoryOption(option, bheight)
  {
    //alert(lastcatopen + ", " + option);
    if (option == lastcatopen)
	  {
	    //alert("equal!");
  		divopen = document.getElementById(option);
		divopen.style.display = "none";
		divopen.style.height = "0px";
		//defaultopen = document.getElementById("default_home");
		//defaultopen.style.display = "block";
		//defaultopen.style.height = "100%";
		lastcatopen = "none";
	  }
	else
	  {
	    //alert("not equal!");
		if (lastcatopen != "none")
		  {
    	    oldopen = document.getElementById(lastcatopen);
	    	oldopen.style.display = "none";
		    oldopen.style.height = "0px";
		  }
		divopen = document.getElementById(option);
	    divopen.style.display = "block";
		if (bheight != '') divopen.style.height = bheight;
		else divopen.style.height = "600px";
		lastcatopen = option;
	  }
	var dheight = getDocHeight();
	//alert(dheight);
    setBodyHeight("main", dheight );
    setBodyHeight("left_panel", dheight);
    setBodyHeight("right_panel", dheight);
  
  
  }


