<!--
/*
Usage:
var countdown = new nf.Countdown ("countdown");
countdown.TargetDate = "12/31/2020 5:00 AM";
countdown.FinishMessage = "Message";
countdown.FinishFunction = function () {};
countdown.initializeCountdown();
*/

nf.Countdown = function (caller) {
	this.caller = caller;
	this.BackColor = "#FFFFFF";
	this.ForeColor = "#000000";
	this.TargetDate = null;
	this.DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
	this.CountActive = true;
	this.FinishFunction = function () {};
	this.FinishMessage = null;
	this.CountStepper = -1;
	this.LeadingZero = true;
	this.SetTimeOutPeriod = null;

	this.initializeCountdown = function () {
		this.CountStepper = Math.ceil(this.CountStepper);
		if (this.CountStepper == 0)
			this.CountActive = false;
		this.SetTimeOutPeriod = (Math.abs(this.CountStepper)-1)*1000 + 990;
		this.putspan(this.BackColor, this.ForeColor);
		var dthen = new Date(this.TargetDate);
		var dnow = new Date();
		if(this.CountStepper > 0) {
			ddiff = new Date(dnow-dthen);
		} else {
			ddiff = new Date(dthen-dnow);
		}
		gsecs = Math.floor(ddiff.valueOf()/1000);
		this.CountBack(gsecs);
	}

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

	this.CountBack = function (secs) {
		if (secs < 0) {
			document.getElementById("cntdwn").innerHTML = this.FinishMessage;
			this.FinishFunction();
			return;
		}
		DisplayStr = this.DisplayFormat.replace(/%%D%%/g, this.calcage(secs,86400,100000));
		DisplayStr = DisplayStr.replace(/%%H%%/g, this.calcage(secs,3600,24));
		DisplayStr = DisplayStr.replace(/%%M%%/g, this.calcage(secs,60,60));
		DisplayStr = DisplayStr.replace(/%%S%%/g, this.calcage(secs,1,60));

		document.getElementById("cntdwn").innerHTML = DisplayStr;
		if (this.CountActive) {
			setTimeout(this.caller + ".CountBack(" + (secs + this.CountStepper) + ")", this.SetTimeOutPeriod);
		}
	}

	this.putspan = function () {
		document.write("<span id='cntdwn' style='background-color:" + this.BackColor + "; color:" + this.ForeColor + "'></span>");
	}

} // Countdown
-->