// Countdown v3.0 // (c) Copyright 2009-10 Gecko Tribe, LLC // by Antone Roundy // http://WhiteHatCrew.com/web-script-collection/ function CountdownPad(n) { return ((n<10)?'0':'')+n; } function DoCountdownHideShow(ids) { var t,i,s,e; if (ids.length) { t=ids.split(','); for (i=t.length-1;i>=0;i--) { s=t[i].split(':'); if ((s.length==2)&&(e=document.getElementById(s[1]))) e.style.display=s[0]; } } } function DoCountdown(which) { if (Countdowns[which][1][0]||(Countdowns[which][1][0]=document.getElementById(Countdowns[which][0][0]))) { var t=new Date(); var d=parseInt(Countdowns[which][1][1]-(t.getTime()/1000)); var rv=Countdowns[which][0][2]; if (d>0) { var days=parseInt(d/86400); var hours=parseInt((d%86400)/3600); var minutes=parseInt((d%3600)/60); var seconds=d%60; rv=Countdowns[which][0][1].replace(/%D%/g,CountdownPad(days)); rv=rv.replace(/%d%/g,days); rv=rv.replace(/%H%/g,CountdownPad(hours)); rv=rv.replace(/%h%/g,hours); rv=rv.replace(/%M%/g,CountdownPad(minutes)); rv=rv.replace(/%m%/g,minutes); rv=rv.replace(/%S%/g,CountdownPad(seconds)); rv=rv.replace(/%s%/g,seconds); } else { clearInterval(Countdowns[which][1][2]); Countdowns[which][1][2]=0; DoCountdownHideShow(Countdowns[which][0][4]); if (Countdowns[which][0][3].length) setTimeout(Countdowns[which][0][3],10); } Countdowns[which][1][0].innerHTML=rv; } } function StartCountdown(id, expired, trigger, endtime, hideshow) { Countdowns[CountdownCount]=new Array( new Array(id,(typeof CountdownFormat!=='undefined')?CountdownFormat:'%D%:%H%:%M%:%S%',expired,trigger,hideshow), new Array(0,endtime+(CountdownTheDate.getTime()/1000)-1714525284,setInterval('DoCountdown('+CountdownCount+')',1000)) ); CountdownCount++; return CountdownCount-1; } function CancelCountdown(which,asIfEnded,endMessage) { if (Countdowns[which][1][2]) { clearInterval(Countdowns[which][1][2]); Countdowns[which][1][2]=0; if (asIfEnded) { DoCountdownHideShow(Countdowns[which][0][4]); Countdowns[which][1][0].innerHTML=(asIfEnded==1)?Countdowns[which][0][2]:endMessage; if (Countdowns[which][0][3].length) setTimeout(Countdowns[which][0][3],10); } } Countdowns[which]=''; if (which==(CountdownCount-1)) while (CountdownCount&&(Countdowns[CountdownCount-1]=='')) CountdownCount--; } var CountdownCount=0; var Countdowns=new Array(new Array( new Array(0,0,0), new Array('','%D%:%H%:%M%:%S%','','','') )); var CountdownTheDate=new Date; if (typeof(CountdownEndTime)!=='undefined') { StartCountdown( (typeof(CountdownID)==='undefined')?'countdown':CountdownID, // timer id (typeof(CountdownExpired)==='undefined')?'...offer expired':CountdownExpired, // finished message (typeof(CountdownTrigger)==='undefined')?'':CountdownTrigger, // function to run at expiration CountdownEndTime, (typeof(CountdownHideShow)==='undefined')?'':CountdownHideShow // IDs of elements to show when time ends ); }