
//SessionTimeOut.js

//set the session time out value here:
var SessTimeout = 1200;  //seconds - default 20 minutes timeout

var tStart = null;
var timerID = 0;
var clockID  = 0;

function Start() 
{
   tStart   = new Date();
   clockID  = 0;
   //document.getElementById('theTime').value = "00:00";
   timerID  = setTimeout("UpdateTimer()", 1000);
}

function Reset() 
{
   tStart = null;
   clockID  = 0;
   //document.getElementById('theTime').value = "00:00";
}

function Stop() 
{
   if(timerID) 
   {
      clearTimeout(timerID);
      timerID  = 0;
   }

   tStart = null;

   document.forms[0].action='expire.asp';
   document.forms[0].submit();
}

function UpdateTimer() 
{
   if(timerID) 
   {
      clearTimeout(timerID);
      timerID  = 0;
   }

   if(!tStart)
      tStart   = new Date();

   var   tDate = new Date();
   var   tDiff = tDate.getTime() - tStart.getTime();

   tDate.setTime(tDiff);

   //document.getElementById('theTime').value = "" 
                                   + tDate.getMinutes() + ":" 
                                   + tDate.getSeconds();
                                   
   clockID++;
   
   if(clockID == SessTimeout)
   //if(clockID == 10)
   {
       Stop();
   }
   
   
   timerID = setTimeout("UpdateTimer()", 1000);
}

//***************************************************************************************

// this function is used/called when the user X's out the browser
// without logging off via the log out button or link.

//Call the function like this:
//<BODY onbeforeunload="UnloadPage();">

function UnloadPage()
{
	window.focus();
	//if (document.all)
	//{
		//test for IE7 and IE6
		if (((window.event.clientX > 0) && (window.event.clientY < 0)) ||((window.event.clientX < 0) && (window.event.clientY < 0))) 
		//if (window.event.clientY < 0) //X button is clicked
		{
			//alert(window.event.clientX + '  ' + window.event.clientY);
			window.location.href='abandon.asp';
		}
	//}
}

//**************************************************************************************

function UnloadPage2()
{
	window.focus();
	//if (document.all)
	//{
		//test for IE7 and IE6
		if (((window.event.clientX > 0) && (window.event.clientY < 0)) ||((window.event.clientX < 0) && (window.event.clientY < 0))) 
		//if (window.event.clientY < 0) //X button is clicked
		{
			//alert(window.event.clientX + '  ' + window.event.clientY);
			window.location.href='../abandon.asp';
		}
	//}
}
