var _timeout = null; 
var _timeoutInterval;
var _redirectURL;

var _tt = "";

function GetTime()
{
	var now = new Date();
	return now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
}
 
 function DoTimeout()
 {
  	/* _tt += 'Timeout at ' + GetTime() + '\n'; */
	  /* alert('Timeout Alert Box \n' + _tt); */
	  
	  alert('Your session has timed out. You will be redirected to the sign-in page.');
	  location.href = _redirectURL;
 }
 

 function ResetTimeout() 
 {
	  /* _tt += 'Reset at ' + GetTime() + '\n'; */
	
	 	if (_timeout != null) {
		  clearTimeout(_timeout);
		  /* alert('Clearing Existing Timeout'); */
  	}

 	  if (_timeoutInterval != null) {
		  _timeout = setTimeout(DoTimeout, _timeoutInterval);
	  }
 }


 function InitTimeout(timeoutInterval, redirectURL) 
 {
    /* alert('Initializing Default.aspx: ' + GetTime()); */
    _timeoutInterval = timeoutInterval;
	  _redirectURL = redirectURL;

	  ResetTimeout();
	  if (document.onkeydown == null)
		  document.onkeydown = ResetTimeout;
	  if (document.onclick == null)
		  document.onclick = ResetTimeout;
 }
 
 /*
  * The default.aspx page contains a frame called content frame.
  * If the InitTimeout function is called in the content frame pages it instantiates
  * a new set of timeout fields/functions to the functions loaded in the Default.aspx page.
  * We need to ensure that we are hitting the same ResetTimeout() function so as the timeouts don't get out
  * of sync with each other. 
  *
  * In effect by calling the parent timeout functions we are acting on one set (global) variables
  * and therefore the timeout times are kept in sync.
  */
 function ChildFrameInitTimeout() 
 {
    /* alert('Initializing Content Frame: ' + GetTime()); */
	  parent.ResetTimeout();
	  if (document.onkeydown == null)
		  document.onkeydown = parent.ResetTimeout;
	  if (document.onclick == null)
		  document.onclick = parent.ResetTimeout;
 }



