var doc = document;
var flip=false;
var cookieInfo = 'expires=Wed, 30-Dec-2037 00:00:00 GMT; path=/; domain=.timercloud.com;';

function clearCookie() {
	document.cookie="user=0;"+cookieInfo;
	document.cookie="start=0";
}

function flashBkgd() {
	if(flip == false) {
		if(doc.height) doc.getElementById("sheet").style.height = doc.height+"px";
		doc.getElementById("sheet").style.display="none";
		flip=true;
	} else {
		if(doc.height) doc.getElementById("sheet").style.height = doc.height+"px";
		doc.getElementById("sheet").style.display="block";
		flip=false;
	}
}

function formVerify() {
	tform = document.timer_set;
	if(tform.h.value == 0 && tform.m.value == 0 && tform.s.value == 0) {
		alert("Opps. Don't forget to set your timer."); return false;
	} else { return true; }
}

function timer() {			
	if(seconds>0) seconds--;
	else { seconds = 00; }
	
	if(seconds < 10) doc.getElementById("timer_ss").innerHTML = "0"+seconds;
	else doc.getElementById("timer_ss").innerHTML = seconds;
	
	if(minutes < 10) doc.getElementById("timer_mm").innerHTML = "0"+minutes;
	else doc.getElementById("timer_mm").innerHTML = minutes;
	
	if(hours < 10) doc.getElementById("timer_hh").innerHTML = "0"+hours;
	else doc.getElementById("timer_hh").innerHTML = hours;
	
	timerID = setTimeout("timer()", 1000);
	
	if(seconds==0 && minutes!=0) {
		seconds = 60;
		minutes--;
	}
	
	if(seconds==0 && minutes==0 && hours!=0) {
		minutes = 59;
		seconds = 60;
		hours--;
	}
	
	if(hours==0 && minutes==0 && seconds==0) {
		doc.getElementById("timer").innerHTML = "<div id='now'>NOW!</div>";	
		doc.getElementById("cancel").style.display = "none";
		doc.getElementById("go_back").style.display = 
		doc.getElementById("adsense").style.display = 
		doc.getElementById("about").style.display = "block";
		
		//clear cookie
		clearCookie();
		window.onbeforeunload = "";
		clearTimeout(timerID);
		play();
	}
}

function makeOptions() {
	tform = document.timer_set;
	for(i=0;i<=12;i++) {
		if(i < 10) tform.h.options[i] = new Option("0"+i,i);
		else tform.h.options[i] = new Option(i,i);
	} 
	for(i=0;i<=59;i++) {
		if(i < 10) tform.m.options[i] = new Option("0"+i,i);
		else tform.m.options[i] = new Option(i,i);
	} 
	for(i=0;i<=59;i++) {
		if(i < 10) tform.s.options[i] = new Option("0"+i,i);
		else tform.s.options[i] = new Option(i,i);
	} 
}

function play() {		
	var bellUrl = "./snd/myclick_edit4.mp3";
	var IFrameObj = document.getElementById("bellFrame");
	IFrameObj.src = "about:blank";
	IFrameObj.src = bellUrl;
	window.focus();
	setTimeout("play()", 4000);			
}

function setCookie(uid) {
  	document.cookie="user="+uid.split("-")[0]+";"+cookieInfo;
	document.cookie="start="+uid.split("-")[1];
}

function stop() { 
	IFrameObj.src = "about:blank"; 
}

function unloadMess() {
	mess = "Leaving this page will end your TimerCloud session.\n"
	return mess;
}