/* Click to Expand Menu */

if (document.getElementById){ 
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

var x=0;
var destination=" ";

var locate = String(window.location);		//finds the current web address
var place = locate.indexOf("?") + 1;		//finds a "?" in the web address, returns the # of 
                                            //the character, and adds +1 for the # of the saved 
											//menu state (1,2,3 or 4)

                                            //var place2 = place + 1; not used
var old = locate.substring(place);			//finds the menu state at the end of the web address (1,2,3 or 4)
var newstring="sub" + old;					//makes a string that says "sub1" "sub2" "sub3" or "sub4". 
											//The original code calls the function like: onclick="SwitchMenu(\'sub1\');"
var state = old;							//makes the old saved state the current saved state, so if another link from 
											//the open menu is clicked the state will be saved.

function SwitchMenu(obj){					//part of original code that opens up the menu, the original mainmenu.js code calls this 
//alert('here1');							//function like: onclick="SwitchMenu(\'sub1\');"
	if(document.getElementById(obj)){
//alert('here2');										//I call this function in the last line of mainmenu.js like:
	var el = document.getElementById(obj);				//SwitchMenu(newstring); to open up the previous menu state when the page loads
//alert('here3');
	var ar = document.getElementById("masterdiv").getElementsByTagName("span");
//alert('here4');
//alert('el.style.display = ' + el.style.display)
		if(el.style.display != "block"){ //DynamicDrive.com change
//alert('here5');		
			for (var i=0; i<ar.length; i++){
//alert('here6');			
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

//this function is called in mainmenu.js.  I changed: onclick="SwitchMenu(\'sub1\');" to:  onclick="SwitchMenu(\'sub1\'); MenuState(\'1\');"
//in the mainmenu.js code so when the a menu is opened, the state is also saved
//this function is called in mainmenu.js when a link is clicked:  <A href="#" onclick="javascript:goPage(\'http://.....')">	
//adds "?1" or "?2" etc. to the destination address to save the menu state		
//browser opens new web address

function MenuState(x){
	state=x;
	}								

function goPage(destination){								
	var address=destination + "?" + state;					
	window.location.href=address;
	}						
