/***********************************************
* Dynamic 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 cdtime(container, targetdate){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.currentTime=new Date()
this.targetdate=new Date(targetdate)
this.timesup=false
this.updateTime()
}

cdtime.prototype.updateTime=function(){
var thisobj=this
this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

cdtime.prototype.displaycountdown=function(baseunit, functionref){
this.baseunit=baseunit
this.formatresults=functionref
this.showresults()
}

cdtime.prototype.showresults=function(){
var thisobj=this


var timediff=(this.targetdate-this.currentTime)/1000 //difference btw target date and current date, in seconds
if (timediff<0){ //if time is up
this.timesup=true
this.container.innerHTML=this.formatresults()
return
}
var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in seconds
var oneWeek=60*60*24*7 //week unit in seconds
var weekfield=Math.floor(timediff/oneWeek)
var dayfield=Math.floor((timediff-weekfield*oneWeek)/oneDay)
var hourfield=Math.floor((timediff-weekfield*oneWeek-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-weekfield*oneWeek-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-weekfield*oneWeek-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
if (this.baseunit=="days"){ //if base unit is days, set "dayfield" to be topmost level
dayfield=weekfield*7+dayfield
weekfield="n/a"
}
else 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"
}
this.container.innerHTML=this.formatresults(weekfield, dayfield, hourfield, minutefield, secondfield)
setTimeout(function(){thisobj.showresults()}, 1000) //update results every second
}

/////CUSTOM FORMAT OUTPUT FUNCTIONS BELOW//////////////////////////////

//Create your own custom format function to pass into cdtime.displaycountdown()
//Use arguments[0] to access "Weeks" left
//Use arguments[1] to access "Days" left
//Use arguments[2] to access "Hours" left
//Use arguments[3] to access "Minutes" left
//Use arguments[4] to access "Seconds" left

//The values of these arguments may change depending on the "baseunit" parameter of cdtime.displaycountdown()
//For example, if "baseunit" is set to "days", arguments[0] becomes meaningless and contains "n/a"
//For example, if "baseunit" is set to "hours", arguments[0] and arguments[1] become meaningless etc


function formatresults(){
if (this.timesup==false){//if target date/time not yet met
var displaystring=arguments[0]+" weeks "+arguments[1]+" days "+arguments[2]+" hours "+arguments[3]+" minutes "+arguments[4]+" seconds left until March 23, 2009 18:25:00"
}
else{ //else if target date/time met
var displaystring="Future date is here!"
}
return displaystring
}

function formatresults2(){
if (this.timesup==false){ //if target date/time not yet met
var displaystring="<span class='lcdstyle'>"+arguments[0]+" <sup>weeks</sup> "+arguments[1]+" <sup>days</sup> "+arguments[2]+" <sup>hours</sup> "+arguments[3]+" <sup>minutes</sup> "+arguments[4]+" <sup>seconds</sup></span> left until this Christmas"
}
else{ //else if target date/time met
var displaystring="" //Don't display any text
alert("Christmas is here!") //Instead, perform a custom alert
}
return displaystring
}

function formatowwsummaryresults(){
if (this.timesup==false){ //if target date/time not yet met
    if (arguments[0] != 'n/a' && arguments[0] != '1' && arguments[0] != '0'){
        displaystring='- only <span style="color:red">'+arguments[0]+' weeks</span> to go';
    }
    else if (arguments[0] != 'n/a' && arguments[0] == '1'){
        displaystring='- only <span style="color:red">1 week</span> to go';
    }
    else if (arguments[1] != 'n/a' && arguments[1] != '1' && arguments[1] != '0'){
        displaystring='- only <span style="color:red">'+arguments[1]+' days</span> to go';
    }
    else{
        displaystring='- only <span style="color:red">1 day</span> to go';
    }
}
else{ //else if target date/time met
var displaystring="" //Don't display any text
}
return displaystring
}

function formatowwfullresults(){
if (this.timesup==false){ //if target date/time not yet met
var displaystring="<span class='owwlcdstyle'>Only <span class='owwlcdstyle_purple'>"+arguments[1]+"</span> days <span class='owwlcdstyle_purple'>"+arguments[2]+"</span> hrs <span class='owwlcdstyle_purple'>"+arguments[3]+"</span> mins <span class='owwlcdstyle_purple'>"+arguments[4]+"</span> secs to go until</span>"
}
else{ //else if target date/time met
var displaystring="" //Don't display any text
}
return displaystring
}

var monthsArray=new Array();
monthsArray[01]="January";
monthsArray[02]="February";
monthsArray[03]="March";
monthsArray[04]="April";
monthsArray[05]="May";
monthsArray[06]="June";
monthsArray[07]="July";
monthsArray[08]="August";
monthsArray[09]="September";
monthsArray[10]="October";
monthsArray[11]="November";
monthsArray[12]="December";
