/*
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">
TargetDate2 = "12/31/2020 5:00 AM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper2 = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage2 = "It is finally here!";
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>
*/

function calcage2(secs2, num12, num22) {
  s2 = ((Math.floor(secs2/num12))%num22).toString();
  if (LeadingZero && s2.length < 2)
    s2 = "0" + s2;
  return "<b>" + s2 + "</b>";
}

function CountBack2(secs2) {
  if (secs2 < 0) {
    document.getElementById("cntdwn2").innerHTML = FinishMessage2;
    return;
  }
  DisplayStr2 = DisplayFormat.replace(/%%D%%/g, calcage2(secs2,86400,100000));
  DisplayStr2 = DisplayStr2.replace(/%%H%%/g, calcage2(secs2,3600,24));
  DisplayStr2 = DisplayStr2.replace(/%%M%%/g, calcage2(secs2,60,60));
  DisplayStr2 = DisplayStr2.replace(/%%S%%/g, calcage2(secs2,1,60));

  document.getElementById("cntdwn2").innerHTML = DisplayStr2;
  if (CountActive)
    setTimeout("CountBack2(" + (secs2+CountStepper2) + ")", SetTimeOutPeriod);
}

function putspan(backcolor, forecolor) {
 document.write("<span id='cntdwn2' style='background-color:" + backcolor + 
                "; color:" + forecolor + "'></span>");
}

if (typeof(BackColor)=="undefined")
  BackColor = "white";
if (typeof(ForeColor)=="undefined")
  ForeColor= "black";
if (typeof(TargetDate2)=="undefined")
  TargetDate2 = "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(FinishMessage2)=="undefined")
  FinishMessage2 = "";
if (typeof(CountStepper2)!="number")
  CountStepper2 = -1;
if (typeof(LeadingZero)=="undefined")
  LeadingZero = true;


CountStepper2 = Math.ceil(CountStepper2);
if (CountStepper2 == 0)
  CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper2)-1)*1000 + 990;
putspan(BackColor, ForeColor);
var dthen2 = new Date(TargetDate2);
var dnow2 = new Date();
if(CountStepper2>0)
  ddiff = new Date(dnow2-dthen2);
else
  ddiff = new Date(dthen2-dnow2);
gsecs2 = Math.floor(ddiff.valueOf()/1000);
CountBack2(gsecs2);

