/*
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.
********************************************************
*/
function calcage(secs, num1, num2)
{
	s = ((Math.floor(secs / num1)) % num2).toString();
	if (LeadingZero && s.length < 2)
	{
		s = "0" + s;
	}
	return s;
}

function CountBack(secs)
{
	if (secs < 0)
	{
		document.getElementById("cntdwn").innerHTML = FinishMessage;
		return;
	}
//	days = num2img(calcage(secs, 86400, 100000));
//	alert(days);
	DisplayStr = DisplayFormat.replace(/%%D%%/g, num2img(calcage(secs, 86400, 100000)));
	DisplayStr = DisplayStr.replace(/%%H%%/g, num2img(calcage(secs, 3600, 24)));
	DisplayStr = DisplayStr.replace(/%%M%%/g, num2img(calcage(secs, 60, 60)));
	DisplayStr = DisplayStr.replace(/%%S%%/g, num2img(calcage(secs, 1, 60)));
	
	document.getElementById("cntdwn").innerHTML = DisplayStr;
	if (CountActive)
	{
		setTimeout("CountBack(" + (secs + CountStepper) + ")", SetTimeOutPeriod);
	}
}

function num2img(num)
{
	strOut = '';
	for (i = 0; i < num.length; i++)
	{
		strOut += '<img src="images/' + num.charAt(i) + '.png" />';
	}
	return strOut;
}

function newImage(arg)
{
	if (document.images)
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

var preloadFlag = false;
function preloadCountDownImages()
{
	countdown_0 = newImage("images/0.png");
	countdown_1 = newImage("images/1.png");
	countdown_2 = newImage("images/2.png");
	countdown_3 = newImage("images/3.png");
	countdown_4 = newImage("images/4.png");
	countdown_5 = newImage("images/5.png");
	countdown_6 = newImage("images/6.png");
	countdown_7 = newImage("images/7.png");
	countdown_8 = newImage("images/8.png");
	countdown_9 = newImage("images/9.png");
	
	preloadFlag = true;
}

if (typeof(CountActive)=="undefined")
  CountActive = true;
if (typeof(FinishMessage)=="undefined")
  FinishMessage = "";
if (typeof(CountStepper)!="number")
  CountStepper = -1;
if (typeof(LeadingZero)=="undefined")
  LeadingZero = true;


CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0)
{
	CountActive = false;
}
var SetTimeOutPeriod = (Math.abs(CountStepper) - 1) * 1000 + 999;

//putspan(BackColor, ForeColor);
var dthen = new Date(TargetDate);

if(CountStepper > 0)
{
	ddiff = new Date(dnow - dthen);
}
else
{
	ddiff = new Date(dthen - dnow);
}
gsecs = Math.floor(ddiff.valueOf()/1000);


