﻿
 var clockID = 0;

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   var tDate = new Date();
   var thours =tDate.getHours();
   var min = tDate.getMinutes();
   var sec = tDate.getSeconds();
   if (thours >12)
   {
      thours = thours - 12
      add = " PM"
    } else {
      thours = thours;
      add = " AM"
    }
    if (thours == 12) {
      add = " PM"
    }
    if (thours == 00) {
      thours = "12"
    }
     if (min <= 9) {
      min = "0" + min; }
    if (sec <= 9) {
      sec = "0" + sec; }
    if (thours < 10) {
      thours = "0" + thours; }
var theTime1= document.getElementById('theTime');
   theTime1.value = "" 
                                   + thours + ":" 
                                   + min + ":" 
                                   + sec
                                   + add ;
   
   clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
   
   }