////////////////////////////////////////
//
// a Javascript Clock in a text field
//
// Author: Andy Spiegl
//
// put this into your HTML file:
//  <BODY onLoad="startclock(); return true">
//
// and IN the body this:
//	 <form name="clock" onSubmit="0">
//	 <input type="text" name="XXX" size=8 value="DEFAULT TEXT">
//	 </form>
//
// where you should replace XXX with one of these:
//	 - LocalClock
//   - UTCClock
//	 - PeruClock
//	 - GermanClock
//
// replace "DEFAULT TEXT" with whatever you like, e.g.
//  "Enable Javascript please"
//
// Original code from:
// Michael P. Scholtis (mpscho@planetx.bloomu.edu)
//
// All rights reserved.  December 22, 1995
// You may use this JavaScript example as you see fit, as long as the
// information within this comment above is included in your script.
//
////////////////////////////////////////

var timerID = null;
var timerRunning = false;
var id,pause=0,position=0;

function startclock () {
        stopclock();
        showtime();
}

function stopclock (){
  if(timerRunning)
         clearTimeout(timerID);
  timerRunning = false;
}

function showtime () {
  var now, hours, minutes, seconds, timeValue;

  now = new Date();
  hours = now.getHours();
  minutes = now.getMinutes();
  seconds = now.getSeconds();

  // Local
  if (document.clock.LocalClock)
  {
    if (hours > 24)
      hours -= 24;
    timeValue = "" + ((hours < 10) ? "0" : "") + hours;
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
    document.clock.LocalClock.value = timeValue;
  }

  // UTC
  if (document.clock.UTCClock)
  {
    hours = now.getUTCHours();
    minutes = now.getUTCMinutes();
    seconds = now.getUTCSeconds();

    if (hours > 24)
      hours -= 24;
    timeValue = "" + ((hours < 10) ? "0" : "") + hours;
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
    document.clock.UTCClock.value = timeValue;
  }

  // Peru
  if (document.clock.PeruClock)
  {
    hours = now.getUTCHours();
    hours -= 5;   /* Offset for Peru */
    if (hours < 0)
      hours += 24;
    if (hours > 24)
      hours -= 24;
    timeValue = "" + ((hours < 10) ? "0" : "") + hours;
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
    document.clock.PeruClock.value = timeValue;
  }

  // Germany
  if (document.clock.GermanClock)
  {
    hours = now.getUTCHours();
    hours += 1;   /* Offset for Germany (NOT respecting DAYLIGHT SAVINGS TIME */

    if (hours > 24)
      hours -= 24;
    timeValue = "" + ((hours < 10) ? "0" : "") + hours;
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
    document.clock.GermanClock.value = timeValue;
  }

  // call again later
  timerID = setTimeout("showtime()",1000);
  timerRunning = true;
}
