
	document.write('<div id="hidTimerInfo" style="display:none"></div>');		//used by AJAX to track session time

	function StartTimer(intTimerDuration) {
		if(intTimerDuration > 0) {
			var rndDelay = new Date().getMilliseconds() * 10;	//try to prevent timers in multiple windows from firing simultaneously
			window.setTimeout( 'CheckSessionTimeout(sessionID);', (intTimerDuration*1000) + rndDelay );
		}
	}

	
	function CheckSessionTimeout(sessionID) {
		document.title = document.location + ':CheckSessionTimeout';
		var ajaxResult = ajaxUpdateElementByID('/LCNet/Services/SessionPing.aspx?SessionID='+sessionID, 'hidTimerInfo', false, 'GET', '', 'ShowTimeoutPopup(sessionID, intWarningDuration);');
	}


	function ShowTimeoutPopup(sessionID, intWarningDuration) {
		var intSecondsRemaining;
		var strSecondsLeft = document.getElementById('hidTimerInfo').innerHTML;

		//if "Format|TimeRemaining|Message" string is returned, parse the string
		if( isNaN(strSecondsLeft) ) {
			var arrTimerInfo = strSecondsLeft.split('|');
			var strFormat = arrTimerInfo[0];						//0=popup, 1=confirm box
			intSecondsRemaining = parseInt(arrTimerInfo[1]);
			var strMessage = arrTimerInfo[2];

			switch (strFormat) {
				case "0" :
					var win = window.open('/LCNet/Controls/PopupTimeout.aspx?timer='+intWarningDuration+'&SessionID='+sessionID+'&lcid='+learnCenterID+'&secs='+intSecondsRemaining+'source='+document.location, 'SessionTimeout', 'height=150,width=300,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes', false);
					break;
				case "1" :
				    //10.0.1 KGC - Changed the message to show intWarningDuration instead of parseInt(intSecondsRemaining / 60)
				    //          The parseInt reduces the duration by 1 min. E.g. it show 23 if the warning duration is 24.
					//strMessage = strMessage.replace('&lt;#timer&gt;', parseInt(intSecondsRemaining / 60));	//truncates seconds (e.g. 1:58 = 1 min.)
					strMessage = strMessage.replace('&lt;#timer&gt;', intWarningDuration);
					if(confirm(strMessage)) {
						var ajaxResult = ajaxUpdateElementByID('/LCNet/Services/SessionPing.aspx?SessionID='+sessionID+'&refresh=true', 'hidTimerInfo', false, 'GET', '', 'RefreshSession();');
					} else {
						var ajaxResult = ajaxUpdateElementByID('/LCNet/Services/SessionPing.aspx?SessionID='+sessionID+'&kill=true', 'hidTimerInfo', false, 'GET', '', 'RedirectParentToLogin();');
					}
					break;
				//TODO: case "2" : add third option of an <DIV> warning message

				default :
					StartTimer(intSecondsRemaining - 60);	//Set the timer to check timeout again 1 minute before session timeout
			}
		} else {
			//Reset timer if returned string contains only time remaining before warning
			intSecondsRemaining = parseInt(strSecondsLeft) - (intWarningDuration*60);

			if(intSecondsRemaining > 0) {
				StartTimer(intSecondsRemaining);
			} else {
				RedirectParentToLogin();
			}
		}
	}

	function RedirectParentToLogin() {
		try {
			if(!window.parent.opener.closed) {
				window.parent.opener.RedirectParentToLogin();		//cascade redirects
				window.parent.opener.location.href = '/login.asp?lcid='+learnCenterID;
			}
		} catch(ex) {
			try {
				window.opener.RedirectParentToLogin();				//cascade redirects
				window.opener.location.href = '/login.asp?lcid='+learnCenterID;
			} catch (ex) {}
		}
			top.location.href = '/LCNet/ControlPanel/Security.aspx?lcid='+learnCenterID+'&Timeout=true';
//			if (top!=self.parent) {
//				top.location.href = '/LCNet/ControlPanel/Security.aspx?lcid='+learnCenterID+'&Timeout=true';
//			} else {
//				location.href = '/LCNet/ControlPanel/Security.aspx?lcid='+learnCenterID+'&Timeout=true';
//			}
			self.focus();
	}

	function RefreshSession() {
		//attempt to refresh any children first
		try {
			if(window.parent.opener != self) window.parent.opener.RefreshSession();
		} catch (err) {
			try {
				if(window.parent != self) window.parent.RefreshSession();
			} catch (err) {}
		}
		StartTimer(intTimerDuration*60);    //10.0.1 - KGC - Added *60 to invoke the timer after that many minutes instead of seconds.
	}


