/*
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.
********************************************************
Completely mangled for this website's use.
See the website above for the full code.
********************************************************
*/

TargetDate = "01/22/2010 11:59 PM";
CountActive = true;
CountStepper = 1;
DisplayFormat = "%%D%%, %%H%%, %%M%%, and %%S%% ago";

function calcage(secs, num1, num2, val) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (s != "1")
    val = val + "s"
  return s + " " + val;
}

function CountBack(secs) {
  DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000,"day"));
  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24,"hour"));
  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60,"minute"));
  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60,"second"));

  document.getElementById("count").innerHTML = DisplayStr;
  if (CountActive)
    setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
}

CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0)
  CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
var dthen = new Date(TargetDate);
var now = new Date();
var utcnow = now.getTime() + (now.getTimezoneOffset() * 60000);
var dnow = utcnow - 14400000;
ddiff = new Date(dnow-dthen);
gsecs = Math.floor(ddiff.valueOf()/1000);
CountBack(gsecs);
