var countDown = null;

function clockLoad()
{
    var now = new Date();
    var targetYear = now.getYear() - 100;
    //increment calendar year if later than July, or July and day greater than 4th
    if(now.getMonth()>6){++targetYear;}
    else
    {
        if((now.getMonth()==6)&&(now.getDate()>4)){++targetYear;}
    }
    if (document.getElementById)
    {
        countDown = document.getElementById('countDown');
        if(countDown)
        {
            countdown(targetYear, 6, 4, 21, 15, 1);
        }        
    }
}

function countdown(year, month, day, hour, minute, format)
{
    if(countDown)
    {
         Today = new Date();
         Todays_Year = Today.getYear() -100;
         //Todays_Month = Today.getMonth() + 1;                  
         Todays_Month = Today.getMonth();
         
         //Convert both today's date and the target date into miliseconds.                           
         Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(),Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
         Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();                  
         
         //Find their difference, and convert that into seconds.                  
         Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
         if(Time_Left < 0) { Time_Left = 0};
         
         switch(format)
         {
            case 0:
                //The simplest way to display the time left.
                countDown.innerHTML = Time_Left + ' seconds';
                break;
            case 1:
                //More detailed.
                days = Math.floor(Time_Left / (60 * 60 * 24));
                Time_Left %= (60 * 60 * 24);
                hours = Math.floor(Time_Left / (60 * 60));
                Time_Left %= (60 * 60);
                minutes = Math.floor(Time_Left / 60);
                Time_Left %= 60;
                seconds = Time_Left;
                
                
                strCountdown = '<table><tr><th>Days</th><th>Hours</th><th>Mins</th><th>Secs</th></tr><tr>';
                strCountdown += '<td>' + days + '</td>';
                strCountdown += '<td>' + hours + '</td>';
                strCountdown += '<td>' + minutes + '</td>';
                strCountdown += '<td>' + seconds + '</td>';
                strCountdown += '</tr></table>';
                countDown.innerHTML = strCountdown;
                break;
            default: 
                //document.all.countdown.innerHTML = Time_Left + ' seconds';
                countDown.innerHTML = Time_Left + ' seconds';
         }
               
         //Recursive call, keeps the clock ticking.
         setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
    }
}