
  var oInterval;
  var MAX_WITHOUT_ACTIVITY=1800000 ; //number of milliseconds without activity before reload.
  
  function InitUserActivity() {
    var oHid_h = document.getElementById("hid_lastActivity_h");
    var oHid_mn = document.getElementById("hid_lastActivity_mn");
    var oHid_s = document.getElementById("hid_lastActivity_s");
    var oDate=new Date();
    oHid_h.value = oDate.getHours();
    oHid_mn.value = oDate.getMinutes();
    oHid_s.value = oDate.getSeconds();
    oInterval = window.setInterval("VerifyActivity()", 30000); // check every 30 seconds    
  }

  function Activity() {
    var oHid_h = document.getElementById("hid_lastActivity_h");
    var oHid_mn = document.getElementById("hid_lastActivity_mn");
    var oHid_s = document.getElementById("hid_lastActivity_s");
    var oDate=new Date();
    oHid_h.value = oDate.getHours();
    oHid_mn.value = oDate.getMinutes();
    oHid_s.value = oDate.getSeconds();
  }
  
  function VerifyActivity() {
	var MAX_WITHOUT_ACTIVITY=1800000;
    var oHid_h = document.getElementById("hid_lastActivity_h");
    var oHid_mn = document.getElementById("hid_lastActivity_mn");
    var oHid_s = document.getElementById("hid_lastActivity_s");
    var oDate=new Date(); // current date and time
	var hourDiff = (-1*oHid_h.value) + oDate.getHours();
	var minDiff = (-1*oHid_mn.value) + oDate.getMinutes();
	var secDiff = (-1*oHid_s.value) + oDate.getSeconds();
	var totalDiff = (secDiff*1000)+(minDiff*60000)+(hourDiff*3600000);
    var oLastActDate=new Date(oDate.getYear(), oDate.getMonth(), oDate.getDate(), oHid_h.value, oHid_mn.value, oHid_s.value); // last activity date and time.
	if (totalDiff > MAX_WITHOUT_ACTIVITY) {
		window.location = '/ee/logout';
	}
	else if (totalDiff > (MAX_WITHOUT_ACTIVITY - 300000)) {
       var stayalive = confirm("You have been idle for at least 25 minutes. Please click OK within the next five minutes to continue your session. Click cancel to logout.");
	   if (stayalive) {
			oHid_h.value = oDate.getHours();
			oHid_mn.value = oDate.getMinutes();
			oHid_s.value = oDate.getSeconds();
	   }
	   else {
		   window.location = '/ee/logout';
	   }
	}
  }

