var sessionTime = 1200;//empire time var delay = 1000; var timeId = null; var timerRunning = false; var windowStatusMsg; var isStatusAvail = true; initTimer(); function initTimer(){ secs = sessionTime; stopClock(); startTimer(); } function stopClock(){ if(timerRunning){ clearTimeout(timeId); } timerRunning = false; } function startTimer(){ if(secs == 0){ stopClock(); windowStatusMsg = "The session is empired"; } else { secs = secs - 1; var min = secs/60; var res = Math.floor(min); var sec = secs%60; timerRunning = true; timerId = self.setTimeout("startTimer()",delay); if(secs>=1 && secs<=59){ if(secs==10){ alert("Session will be expired after 10 seconds!"); } windowStatusMsg = "Your session will expire within "+sec+ " second(s)"; }else{ windowStatusMsg = "Your session will expire within "+res+" minute(s) and " +sec+ " second(s)"; } } if(isStatusAvail){ window.status = windowStatusMsg; } }
?