//document.onmousemove = resetSession;
//document.onmousedown = resetSession;

var timerID;
var minutes=30;//30
var seconds=0;
function startClock(){
	if(document.getElementById("sessiontime")==null) return;
   // Initial call
   document.getElementById("sessiontime").innerHTML = "00:"+addZero(minutes)+":"+addZero(seconds);
   timerID = window.setTimeout("showClock()", 1000); // 1-second interval
}

function stopClock(){
	if(document.getElementById("sessiontime")==null) return;
   window.clearTimeout(timerID);
   document.getElementById("sessiontime").innerHTML = "Stopped!";
}

function showClock(){
   if(document.getElementById("sessiontime")==null) return;
   document.getElementById("sessiontime").innerHTML = "00:"+addZero(minutes) + ":" + addZero(seconds);
   timerID = window.setTimeout("showClock()", 1000); // repeat call
   if(minutes <= 0 && seconds <= 0){
   	stopClock();
	
	location = "/cms/logout.php";
   }
   if(seconds<=0){
   	minutes--;
	seconds=59;
   }
   --seconds;
}

function resetSession(){
	minutes = 30;//30
	seconds = 0;
}

function addZero(sec){
	var retval='';
	if(sec<10)
		retval = '0'+''+sec;
	else retval = sec;
	return retval;
}
