
function topcalcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero && s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function topCountBack(secs) {
  if (secs < 0) {
    document.getElementById("cntdwntop").innerHTML = "<table cellpadding=0 cellspacing=0 border=0><tr><td class=topCountdownCell1><span class=topCountdownLargeText><a href='http://onlinecampus.reallifechurch.org' target='_blank'><nobr>" + FinishMessage + "</nobr></a></span></td></tr></table>";
    return;
  }
  DisplayStr = topDisplayFormat.replace(/%%D%%/g, topcalcage(secs,86400,100000));
  DisplayStr = DisplayStr.replace(/%%H%%/g, topcalcage(secs,3600,24));
  DisplayStr = DisplayStr.replace(/%%M%%/g, topcalcage(secs,60,60));
  DisplayStr = DisplayStr.replace(/%%S%%/g, topcalcage(secs,1,60));

  document.getElementById("cntdwntop").innerHTML = DisplayStr;
  if (CountActive)
    setTimeout("topCountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
}

function topputspan(backcolor, forecolor) {
 document.write("<span id='cntdwntop' style='background-color:" + backcolor + 
                "; color:" + forecolor + "'></span>");
}

if (typeof(topBackColor)=="undefined")
  BackColor = "transparent";
if (typeof(topForeColor)=="undefined")
  ForeColor= "white";
if (typeof(TargetDate)=="undefined")
  TargetDate = "12/31/2020 5:00 AM";
if (typeof(topDisplayFormat)=="undefined")
  topDisplayFormat = "<table cellpadding=0 cellspacing=0 border=0><tr><td class=topCountdownCell><span class=topCountdownLargeText style=padding-right:10px;></td><td class=topCountdownCell><span class=topCountdownLargeText>%%D%%</span><br/><span class=topCountdownSmallText>days</span></td><td class=topCountdownCell><span class=topCountdownLargeText>:</span></td><td class=topCountdownCell><span class=topCountdownLargeText>%%H%%</span><br/><span class=topCountdownSmallText>hours</span></td><td class=topCountdownCell><span class=topCountdownLargeText>:</span></td><td class=topCountdownCell><span class=topCountdownLargeText>%%M%%</span><br/><span class=topCountdownSmallText>min</span></td><td class=topCountdownCell><span class=topCountdownLargeText>:</span></td><td class=topCountdownCell><span class=topCountdownLargeText>%%S%%</span><br/><span class=topCountdownSmallText>sec</span></td><tr></table>";
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;
topputspan(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);
topCountBack(gsecs);
                 
