var NS5;
var IE;
var NS6;
var IntervalID;
var gCurLayer;
var timer;
var gTurnOff;
var gLoaded = false;
var gCurTD;
var gSecTD;
var gShowMenus;
var scriptTimeOutID;
var scriptTimeOutSec = 900000; //15 minutes
var gTimedOut = false;
var messageStr = "";

//	07/23/2008	RWhitlock	Added 'regBgColor', 'curBgColor' and 'selBgColor' variables
//					These should be set in 'left_menu.asp'
var regBgColor = '#808080';
var curBgColor = '#A0A0A0';
var selBgColor = '#E0E0E0';
var regFgColor = '#FFFFFF';
var selFgColor = '#000000';
var itemId = 0;

//------------------Menu object--------------------
function Menu(name,left,top,w,h,zInd, bgcolor) {
	this.name = name;
	this.left = left;
	this.top = top;
	this.width = w;
	this.height = h;
	this.zInd = zInd;
	this.bgcolor = bgcolor;
	this.menuHTML = "<table border='0' width='" + this.width + "' cellspacing='0' cellpadding='1'><tr><td width='100%' bgcolor='#948ED8'><table border='0' width='100%' cellspacing='0' cellpadding='0'  bgcolor='#BCB8EB'>"; //add any opening HTML for this layer here
	this.addTitle = addTitle;
	this.addTitleOpenNew = addTitleOpenNew;
	this.addItem = addItem;
	this.CloseAndWriteMenu = CloseAndWriteMenu;
}

function openMenu() {
	gTurnOff = true;	
	clearTimeout(IntervalID);
	hlcell(gCurTD);	
	if (IE) document.all[this.id].style.visibility = "visible";
	else if (NS5) document.layers[this.id].visibility = "visible";
	else if (NS6) document.getElementById(this.id).style.visibility = "visible";	
}


function closeMenu(e) {		
	if (gTurnOff) turnOffMenu(this.id);						
	gTurnOff = false;	
}

function addTitle(content,link) {
	//add title content for a menu 				
	this.menuHTML += "<tr>"	
	this.menuHTML += "<td nowrap valign='center' bgColor='#FFCC66' height='20' style=\"cursor:hand\" onclick=\"self.location='" + link + "'\">"	
	this.menuHTML += "<a style='padding-left:4px;FONT-SIZE:12px;COLOR:#270F4D;FONT-FAMILY:Verdana;FONT-WEIGHT:bold;TEXT-DECORATION:none;background-color:#FFCC66;' href='" + link + "'>" + content + "</a>";								
	this.menuHTML += "</td></tr>";
	this.menuHTML += "<tr><td  bgcolor='#33007F'><img src='images/1x1.gif' width='1' height='1'></td></tr>";		
}

function addTitleOpenNew(content,link) {
	//add title content for a menu 				
	this.menuHTML += "<tr>"	
	//this.menuHTML += "<td nowrap valign='center' bgColor='#FFCC66' height='20' style=\"cursor:hand\" onclick=\"window.open('" + link + "')\">"	
	
	this.menuHTML += "<td nowrap valign='center' bgColor='#FFCC66' height='20' style=\"cursor:hand\" >"
	this.menuHTML += "<a style='padding-left:4px;FONT-SIZE:12px;COLOR:#270F4D;FONT-FAMILY:Verdana;FONT-WEIGHT:bold;TEXT-DECORATION:none;background-color:#FFCC66;' href='" + link + "' target='_blank'>" + content + "</a>";								
	this.menuHTML += "</td></tr>";
	this.menuHTML += "<tr><td  bgcolor='#33007F'><img src='images/1x1.gif' width='1' height='1'></td></tr>";		
}

function addItem(content,link) {
	//add any HTML around content and link			
		
	this.menuHTML += "<tr>"
	if (link=="") {
		this.menuHTML += "<td bgcolor='#33007F' style='padding-left:4px;'>";		
		this.menuHTML += "<span style='padding-left:2px;FONT-SIZE:11px;COLOR:#FFFFFF;FONT-FAMILY:Verdana;TEXT-DECORATION:none;'>" + content + "</span>";				
	}		
	else {
		itemId++;
//		this.menuHTML += "<td nowrap valign='center' bgcolor='#E3E3FF' style=\"cursor:hand\" onmouseover=\"this.style.backgroundColor='#CCCCFF';\" onmouseout=\"this.style.backgroundColor='#E3E3FF';\" onclick=\"self.location='" + link + "'\">"	
//		this.menuHTML += "<td nowrap valign='center' bgcolor='"+regBgColor+"' style=\"cursor:hand\" onmouseover=\"this.style.color='"+selFgColor+"';this.style.backgroundColor='"+selBgColor+"';\" onmouseout=\"this.style.color='"+regFgColor+"';this.style.backgroundColor='"+regBgColor+"';\" onclick=\"self.location='" + link + "'\">"	
		this.menuHTML += "<td nowrap valign='center' bgcolor='"+regBgColor+"' style=\"FONT-FAMILY:Arial;FONT-SIZE:9pt;COLOR: "+regFgColor+";cursor:hand\" onmouseover=\"getElementById('link_"+itemId+"').style.color='"+selFgColor+"';this.style.backgroundColor='"+selBgColor+"';\" onmouseout=\"getElementById('link_"+itemId+"').style.color='"+regFgColor+"';this.style.backgroundColor='"+regBgColor+"';\" onclick=\"self.location='" + link + "'\">"	

//		this.menuHTML += "<img src='images/1x1.gif' width='2' height='18'><span style='FONT-FAMILY:Arial;FONT-SIZE:9pt;COLOR: #330099;'>&#149;&nbsp;<a style='FONT-FAMILY:Arial;FONT-SIZE:9pt;COLOR:#330099;TEXT-DECORATION:none;' href='" + link + "' title=' " + content + "'>" + content + "</a></span>";				
//		this.menuHTML += "<img src='images/1x1.gif' width='2' height='18'><span style='FONT-FAMILY:Arial;FONT-SIZE:9pt;COLOR: "+regFgColor+";'>&#149;&nbsp;<a style='FONT-FAMILY:Arial;FONT-SIZE:9pt;COLOR:"+regFgColor+";TEXT-DECORATION:none;' href='" + link + "' title=' " + content + "'>" + content + "</a></span>";				
		this.menuHTML += "<img src='images/1x1.gif' width='2' height='18'><a id='link_"+itemId+"' style='FONT-FAMILY:Arial;FONT-SIZE:9pt;COLOR:"+regFgColor+";TEXT-DECORATION:none;' href='" + link + "' title=' " + content + "'>&#149;&nbsp;" + content + "</a>";				
	}		
	this.menuHTML += "<br></td></tr>";
	this.menuHTML += "<tr><td  bgcolor='#33007F'><img src='images/1x1.gif' width='1' height='1'></td></tr>";		
}

function CloseAndWriteMenu() {
	var content,ref;
	
	//add any closing HTML for this layer here:
	this.menuHTML += "<tr><td bgcolor='#33007F'><img src='images/1x1.gif' width='1' height='3'></td></tr>";
	this.menuHTML += "</table></td></tr></table>";		
	
	if (IE || NS6) {
			  document.open("text/html");					   
			  content = '<div id="' + this.name + '" style="position:absolute;left:' + this.left + 'px;top:' + this.top +'px;width:' + this.width + 'px;height:' + this.height +'px;'
			  if (this.bgcolor) content += 'background:'	+ this.bgcolor + ';' 
			  content += 'z-index:' + this.zInd +';visibility:hidden">\n' +
						this.menuHTML + 
						'</div>\n';			
			 document.write(content);			 
			 document.close();  			 			 
	}
	else if (NS5) {  			
		layerRef = new Layer(this.width);													
		layerRef.left = this.left;
		layerRef.top = this.top;		
		layerRef.height = this.height;		
		if (this.bgcolor) layerRef.bgColor = this.bgcolor;		
        layerRef.visibility = "hide";        
        layerRef.document.open("text/html");                
        layerRef.document.write(this.menuHTML);
        layerRef.document.close();				                                
        ref = document.layers[layerRef.name];     
	}		
	if (IE) ref = document.all[this.name];
	else if (NS6) ref = document.getElementById(this.name);					
	
	ref.onmouseover = openMenu;
	ref.onmouseout = closeMenu;		
	
	return (ref.id);
}
//------------------end Menu object-----------------

function init() {	
	NS5 = document.layers;
	IE = document.all;
	NS6 = document.getElementById && !document.all;
	IntervalID = -1;	
	timer = 400;
	gTurnOff = false;
}
function initTD(paramTD) {
	gCurTD = paramTD;
	gSecTD = paramTD;
}
function getRef(lyr) {
	if (IE) return document.all[lyr].style;
	else if (NS5) return document.layers[lyr];
	else return document.getElementById(lyr).style;
}

function openMenuRoll(m,td1) {	
	if (!gLoaded) return;			
	gTurnOff = true;			
	hlcell(td1);	
	turnAllOff();				
	clearTimeout(IntervalID);
	
	//pop menu upwards						
	if (IE) {		
		if ((m.height + m.top) > parseInt(document.body.clientHeight) + document.body.scrollTop) {		
			getRef(m.name).pixelTop = (parseInt(document.body.clientHeight) + document.body.scrollTop - m.height);			
		}				
		else getRef(m.name).pixelTop = m.top;		
	}
	else if (NS5 || NS6) {		
		if ((m.height + m.top) > window.innerHeight + self.pageYOffset) {		
			if (NS5) getRef(m.name).top = (window.innerHeight + self.pageYOffset - m.height);			
			else getRef(m.name).top = (window.innerHeight + self.pageYOffset - m.height) + "px";			
		}				
		else {
			if (NS5) getRef(m.name).top = m.top;
			else getRef(m.name).top = m.top + "px";
		}	
	}	
	if (gShowMenus) getRef(m.name).visibility = "visible";		
	
}


function closeMenuRoll(lyr) {
	getRef(lyr).visibility = "hidden";	
	gTurnOff = false;	
}

function turnAllOff() {
	if (!gLoaded) return;	
	closeMenuRoll(gCurLayer);	
}

function turnOffMenu(m) {	
	if (!gLoaded) return;		
	if (m.name) gCurLayer = m.name;		
	else gCurLayer = m;		
	tocell(gCurTD);		
	if (gCurTD != gSecTD) tocell(gCurTD);						
	IntervalID = setTimeout("turnAllOff()",timer);							
}
function hlcell(id1) {
	gCurTD = id1;
	if (document.getElementById) {	
		if(gCurTD == "td111")
			document.getElementById(id1).style.backgroundColor='#FF0000';
		else
//		document.getElementById(id1).style.backgroundColor='#E3E3FF';
		document.getElementById(id1).style.backgroundColor=selBgColor;
		document.getElementById(id1).className='leftnavhlight';
		if (document.getElementById(id1+"_r")) {
			if(gCurTD == "td111")
				document.getElementById(id1+"_r").style.backgroundColor='#FF0000';
			else
//			document.getElementById(id1+"_r").style.backgroundColor='#E3E3FF';
			document.getElementById(id1+"_r").style.backgroundColor=selBgColor;
			document.getElementById(id1+"_r").className='leftnavhlight';
		}	
	}
}
function tocell(id1) {	
	if (document.getElementById) {
		if (gCurTD != gSecTD) {
			if(id1 == "td111")
				document.getElementById(id1).style.backgroundColor='#FF0000';
			else
//			document.getElementById(id1).style.backgroundColor='#9999CC';
			document.getElementById(id1).style.backgroundColor=regBgColor;
			document.getElementById(id1).className='leftnavwhite';
			if (document.getElementById(id1+"_r")) {
				if(id1 == "td111")
					document.getElementById(id1+"_r").style.backgroundColor='#FF0000';
				else
//				document.getElementById(id1+"_r").style.backgroundColor='#9999CC';
				document.getElementById(id1+"_r").style.backgroundColor=regBgColor;
				document.getElementById(id1+"_r").className='leftnavwhite';
			}
		}
		else {
			if(id1 == "td111")
				document.getElementById(id1).style.backgroundColor='#FF0000';			
			else
//			document.getElementById(id1).style.backgroundColor='#CCCCFF';			
			document.getElementById(id1).style.backgroundColor=curBgColor;			
			if (document.getElementById(id1+"_r")) {
					if(id1 == "td111")
						document.getElementById(id1+"_r").style.backgroundColor='#FF0000';
					else
//					document.getElementById(id1+"_r").style.backgroundColor='#CCCCFF';
					document.getElementById(id1+"_r").style.backgroundColor=curBgColor;
			}
		}	
	}
}
//----------------------
function openWin(file,w,h) {
	var win1  = open(file,"w","status=yes,scrollbars=auto,location=0,menubar=0,resizable=0,toolbar=0,top=0,left=0,width="+w+",height="+h);
	
	win1.focus();
}
//------------------Script Timeout Functions--------------------
function alertTimeOut() {
	self.focus();
	var d = new Date();
	d.setTime(parseInt(d.getTime() + 300000)); //add 5 minutes	
	var strPMAM = "am";
	var iHours = d.getHours();
	if (iHours >= 12) strPMAM = "pm";		
	if (iHours > 12) iHours = iHours - 12;				
	var iMinutes = d.getMinutes();
	if (iMinutes < 10) iMinutes = "0" + "" + iMinutes;
	
	if (messageStr != "") {	
		alert("You will be automatically logged out in 5 minutes, at " + iHours + ":" + (iMinutes) + " " + strPMAM + "." + messageStr)	
	}	
	else {
		alert("Our system has noted extended inactivity. You may be automatically logged out in 5 minutes, at " + 
		iHours + ":" + (iMinutes) + " " + strPMAM + "." + 
		"You can log in again by clicking on the Log In link at the top of any page.")		
	}
	gTimedOut = true;
	clearTimeout(scriptTimeOutID);
}
function setScriptTimeout() {
	scriptTimeOutID = setTimeout("alertTimeOut()",scriptTimeOutSec);							
}
function restartScriptTimeoutCheck() {
	if (!gTimedOut) {
		clearTimeout(scriptTimeOutID);
		setScriptTimeout();
	}	
}
//----------------------

