/*
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";
BackColor2 = "palegreen";
ForeColor2 = "navy";
CountActive2 = true;
DisplayFormat2 = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage2 = "It is finally here!";
</script>
<script language="JavaScript" src="http://www.hashemian.com/js/countdown.js"></script>
*/

function calcage2(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBack2(secs) {
  if (secs < 0) {
    document.getElementById("cntdwn2").innerHTML = FinishMessage2;
    return;
  }
  DisplayStr2 = DisplayFormat2.replace(/%%D%%/g, calcage2(secs,86400,100000));
  DisplayStr2 = DisplayStr2.replace(/%%H%%/g, calcage2(secs,3600,24));
  DisplayStr2 = DisplayStr2.replace(/%%M%%/g, calcage2(secs,60,60));
  DisplayStr2 = DisplayStr2.replace(/%%S%%/g, calcage2(secs,1,60));

  document.getElementById("cntdwn2").innerHTML = DisplayStr2;
  if (CountActive2)
    setTimeout("CountBack2(" + (secs-1) + ")", 990);
}

function putspan(BackColor2, ForeColor2) {
 document.write("<span id='cntdwn2' style='background-color:" + BackColor2 + 
                "; color:" + ForeColor2 + "'></span><br><br><br>");
}

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 = "";
putspan(BackColor2, ForeColor2);
var dthen = new Date(TargetDate2);
var dnow = new Date();
ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
CountBack2(gsecs);
