var msgInternet = "The selected link is not accessible from an Internet connection.\nTo access this link, you must connect directly to the GE internal network.";
try
{
  var root = parent.leftNav.document.location.pathname;
}
catch(e){}

function SetCookie (name, value) {
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value)+
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1)
      		endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen) 
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg)
			return getCookieVal (j);
    i=document.cookie.indexOf(" ",i)+1;
    if (i==0) break;
  }
	return null;
}

var saveLinkName = '';
var highlightColor = "#666666";
var originalColor = "#3771b5";

function clickLink(lineage)
{
  var c = document.getElementById(lineage)

	c.style.color = highlightColor;
	if(saveLinkName != '' && saveLinkName != c.id)
		document.getElementById(saveLinkName).style.color = originalColor;
	saveLinkName = c.id;
}

function openURL(lineage, url)
{
	clickLink(lineage); // sets the Link color
	if(url!="")
	{
		try
		{
			top.main.location.href = url;
		}
		catch(e)
		{
			window.location.href = url;
		}
	}
}

function openTop(url)
{
	if(url!="")
	{
		try
		{
			top.location.href = url;
		}
		catch(e)
		{
			window.location.href = url;
		}
	}
}

function openNew(url)
{
	if(url!="")
	{
	  window.open(url, "", "");
	}
}

var lastMainId = null; // Remember last Main link ID

function hideUnhide(id, depth)
{
	if(document.getElementById(id) == null)
	{
		return;
	}
	var level = id.substring(1, id.length); // the id number
	
	if(lastMainId == level)
		return;	// user clicked on same Main link
	clickLink('a' + level); // sets the Link color
		
	if(document.getElementById(level) != null) //Main menu with sub-menus (i.e. Welcome doesn't have sub-menu and goes to else)
	{
	  if(document.getElementById(level).className == 'hide') //Down
	  {
	  	//collapse prior main node
	  	if(depth == 1)
	  	{
	  		if(lastMainId != null)
	  		{
	  			//try
	  			{
	  				document.getElementById('IR' + lastMainId).className = 'show';
	  				document.getElementById('ID' + lastMainId).className = 'hide';        
	  				document.getElementById(lastMainId).className = 'hide';
	  			}
	  			//catch(e){}
	  		}
	  		lastMainId = level;
	  	}
	  	document.getElementById('IR' + level).className = 'hide';
	  	document.getElementById('ID' + level).className = 'show';
	  	document.getElementById(level).className = 'show';
	  }
	  else //Right
	  {
	  	document.getElementById('IR' + level).className = 'show';
	  	document.getElementById('ID' + level).className = 'hide';        
	  	document.getElementById(level).className = 'hide';      
	  }
	}
	else if(id.substring(0, 1) == 'M') // Main menu with no sub-menu (i.e. Welcome), then hide prior
	{
		if(lastMainId != null)
		{
			//try
			{
				document.getElementById('IR' + lastMainId).className = 'show';
				document.getElementById('ID' + lastMainId).className = 'hide';        
				document.getElementById(lastMainId).className = 'hide';
			}
			//catch(e){}
		}
		lastMainId = null;
	}
}

function openMenu(str)
{
	// s can be either a level (i.e. /143/149/) or the link display
	// if querystring contains menu level then expand menu
	var level;
	if (str.substring(0, 1) == '/')
		level = str;
	else
	{
		try
		{
			level = document.getElementsByName(str)[0].id;
		}
		catch(e)
		{
			alert('Menu: ' + str + ' - Access Prohibited');
			return;
		}
	}
	var a = level.split('/');
	var s = '/';

	for (var i = 1; i < a.length - 1; i++)
	{
		s += a[i] + '/'; 
		hideUnhide('M' + s, i);
	}
	try
	{
		//eval(document.getElementById('a' + s).focus());
		eval(document.getElementById('a' + s).href);
	}
	catch(e)
	{
		alert('Menu: ' + str + ' - Access Prohibited');
		return;
	}
}

function openLeftNav(s)
{ // this is called from main frame
	//window.parent.frames['leftNav'].location.href = '/site/leftnav.asp?l=' + s;

	try
	{
		parent.leftNav.location.href = root + '?l=' + escape(s);
	}
	catch(e)
	{
		window.document.location.href = root + '/index.php';
	}
}

function parentOpenLeftNav(s)
{ // this is called from popup dialog
  var doc = window.opener.parent.frames['leftNav'].document;
	try
	{
    doc.location.href = 'menu.php?l=' + s;
	}
	catch(e)
	{
		//window.document.location.href = root + '/index.php';
	}
}

function openAndSync(s, url)
{
	//s is the left menu name
	//url is the href if not found in the menu
	var id = 0;
  
  try
  {
    id = parent.leftNav.document.getElementsByName(s)[0].id;
  }
  catch(e) 
  {
    id = null;
  }
	if(id == null)
	{
    if (url == undefined)
    {
      alert(s + ' can not be found');
      return;
    }
		window.document.location.href = url;
	}
	else
	{
		openLeftNav(s);
	}
}

function hideItem(s)
{
  s = document.getElementsByName('calendar')[0].id.substr(1); //get the id for 'calendar' table
  document.getElementById('T' + s).className = 'hide';

}
