var clock = 0; function UpdateClock() { if(clock) { clearTimeout(clock); clock = 0; } document.getElementById('clock').innerHTML = ReplaceNumbers(GetTime()); clock = setTimeout("UpdateClock()", 1000); } function StartClock() { clock = setTimeout("UpdateClock()", 500); } function GetTime(){ var tDate = new Date(); hour = ''+tDate.getHours(); minutes = ''+tDate.getMinutes(); seconds = ''+tDate.getSeconds(); if(hour.length == 1){ hour = '0'+hour; } if(minutes.length == 1){ minutes = '0'+minutes; } if(seconds.length == 1){ seconds = '0'+seconds; } return hour+':'+minutes+':'+seconds; } function ReplaceNumbers(string){ string = string.replace(/0/g,'0'); string = string.replace(/1/g,'1'); string = string.replace(/2/g,'2'); string = string.replace(/3/g,'3'); string = string.replace(/4/g,'4'); string = string.replace(/5/g,'5'); string = string.replace(/6/g,'6'); string = string.replace(/7/g,'7'); string = string.replace(/8/g,'8'); string = string.replace(/9/g,'9'); string = string.replace(/:/g,':'); return string; } function KillClock() { if(clock) { clearTimeout(clock); clock = 0; } }