/*
Author: Robert Hashemian
http://www.hashemian.com/

You can use this code in any manner so long as the author's
name, Web address and this disclaimer is kept intact.
********************************************************
Usage Sample:

<script language="JavaScript">
TargetDate = "12/31/2020 5:00 AM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "Airplane Day";
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>
*/

function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero && s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBack(secs) {
  if (secs < 0) {
    document.getElementById("clockDiv").innerHTML = FinishMessage;
    return;
  }
  DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

  document.getElementById("clockDiv").innerHTML = DisplayStr;
  if (CountActive)
    setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
}

function calcage2(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero2 && s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBack2(secs) {
  if (secs < 0) {
    document.getElementById("clockDiv2").innerHTML = FinishMessage2;
    return;
  }
  DisplayStr = DisplayFormat2.replace(/%%D%%/g, calcage2(secs,86400,100000));
  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage2(secs,3600,24));
  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage2(secs,60,60));
  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage2(secs,1,60));

  document.getElementById("clockDiv2").innerHTML = DisplayStr;
  if (CountActive2)
    setTimeout("CountBack2(" + (secs+CountStepper2) + ")", SetTimeOutPeriod);
}

function putspan(backcolor, forecolor) {
 document.write("<span id='cntdwn' style='background-color:" + backcolor + 
                "; color:" + forecolor + "'></span>");
}

function calcage3(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero3 && s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBack3(secs) {
  if (secs < 0) {
    document.getElementById("clockDiv3").innerHTML = FinishMessage3;
    return;
  }
  DisplayStr = DisplayFormat3.replace(/%%D%%/g, calcage3(secs,86400,100000));
  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage3(secs,3600,24));
  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage3(secs,60,60));
  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage3(secs,1,60));

  document.getElementById("clockDiv3").innerHTML = DisplayStr;
  if (CountActive3)
    setTimeout("CountBack3(" + (secs+CountStepper3) + ")", SetTimeOutPeriod);
}

function putspan(backcolor, forecolor) {
 document.write("<span id='cntdwn' style='background-color:" + backcolor + 
                "; color:" + forecolor + "'></span>");
}
if (typeof(BackColor)=="undefined")
  BackColor = "white";
if (typeof(ForeColor)=="undefined")
  ForeColor= "black";
if (typeof(TargetDate)=="undefined")
  TargetDate = "12/31/2020 5:00 AM";
if (typeof(DisplayFormat)=="undefined")
  DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
if (typeof(CountActive)=="undefined")
  CountActive = true;
if (typeof(FinishMessage)=="undefined")
  FinishMessage = "";
if (typeof(CountStepper)!="number")
  CountStepper = -1;
if (typeof(LeadingZero)=="undefined")
  LeadingZero = true;


CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0)
  CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
putspan(BackColor, ForeColor);
var dthen = new Date(TargetDate);
var dnow = new Date();
if(CountStepper>0)
  ddiff = new Date(dnow-dthen);
else
  ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
CountBack(gsecs);



if (typeof(BackColor2)=="undefined")
  BackColor2 = "white";
if (typeof(ForeColor2)=="undefined")
  ForeColor2= "black";
if (typeof(TargetDate2)=="undefined")
  TargetDate2 = "12/31/2020 5:00 AM";
if (typeof(DisplayFormat2)=="undefined")
  DisplayFormat2 = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
if (typeof(CountActive2)=="undefined")
  CountActive2 = true;
if (typeof(FinishMessage2)=="undefined")
  FinishMessage2 = "";
if (typeof(CountStepper2)!="number")
  CountStepper2 = -1;
if (typeof(LeadingZero2)=="undefined")
  LeadingZero2 = true;

CountStepper2 = Math.ceil(CountStepper2);
if (CountStepper2 == 0)
  CountActive2 = false;
var SetTimeOutPeriod2 = (Math.abs(CountStepper2)-1)*1000 + 990;
putspan(BackColor2, ForeColor2);
var dthen2 = new Date(TargetDate2);
var dnow2 = new Date();
if(CountStepper2 > 0)
  ddiff2 = new Date(dnow2-dthen2);
else
  ddiff2 = new Date(dthen2-dnow2);
gsecs2 = Math.floor(ddiff2.valueOf()/1000);
CountBack2(gsecs2);



if (typeof(BackColor3)=="undefined")
  BackColor3 = "white";
if (typeof(ForeColor3)=="undefined")
  ForeColor3= "black";
if (typeof(TargetDate3)=="undefined")
  TargetDate3 = "13/31/3030 5:00 AM";
if (typeof(DisplayFormat3)=="undefined")
  DisplayFormat3 = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
if (typeof(CountActive3)=="undefined")
  CountActive3 = true;
if (typeof(FinishMessage3)=="undefined")
  FinishMessage3 = "";
if (typeof(CountStepper3)!="number")
  CountStepper3 = -1;
if (typeof(LeadingZero3)=="undefined")
  LeadingZero3 = true;

CountStepper3 = Math.ceil(CountStepper3);
if (CountStepper3 == 0)
  CountActive3 = false;
var SetTimeOutPeriod3 = (Math.abs(CountStepper3)-1)*1000 + 990;
putspan(BackColor3, ForeColor3);
var dthen3 = new Date(TargetDate3);
var dnow3 = new Date();
if(CountStepper3 > 0)
  ddiff3 = new Date(dnow3-dthen3);
else
  ddiff3 = new Date(dthen3-dnow3);
gsecs3 = Math.floor(ddiff3.valueOf()/1000);
CountBack3(gsecs3);


