var timerID = null;
var runTimer = false;

function startclock(){
  
   stopClock();
   displayTime();
}

function stopClock(){
   if(runTimer)
      clearTimeout(timerID)
   runTimer = false;
}

function displayTime(){
   var now = new Date();
   var hours = now.getHours();
   var minutes = now.getMinutes();
   var seconds = now.getSeconds();
   var time = "" + ((hours > 12 ) ? hours - 12 :  hours);
   var timeStr= time.toString();
   if ( timeStr.length < 2) { time = "0" + time;}
   time += ((minutes < 10) ? ":0" : ":") + minutes;
   time += ((seconds < 10) ? ":0" : ":") + seconds;
   time += ((hours >= 12) && (hours != 24)) ? " P.M." : " A.M."
   document.clock.face.value = time;
   timerID = setTimeout("displayTime()",1000);
   runTimer = true;
}
