﻿var _clockid;
var _GTM=0;

function InitClock(_id, GTMTime)
{
    if (document.getElementById(_id) != null)
    {
        var _GTMTime=0;
        _clockid = _id;
        if (IsNumeric(GTMTime)) {
            _GTMTime = parseFloat(GTMTime, 10) + 1; // +1 durring summer time
            var currentTime = new Date();
            _GTM = (currentTime.getTimezoneOffset() * 60000) + (_GTMTime * 3600000);
            updateClock();
        }
    }
}

function updateClock()
{
  var currentTime = new Date();
  var currentTime = new Date(currentTime.getTime()+_GTM);
  var currentHours = currentTime.getHours();
  var currentMinutes = currentTime.getMinutes();
  //var currentSeconds = currentTime.getSeconds ( );

  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  //currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

//  // Choose either "AM" or "PM" as appropriate
//  var timeOfDay = ( currentHours < 12 ) ? "בבוקר" : "בערב";

//  // Convert the hours component to 12-hour format if needed
//  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

//  // Convert an hours component of "0" to "12"
//  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes;// + ":" + currentSeconds;// + " " + timeOfDay;

  // Update the time display
  document.getElementById(_clockid).innerHTML = currentTimeString;
  setTimeout('updateClock()', 30000);
}

function IsNumeric(input) 
{ 
   return (input - 0) == input && input.length > 0; 
} 

