//LeftMenuWidth is a global var that specifies
//the width of the left collapsable menu
var LeftMenuWidth = 200;
var iLogoutTimer, iWarningTimer;

function LoadPageTimeOut(iTimeoutValue, sLogoutURL)
{
	if (window.top != window){
		try
		{
			window.top.resetTimeout(iTimeoutValue, sLogoutURL);
		}
		catch (exception)
		{
			setWindowTimeout(iTimeoutValue, sLogoutURL);
		}
	}
	else if (null != window.opener){
		try
		{
			window.opener.resetTimeout(iTimeoutValue, sLogoutURL);
		}
		catch (exception)
		{
			setWindowTimeout(iTimeoutValue, sLogoutURL);
		}
	}
	else{
		setWindowTimeout(iTimeoutValue, sLogoutURL);
	}
}

function setWindowTimeout(iTimeoutValue, sLogoutURL)
{
		var iWarningValue;
		var TWO_MINUTES = 120000;
		var THIRTY_SECONDS = 30000;
		// If the timeout value is more than 2 minutes, set the warning time to 2 minutes
		if (TWO_MINUTES < iTimeoutValue){
			iWarningValue = iTimeoutValue - TWO_MINUTES;
		}
		else{
			iWarningValue = THIRTY_SECONDS;
		}
		window.clearTimeout(iWarningTimer);
		window.clearTimeout(iLogoutTimer);
		iWarningTimer = window.setTimeout("showTimeoutPopup(" + iTimeoutValue + ")", iWarningValue);
		// We need to give a 30 second leeway to make sure that the user doesn't get a logged out error
		// when trying to access the logout page!
		iLogoutTimer = window.setTimeout("logout('" + sLogoutURL + "')", iTimeoutValue - 30000);
}
function resetTimeout(iTimeoutValue, sLogoutURL)
{
	window.clearTimeout(iWarningTimer);
	window.clearTimeout(iLogoutTimer);
	LoadPageTimeOut(iTimeoutValue, sLogoutURL);				
}
function showTimeoutPopup(iTimeoutValue)
{
	var iWarningWindowClose;
	var TWO_MINUTES = 120000;
	var THIRTY_SECONDS = 30000;
	if (TWO_MINUTES < iTimeoutValue){
		iWarningWindowClose = TWO_MINUTES-20000;
	}
	else{
		iWarningWindowClose = THIRTY_SECONDS;
	}
	var timeoutMsg ="Your session is about to time out. Sessions last for " + (iTimeoutValue)/60000 + " minutes of inactivity.";
	var timeout_popup_win = window.open("blankTemplate.html", "timeoutWarning", "toolbar=0,location=0,directories=0,status=0" + 
		",menubar=0,scrollbars=0,resizable=0,width=320,height=210", true);
	
	if (null != timeout_popup_win){
		timeout_popup_win.document.write("<HTML><HEAD><TITLE>DeepSight Session Warning</TITLE>\n");
		timeout_popup_win.document.write("<style TYPE=\"text/css\">body{ font-size: 11px; font-family: Verdana, Arial; background-color: #ffffff;}");
		timeout_popup_win.document.write(".FormButton{ BORDER-RIGHT: #7F9DB9 1PX RIDGE;	PADDING-RIGHT: 0PX;	BORDER-TOP: #7F9DB9 1PX RIDGE; PADDING-LEFT: 0PX; FONT-SIZE: 12PX; PADDING-BOTTOM: 0PX; BORDER-LEFT: #7F9DB9 1PX RIDGE; PADDING-TOP: 0PX; BORDER-BOTTOM: #7F9DB9 1PX RIDGE; FONT-FAMILY: VERDANA, ARIAL; BACKGROUND-COLOR: #F2F9FF; TEXT-DECORATION: NONE;}");
		timeout_popup_win.document.write("H1 {BORDER-RIGHT: #9DA1AE 0PX SOLID; PADDING-RIGHT: 10PX; BORDER-TOP: #C7CBD8 0PX SOLID; PADDING-LEFT: 0PX; FONT-WEIGHT: NORMAL; FONT-SIZE: 11PX; PADDING-BOTTOM: 3PX; BORDER-LEFT: #C7CBD8 0PX SOLID; WIDTH: 100%; COLOR: #003260; PADDING-TOP: 16PX; BORDER-BOTTOM: #9DA1AE 1PX SOLID; FONT-FAMILY: VERDANA, ARIAL; BACKGROUND-COLOR: #FDFFFF; TEXT-DECORATION: NONE;}</style>");
		timeout_popup_win.document.write("</head>\n");
		timeout_popup_win.document.write("<body onload='window.setTimeout(\"this.close()\", " + iWarningWindowClose + ");'>\n");
		timeout_popup_win.document.write("<FORM METHOD=POST name=frmTimeout ACTION='refreshSession.aspx'>\n");
		timeout_popup_win.document.write("<H1>Session Timeout Warning</H1>\n");
		timeout_popup_win.document.write("<p>\n");
		timeout_popup_win.document.write(timeoutMsg + " Click OK to continue your current session.");
		timeout_popup_win.document.write("</p>\n");
		timeout_popup_win.document.write("<input type=submit name=bsubmit value=OK class='FormButton'>\n");
		timeout_popup_win.document.write("</form>\n");
		timeout_popup_win.document.write("</body>\n");
		timeout_popup_win.document.write("</html>\n");
		timeout_popup_win.document.close();
	}
	else{
		alert(timeoutMsg);
	}
}
function logout(sLogoutURL)
{
	window.top.location.href = sLogoutURL;
}
function UnloadPage(iTimeoutValue, sLogoutURL){

	if (window.top != window){
		window.top.resetTimeout(iTimeoutValue, sLogoutURL);
	}
	else{
		window.clearTimeout(iWarningTimer);
		window.clearTimeout(iLogoutTimer);
	}
}

// validates false when a text box is empty
function ValidateEmptyFields(text)
{
	if (text.length >= 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

// validates false if not numeric value (int32)
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
	// do only for less than Int32 max value
	if (sText < 2147483648)
	{
		for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
		}
		
	}
	else
	{
		IsNumber = false;
	}
	      
   return IsNumber;   
}

function validateRequiredNumeric(elementId, friendlyName)
{
	var obj = document.getElementById(elementId);
	if ( obj != null)
	{
		if (ValidateEmptyFields(obj.value))
		{
			if (IsNumeric(obj.value))
			{
				return true;
			}
			else
			{
				alert(friendlyName + " must be a valid integer value.");
				return false;
			}
		}
		else
		{
			alert(friendlyName + " cannot be empty.");
			return false;
		}
	}
	else
	{
		return false;
	}
}



function on(o)
{
	o.runtimeStyle.color = "#000000";
	o.runtimeStyle.backgroundColor = "#efefeb";
}

function off(o)
{
	o.runtimeStyle.color = "";
	o.runtimeStyle.backgroundColor = "";
}

//function hidePreview()
//{
//document.getElementById("PreviewFrame").style.display="none";
//document.getElementById("ImgArrow").src = "images/box_on_right_down.gif";
//document.getElementById("PreviewTd").runtimeStyle.backgroundColor = "#a5a5a5";
//}

//function showPreviewFrame(o,previewFrameName)
//{
//	if (document.getElementById(previewFrameName).style.display=="none")
//	{
//		with (o.parentElement)
//		{
			//children[0].firstChild.src = "images/clear.gif";
//			children[0].runtimeStyle.backgroundColor = "";
//			document.getElementById(previewFrameName).style.display = "block";
//		}
		//topTR.height = "70%";
//		o.firstChild.src = "images/box_on_right_up.gif";
//	}
//	else
//	{
//		with (o.parentElement)
//		{
			//children[0].firstChild.src = "images/clear.gif";
//			children[0].runtimeStyle.backgroundColor = "#a5a5a5";
//			document.getElementById(previewFrameName).style.display="none";
//		}
		//topTR.height = "100%";
//		o.firstChild.src = "images/box_on_right_down.gif";
//	}
//}
//function show(o)
//{
//	if(o.parentElement.nextSibling.firstChild.style.display == "none")
//	{
//		with (o.parentElement)
//		{
			//children[0].firstChild.src = "images/clear.gif";
//			children[0].runtimeStyle.backgroundColor = "";
//			nextSibling.firstChild.style.display = "";
//		}
		//topTR.height = "70%";
//		o.firstChild.src = "images/box_on_right_up.gif";
//	}
//	else
//	{
//		with (o.parentElement)
//		{
			//children[0].firstChild.src = "images/clear.gif";
//			children[0].runtimeStyle.backgroundColor = "#a5a5a5";
//			nextSibling.firstChild.style.display = "none";
//		}
		//topTR.height = "100%";
//		o.firstChild.src = "images/box_on_right_down.gif";
//	}

//}
function showPreview(o, tableName, tdName, frameName)
{
	var table = document.getElementById(tableName);
	
	if (table != null)
	{

		if (table.style.display != 'undefined')
		{
			//alert('here');
			if (table.style.display=="none")
			{
				var td = document.getElementById(tdName);		
				if (td != null)
				{	
					td.backgroundColor = "";
					table.style.display = "block";
				}
				//set arrow
				o.src = PathBase + "/images/box_on_right_up.gif";
			}
			else
			{
				var td = document.getElementById(tdName);
				
				if (td != null)
				{	
					td.backgroundColor = "#a5a5a5";
					table.style.display="none";
				}
				o.src = PathBase + "/images/box_on_right_down.gif";
			}
		}
	}
	
	//netscape sucks so badly
	//var childFrame = document.getElementById(frameName);
//		alert(childFrame.PageResize());
	//childFrame
}
//When entering a page, determine the state of the icon
//respective to the Search Panel state
function SearchIconToggle(icon)
{
	icon = document.getElementById(icon);
	
	if (icon!=null)
	{
		var image = document.getElementById("SearchPanelState");

		if (image.value == 'close')
		{
			icon.src= PathBase + '/images/box_on_down.gif';
		}
		else if (image.value == 'open')
		{
			icon.src= PathBase + '/images/box_on_up.gif';
		}
	}
}
function SearchPanelToggle(a, b)
{
	a = document.getElementById(a);
	
	if (a.style.display == '')
	{
		a.style.display = 'none';
		var image = document.getElementById("SearchPanelState");
		image.value = 'close';
		b.src= PathBase + '/images/box_on_down.gif';
	}
	else
	{
		a.style.display = '';
		var image = document.getElementById("SearchPanelState");
		image.value = 'open';
		b.src= PathBase + '/images/box_on_up.gif';
	}
}

function PersistSearchPanelState(a)
{
	a = document.getElementById(a);
	var searchpanelstate = document.getElementById("SearchPanelState");
	
	if (searchpanelstate.value == 'open')
	{
		a.style.display = '';
	}
	else
	{
		a.style.display = 'none';
	}
}

function openCenteredWindow(url, height, width, name, parms) {
   var left = Math.floor( (screen.width - width) / 2);
   var top = Math.floor( (screen.height - height) / 2);
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (parms) { winParms += "," + parms; }
   var win = window.open(url, name, winParms);
   if (null != win){ 
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); } 
    return win;
   }
   else{
	alert("Our pop-up was blocked, please allow pop-ups for this site in order to access this functionality.");
   }
}
function openAddressWindow(dropDown)
{

	var AddressURL = 'Addresses.aspx?AddressNumber=' + dropDown.options[dropDown.selectedIndex].value;
	var mywindow = openCenteredWindow(AddressURL, 700, 1050, 'addresses', 'location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=no')	
}
function SetIFrameSize(frameName)
{	
	if( navigator.appName.charAt(0) == 'N' )
	{
		var curFrame = window.top.frames[frameName];
		
		if (curFrame != "undefined" && curFrame != null)
		{
			//reset the size to null
			//re-setting the size to 0 had strange effects
			//re-inialize using null
			var childFrame = top.document.getElementById(frameName);
			if (childFrame != "undefined" && childFrame != null)
			{
				childFrame.style.height = null;
			}
			
			//var obj = top.document.frames[frameName];
			var childFrameDoc;
			if (childFrame.contentDocument)
			{childFrameDoc = childFrame.contentDocument; }
			else if (childFrame.contentWindow)
			{ childFrameDoc = childFrame.contentWindow.document;}
			else if (childFrame.document)
			{ childFrameDoc = childFrame.document; }
			
			childFrameDoc.body.scrollHeight;

			var bodyHeight = childFrameDoc.body.scrollHeight;
			var bodyWidth = childFrameDoc.body.scrollWidth;
			//netscape sucks!
			childFrame.style.height = bodyHeight + 15;
			childFrame.style.width = bodyWidth;
		}
	}
	// for IE
	else
	{
		if (top.document.frames[frameName] != "undefined" && top.document.frames[frameName] != null)
		{
			//reset the size to null
			//re-setting the size to 0 had strange effects
			//re-inialize using null
			var obj = top.document.getElementById(frameName);
			if (obj != "undefined" && obj != null)
			{
				obj.style.height = null;
			}		
					
			//var obj = top.document.frames[frameName];
			var obj = top.document.getElementById(frameName);
			var bodyHeight = document.body.scrollHeight;
			obj.style.height = bodyHeight;
		}
	}
}
//not sure where Susan's calling this from, but it is modified like the one above
function SetParentIFrameSize(frameName)
{
	if( navigator.appName.charAt(0) == 'N' )
	{
		var curFrame = window.top.frames[frameName];
		if (curFrame != "undefined" && curFrame != null)
		{
			//reset the size to null
			//re-setting the size to 0 had strange effects
			//re-inialize using null
			var obj = parent.document.getElementById(frameName);
			if (obj != "undefined" && obj != null)
			{
				obj.style.height = null;
			}		
					
			var obj = parent.top.document.getElementById(frameName);
			var bodyHeight = document.body.scrollHeight;
			//netscape sucks!
			obj.style.height = bodyHeight + 15;
		}
	}
	// for IE
	else
	{
		if (parent.document.frames[frameName] != "undefined" && parent.document.frames[frameName] != null)
		{
			var obj = parent.document.getElementById(frameName);
			if (obj != "undefined" && obj != null)
			{
				obj.style.height = null;
			}		
			
			var obj = parent.document.getElementById(frameName);
			var bodyHeight = document.body.scrollHeight;
			obj.style.height = bodyHeight;
		}
	}
}

function GoBack(pagenum)
{
	history.back(pagenum);
}