//***********************************
// Global variables
var SECONDS = 60000;
var WarningMins = 1; //In Minutes
var TimeOutMins = 2; //In Minutes
var ThresholdMils = SECONDS * WarningMins;
var WarningTimer = null;
var LOGINPAGE = "Login.aspx";
var TimeOutWindow = null;
var Content = "";
var StartMils = Date.parse(new Date().toLocaleString());
var TimeOutMils = StartMils + (SECONDS * TimeOutMins);
//***********************************
function BuildContent()
{
Content = '<body bgcolor="#ffffff" onLoad="self.focus"><font face="arial,helvetica" size="2">';
Content += 'Due to inactivity, you are about to be logged out. ';
Content += 'If you wish to stay logged in, click "Yes" below.';
Content += 'If you select "No" or do not respond to this screen,
Content += 'you will automatically be logged out for security reasons.';
Content += '<p><div align="center"><a ';
Content += 'href="javascript:opener.ResetTimer();top.parent.opener.focus();self.close();">Yes</a>';
Content += '</div></p></font></body></html>';
}
function CountDown()
{
clearTimeout(WarningTimer);
var w = 400;
var h = 200;
if (document.all || document.layers)
{
w = screen.availWidth;
h = screen.availHeight;
}
var popW = 400;
var popH = 200;
var leftPos = (w - popW) / 2;
var topPos = (h - popH) / 2;
if (TimeOutWindow && !TimeOutWindow.closed)
TimeOutWindow.close();
var params = 'menubar=0,toolbar=0,status=0,scrollbars=0,resizable=0,width=';
params += popW + ',height='+ popH + ',top=' + topPos + ',left=' + leftPos;
TimeOutWindow = window.open('','TimeOut',params);
TimeOutWindow.document.writeln('<html><head><title>TimeOut</title></head><body bgcolor=white onLoad="self.focus()">'+Content+'</body></html>');
TimeOutWindow.document.close();
WarningTimer = setTimeout('CountDown()', ThresholdMils);
}
function ValidateSession()
{
//******************************************
//Call AJAX Function to Check Session Check
//******************************************
return true;
}
function ResetTimer()
{
window.focus();
setTimeout(top.window.focus, 1000);
alert("Your Session will be extended!!!");
clearTimeout(WarningTimer);
var SessionCheck = ValidateSession();
if (SessionCheck)
{
StartMils = Date.parse(new Date().toLocaleString());
TimeOutMils = StartMils + (SECONDS * TimeOutMins);
WarningTimer = setTimeout('CountDown()', ThresholdMils);
TimeOutWindow = null;
}
else
{
//****************
//Logout the User
//****************
}
}
var CurrentWindowUrl = window.location.href;
//******************************
//IF THE PAGE IS NOT LOGIN PAGE
//******************************
if (CurrentWindowUrl.indexOf(LOGINPAGE) == -1)
{
BuildContent();
WarningTimer = setTimeout('CountDown()', ThresholdMils);
}