/* This set of functions simulates :hover for submit buttons in IE. To use, apply onmouseover and onomouseout attributes
	to the input element and then define the CSS for "thatelement".hover-off and "thatelement".hover-on.

	-----------

	For example:

	<style type="text/css">
		.hover-off
		{
			background-color: #00FF00;
			color:            #000000;
		}
		.hover-on {
			background-color: #000000;
			color:            #00FF00;
		}
	</style>

   <input type="submit" class="hover-off" onmouseover="hoverOn(this);" onmouseout="hoverOff(this);" />

	-----------

	From here:
	http://phd.netcomp.monash.edu.au/RobertMarkBram/javaScript/examples/ieHoverFix/default.asp */

function hoverOff(hoverElement)
{
	hoverElement.className = "submitbutton hover-off";
}

function hoverOn(hoverElement)
{
	hoverElement.className = "submitbutton hover-on";
}

var timeAndDateElt = null;

function loadElementById(eltId) {
	if (document.getElementById) {
		return document.getElementById(eltId);
	} else if (document.all) {
		return document.all[eltId];
	}
}

function prettyTime(cT) {
	// Configure our constants for the day of week, month, and ordinal unit for the day

	dayofWeek = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
	month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
	ordinalUnit = ['th','st','nd','rd','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','st','nd','rd','th','th','th','th','th','th','th','st']

	// Look at the hours and calculate the meridian (am vs pm).
	// 		The calculation checks against "11" since "12" would be after-noon and thus "pm"
	if (cT.getHours()>11) { meridian = "pm"; }
	else { meridian = "am"; }

	// Convert the hours from 24-hour format to 12-hour format
	if (cT.getHours()>12) { hours = cT.getHours() - 12; }
	else { hours = cT.getHours(); }

	// Format minutes and seconds so that they're prepended with a zero if needed
	if (cT.getSeconds()<10) { seconds = "0"+cT.getSeconds(); }
	else { seconds = cT.getSeconds(); }
	if (cT.getMinutes()<10) { minutes = "0"+cT.getMinutes(); }
	else { minutes = cT.getMinutes(); }

	// Put all the time elements together so that they look like 3:05:26pm Friday 14th April
    formattedTime = hours+":"+minutes+":"+seconds+meridian+" "+dayofWeek[cT.getDay()]+" "+cT.getDate()+ordinalUnit[cT.getDate()]+" "+month[cT.getMonth()];

	return formattedTime;
}

// Get the current time and display it

function clockHandler() {
	currentTime = new Date();

	// Stick the currentTime in the time-and-date element
	timeAndDateElt.innerHTML = prettyTime(currentTime);
}

// Initialize our interval timer, and onclick handler

function initClockHandler() {
	// Load the time-and-date element and kick everything off

	if (!timeAndDateElt) {
		timeAndDateElt = loadElementById('time-and-date');
		if (timeAndDateElt) {
			clockHandler();
			timeAndDateElt.intervalId = window.setInterval(clockHandler, 1000);
			timeAndDateElt.stopped = 0;
			timeAndDateElt.onclick = clockClickHandler;
			timeAndDateElt.title = "Click to toggle clock on and off";
		} else {
			window.setTimeout(initClockHandler,250);
		}
	}
}

// Handle any onclick requests to toggle the clock on and off

function clockClickHandler() {

	if (timeAndDateElt.stopped) {

		// If the clock is stopped, start it again immediately, and set the timer

		clockHandler();
		timeAndDateElt.intervalId = window.setInterval(clockHandler, 1000);
		timeAndDateElt.stopped = 0;
	} else {

	// Cancel the clock and wait for the user to start it back up again

		window.clearInterval(timeAndDateElt.intervalId);
		timeAndDateElt.stopped = 1;
	}
}

initClockHandler();
