//
// ...Specify the time zones
var WeekDay = new Array('Sun', 'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat');
var Month = new Array('January', 'February', 'March', 'April', 'May', 'June',
  'July', 'August', 'September', 'October', 'November', 'December');
var MonthAbbrev = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var TimeCity = new Array('Abu Dhabi', 'Amman', 'Baghdad', 'Beruit', 'Cairo', 
  'Casablanca', 'Charlotte', 'Chicago', 'Doha', 'Dubai', 'Istanbul', 'Jeruselum',
  'Los Angeles', 'London', 'Manama', 'Mecca', 'Muscat', 'Nablus', 'New York',
  'Phoenix', 'Riyadh');
var TimeChange = new Array('S', 'D', 'D', 'D', 'D', 'S', 'D', 'D', 'S', 'S',
  'D', 'D', 'D', 'D', 'S', 'S', 'S', 'D', 'D', 'S', 'S');
var TimeOffset = new Array(4, 2, 3, 2, 2, 0, -5, -6, 3, 4, 2, 2, -8, 0, 3, 3, 4,
  2, -5, -7, 3);
var TimeAreaSpeed = 2000, TimeAreaMax = 9, NewYorkOffset = 18, GreenTime;
var LastTimeArea = 0, TimeAreaTimer, TimeAreaTable, NewYorkArea, TR, TD;
var RightTopArea, RightTopLines, RightTopLast = 0, RightTopMax = 10;
var RightBtmArea, RightBtmLines, RightBtmLast = 0, RightBtmMax = 10;
var RightSpeed = 2, RightWait = 0;
function StartTimeArea() {
  //
  // ...Start the time area
  GreenTime = new Date();
  var m = GreenTime.getUTCMonth(), i = 0;
  NewYorkArea = document.getElementById('NewYork');
  TimeAreaTable = document.getElementById('TimeArea').firstChild;
  LastTimeArea = TimeCity.length;
  if (m > 3 && m < 10) for (i = 0; i < LastTimeArea; i++)
    if (TimeChange[i] == 'D') TimeOffset[i]++;
  SetNewYorkTime();
  if (LastTimeArea > TimeAreaMax) LastTimeArea = TimeAreaMax;
  for (i = 0; i < LastTimeArea; i++) {
    TR = TimeAreaTable.appendChild(document.createElement('TR'));
    TD = TR.appendChild(document.createElement('TD'));
    TD.className = 'TimeArea';
    TD.noWrap = true;
    TD.innerHTML = TimeCity[i];
    TD = TR.appendChild(document.createElement('TD'));
    TD.className = 'TimeArea';
    TD.noWrap = true;
    TD.innerHTML = FormatTimeTime(i);
    TD = TR.appendChild(document.createElement('TD'));
    TD.className = 'TimeArea';
    TD.noWrap = true;
    TD.innerHTML = FormatTimeDate(i);}
  //
  // ...Start the right scroller areas
  RightTopArea = document.getElementById('MIDEAST-RIGHT-TOP');
  if (RightTopArea) {
    RightTopLines = RightTopArea.innerHTML.replace(/<BR>/g, '\r').split('\r');
    RightTopShow();}
  RightBtmArea = document.getElementById('MIDEAST-RIGHT-BOTTOM');
  if (RightBtmArea) {
    RightBtmLines = RightBtmArea.innerHTML.replace(/<BR>/g, '\r').split('\r');
    RightBtmShow();}
  TimeAreaTimer = setTimeout('NewTimeArea();', TimeAreaSpeed);
  return;}
function NewTimeArea() {
  GreenTime = new Date();
  SetNewYorkTime();
  TimeAreaTable.removeChild(TimeAreaTable.firstChild);
  if (++LastTimeArea >= TimeCity.length) LastTimeArea = 0;
  TR = TimeAreaTable.appendChild(document.createElement('TR'));
  TD = TR.appendChild(document.createElement('TD'));
  TD.className = 'TimeArea';
  TD.noWrap = true;
  TD.innerHTML = TimeCity[LastTimeArea];
  TD = TR.appendChild(document.createElement('TD'));
  TD.className = 'TimeArea';
  TD.noWrap = true;
  TD.innerHTML = FormatTimeTime(LastTimeArea);
  TD = TR.appendChild(document.createElement('TD'));
  TD.className = 'TimeArea';
  TD.noWrap = true;
  TD.innerHTML = FormatTimeDate(LastTimeArea);
  if (++RightWait > RightSpeed) {
    if (RightTopArea) RightTopShow();
    if (RightBtmArea) RightBtmShow();
    RightWait = 0;}
  TimeAreaTimer = setTimeout('NewTimeArea();', TimeAreaSpeed);
  return;}
function SetNewYorkTime() {
  var ny = 'New York: ' + FormatTimeTime(NewYorkOffset) + '   ';
  var d = new Date(GreenTime.getTime() + TimeOffset[NewYorkOffset] * 3600000);
  ny += String(d.getUTCDate()) + ' ';
  ny += Month[d.getUTCMonth()] + ' ';
  ny += String(d.getUTCFullYear());
  NewYorkArea.innerText = ny;
  return;}
function FormatTimeTime(i) {
  var d = new Date(GreenTime.getTime() + TimeOffset[i] * 3600000);
  var h = d.getUTCHours();
  var a = 'AM';
  if (h > 11) a = 'PM';
  if (!h) h = 24;
  if (h > 12) h -= 12;
  var s = '';
  if (h.length < 2) s += '0';
  s += h + ':';
  h = String(d.getUTCMinutes());
  if (h.length < 2) s += '0';
  s += h + ' ' + a;
  return s;}
function FormatTimeDate(i) {
  var d = new Date(GreenTime.getTime() + TimeOffset[i] * 3600000);
  var s = String(d.getUTCDate()) + ' ';
  s += MonthAbbrev[d.getUTCMonth()] + ' ';
  s += String(d.getUTCFullYear());
  return s;}
function RightTopShow() {
  TR = '';
  var n = RightTopLast++;
  if (RightTopLast >= RightTopLines.length) RightTopLast = 0;
  for (i = 0; i < RightTopMax; i++) {
    TR += RightTopLines[n++] + '<br>';
    if (n >= RightTopLines.length) n = 0;}
  RightTopArea.innerHTML = TR;
  return;}
function RightBtmShow() {
  TR = '';
  var n = RightBtmLast++;
  if (RightBtmLast >= RightBtmLines.length) RightBtmLast = 0;
  for (i = 0; i < RightBtmMax; i++) {
    TR += RightBtmLines[n++] + '<br>';
    if (n >= RightBtmLines.length) n = 0;}
  RightBtmArea.innerHTML = TR;
  return;}
