var dow1=["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
var dow2=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
var month2name1=["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
var month2name2=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

function showTime(container, offset, format, gmtstring) {
  if (document.getElementById && document.getElementById(container)) {
    this.container=document.getElementById(container)
    this.format=format
    this.timer=this.gmdate=new Date(gmtstring)
    this.timer.setTime(this.gmdate.getTime() + offset*1000)
    this.updateTime()
  }
}

showTime.prototype.updateTime = function() {
  var this2 = this
  var year = this.timer.getFullYear()
  var month = this.timer.getMonth()
  var daymonth = this.timer.getDate()
  var day = this.timer.getDay()
  var hr = this.timer.getHours()
  var min = this.timer.getMinutes()
  var sec = this.timer.getSeconds()
  
  this.timer.setSeconds(this.timer.getSeconds()+1)
  if (this.format=="full")
    this.container.innerHTML=this.timer.toLocaleString()
  else if (this.format == "time")
    this.container.innerHTML = (hr%12 ? hr%12 : 12) + ":" + ((min <= 9)? "0"+min : min) + ":" + ((sec <= 9)? "0"+sec : sec) + " " + ((hr >= 12) ? "pm" : "am")
  else if (this.format == "date")
    this.container.innerHTML = dow2[day] + ", " + month2name2[month] + " " + daymonth + ", " + year
  else if (this.format == "UTC")
    this.container.innerHTML = year+"-"+((month+1)<10 ? "0"+(month+1) : (month+1))+"-"+(daymonth<10 ? "0" : "")+daymonth+"T"+ ((hr <= 9)? "0"+hr : hr) +":"+((min <= 9)? "0"+min : min) + ":" + ((sec <= 9)? "0"+sec : sec)
  else
    this.container.innerHTML = dow1[day] + ", " + (hr%12 ? hr%12 : 12) + ":" + ((min <= 9)? "0"+min : min) + ":" + ((sec <= 9)? "0"+sec : sec) + ((hr >= 12) ? "pm" : "am")
  setTimeout(function() {this2.updateTime()}, 1000)
}

function refresher(delay)
{
    setTimeout( "refresh()", delay*1000 );
}

function refresh()
{
    window.location.reload();
}