var stay_msg="You must stay for " + staytime + " seconds please.";

function display(){
window.status="Time Remaining: " + timeRemaining();
window.setTimeout("checktime()",1000);
}

function toMinutes(t) {
	if (t>60)
		m=parseInt(t/60);
	else{
		m=0;
	}
	s=parseInt(t-m*60);
	if(s<10) s="0"+s
	return m+":"+s;
}

function timeRemaining(){
	rtime=etime-ctime;
	return toMinutes(rtime);
}


function settimes(){
	/*
msg = "You must stay for " + toMinutes(staytime) + " minute";
if(staytime >= 120) {
	msg = msg + "s please.";
} else {
	msg = msg + " please.";
}*/
if(timeok!=true) {
	alert(stay_msg)
} else {
	return false;
} 
var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
etime=hours*3600+mins*60+secs;
etime+=staytime;  //You can change the value of 1200 according to how much time you wish to set the timer. Where 1200 is time in secs (1200 = 20 mins * 60 secs/min). Max time is 60 mins (3600secs)

checktime();
}

function checktime(){
var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
ctime=hours*3600+mins*60+secs

if(ctime>etime){
timeok=true
}
else
display();
}

function expired(U,S){
if(timeok==false)alert("Time Remaining: "+timeRemaining());
else location.href="unit.php?subunit="+S;  //Put here the next page
}
function gotest(U,S){
if(timeok==false)alert("Time Remaining: "+timeRemaining());
else location.href="test.php?subunit="+S;  //Put here the next page
}
function gooutline(U,S){
  location.href="../outline.php?subunit="+S;  //Put here the next page
}



