/*
#
# Date/Time Messages JavaScript
#
# Purpose:
#   To display the current date/time with a particular
#   format and to provide messages if required.
#
#   To display the last updated date of the current
#   file.
#
*/

/*
#
# dateStyle			Example 
# ===============	=======================
# showDateShort		Sun Jun 13 2004  
# showDate			13 June 2004  
# showDateTime		13 June 2004 08:18:30  
# showTime			08:18:30  
#
*/

var showDateShort = 1;
var showDate= 2;
var showDateTime= 3;
var showTime= 4;

function ShowDateTime(dateStyle)
{
	var today = new Date();
	var dStr = "";
	
	switch (dateStyle)
	{
		case showDateShort:
			dStr = today.toDateString();
			break;
		case showDateTime:
			dStr = today.toLocaleString();
			break;
		case showTime:
			dStr = today.toLocaleTimeString();
			break;
		case showDate:
		default:
			dStr = today.toLocaleDateString();
			break;
	}
	document.write(dStr);
}

/*
#
# Last Modified Script
#
*/

function showLastModified(id) {
	obj = document.getElementById(id);
	obj.innerHTML = lastMod();
}

function lastMod()
{
	var x = new Date (document.lastModified);
	Modif = new Date(x.toGMTString());
	Year = takeYear(Modif);
	Month = Modif.getMonth();
	Day = Modif.getDate();
	Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
	x = new Date();
	today = new Date(x.toGMTString());
	Year2 = takeYear(today);
	Month2 = today.getMonth();
	Day2 = today.getDate();
	now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
	daysago = now - Mod;
	if (daysago < 0) return '';
	unit = 'days';
	if (daysago > 730)
	{
		daysago = Math.floor(daysago/365);
		unit = 'years';
	}
	else if (daysago > 60)
	{
		daysago = Math.floor(daysago/30);
		unit = 'months';
	}
	else if (daysago > 14)
	{
		daysago = Math.floor(daysago/7);
		unit = 'weeks'
	}
	var towrite = 'Last Updated &raquo; ';
	if (daysago == 0) towrite += 'Today';
	else if (daysago == 1) towrite += 'Yesterday';
	else towrite += daysago + ' ' + unit + ' ago';
	return towrite;
}


function takeYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}


