//Save state
function setCookie(cookieName, cookieValue)
{
	document.cookie=cookieName + "=" + escape(cookieValue);
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{ 
		c_start=document.cookie.indexOf(c_name + "=");
		
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
		
			if (c_end==-1) {
				 c_end=document.cookie.length;
			}
			
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	
	return null
}

function openLastSelectedMenu() {

	var activeMenuId = getCookie(window.parent.name);
	var activeMenu = null;
	
	if (typeof(document.getElementById) != 'undefined') {

		if (activeMenuId != null) {
			activeMenu = document.getElementById(activeMenuId);
			if(activeMenu!=null){
				
				menuSwitch(activeMenu, 'show');
			}
			
    	}
	}
	
	return true;
}
//End Save State


var activeMenu = null;

function menuSwitch(tableTarget, action)
{
	var tableRows = null;
	
	//Gets the rows for the current table and exits if the browser can't get it;
	if (typeof(document.getElementsByTagName) != 'undefined') {
		tableRows = tableTarget.getElementsByTagName('tr');
	}else if (typeof(tableTarget.rows) != 'undefined') {
		tableRows = tableTarget.rows;
	} else {
		return false;
	}
	
	var tableRowsCount  = tableRows.length;
	
	for (c = 1; c < tableRowsCount; c++) {
		
		if(action == 'show') {
			if(tableRows[c].id=='')
				tableRows[c].style.display="";		
			
		}else if(action=='subshow')
		{
			tableRows[c].style.display="";	
			tableTarget=tableRows[c];
			
		}
		else
		{
			tableRows[c].style.display="none";			
		}
	}

	/*if((activeMenu != null) && (activeMenu != tableTarget) ) {
		menuSwitch(activeMenu, 'hide');
	}*/

	activeMenu = tableTarget;

	//Save active menu;
	window.name = activeMenu.id;
	setCookie(window.name, activeMenu.id);
	
	return true;
}

function subMenuSwitch(tableTarget, action)
{
	
	var tableRows = null;

	//Gets the rows for the current table and exits if the browser can't get it;
	if (typeof(document.getElementsByTagName) != 'undefined') {
		tableRows = tableTarget.getElementsByTagName('tr');
	}else if (typeof(tableTarget.rows) != 'undefined') {
		tableRows = tableTarget.rows;
	} else {
		return false;
	}
	
	var tableRowsCount  = tableRows.length;
	
	for (c = 1; c < tableRowsCount; c++) {
		
		if(action == 'show') {
			tableRows[c].style.display="";
		}/*else{
			tableRows[c].style.display="none";
		}*/
	}

	/*if((activeMenu != null) && (activeMenu != tableTarget)) {
		menuSwitch(activeMenu, 'hide');
	}
	
	activeMenu = tableTarget;

	//Save active menu;
	window.name = activeMenu.id;
	setCookie(window.name, activeMenu.id);*/
	
	return true;
}