﻿var aDoW = new Array("Воскресенье","Понедельник","Вторник","Среда","Четверг","Пятница","Суббота");
var tTimeShift = new Date();
var iStartDay = 0;

function startClock(sServTime)
{
    tTimeShift = new Date();
    //tServTime = new Date(sServTime);
    tServTime = new Date();
    iStartDay = tServTime.getDay();
    tTimeShift.setTime(tTimeShift.getTime() - tServTime.getTime());
    ClockEvent();
}

function ClockEvent()
{
    var tCurrTime = new Date();
    tCurrTime.setTime(tCurrTime.getTime() - tTimeShift.getTime());
    if(document.getElementById("time"))
      if(tCurrTime.getDay() != iStartDay || 1 == 1){
          document.getElementById("day").innerHTML = aDoW[tCurrTime.getDay()];
          document.getElementById("date").innerHTML = 
              normNum(tCurrTime.getDate()) + "." 
              + normNum(tCurrTime.getMonth() + 1) + "." 
              + tCurrTime.getFullYear().toString() 
              + " <span>" 
              + normNum(tCurrTime.getHours()) + ":"
              + normNum(tCurrTime.getMinutes())
              + ", Москва</span>";
      }else
          document.getElementById("time").innerHTML = 
             normNum(tCurrTime.getHours()) + ":"
             + normNum(tCurrTime.getMinutes()) + ", Москва";
    setTimeout("ClockEvent()", 60000);
}

function normNum(iNum)
{
    sVal = iNum.toString();
    if(iNum < 10) sVal = "0" + sVal;
    return sVal;
}