var LiveClock
var LCd
var LCmon
var LCy
var LCs
var LCmin
var LCh
var arrMonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
// To use the time from the server, set LiveClockDate on the calling page.
var LiveClockDate = new Date()
function getDateAndTime(){
  // DATE
  LCd = twoDigitClock(LiveClockDate.getDate())
  LCmon = arrMonth[LiveClockDate.getMonth()]
  LCy = LiveClockDate.getYear()
  if(LCy < 1000) LCy += 1000
  // TIME
  LCs = twoDigitClock(LiveClockDate.getSeconds())
  LCmin = twoDigitClock(LiveClockDate.getMinutes())
  LCh = twoDigitClock(LiveClockDate.getHours())
  
  LiveClockDate.setMilliseconds(LiveClockDate.getMilliseconds() + 1000)
  try{
    document.all.LiveClock.innerText = LCd+" "+LCmon+" "+LCy+" - "+LCh+":"+LCmin+":"+LCs
  }catch(JSErrorMessage) {} // Error occurs when the file download box pops up.
}
function twoDigitClock(value){
  if(value < 10) return "0"+ value;
  else return value;
}
function startTheClock() { 
  if(document.all.LiveClock){
    LiveClock = setInterval("getDateAndTime()", 1000)
    if(Math.round(Math.random()*500) == 0) setTimeout("dateCheck()", (Math.round(Math.random()*30000)))
    //document.all.LiveClock.attachEvent("oncontextmenu", dateCheck)
  }
}
function stopTheClock() { clearInterval(LiveClock) }
function dateCheck() {
  clearInterval(LiveClock)
  document.all.LiveClock.innerText = getLCMessage()
  LiveClock = setInterval("getDateAndTime()", 1000)
  return false;
}

// ------ IGNORE THIS RUBBISH ------
function getLCMessage(){
  l = Math.round(Math.random() * 5)
  if(LCCoolDates[l] != undefined){
    ld = new Date(LCCoolDates[l].year,LCCoolDates[l].month,LCCoolDates[l].day)
    if(LCCoolDates[l].comp == "years") t = LCyearsaway(ld)
    if(LCCoolDates[l].comp == "days")  t = LCdaysaway(ld)
    if(t == 0 && LCCoolDates[l].comp == "days") return "Its "+ LCCoolDates[l].msg +" today!!"
    if(t < 0) return "Its been "+ -t +" "+ LCCoolDates[l].comp +" since "+ LCCoolDates[l].msg +"!!"
    else return "Only "+ t +" "+ LCCoolDates[l].comp +" to go until "+ LCCoolDates[l].msg +"!!"
  }
  return LCd+" "+LCmon+" "+LCy+" - "+LCh+":"+LCmin+":"+LCs
}
function LCDate(day,month,year,comp,msg){ this.day=day; this.month=month; this.year=year; this.comp=comp; this.msg=msg }
function LCList() {}
function LCdaysaway(when){ return Math.round((when.getTime()-LiveClockDate.getTime())/86400000) }
function LCyearsaway(when){ return Math.floor((when.getTime()-LiveClockDate.getTime())/31536000000)+1 }
LCCoolDates=new LCList()
LCCoolDates[0]=new LCDate(25,11,LiveClockDate.getYear(),"days","Christmas")
LCCoolDates[1]=new LCDate(1,0,LiveClockDate.getYear()+1,"days","New Years Day")
LCCoolDates[2]=new LCDate(LiveClockDate.getDay(),LiveClockDate.getMonth(),LiveClockDate.getYear(),"years","just another day at the office")
LCCoolDates[3]=new LCDate(1,1,2000,"days","the Millenium")
LCCoolDates[4]=new LCDate(30,6,1966,"years","England won the world cup")
LCCoolDates[5]=new LCDate(5,10,LiveClockDate.getYear()+1,"days","Bonfire night")
