/*
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">
TargetDate = "12/31/2020 5:00 AM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
</script>
<script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>
*/

 
function countDown(fulldate,division){
  
  this.target =  document.getElementById(division);
  this.calcage  = function(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString();  if (this.LeadingZero && s.length < 2)    s = "0" + s;  return "<b>" + s + "</b>"; }
  this.CountBack  = function(secs) {   
    //if (secs < 0) { return; }

    var DisplayStr = '';
    //DisplayStr = this.DisplayFormat.replace(/%%D%%/g, this.calcage(secs,86400,100000));
    DisplayStr = this.DisplayFormat;
    DisplayStr = DisplayStr.replace(/%%H%%/g, this.calcage(secs,3600,24));
    DisplayStr = DisplayStr.replace(/%%M%%/g, this.calcage(secs,60,60));
    DisplayStr = DisplayStr.replace(/%%S%%/g, this.calcage(secs,1,60));
    this.target.innerHTML = DisplayStr;
    setTimeout(division+".CountBack(" + (secs+this.CountStep) + ")", this.SetTimeOutPeriod);
  }
    
  this.timeOut = '';
  
  this.TargetDate = fulldate;
  //this.DisplayFormat = "Plus que  %%D%%j %%H%%h %%M%%min %%S%%s";
  this.DisplayFormat = "Flash! %%H%%h %%M%%min %%S%%s";
  this.CountActive = true;
  this.CountStep = -1;
  this.LeadingZero = false;
  this.SetTimeOutPeriod = (Math.abs(this.CountStep)-1)*1000 + 990;
  this.dthen = new Date(this.TargetDate);
  this.dnow = new Date();
  this.ddiff = new Date(this.dthen-this.dnow);
  this.gsecs = Math.floor(this.ddiff.valueOf()/1000);
  this.CountBack(this.gsecs);


}

