function calcage(secs, num1, num2)
{
  s = ((Math.floor(secs/num1))%num2).toString();
  
  if (LeadingZero && s.length < 2)
    s = "0" + s;
	
  return "<b>" + s + "</b>";
}

function CountBack(secs) 
{
  if (secs < 0) 
  {
    document.getElementById("cntdwn").innerHTML = FinishMessage;
	document.location.href = LocationHeaderURL;
    return;
  }
  
  DisplayStr = DisplayFormat.replace(/%%S%%/g, calcage(secs,1,60));
  document.getElementById("cntdwn").innerHTML = DisplayStr;
  
  if (CountActive)
    setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
}

document.write("<span id='cntdwn'></span>");

if (typeof(DisplayFormat)=="undefined")
  DisplayFormat = "This page will expire in %%S%% seconds";
  
if (typeof(CountActive)=="undefined")
  CountActive = true;
  
if (typeof(FinishMessage)=="undefined")
  FinishMessage = "...time-out...";
  
if (typeof(CountStepper)!="number")
  CountStepper = -1;
  
if (typeof(LeadingZero)=="undefined")
  LeadingZero = false;
  
if (typeof(CounterStart)=="undefined")
  CounterStart = 60;
  
CountStepper = Math.ceil(CountStepper);

if (CountStepper == 0)
  CountActive = false;
  
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
start = new Date(CounterStart);
gsecs = Math.floor(start.valueOf());
CountBack(gsecs);

