function cdLocalTime(container, servermode, offsetMinutes, targetdate, debugmode){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
var servertimestring=(servermode=="server-php")? 'July 02, 2009 20:23:04' : (servermode=="server-ssi")? '' : '<%= Now() %>'
this.localtime=this.serverdate=new Date(servertimestring)
this.targetdate=new Date(targetdate)
this.debugmode=(typeof debugmode!="undefined")? 1 : 0
this.timesup=false
this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time
this.updateTime()
}
cdLocalTime.prototype.updateTime=function(){
var thisobj=this
this.localtime.setMilliseconds(this.localtime.getMilliseconds()+25)
setTimeout(function(){thisobj.updateTime()}, 25) //update time every second
}
cdLocalTime.prototype.displaycountdown=function(baseunit, functionref){
this.baseunit=baseunit
this.formatresults=functionref
this.showresults()
}
cdLocalTime.prototype.showresults=function(){
var thisobj=this
var debugstring=(this.debugmode)? "
Debug Mode on!
Current Local time: "+this.localtime.toLocaleString()+"
Verify this is the correct current local time, in other words, time zone of count down date.
Target Time: "+this.targetdate.toLocaleString()+"
Verify this is the date/time you wish to count down to (should be a future date).
" : ""
var timediff=(this.targetdate-this.localtime) //difference btw target date and current date, in seconds
if (timediff<0){ //if time is up
this.timesup=true
this.container.innerHTML=debugstring+this.formatresults()
return
}
var oneSecond=1000
var oneMinute=60*oneSecond //minute unit in seconds
var oneHour=60*oneMinute //hour unit in seconds
var oneDay=24*oneHour //day unit in seconds
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute)/oneSecond)
var millisfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute-secondfield*oneSecond))
if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
hourfield=dayfield*24+hourfield
dayfield="n/a"
}
else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield
dayfield=hourfield="n/a"
}
else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
var secondfield=timediff
dayfield=hourfield=minutefield="n/a"
}
if (dayfield <= 9) {
dayfield = "0" + dayfield
}
if (hourfield <= 9) {
hourfield = "0" + hourfield
}
if (minutefield <= 9) {
minutefield = "0" + minutefield
}
if (secondfield <= 9) {
secondfield = "0" + secondfield
}
if (millisfield <= 9) {
millisfield = "00" + millisfield
} else if (millisfield <=99) {
millisfield = "0" + millisfield
}
this.container.innerHTML=debugstring+this.formatresults(dayfield, hourfield, minutefield, secondfield, millisfield)
setTimeout(function(){thisobj.showresults()}, 25) //update results every second
}
function formatresults(){
if (this.timesup==false){ //if target date/time not yet met
var displaystring="Countdown | "+arguments[0]+":"+arguments[1]+":"+arguments[2]+":"+arguments[3]+":"+arguments[4]+".
"
}
else{ //else if target date/time met
var displaystring="" //Don't display any text
alert("Outta here!") //Instead, perform a custom alert
}
return displaystring
}