

var g_MonthArray = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 
				'August', 'September', 'October', 'November', 'December');
var g_headerArray = new Array('S', 'M', 'T', 'W', 'T', 'F', 'S');
var g_DayArray = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');

/************************************************************************
**	Function:	jsg_sFormatHours (dateObj, timeZone, timeFormat)
**
**	Purpose:	converts a date object into a local time representation
**				based on the timeFormat string
**			e.g. 8:00 P.M., 7:30 A.M., etc.
*************************************************************************/
function jsg_sFormatHours (dateObj, timeZone, timeFormat)
{
	var hour = dateObj.getHours();
	var longHour = hour;
	var milHour = hour;
	var longMilHour = hour;
	var minutes = dateObj.getMinutes().toString();
	var longMinutes = minutes;
	var seconds = dateObj.getSeconds().toString();
	var longSeconds = seconds;
	var reTz = /[a-zA-Z]+/g;
	var tz = "";
	var outStr = "";
	
	if (timeZone && timeZone.length > 0)
	{
		var tzArray = timeZone.match(reTz);
		
		if (tzArray.length >= 1)
			tz = " " + tzArray[tzArray.length-1];
	}
	
	var merid = (hour < 12 ? " A.M." : " P.M.");
	
	if (hour == 0)
		hour = 12;
	else if (hour > 12)
		hour -= 12;
		
	if (hour.length < 2)
		longHour = "0" + hour;
	if (milHour.length < 2)
		longMilHour = "0" + milHour;
		
	if (minutes.length < 2)
		longMinutes = "0" + minutes;
		
	if (seconds.length < 2)
		longSeconds = "0" + seconds;
		
	outStr = timeFormat.replace(/hhhh/g, longMilHour);
	outStr = outStr.replace(/hhh/g, milHour);
	outStr = outStr.replace(/hh/g, longHour);
	outStr = outStr.replace(/h/g, hour);
	outStr = outStr.replace(/mm/g, longMinutes);
	outStr = outStr.replace(/m/g, minutes);
	outStr = outStr.replace(/ss/g, longSeconds);
	outStr = outStr.replace(/s/g, seconds);
	outStr = outStr.replace(/AM\/PM/gi, merid);
	
	return(outStr + tz);
}

/************************************************************************
**	Function:	jsg_sFormatDate(dateObj, dateFormat)
**
**	Purpose:	converts a date object into a local time representation
**				based on the dateFormat string
**			e.g. Wednesday Nov 27, 2002
*************************************************************************/
function jsg_sFormatDate(dateObj, dateFormat)
{
	var outStr = "";
	
	var month = (dateObj.getMonth()+1).toString();
	var longMonth = month;
	var curDate = dateObj.getDate().toString();
	var longDate = curDate;
	
	if (month.length < 2)
		longMonth = "0" + month;
	
	if (curDate.length < 2)
		longDate = "0" + curDate;
	
	outStr = dateFormat.replace(/yyyy/g, dateObj.getFullYear());
	outStr = outStr.replace(/yy/g, dateObj.getFullYear().toString().substring (2, 4));
	// replace with placeholder to keep from replacing charatcers in the month name with formatting data
	outStr = outStr.replace(/mmmm/g, "MMMM");
	outStr = outStr.replace(/mm/g, longMonth);
	outStr = outStr.replace(/m/g, month);
	// replace with placeholder to keep from replacing charatcers in the date name with formatting data
	outStr = outStr.replace(/dddd/g, "DDDD");
	outStr = outStr.replace(/dd/g, longDate);
	outStr = outStr.replace(/d/g, curDate);
	
	// replace these last since the month name and date name might throw off the formatting
	outStr = outStr.replace(/DDDD/g, g_DayArray[dateObj.getDay()]);
	outStr = outStr.replace(/MMMM/g, g_MonthArray[dateObj.getMonth()]);
	
	return(outStr);
}


function funDateTimeObj(objName, spanName, text, timeFormat, dateFormat)
{
	this.objName = objName;
	this.spanName = spanName;
	this.text = text;
	this.timeFormat = timeFormat;
	this.dateFormat = dateFormat;
	
	var curDate = new Date();
	
	var useText = this.text.replace(/%d/g, jsg_sFormatDate(curDate, dateFormat));
	useText = useText.replace(/%t/g, jsg_sFormatHours (curDate, '', timeFormat));
	document.write('<span id="'+spanName+'">'+useText.replace (/ /ig, '&nbsp;')+'</span>');
	
	if (document.getElementById)
		onLoadStr += "funUpdateTime("+objName+");";

}

function funUpdateTime(obj) 
{
	with(obj)
	{
		var useSpan = document.getElementById(spanName);
		if(useSpan)
		{
			if (useSpan.innerHTML)
			{
				var curDate = new Date();
				var useText = text.replace(/%d/gi, jsg_sFormatDate(curDate, dateFormat));
				useText = useText.replace(/%t/gi, jsg_sFormatHours (curDate, '', timeFormat));
				useSpan.innerHTML = useText.replace (/ /ig, '&nbsp;')
				setTimeout("funUpdateTime("+objName+")",1000);
			}
		}
	}

}




