/*
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">
TargetDate1 = "12/31/2020 5:00 AM";
BackColor1 = "palegreen";
ForeColor1 = "navy";
CountActive1 = true;
CountStepper1 = -1;
LeadingZero1 = true;
DisplayFormat1 = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage1 = "It is finally here!";
</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 (LeadingZero1 && s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBack(secs) {
  if (secs < 0) {
    document.getElementById("cntdwn1").innerHTML = FinishMessage1;
    return;
  }
  DisplayStr = DisplayFormat1.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("cntdwn1").innerHTML = DisplayStr;
  if (CountActive1)
    setTimeout("CountBack(" + (secs+CountStepper1) + ")", SetTimeOutPeriod);
}

function putspan(backcolor, forecolor) {
 document.write("<span id='cntdwn1' style='background-color:" + backcolor + 
                "; color:" + forecolor + "'></span>");
}

if (typeof(BackColor1)=="undefined")
  BackColor1 = "white";
if (typeof(ForeColor1)=="undefined")
  ForeColor1= "black";
if (typeof(TargetDate1)=="undefined")
  TargetDate1 = "12/31/2020 5:00 AM";
if (typeof(DisplayFormat1)=="undefined")
  DisplayFormat1 = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
if (typeof(CountActive1)=="undefined")
  CountActive1 = true;
if (typeof(FinishMessage1)=="undefined")
  FinishMessage1 = "";
if (typeof(CountStepper1)!="number")
  CountStepper1 = -1;
if (typeof(LeadingZero1)=="undefined")
  LeadingZero1 = true;


CountStepper1 = Math.ceil(CountStepper1);
if (CountStepper1 == 0)
  CountActive1 = false;
var SetTimeOutPeriod = (Math.abs(CountStepper1)-1)*1000 + 990;
putspan(BackColor1, ForeColor1);
var dthen = new Date(TargetDate1);
var dnow = new Date();
if(CountStepper1>0)
  ddiff = new Date(dnow-dthen);
else
  ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
CountBack(gsecs);
