function simpleCountdown (sec) {
	var Seconds = sec;
	var Time = "";
	if (Value = Math.floor(sec / 86400)) {
		Time += Value + " Days, ";
		sec = sec % 86400;
	}
	if (Value = Math.floor(sec / 3600)) {
		Time += Value + ":";
		sec = sec % 3600;
	}
	if (Time || sec > 60) {
		Value = Math.floor(sec / 60);
		if (Value <= 9) {
			Time += "0";
		}
		Time += Value + ":";
		sec = sec % 60;
	}
	if (Time) {
		if (sec <= 9) {
			Time += "0";
		}
		Time += sec;
	} else {
		Time += sec;
	}
	$("cdout").update(Time);
	if (Seconds > 0) {
		window.setTimeout("simpleCountdown("+(Seconds-1)+")", 999);
	}
}

function Countdown (sec) {
	var Seconds = sec;
	var Time = "";
	if (Value = Math.floor(sec / 86400)) {
		Time += Value + " Days, ";
		sec = sec % 86400;
	}
	if (Value = Math.floor(sec / 3600)) {
		Time += Value + " hours ";
		sec = sec % 3600;
	}
	if (Time || sec > 60) {
		Value = Math.floor(sec / 60);
		if (Value <= 9) {
			Time += "0";
		}
		Time += Value + " minutes ";
		sec = sec % 60;
	}
	if (Time) {
		if (sec <= 9) {
			Time += "0";
		}
		Time += sec + " seconds";
	} else {
		Time += sec + " second";
		if (sec != 1) {
			Time += "s";
		}
	}
	document.getElementById("cdout").firstChild.nodeValue = Time;
	if (Seconds > 0) {
		window.setTimeout("Countdown("+(Seconds-1)+")", 999);
	} else {
		document.getElementById("remove").style.display = "none";		
		document.getElementById("retry").style.display = "block";		
	}
}

function MultiCountdown (count) {
	for (i = 0; i < count; i++) {
		if (document.getElementById('time'+i))	{
			time = document.getElementById('time'+i).firstChild.data;
			CountdownChild(time, i);
		}
	}
}

function CountdownChild (sec, index) {
	Seconds = sec;
	Time = "";
	if (Value = Math.floor(sec / 86400)) {
		Time += Value + " Day";
		if (Value != 1) {
			Time += "s";
		}
		Time += " ";
		sec = sec % 86400;
	}
	if (Value = Math.floor(sec / 3600)) {
		Time += Value + ":";
		sec = sec % 3600;
	}
	if (Time || sec > 60) {
		Value = Math.floor(sec / 60);
		if (Time && Value <= 9) {
			Time += "0";
		}
		Time += Value + ":";
		sec = sec % 60;
	}
	if (Time) {
		if (sec <= 9) {
			Time += "0";
		}
		Time += sec + "";
	} else {
		Time += sec + " second";
		if (sec != 1) {
			Time += "s";
		}
	}
	document.getElementById("cdout"+index).firstChild.data = Time;
	if (Seconds > 0) {
		window.setTimeout("CountdownChild("+(Seconds-1)+", "+index+")", 999);
	} else {
		if (document.getElementById("remove"+index)) {	
			document.getElementById("remove"+index).style.display = "none";		
		}
		if (document.getElementById("retry"+index)) {	
			document.getElementById("retry"+index).style.display = "block";		
		}
		hidebutton = document.getElementsByName("hideme");
		if (hidebutton.length) {
			for (j=0; j < hidebutton.length; j++)
				hidebutton[j].style.display = "none";		
		}
		showbutton = document.getElementsByName("showme");
		if (showbutton.length) {
			for (j=0; j < showbutton.length; j++)
				showbutton[j].style.display = "inline";		
		}
	}
}

function CountdownSec (sec) {
	Timestring = sec + " second";
	if (sec != 1) {
		Timestring += "s";
	}
	document.getElementById("cdout").firstChild.nodeValue = Timestring;
	if (sec > 0) {
		window.setTimeout("CountdownSec("+(sec-1)+")", 999);
	} else {
		document.getElementById("remove").style.display = "none";		
		document.getElementById("retry").style.display = "block";		
	}
}

function CountdownSecList (sec, index) {
	$("cdout"+index).update(sec);
	if (sec > 0) {
		window.setTimeout("CountdownSecList("+(sec-1)+", '"+index+"')", 999);
	} else {
		$("remove"+index).style.display = "none";		
		$("retry"+index).style.display = "inline";		
	}
}
