var week = Array("Sunday", "Monday", "Tuesday", "Wednseday", "Thirsday", "Friday", "Saturday")
var mnth = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")

function Clock() {
  var time = new Date()
  var hour = time.getHours()
  var minute = time.getMinutes()
  var second = time.getSeconds()
  var now = new srvClock(time.getDate() + "." + time.getMonth() + "." + time.getFullYear() + "." + time.getDay())

////// для NN //////
//  srvClock.call(this,time.getDate() + "." + time.getMonth() + "." + time.getFullYear() + "." + time.getDay())

  for (var i in now) {this[i] = now[i]}
  
  if (hour < 10) hour = "0" + hour
  if (minute < 10) minute = "0" + minute
  if (second < 10) second = "0" + second
  
  this.hour = hour
  this.minute = minute
  this.second = second
  
  this.fullTime = hour + ":" + minute
}

function srvClock(fDate) {
  this.date = eval(fDate.split(".")[0])
  this.month = eval(fDate.split(".")[1]) + 1
  this.monthW = mnth[this.month-1]
  this.year = eval(fDate.split(".")[2])
  
  if (arguments.length>3) this.day = week[eval(fDate.split(".")[3])]
    else this.day = week[new Date(this.year,this.month-1,this.date).getDay()]

  this.fullDateW = (this.date[0]=="0" ? this.date.substring(1,this.date.length) : this.date) + " " + this.monthW + " " + this.year + ", " + this.day
  
  yestDate(this.date,this.month,this.year)
  this.dateYst = dYst
  this.monthYst = mYst
  this.yearYst = yYst
  
  yestDate(this.dateYst,this.monthYst,this.yearYst)
  this.yearBefYst = yYst
  this.monthBefYst = mYst
  this.dateBefYst = dYst
  
  this.fullDate = ((this.date < 10) ? "0" + this.date : this.date) + "." + ((this.month < 10) ? "0" + this.month : this.month) + "." + this.year
  this.fullYesterday = ((this.dateYst < 10) ? "0" + this.dateYst : this.dateYst) + "." + ((this.monthYst < 10) ? "0" + this.monthYst : this.monthYst) + "." + this.yearYst
  this.fullBefYesterday = ((this.dateBefYst < 10) ? "0" + this.dateBefYst : this.dateBefYst) + "." + ((this.monthBefYst < 10) ? "0" + this.monthBefYst : this.monthBefYst) + "." + this.yearBefYst
}

function yestDate(d,m,y) {
  yYst = y
  mYst = m
  dYst = d - 1
  if (dYst == 0) {
    mYst = mYst - 1
    if (mYst == 0) {
      mYst = 12
      yYst = yYst - 1
    }
    dYst = lastDate(mYst, yYst)
  }
}

function lastDate(mnth,yr) {
  switch (mnth) {
    case 1:
      return 31
      break
    case 2:
      if (parseInt(yr/4) == yr/4) return 29
        else return 28
      break
    case 3:
      return 31
      break
    case 4:
      return 30
      break
    case 5:
      return 31
      break
    case 6:
      return 30
      break
    case 7:
      return 31
      break
    case 8:
      return 31
      break
    case 9:
      return 30
      break
    case 10:
      return 31
      break
    case 11:
      return 30
      break
    case 12:
      return 31
      break
  }
}
