/*
+--------------------------------------------------------------------------+
| StormSoft Clock Script                                                   |
| © 2005, www.StormSoft.com - All rights reserved                          |
|                                                                          |
| The StormSoft Clock Script was written in its entirety by                |
| Harold Krueger IV (harold@stormsoft.com) for private use by              |
| www.StormSoft.com                                                        |
|                                                                          |
| Dependencies: <span> element with an id of "clock" on target html page   |
|                                                                          |
| Description: displays a timestamp from the client machine and updates    |
|              it continuously to create a running clock                   |
+--------------------------------------------------------------------------+
*/

// this method gets the current time, formats it to a string, and outputs it to the "clock" element in the document
function getTime()
{

	// arrays to translate numbers into words
	var dyarray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var moarray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

	// get the current datetime and extract the individual elements
	var theTime = new Date();
	var yr = theTime.getYear();
	var dy = theTime.getDay();
	var mo = theTime.getMonth();
	var dt = theTime.getDate();
	var hr = theTime.getHours();
	var mn = theTime.getMinutes();
	var sc = theTime.getSeconds();

	// determine am/pm and convert time to 12 hour
	var ap = "a.m.";
	if(hr > 11) ap = "p.m.";
	if(hr > 12) hr -= 12;
	else if(hr == 0) hr = 12;

	// make sure the minute and second elements are in 2-digit format
	if(mn < 10) mn = "0" + mn;
	if(sc < 10) sc = "0" + sc;

	// build the output string
	var timeString = dyarray[dy] + ", " + moarray[mo] + " " + dt + ", " + yr + " " + hr + ":" + mn + ":" + sc + " " + ap;

	// run the appropriate method to output "timeString" to the document (browser compatability)
	if(document.all) document.all.clock.innerHTML = timeString;
	else if(document.getElementById) document.getElementById("clock").innerHTML = timeString;
	else document.write(timeString);
}

// this method runs the getTime() method every second giving us a "ticking" clock
function timeScript()
{

	// we need to run this method by itself once to start or
	// there will be a 1 second delay of the clock appearing
	getTime();

	// now we "getTime()" once every second
	setInterval("getTime()",1000);
}
// by using attachEvent, we can start the time script here instead of using the onload property in the body tag
window.attachEvent("onload", timeScript);