function Clock(){
  if (window.yyyy && window.mon && window.dd && window.hh&& window.mm && window.ss) {
    // this.date = new Date(window.datestring);    
    this.date = new Date(window.yyyy, window.mon - 1, window.dd, window.hh, window.mm, window.ss);
    this.timer = null;
    this.display = document.getElementById("clock");
  }
}

Clock.prototype={
  start : function() {
    if (window.yyyy && window.mon && window.dd && window.hh && window.mm &&  window.ss && this.display) {
      this.update();
    }
  },
  update : function() {
    var clock = (this.clock) ? this.clock : this;
    var update_function = function () { clock.update(); };
    var hours = clock.date.getHours();
    var minutes = clock.date.getMinutes();
    var seconds = clock.date.getSeconds();
    var tt = "";
    
    tt = (hours >= 12) ? " PM" : " AM";
    hours = (hours >12) ? hours - 12 : hours;    
    hours = (hours < 10) ? "0"  + hours : ""  + hours;
    minutes = (minutes < 10) ? "0"  + minutes : ""  + minutes;    
    
    clock.display.innerHTML = hours + ":" + minutes + " " + tt;    
    clock.date = new Date(clock.date.getTime() + 60000); 
    window.clearTimeout(clock.timer);           
    clock.timer = window.setTimeout(update_function, 60000);
  },
  stop : function() {
    var clock = (this.clock) ? this.clock : this;
    window.clearTimeout(clock.timer);
  }  
}

