<!--
// Some of this code borrowed from http://www.avedatech.com/technotes/gracefultimeout.jsp
// Initialization
var timeout = 3600;
timeout = timeout * 1000;

// Number of seconds before we alert the user
var alertBeforeSeconds = 300;
alertBeforeSeconds = alertBeforeSeconds * 1000;

if(alertBeforeSeconds > timeout)
	alertBeforeSeconds = timeout - 10 * 1000;

var timeUnits = "seconds";
var alertDisplay = alertBeforeSeconds / 1000;
if(alertBeforeSeconds > (59 * 1000)) {
	alertDisplay = parseInt(alertDisplay / 60);
	if(alertDisplay > 1)
		timeUnits = "minutes";
	else
		timeUnits = "minute";
}

// URL to call to reactivate session
var url = "/global/inc_dummy_keep_alive.jsp";

// Text To Display as alert
var textActive = "<div id=\"overlaytext\">Your browser session will expire in " + alertDisplay + " " + timeUnits + ". Click the refresh button to return to your current web page.</div></br><a href=\"\" onclick=\"loadXMLDoc();timesRefreshed=1;return false\"><img src=\"/media/images/buttons/button_refresh.gif\"></a>";

// Text to display as session has expired
var textTimedOut;

// URL to redirect to
var loginURL;
//if(isLoggedIn) {
//	loginURL = "/member_info/signinRegister.jsp";
//	textTimedOut = "<div id=\"overlaytext\">We're sorry, your browser session has expired.</div></br><a href=\"" + loginURL + "\"><img src=\"/media/images/buttons/button_returnLogin.gif\"></a>";
//} else {
	loginURL = "/home/home.jsp";
	textTimedOut = "<div id=\"overlaytext\">We're sorry, your browser session has expired.</div></br><a href=\"" + loginURL + "\"><img src=\"/media/images/buttons/button_returnHome.gif\"></a>";
//}

/* INITIALIZATION COMPLETE */

var iTimerID1;
var iTimerID2;
var timesRefreshed = 1;
var refreshLimit = 8;

function displayOverlay()
{
	if((!isLoggedIn && itemsInCart && timesRefreshed >= refreshLimit) || (isLoggedIn && timesRefreshed >= refreshLimit)) {
		hideSelectBoxes();
		document.getElementById("overlaybase").style.display = "block";
		document.getElementById("overlay").style.display = "block";
		document.getElementById("overlaytitle").style.display = "block";
		centerDialog();
	} else if(isLoggedIn || (!isLoggedIn && itemsInCart && timesRefreshed < refreshLimit)) {
		loadXMLDoc();
		timesRefreshed++;
	}
}

function hideOverlay()
{
	document.getElementById("overlaybase").style.display = "none";
	document.getElementById("overlay").style.display = "none";
	document.getElementById("overlaytitle").style.display = "none";
	displaySelectBoxes();
}

function displayTextActive()
{
	document.getElementById("overlaybody").innerHTML = textActive;
}

function displayTextTimedOut()
{
	document.getElementById("overlaybody").innerHTML = textTimedOut;
}

function centerDialog() {
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	var scLeft,scTop;
	if (self.pageYOffset) {
		scLeft = self.pageXOffset;
		scTop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		scLeft = document.documentElement.scrollLeft;
		scTop = document.documentElement.scrollTop;
	} else if (document.body) {
		scLeft = document.body.scrollLeft;
		scTop = document.body.scrollTop;
	} 

	document.getElementById("overlay").style.left = (fullWidth - 350) / 2;
	document.getElementById("overlay").style.top = fullHeight / 2 - 150 + scTop;
	document.getElementById("overlaybase").style.width = fullWidth;
	document.getElementById("overlaybase").style.height = fullHeight;
	document.getElementById("overlaybase").style.left = scLeft;
	document.getElementById("overlaybase").style.top = scTop;
}
//addEvent(window, "resize", centerDialog);
window.onscroll = centerDialog;
window.onresize = centerDialog;

var AltPopSupported = (document.getElementById && document.createElement );//&& !window.opera);

function StartSessionTimerToDisplay()
{
	var remindMeIn = timeout - alertBeforeSeconds;	
	if (AltPopSupported)
	{
		iTimerID1 = window.setTimeout("displayOverlay(); displayTextActive();",remindMeIn);
		iTimerID2 = window.setTimeout("displayOverlay(); displayTextTimedOut();",timeout);
	}
}

//window.onload = StartSessionTimerToDisplay;
StartSessionTimerToDisplay();

function loadXMLDoc() 
{
	sendXMLRequest("POST", "/global/inc_dummy_keep_alive.jsp", null);
	window.clearTimeout(iTimerID1);
	window.clearTimeout(iTimerID2);
	StartSessionTimerToDisplay();
	hideOverlay();
}

// The following four functions were borrowed from subModal: http://www.subimage.com/dhtml/subModal/
/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/ *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}

function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}

/**
* Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
* Thanks for the code Scott!
*/
function hideSelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
}

/**
* Makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*/
function displaySelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}

//Write the css import statement.
document.write('<style type="text/css" media="screen">@import "/media/styles/session_timeout.css";</style>');

// Write the xhtml.
document.write('<div id="overlaybase" style="display:none"></div><div id="overlay" style="display:none"><div id="overlaytitle" style="display:none">Session Timeout</div><div id="overlaybody"></div></div>');
-->
