/**
 * JavaScript by Jeffrey Ouma.
 * Copyright© 2008 artkenya.net Ltd.
 * All rights reserved.
 *
 * Script name: main.js
 * Purpose: Defines namespaces and common functions that are executed by every page.
 */
Site = {}; // Namespace: Defines functions that are specific to this website, but used widely.
Site.main = {};
Site.main.LocalTime = function() {
	// Adjust the local time every minute
	// Initialize date and time variables
	var elm = Dom.get("loctime");
	if (elm.title) {
		Site.main.realtime = new Date(elm.title); // The initial date and time
		elm.title = "";
	}
	var h = Site.main.realtime.getHours(); // Extract the hour from the date
	var m = Site.main.realtime.getMinutes(); // Extract the minutes from the date
	//var s = Site.main.realtime.getSeconds(); // Extract the seconds from the date (Optional: for testing purposes only)
	var t = "" + ((h > 12) ? h - 12 : h); // 12-hour format
	if (h == 0) {
		// Set 0 (midnight) to 12am
		t = "12";
	} else if (t < 10) {
		// Format to 2-digit hour format
		t = "0" + t;
	}
	t += ((m < 10) ? ":0" : ":") + m; // Add the minutes to the formatted hour
	//t += ((s < 10) ? ":0" : ":") + s; // Add the seconds to the formatted time (Optional: for testing purposes only)
	t += (h >= 12) ? " PM" : " AM"; // Add the meridiem indicator
	elm.innerHTML = t;
	Site.main.realtime.setTime(Site.main.realtime.getTime() + 60000);
	setTimeout("Site.main.LocalTime()", 60000);
};
/**
 * Function name: Init
 * Purpose: Executes when the page loads after the DOM is ready. Performs initialization of any
 * elements or values to their default.
 */
Site.main.Init = function() {
	try {
		var elm, elmArray;
		elmArray = Dom.getElementsByClassName("scrub");
		Event.addFocusListener(elmArray, function() {
			try {
				BLEEZ.util.Scrub(this);
			} catch (e) {
				errorHandler(e);
			}
		});
		if (Dom.get("localtime")) {
			Site.main.LocalTime();
		}
	} catch (e) {
		errorHandler(e);
	}
};
try {
	Event.onDOMReady(Site.main.Init);
} catch (e) {
	errorHandler(e);
}

