/*
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">
TargetDateB = "12/31/2020 5:00 AM";
BackColorB = "palegreen";
ForeColorB = "navy";
CountActiveB = true;
CountStepperB = -1;
LeadingZeroB = true;
DisplayFormatB = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessageB = "It is finally here!";
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>
*/

function calcageB(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZeroB && s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBackB(secs) {
  if (secs < 0) {
    document.getElementById("cntdwnB").innerHTML = FinishMessageB;
    return;
  }
  DisplayStrB = DisplayFormatB.replace(/%%D%%/g, calcageB(secs,86400,100000));
  DisplayStrB = DisplayStrB.replace(/%%H%%/g, calcageB(secs,3600,24));
  DisplayStrB = DisplayStrB.replace(/%%M%%/g, calcageB(secs,60,60));
  DisplayStrB = DisplayStrB.replace(/%%S%%/g, calcageB(secs,1,60));

  document.getElementById("cntdwnB").innerHTML = DisplayStrB;
  if (CountActiveB)
    setTimeout("CountBackB(" + (secs+CountStepperB) + ")", SetTimeOutPeriod);
}

function putspan(BackColorB, ForeColorB) {
 document.write("<span id='cntdwnB' style='background-color:" + BackColorB + 
                "; color:" + ForeColorB + "'></span>");
}

if (typeof(BackColorB)=="undefined")
  BackColorB = "white";
if (typeof(ForeColorB)=="undefined")
  ForeColorB= "black";
if (typeof(TargetDateB)=="undefined")
  TargetDateB = "12/31/2020 5:00 AM";
if (typeof(DisplayFormatB)=="undefined")
  DisplayFormatB = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
if (typeof(CountActiveB)=="undefined")
  CountActiveB = true;
if (typeof(FinishMessageB)=="undefined")
  FinishMessageB = "";
if (typeof(CountStepperB)!="number")
  CountStepperB = -1;
if (typeof(LeadingZeroB)=="undefined")
  LeadingZeroB = true;


CountStepperB = Math.ceil(CountStepperB);
if (CountStepperB == 0)
  CountActiveB = false;
var SetTimeOutPeriod = (Math.abs(CountStepperB)-1)*1000 + 990;
putspan(BackColorB, ForeColorB);
var dthen = new Date(TargetDateB);
var dnow = new Date();
if(CountStepperB>0)
  ddiff = new Date(dnow-dthen);
else
  ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
CountBackB(gsecs);

