/*
+---------------------------------------------------------------+
|	TMS -  TOURNAMENT MANAGEMENT SYSTEM
|		http://www.tourneyaddicts.com
|		Copyright © Billy Smith
|		admin@tourneyaddicts.com
|
|	Designed for use with the e107 website system.
|		http://e107.org
|
|	Released under the terms and conditions of the GNU GPL.
|		GNU General Public License (http://gnu.org)
|
|		Revision: 1.0.0
|		Date: 2005-10-23
+---------------------------------------------------------------+
*/
/*
TMS COUNTDOWN
*/

//###########################################################
//	ADJUSTABLE VARIABLES
//###########################################################
var attempts = 3;

var background_color = "000000";
var before_start_color = "00FF00";
var during_start_color = "FFFF00";
var after_start_color = "FF0000";

//###########################################################
// 	MESSAGES
//###########################################################
var before_start="STARTS IN - ";
var during_start="STARTING NOW!!!";
var after_start="-- REFRESH PAGE --";

//###########################################################
//	DO NOT EDIT BELOW HERE
//###########################################################
function start_countdown(){
if(document.getElementById('to')){
t_g = document.getElementById('tg').value;
t_o = document.getElementById('to').value;
document.getElementById('tmscountdown').style.backgroundColor=background_color;
document.getElementById('tmscountdown').style.textAlign = "center";
countdown();
}else{
if(attempts > 0 ){
attempts--;
setTimeout('start_countdown()',1000);
if(document.getElementById('tmscountdown')){
document.getElementById('tmscountdown').innerHTML  = "";
}	
}	
}
}	
function countdown(){
var today=new Date();
gmt = (Math.floor(today.getTime()/1000));
dd=t_g-(gmt+((t_o*(3600))));
dhour=Math.floor((dd%(3600*48))/(3600));
dmin=Math.floor(((dd%(3600*24))%(3600))/(60));
dsec=Math.floor(((dd%(3600*24))%(3600))%(60));
if (dd<=-300){
document.getElementById('tmscountdown').style.color = after_start_color;
document.getElementById('tmscountdown').innerHTML  = after_start;
return;
}else if(dd<=0){
document.getElementById('tmscountdown').style.color= during_start_color;
document.getElementById('tmscountdown').innerHTML  = during_start;
}else{
if (dmin <10){
dmin = "0" + dmin;
}
if (dsec <10){
dsec = "0" + dsec;
}
document.getElementById('tmscountdown').style.color= before_start_color;
document.getElementById('tmscountdown').innerHTML  = before_start+dhour+":"+dmin+":"+dsec;
}
setTimeout('countdown()',1000);
}
window.onload=start_countdown;
