obj_hours=document.getElementById("hours");
obj_ctoday=document.getElementById("ctoday");
name_month=new Array ("января","февраля","марта", "апреля","мая", "июня","июля","августа","сентября", "октября","ноября","декабря");
name_day=new Array ("воскресенье","понедельник", "вторник","среда","четверг", "пятница","суббота");

function wr_hours()
{
time=new Date();
time_sec=time.getSeconds()+1;
time_min=time.getMinutes();
time_hours=time.getHours();
time_wr="<b>"+((time_hours<10)?"0":"")+time_hours;
time_wr+=":";
time_wr+=((time_min<10)?"0":"")+time_min;
time_wr+=":";
time_wr+=((time_sec<10)?"0":"")+(time_sec)+"</b>";
time_wr=obj_hours.innerHTML=time_wr;
}
  wr_hours();
  setInterval("wr_hours();",1000);

function wr_today()
{
time=new Date();
time_td="<b>Сегодня <br>"+time.getDate()+" "+name_month[time.getMonth()]+" "+time.getFullYear()+" г.</b>";
time_td=obj_ctoday.innerHTML=time_td;
}
  wr_today();
  setInterval("wr_today();",1000);


BackColor = "white";
ForeColor = "black";
CountActive = true;
LeadingZero = true;
FinishMessage = "";

function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero && s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBack() {
tM = (((time.getMonth()+1)<10)?"0":"")+(time.getMonth()+1); 
tD = ((time.getDate()<10)?"0":"")+time.getDate();
tY = time.getFullYear(); 
if ((time.getDay() == 0) || (time.getDay() == 6))
  {
  tT = " 08:00 PM";
  tW = " 20:00";
  }
else
  {
  tT = " 10:00 PM";
  tW = " 22:00";
  }
if ((time_hours >= 10) && (time_hours < 22))
  {
    TargetDate = tM +"/"+ tD +"/"+  tY + tT;
    CountStepper = -1;
    DisplayFormat = "Сегодня мы работаем до"+tW+"<br>до закрытия %%H%%:%%M%%:%%S%%";
  }

if (time_hours < 10)
  {
    TargetDate = tM +"/"+ tD +"/"+  tY +" 10:00 AM";
    CountStepper = -1;
    DisplayFormat = "Мы работаем с 10:00<br>до открытия %%H%%:%%M%%:%%S%%";
  }
if (time_hours >= 22)
  {
    TargetDate = tM +"/"+ (tD+1) +"/"+  tY +" 10:00 AM";
    CountStepper = -1;
    DisplayFormat = "Мы работаем с 10:00<br>до открытия %%H%%:%%M%%:%%S%%";
  }

CountStepper = Math.ceil(CountStepper);
var dthen = new Date(TargetDate);
var dnow = new Date();
if(CountStepper>0)
  ddiff = new Date(dnow-dthen);
else
  ddiff = new Date(dthen-dnow);
secs = Math.floor(ddiff.valueOf()/1000);

  DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

  document.getElementById("cntdwn").innerHTML = DisplayStr;
}

if (typeof(BackColor)=="undefined")
  BackColor = "white";
if (typeof(ForeColor)=="undefined")
  ForeColor= "black";
if (typeof(TargetDate)=="undefined")
  TargetDate = "12/31/2020 5:00 AM";
if (typeof(DisplayFormat)=="undefined")
  DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
if (typeof(CountActive)=="undefined")
  CountActive = true;
if (typeof(FinishMessage)=="undefined")
  FinishMessage = "";
if (typeof(CountStepper)!="number")
  CountStepper = -1;
if (typeof(LeadingZero)=="undefined")
  LeadingZero = true;


CountBack();
setInterval("CountBack();",1000);
