<script type="text/javascript">
function DaysHMSCounter(initDate, id){
this.counterDate = new Date(initDate);
this.container = document.getElementById(id);
this.update();
}
DaysHMSCounter.prototype.calculateUnit=function(secDiff, unitSeconds){
var tmp = Math.abs((tmp = secDiff/unitSeconds)) < 1? 0 : tmp;
return Math.abs(tmp < 0 ? Math.ceil(tmp) : Math.floor(tmp));
}
DaysHMSCounter.prototype.calculate=function(){
var secDiff = Math.abs(Math.round(((new Date()) - this.counterDate)/1000));
this.days = this.calculateUnit(secDiff,86400);
this.hours = this.calculateUnit((secDiff-(this.days*86400)),3600);
this.mins = this.calculateUnit((secDiff-(this.days*86400)-(this.hours*3600)),60);
this.secs = this.calculateUnit((secDiff-(this.days*86400)-(this.hours*3600)-(this.mins*60)),1);
}
DaysHMSCounter.prototype.update=function(){
this.calculate();
this.container.innerHTML =
" " + this.days + " " + (this.days == 1? "day" : "days") +
" " + this.hours + " " + (this.hours == 1? "hour" : "hours") +
" " + this.mins + " " + (this.mins == 1? "min" : "mins") +
" " + this.secs + " " + (this.secs == 1? "sec" : "secs");
var self = this;
setTimeout(function(){self.update();}, (1000));
}
window.onload=function(){ new DaysHMSCounter('January 01, 2013 00:00:00', 'counter'); }
</script>