// Script Name:  jcm_clk_01.js
// Date: 2008 11 21
// 
// Clock routines by jcm.

var timerID = null;
var timer2ID = null;
var timerRunning = false;
var timer2Running = false;
function stop_clock(){
   if(timerRunning) clearTimeout(timerID);
   timerRunning = false;
   if(timer2Running) clearTimeout(timer2ID);
   timer2Running = false;
}
function start_clock(){
   // Make sure the clock is stopped
   stop_clock();
   show_time();
//   show_time_mil();  // Military Time
   show_date();
}
function show_time(){
   var now = new Date();
   var hours = now.getHours();
   var hours2 = hours;
   if( hours2 == 0 ) hours2 = 12;
   if( hours2 > 12 ) hours2 = hours2 - 12;
   var minutes = now.getMinutes();
   var seconds = now.getSeconds();
//   var timeValue = "" + ((hours > 12) ? hours2 - 12 : hours2);
   var timeValue = "" + ((hours2 < 10) ? "0" : "") + hours2;
   timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
   timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
   timeValue += (hours >= 12) ? " PM" : " AM";
   document.sys_time.sys_time_time.value = timeValue;
   timerID = setTimeout("show_time()",1000);
   timerRunning = true;
}
function show_time_mil(){  // Military Time
   var now = new Date();
   var hours = now.getHours();
   var minutes = now.getMinutes();
   var seconds = now.getSeconds();
   var timeValue = "" + ((hours < 10) ? "0" : "") + hours;
   timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
   timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
   document.clock.face.value = timeValue;
   timerID = setTimeout("show_time_mil()",1000);
   timerRunning = true;
}
function show_date(){
   var now = new Date();
   var day = now.getDate();
   var month = now.getMonth() + 1;
   var year = now.getFullYear();
   var dateValue = "" + ((month < 10) ? "0" : "") + month;
   dateValue += ((day < 10) ? "/0" : "/") + day;
   if (year < 10 ){
     dateValue += ((year < 10) ? "/0" : "/") + year;
   } else if (year < 100 ){
     dateValue += ((year < 100) ? "/00" : "/") + year;
   } else if (year < 1000 ){
     dateValue += ((year < 1000) ? "/000" : "/") + year;
   } else {
     dateValue += "/" + year;
   }
   document.sys_date.sys_date_date.value = dateValue;
   timer2ID = setTimeout("show_date()",1000);
   timer2Running = true;
}

