/******************************************************************************
 *
 * itbeat.js - Internet Time Display Version 2.0.1
 *
 * Copyright (c) 1999 - 2004 NI-Lab.
 *
 * Author: NI-Lab.
 * Access: http://www.nilab.info/
 * Since : 1999-09-09
 *
 *****************************************************************************/

/*
 * Internet Time Display License
 *
 * Copyright (c) 1999 - 2004 NI-Lab.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

/*
 * ChangeLog (and Comment)
 *
 *
 * 2004-09-02(Version 2.0.1)  NI-Lab.
 *
 *   * Fix harmless bug in function initInternetTimeModule.
 *
 *
 * 2004-08-16(Version 2.0.0)  NI-Lab.
 *
 *   * Large revision. But it is the same that it is realizable.
 *
 *   * The notation format of a version was changed.
 *
 *   * About a license, it was from link wear. It changed into MIT License.
 *
 *
 * 2000-07-06(Version 1.11)  NI-Lab.
 *
 *   * The program was carried out to the Java Script external file.
 *     By this, this program can be used (maybe) also by
 *     those who do not know Java Script and know HTML.
 *
 *
 * 2000-07-05(Version 1.01)  NI-Lab.
 *
 *   * The error which occurs only by Internet Explorer is solved.
 *     As for a cause, the GMT display format of Internet Explorer
 *     differs from NetScape Navigator.
 *     Somewhat, although it is forcing correction,
 *     what cannot perform elegant programming is unavoidable.
 *
 *
 * 1999-09-09(Version 1.00)  NI-Lab.
 *
 *   * The interim version.
 *
 *   * It wondered considering such a time concept.
 *     By the way, what reason will not yet spread.
 *     Utility value may not be produced
 *     if there is also no international bulletin board.
 *     The idea of losing TIME ZONE is interesting.
 *
 */

///////////////////////////////////////////////////////////////////////////////

// global variables
var g_target; // display target element

// @param target        - display target element
// @param interval_msec - update interval time in milli-seconds
function initInternetTimeModule(target, interval_msec){

  // set target element
  g_target = target;

  if(interval_msec == null){
    // default interval time is 1 second(=1000 milli-seconds);
    interval_msec = 1000;
  }

  // first call function
  displayInternetTime();

  // set funcion call timer
  setInterval("displayInternetTime()", interval_msec);
}

function displayInternetTime() {

  // get InternetTime
  beat = getInternetTime(new Date());

  // format string
  zero = "";
  if (beat < 100) zero =  "0";
  if (beat <  10) zero = "00";

  // set value
  g_target.value = zero + beat;
}

function getInternetTime(date) {

  h = date.getUTCHours();
  m = date.getUTCMinutes();
  s = date.getUTCSeconds();

  // The time difference between London and Biel is one hour(= 3600 seconds).
  // The Biel's time zone is same as the Paris's.
  beat = (h * 3600 + m * 60 + s + 3600) / 86.4;

  // 0 <= internet time < 1000
  if (beat >= 1000){
    beat = beat - 1000;
  }

  beat = Math.floor(beat);

  return beat;
}

///////////////////////////////////////////////////////////////////////////////
