var clockID = 0;
function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
   var tDate = new Date();
   var hours=tDate.getHours();
   var minutes=tDate.getMinutes();
   var seconds=tDate.getSeconds();

   var timevalue = "<span>";
   timevalue += ((hours<10) ? "0" : "") + hours;
   timevalue += ((minutes<10) ? ":0" : ":") + minutes;
   timevalue += ((seconds<10) ? ":0" : ":") + seconds;
   timevalue += "</span>";

   var clockObj = document.getElementById("clock");
   clockObj.innerHTML = timevalue;
   
   clockID = setTimeout("UpdateClock()", 1000);
}

function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}

function StopClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}
