function RaceClock() { this.m_Months=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") this.m_RaceDay; this.m_RaceMonth; this.m_RaceYear; this.m_RaceHour; this.m_RaceMinute; this.SetRaceDay = function SetRaceDay(_month, _day, _year){ this.m_RaceDay = _day; this.m_RaceMonth = _month; this.m_RaceYear = _year; } this.SetRaceTime = function SetRaceTime(_hour, _minute) { this.m_RaceHour = _hour; this.m_RaceMinute = _minute; } this.GetFormattedRaceDate = function GetFormattedRaceDate(){ return this.m_RaceMonth + '.' + this.m_RaceDay + '.' + this.m_RaceYear; } this.GetFormattedRaceTime = function GetFormattedRaceTime(){ return this.m_RaceHour % 12 + ':' + this.m_RaceMinute; } this.TimeToRace = TimeToRace; } function TimeToRace(_id) { var now = new Date(); var timeout = 1000; var currentHour = now.getUTCHours() - 4; raceDate = this.m_Months[this.m_RaceMonth-1]+", "+this.m_RaceDay+", "+this.m_RaceYear+" "+this.m_RaceHour+":"+this.m_RaceMinute+":00"; currently = this.m_Months[now.getUTCMonth()]+" "+now.getUTCDate()+", "+now.getUTCFullYear()+ " "+currentHour+":"+now.getUTCMinutes()+":"+now.getUTCSeconds(); dateDiff=Date.parse(raceDate)-Date.parse(currently) diffDay=Math.floor(dateDiff/(60*60*1000*24)*1) diffHour=Math.floor((dateDiff%(60*60*1000*24))/(60*60*1000)*1) diffMin=Math.floor(((dateDiff%(60*60*1000*24))%(60*60*1000))/(60*1000)*1) diffSec=Math.floor((((dateDiff%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1) if(diffDay < 10) diffDay = "0" + diffDay; if(diffHour < 10) diffHour = "0" + diffHour; if(diffMin < 10) diffMin = "0" + diffMin; if(diffSec < 10) diffSec = "0" + diffSec; if(document.getElementById(_id)){ if(isNaN(diffDay) || isNaN(diffHour) || isNaN(diffMin) || isNaN(diffSec)) document.getElementById(_id).innerHTML = ''; else document.getElementById(_id).innerHTML = diffDay + ":" + diffHour + ":" + diffMin + ":" + diffSec; } else timeout = 20; var obj = this; window.setTimeout( function(){ obj.TimeToRace(_id) }, timeout); }