

function calcage_RF(secs, num1, num2) {
  s1 = ((Math.floor(secs/num1))%num2).toString();  
  return  s1;
}

function CountBack_RF(secs, countdown) {
 
  if (secs < 0) {

	document.getElementById(countdown).innerHTML = "Just Missed!";
    
    return;
  }
  if (secs < 5) {

	document.getElementById(countdown).innerHTML = "Closing Now!";
    
    return;
  }
  
      var hours = calcage_RF(secs,3600,24); 
      if (parseInt(hours) > 1)
	{
      		DisplayStr_RF = DisplayFormat_RF.replace(/%%H%%/g, hours + "h "); 
	}
      else if (parseInt(hours) == 1)
	{
      		DisplayStr_RF = DisplayFormat_RF.replace(/%%H%%/g, hours + "h "); 
	}
     else 
	{

      		DisplayStr_RF = DisplayFormat_RF.replace(/%%H%%/g, ""); 
	}


      var _mins = calcage_RF(secs,60,60);

      if (parseInt(_mins)  == 1)
	{
      		DisplayStr_RF = DisplayStr_RF.replace(/%%M%%/g, _mins + "m "); 
	}
      else 
	{
      		
     	 	DisplayStr_RF = DisplayStr_RF.replace(/%%M%%/g, _mins + "m "); 
	}

      var _secs = calcage_RF(secs,1,60);

      if (parseInt(_secs)  ==  1)
	{
      		DisplayStr_RF = DisplayStr_RF.replace(/%%S%%/g, _secs + "s");       		
	}
      else 
	{
     	 	DisplayStr_RF = DisplayStr_RF.replace(/%%S%%/g, _secs + "s"); 
	}
 
      document.getElementById(countdown).innerHTML = DisplayStr_RF;
	   
 

  if (CountActive)
    setTimeout("CountBack_RF(" + (secs+CountStepper) + " , '" + countdown + "')", SetTimeOutPeriod);
}

function putspan_RF(countdown,backcolor, forecolor, secs) {
 if (secs < 300) {
	 document.write("<span id='" +countdown +"' class='rapidmidtimer' style='background-color:" + backcolor + 
                "; color: #f00'></span>");
 }
 else {
	 document.write("<span id='" +countdown +"' class='rapidmidtimer' style='background-color:" + backcolor + 
                "; color:" + forecolor + "'></span>");
 } 
}


if (typeof(BackColor)=="undefined")
  BackColor = "white";
if (typeof(ForeColor)=="undefined")
  ForeColor= "black";
if (typeof(TargetDate)=="undefined")
  TargetDate = "12/31/2020 5:00 AM";
if (typeof(DisplayFormat_RF)=="undefined")  
    DisplayFormat_RF = "%%H%%%%M%%%%S%%";
if (typeof(CountActive)=="undefined")
  CountActive = true;
if (typeof(FinishMessage)=="undefined")
  FinishMessage = "Time's up! Please Refresh";
if (typeof(CountStepper)!="number")
  CountStepper = -1;
if (typeof(LeadingZero)=="undefined")
  LeadingZero = true;
  if (typeof(TargetDate)=="spantag")
  spantag = "count";



CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0)
  CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
var dthen = new Date(TargetDate);
var dnow = new Date(CurrentDate);
if(CountStepper>0)
  ddiff = new Date(dnow-dthen);
else
  ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
putspan_RF(spantag, BackColor, ForeColor, gsecs);
CountBack_RF(gsecs, spantag);
