var sessionEndTime = null;

function startSessionCountdown(secondsRemaining, expireMilliseconds) {
	if (document.getElementById) {
		sessionEndTime = (new Date() / 1000) + secondsRemaining;
		
		var elementDisplay = document.getElementById('sessionCountdownDisplay');
		if (elementDisplay != null) {
			elementDisplay.style.display = 'inline';
			setTimeout("changeSessionCountdown()", 1000);
		}
		/*
		 * sessionExpireWarning is turned off for FF1.5 due to a bug that fires the warning immediately. 
		 * The occurrance is random and not reliably reproducable, so it is turned off for now. JM - 2/6/2006
		 */
		var isFirefox15 = (navigator.userAgent.toLowerCase().indexOf("firefox/1.5") > -1);
		if (!isFirefox15) {
			setTimeout("sessionExpireWarning()", expireMilliseconds);
		}
	}
}

function changeSessionCountdown() {
	var elementDisplay = document.getElementById('sessionCountdownDisplay');
	var now = new Date() / 1000;
	
	var secondsRemaining = sessionEndTime - now;
	var hr = Math.floor((secondsRemaining) / (60 * 60));
	var min = Math.floor(((secondsRemaining) - (hr * 60 * 60)) / 60);
	var sec = Math.floor((secondsRemaining) - (hr * 60 * 60) - (min * 60));
	
	var minPadding = (min < 10) ? "0" : "";
	var secPadding = (sec < 10) ? "0" : "";
	
	if ((hr <= 0) && (min <= 19)) {
		elementDisplay.style.textDecoration = 'blink';
		elementDisplay.style.color = '#f00';
	}
	
	if ((sec >= 0) && (min >= 0) && (hr >=0)) {
		elementDisplay.firstChild.nodeValue = hr + "hr " + minPadding + min + "min " + secPadding + sec + "sec";
		setTimeout("changeSessionCountdown()", 1000);
	} else {
		elementDisplay.style.textDecoration = 'none';
		elementDisplay.firstChild.nodeValue = "Expired";
	}
}