/*
* This file is used to support the control for the Count Down of the Events.
*
* Comment version: 1.3.2a
*/

var oTimer
var jsalarm = {
	padfield: function(f) {
		return (f < 10) ? "0" + f : f
	},
	showcurrenttime: function() {
		// Locals
		var ct

		// Get Minutes
		//alert(this.tmrMins);
		if (this.tmrMins == 0) {
			if (this.tmrHours == 0) {
				if (this.tmrDays == 0) {
					//alert("If we ever hit here this means that the timer went over one minute")
				} else {
					this.tmrDays = this.tmrDays - 1
					this.tmrHours = 24
				}
			} else {
				this.tmrHours = this.tmrHours - 1
			}
			this.tmrMins = 59
			ct = 59
		} else {
			ct = (this.tmrMins - 1)
		}

		// Show the minutes
		this.tmrMins = ct
		ct = (ct > 9) ? ("" + ct) : ("0" + ct) // This is for casting the value and padding it with a leading zero if necessary.
		//alert("Minutes: " + ct)
		this.ctrefMins.innerHTML = ct
		this.ctrefMins.setAttribute("title", ct)
		// Show the hours
		ct = (this.tmrHours > 9) ? ("" + this.tmrHours) : ("0" + this.tmrHours)
		//alert("Hours: " + ct)
		this.ctrefHours.innerHTML = ct
		this.ctrefHours.setAttribute("title", ct)
		// Show the days
		ct = (this.tmrDays > 9) ? ("" + this.tmrDays) : ("0" + this.tmrDays) // This is for casting the value and padding it with a leading zero if necessary.
		//alert("Days: " + ct)
		this.ctrefDays.innerHTML = ct
		this.ctrefDays.setAttribute("title", ct)

		// Check that the timer has come to an end
		if (this.tmrMins == 0 && this.tmrHours == 0 && this.tmrDays == 0) {
			//alert("Clock has come to a stop")
			clearInterval(oTimer)
		}
	},
	init: function(nDays, nHours, nMins) {
		// Locals
		var ct

		this.tmrDays = nDays;
		this.tmrHours = nHours;
		this.tmrMins = nMins;

		this.ctrefDays = document.getElementById("eventDays")
		this.ctrefHours = document.getElementById("eventHours")
		this.ctrefMins = document.getElementById("eventMins")

		// Set the values
		this.ctrefDays.innerHTML = (this.tmrDays > 9) ? ("" + this.tmrDays) : ("0" + this.tmrDays)
		this.ctrefHours.innerHTML = (this.tmrHours > 9) ? ("" + this.tmrHours) : ("0" + this.tmrHours)
		this.ctrefMins.innerHTML = (this.tmrMins > 9) ? ("" + this.tmrMins) : ("0" + this.tmrMins)
	}
}
