Hi All,

I am using a small script to display some counters counter (times since a certain datetime values) - now working thanks to member vwphillips. I have been trying to work out how to change the script so that the format of the results is a little different, but im stumped.

The format of the counter is currently %%D%% Days %%H%%:%%M%%:%%S%%. However, i would like the format to be just %%H%%:%%M%%:%%S%% if the total time is less than 24 hours, otherwise i would like it to say 'more than 1 day' (for 24-48 hours), 'more than 2 days' (for 48-36 hours), etc...

Does anyone have any idea how i can change the script to do this?

Many thanks in advance for any ideas.

Matt

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <title></title>
</head>

<body>
<div id="cntdwn1" ></div>
<div id="cntdwn2" ></div>
<script type="text/javascript">
/*<![CDATA[*/

var CountDown={

 start:function(o){
  o.obj=document.getElementById(o.ID);
  if (o.obj){
   o.TargetDate=o.TargetDate||"12/31/2020 05:00:00";
   o.DisplayFormat = o.DisplayFormat||"%%D%% days, %%H%% hours, %%M%% minutes, %%S%% seconds.";
   o.CountActive = o.CountActive!==false;
   o.FinishMessage = o.FinishMessage||"no data";
   o.CountStepper =o.CountStepper||+1;
   o.LeadingZero = o.LeadingZero!==false;
   o.CountStepper = Math.ceil(o.CountStepper);
   if (o.CountStepper == 0)
    o.CountActive = false;
   o.SetTimeOutPeriod = (Math.abs(o.CountStepper)-1)*1000 + 1000;
   var dthen = new Date(o.TargetDate),dnow = new Date(),ddiff;
   if(o.CountStepper>0)
    ddiff = new Date(dnow-dthen);
   else
    ddiff = new Date(dthen-dnow);
   this.CountBack(o,Math.floor(ddiff.valueOf()/1000));
  }

 },

 calcage:function(o,secs, num1, num2) {
  var s = ((Math.floor(secs/num1))%num2).toString();
  if (o.LeadingZero && s.length < 2)
    s = "0" + s;
  return  s;
 },

 CountBack:function(o,secs) {
  if (secs < 0) {
    o.obj.innerHTML = o.FinishMessage;
    return;
  }
  var oop=this,d = o.DisplayFormat.replace(/%%D%%/g, oop.calcage(o,secs,86400,100000));
  d = d.replace(/%%H%%/g, oop.calcage(o,secs,3600,24));
  d = d.replace(/%%M%%/g, oop.calcage(o,secs,60,60));
  d = d.replace(/%%S%%/g, oop.calcage(o,secs,1,60));

  o.obj.innerHTML = d;
  if (o.CountActive)
    o.to=setTimeout(function(){ oop.CountBack(o,secs+o.CountStepper); }, o.SetTimeOutPeriod);
 }

}

CountDown.start({
 ID:'cntdwn1',
 TargetDate:"06/20/2013 00:00:01",
 FinishMessage:"done",
 CountActive:true,
 LeadingZero:true,
 DisplayFormat:"%%D%% Days %%H%%:%%M%%:%%S%% "
});

CountDown.start({
 ID:'cntdwn2',
 TargetDate:"06/20/2013 00:00:01",
 FinishMessage:"done",
 CountActive:true,
 LeadingZero:true,
 DisplayFormat:"%%D%% Days %%H%%:%%M%%:%%S%% "
});

/*]]>*/
</script>
</body>

</html>