var initialTimeoutMsg = 1200000; // millis
var timedOutMsgIntrvl = 300; //seconds

var prompttitle = "Session Timeout";
var message = "Do you want to continue using MainStay Online Sales Desk? <br>";

var logOffTime;
var message2 = "If you do not respond, you will be logged off at ";

var timeoutmessage = "Sorry, your session has timed out.";


var timedOutHTML = "<table cellspacing='0' cellpadding='1' border='0' class='bgMain' width='100%'><tr width='100%'><td><table cellspacing='0' cellpadding='8' border='0' width='100%'><tr valign='middle' width='100%'><td colspan='2' class='bgMain'><b><font size='+1'>" + prompttitle + "</font></b></td></tr><tr width='100%'><td colspan='2' class='bgInterior'>" + timeoutmessage + "</td></tr><tr width='100%'><td align='middle' class='bgInterior' colspan='2'><br><img src='/polos/images/BUT_login.gif' border='0' class='formElements' onClick='loguseroff(); document.getElementsByTagName(\"body\")[0].removeChild(document.getElementById(\"prompt2\"))'></td></tr></table></td></tr></table>"; 


	function promptAlert(promptid, pos, v_top, v_left, v_width, v_innerHTML) { 
		promptbox = document.createElement('div'); 
		promptbox.setAttribute ('id' , promptid);
		promptbox.setAttribute('z-index', '3');
		document.getElementsByTagName('body')[0].appendChild(promptbox); 
		promptbox = eval("document.getElementById(promptid).style"); 
		var xy = getScrollXY();
		promptbox.position = pos; 
		promptbox.top = xy[1] + v_top; 
		promptbox.left = xy[0] + v_left; 
		promptbox.width = v_width; 
		promptbox.border = 'outset 1 #bbbbbb'; 
		document.getElementById(promptid).innerHTML = v_innerHTML;
		showWindowsObjects(false);
	} 

	function decide(arg) {
		var staticDiff = timedOutMsgIntrvl; //30;
		showWindowsObjects(true);
			document.getElementsByTagName("body")[0].removeChild(document.getElementById("prompt"));
		if (arg == true) {
			diff = ((new Date()).getTime() - currentT.getTime())/1000;
			if (diff > staticDiff) {
				promptAlert('prompt2', 'absolute', 220,300,220,timedOutHTML);
			} else {
				refreshUserLogin();
			}
		} else {
			diff = ((new Date()).getTime() - currentT.getTime())/1000;
			if (diff > staticDiff) {
				promptAlert('prompt2', 'absolute', 220,300,220,timedOutHTML);
			} else {					
				// window.setTimeout("loguseroff()", 120000);
				window.setTimeout("loguseroff()", timedOutMsgIntrvl * 1000);
			}
		}
	}

	function checkLoggedTime ()  {
		// Initialize the new date/time
		currentT = new Date();
		var logOffTimeT = new Date(currentT.getTime() + (timedOutMsgIntrvl * 1000));
		
		if (logOffTimeT.getHours() > 12) 
			logOffTime = (logOffTimeT.getHours() - 12);
		else
			logOffTime = logOffTimeT.getHours();
		logOffTime += ":";
		if (logOffTimeT.getMinutes() < 10)
			logOffTime += "0" + logOffTimeT.getMinutes();
		else
			logOffTime += logOffTimeT.getMinutes();

		logOffTime += ":";
		if (logOffTimeT.getSeconds() < 10)
			logOffTime += "0" + logOffTimeT.getSeconds();
		else
			logOffTime += logOffTimeT.getSeconds();

		if (logOffTimeT.getHours() > 11) 
			logOffTime += " PM.";
		else
			logOffTime += " AM.";
		
		self.focus();

		var innerDivHTML = "<table cellspacing='0' cellpadding='1' border='0' class='bgMain'><tr><td><table cellspacing='0' cellpadding='8' border='0' width='100%'><tr valign='middle'><td colspan='2' class='bgMain'><b><font size='+1'>" + prompttitle + "</font></b></td></tr> <tr><td colspan='2' class='bgInterior'>" + message + "</td></tr><tr><td align='middle' class='bgInterior' colspan='2'> <img src='/polos/images/buttons_yes.gif' border='0' class='formElements' onClick='decide(true);'> <img src='/polos/images/buttons_no.gif' border='0' class='formElements' onClick='decide(false);'> </td></tr><tr><td colspan='2' class='bgInterior'>" + message2 + logOffTime + "</td></tr></table></td></tr></table>"; 

		promptAlert('prompt', 'absolute', 220,300,300,innerDivHTML);
	}
