﻿var CDmonth = '10'; // 1 through 12 or '*' within the next month, '0' for the current month
var CDday = '6';   // day of month or + day offset
var CDdow = 0;     // day of week sun=1 sat=7 or 0 for whatever day it falls on
var CDhour = 11;    // 0 through 23 for the hour of the day
var CDtz = -4;     // offset in hours from UTC to your timezone
var CDlab = 'CDHolder';  // id of the entry on the page where the counter is to be inserted

function CDstart() 
{
    displayCountdown(setCountdown(CDmonth,CDday,CDhour,CDtz),CDlab);
}
CDloaded(CDlab,CDstart);


var CDpageLoaded = 0; 
//window.onload = function() {CDpageLoaded = 1;}
function CDloaded(CDi,CDf) 
{
    if (document.getElementById && document.getElementById(CDi) != null)
         CDf(); 
    else if (!CDpageLoaded) 
        setTimeout('CDloaded(\''+CDi+'\','+CDf+')',100);
}
function setCountdown(CDmonth,CDday,CDhour,CDtz) 
{
    var CDmm = CDmonth; if (CDmonth=='*') CDmm = 0;
    var CDcc = setC(CDmm,CDday,CDhour,CDtz); 
    if (CDmonth == '*' && CDcc < 0)  
        CDcc = setC('*',CDday,CDhour,CDtz); 
        return CDcc;
} 
function setC(CDmonth,CDday,CDhour,CDtz)
{
 var toDate = new Date();
 if (CDday.substr(0,1) == '+') 
 {
    var day1 = parseInt(CDday.substr(1));
    toDate.setDate(toDate.getDate()+day1);
  } 
  else
  {
    toDate.setDate(CDday);
  }
  if (CDmonth == '*')toDate.setMonth(toDate.getMonth() + 1);
  else if (CDmonth > 0) 
  { 
    if (CDmonth <= toDate.getMonth())toDate.setFullYear(toDate.getFullYear() + 1);
    toDate.setMonth(CDmonth-1);
  }
    if (CDdow >0) 
    toDate.setDate(toDate.getDate()+(CDdow-1-toDate.getDay())%7);
    
    toDate.setHours(CDhour);toDate.setMinutes(0-(CDtz*60));
    toDate.setSeconds(0);
    var fromDate = new Date();
    fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
    var diffDate = new Date(0);diffDate.setMilliseconds(toDate - fromDate);
    return Math.floor(diffDate.valueOf()/1000);
}
function displayCountdown(countdn,CDHolder) 
{
    if (countdn < 0) document.getElementById(CDHolder).innerHTML = "<font color='#4080b6'>The air show is here!.</font>"; 
    else 
    {
    var secs = countdn % 60;
     if (secs < 10) secs = '0'+secs;var countdn1 = (countdn - secs) / 60;
     var mins = countdn1 % 60; 
     if (mins < 10) mins = '0'+mins;countdn1 = (countdn1 - mins) / 60;var hours = countdn1 % 24;
     var days = (countdn1 - hours) / 24;
     document.getElementById(CDHolder).innerHTML = '<font color="#4080b6">&nbsp;' + days+' &nbsp;&nbsp;:&nbsp; '+hours+' &nbsp;:&nbsp;&nbsp; '+mins+' &nbsp;&nbsp;:&nbsp; '+secs+ '&nbsp;</font>';setTimeout('displayCountdown('+(countdn-1)+',\''+CDHolder+'\');',999) ;
     }
 }
