var _countDowncontainer=0;
var _currentSeconds=0;
if(document.getElementById("sTimeout")!=null)
var _timeout = document.getElementById("sTimeout").innerHTML;
var _sessionTimeout = parseInt(_timeout);
var _timeLeft = 2; //minutes
var _warningTime = (_sessionTimeout - _timeLeft)*60000;

function ActivateCountDown(strContainerID, initialValue) {
	_countDowncontainer = document.getElementById(strContainerID);
	
	if (!_countDowncontainer) {
		alert("count down error: container does not exist: "+strContainerID+
			"\nmake sure html element with this ID exists");
		return;
	}
	
	SetCountdownText(initialValue);
	window.setTimeout("CountDownTick()", 1000);
}

function CountDownTick() {
	if (_currentSeconds <= 0) {
		_countDowncontainer.innerHTML = "<span style='color:#f00;font-weight:bold;'>Your page expired!<br/>Please refresh the page before making further changes.</span>";
		return;
	}
	
	SetCountdownText(_currentSeconds-1);
	window.setTimeout("CountDownTick()", 1000);
}

function SetCountdownText(seconds) {
	//store:
	_currentSeconds = seconds;
	
	//get minutes:
	var minutes=parseInt(seconds/60);
	
	//shrink:
	seconds = (seconds%60);
	
	//get hours:
	var hours=parseInt(minutes/60);
	
	//shrink:
	minutes = (minutes%60);
	
	//build text:
	var strText='';
	if (minutes <= 2){
		strText = "<span style='color:#f00;font-weight:bold;'>Your page is about to expire! Save your data soon.</span>";
	}
	else
	{
	strText = "Time Left Before Page Expires:";
	}
	 strText = strText +"&nbsp; [" + AddZero(hours) + ":" + AddZero(minutes) + ":" + AddZero(seconds) + "]";
	
	//apply:
	_countDowncontainer.innerHTML = strText;
}

function AddZero(num) {
	return ((num >= 0)&&(num < 10))?"0"+num:num+"";
}

window.onload = function init() {
	ActivateCountDown("disp", _sessionTimeout * 60);
}
