/*********************************************** * Universal Countdown script- Dynamic Drive (http://www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit http://www.dynamicdrive.com/ for this script and 100s more. ***********************************************/ function cdLocalTime(container, servermode, offsetMinutes, targetdate, debugmode){ if (!document.getElementById || !document.getElementById(container)){ return;} this.container=document.getElementById(container) var servertimestring=(servermode=="server-php")? 'February 22, 2012 18:26:03' : '<%= 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.setSeconds(this.localtime.getSeconds()+1); setTimeout(function(){thisobj.updateTime()}, 1000) ;//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=''; var timediff=(this.targetdate-this.localtime)/1000 if (timediff<0){ this.timesup=true; this.container.innerHTML=debugstring+this.formatresults(); return; } var oneMinute=60 ; var oneHour=60*60 ; var oneDay=60*60*24 ; 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)); if (this.baseunit=="days"){ hourfield=dayfield*24+hourfield ; dayfield="na"; } else if (this.baseunit=="minutes"){ minutefield=dayfield*24*60+hourfield*60+minutefield; dayfield=hourfield="na"; } else if (this.baseunit=="seconds"){ var secondfield= timediff; dayfield=hourfield=minutefield="na"; } this.container.innerHTML = debugstring+this.formatresults(dayfield, hourfield, minutefield, secondfield); setTimeout(function(){thisobj.showresults()}, 1000) ;//update results every second } //) Display countdown using plain text function formatresults(){ if (this.timesup==false){ var pad0 =''; var pad1 =''; var pad2 =''; var pad3 =''; if (arguments[0] < 10){pad0='0';} if (arguments[1] < 10){pad1='0';} if (arguments[2] < 10){pad2='0';} if (arguments[3] < 10){pad3='0';} var displaystring='Realtime pricing updates in
'+pad2+''+arguments[2]+':
'+pad3+''+arguments[3]+'
'; } else{ window.location = "/basket.php?rt=1"; var displaystring='Realtime price update'; } return displaystring; }