
var remTimeOut;
var remTimeOut2;
var blnTimeOutStopped;
var thistimeText;

	StartClock();

	// Get the Div Name/ID from Pageheader
	var follower = xbGetElementById("divTimeOut");
	var followerBG = xbGetElementById("divTimeOutBG");
	
	// Make sure we're able to see the div when it shows
	window.onscroll = do_follow;
	window.onresize = do_follow;

	function do_follow() {
		divTimeOutBG.style.top = document.body.scrollTop;
		divTimeOut.style.top = document.body.scrollTop;
	}
		
	function setRemainingTimeBeforeTimeout(varHour, varMin, varSec)
	{
	  remTimeOut = new Date(00, 00, 00,varHour,varMin,varSec, 00);
	  startCountdownForTimeOut();
	}

	// recursive call to
	function startCountdownForTimeOut()
	{
	  zeroDate = new Date(00,00,00,00,00,00);
					
	  if((remTimeOut - 1000) >= zeroDate){
	    var varNewRemTimetimeout;
	    var H;
	    var M;
	    var S;

	    //decrement remaining time by 1000ms
		remTimeOut = new Date(remTimeOut - 1000);
		H = remTimeOut.getHours();
		M = (remTimeOut.getMinutes() > 9)? remTimeOut.getMinutes(): "0" + remTimeOut.getMinutes();
		S = (remTimeOut.getSeconds() > 9)? remTimeOut.getSeconds(): "0" + remTimeOut.getSeconds();

		setTimeout('startCountdownForTimeOut()',1000);
	  }
	  else
	  {
		// call the Preliminary Logout Script (2 min warning)
		Logout(); 
	  }
	}

function Logout()
{
	// set another 2 min countdown so we automatically logoff if we don't answer
	setRemainingTimeBeforeTimeout2(0,2,00);
	
	StartClock();
	var thisTimeOut;

	// Get the hidden div to display
	thisTimeOut = xbGetElementById("divTimeOut");
	thisTimeOutBG = xbGetElementById("divTimeOutBG");

	// Make the Hidden Div Visible ...
	thisTimeOutBG.style.visibility = "visible";
	thisTimeOut.style.visibility = "visible";
}

function KeepSessionActive() {
	var thisSession
	var thisHTML
	var thisTimeOut;
	var thisKeepSessionActive
	StopClock();
	
	thisKeepSessionActive = xbGetElementById("keepSessionActive");
	thisKeepSessionActive.innerHTML = "<iframe frameborder='0' marginwidth='0' marginheight='0' border='1' width='1' height='1' src='/script/KeepSessionActive.asp'></iframe>";
	thisTimeOutBG = xbGetElementById("divTimeOutBG");
	thisTimeOut = xbGetElementById("divTimeOut");	
	// Give the script time to run
	setTimeout("",3000);
	thisTimeOutBG.style.visibility = "hidden";
	thisTimeOut.style.visibility = "hidden";
	thisKeepSessionActive.innerHTML = "";

	//restart the global page timer

	//setRemainingTimeBeforeTimeout(0, 0, 20)
	setRemainingTimeBeforeTimeout(0, 17, 45)
	
}

function StopClock() {
	blnTimeOutStopped = true;
}
function StartClock() {
	blnTimeOutStopped = false;
}

function setRemainingTimeBeforeTimeout2(varHour, varMin, varSec)
{
	remTimeOut2 = new Date(00, 00, 00,varHour,varMin,varSec, 00);
	StartClock();
	startCountdownForTimeOut2();
}
  
function startCountdownForTimeOut2()
{
  zeroDate = new Date(00,00,00,00,00,00);
				
	if((remTimeOut2 - 1000) >= zeroDate){
	  var varNewRemTimetimeout;
	  var H;
	  var M;
	  var S;

		remTimeOut2 = new Date(remTimeOut2 - 1000);
		H = remTimeOut2.getHours();
		M = (remTimeOut2.getMinutes() > 9)? remTimeOut2.getMinutes(): "0" + remTimeOut2.getMinutes();
		S = (remTimeOut2.getSeconds() > 9)? remTimeOut2.getSeconds(): "0" + remTimeOut2.getSeconds();

		varNewRemTimetimeout =  M + ":" + S;

		thistimeText = xbGetElementById("countdowntimeText");
		thistimeText.innerHTML = "Automatic Logout in: " + varNewRemTimetimeout;
	
		if (!blnTimeOutStopped) {
			setTimeout('startCountdownForTimeOut2()',1000);
		}
	} else {
		// Proper Logout
		window.location.href = "/script/logout.asp";
	}
}
