//######################  putLastModified()  #######################
//
//	Formats and document.write()s the date and time obtained from the 
//	document.lastModified property.  Include this file where you want 
//	the date to appear and surround it with <SPAN></SPAN>, or something, 
//	to get the desired text effect.  For example:
//
//	<SPAN STYLE="font-size:8pt; color:#6699FF;">
//		<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript" SRC="Includes/putLastModified.js"></SCRIPT>
//	</SPAN>
//
//	Yields something like --  Last updated today (2005-03-16 19:03:02).
//
// 2005-03-16	Initial.
// 2005-04-27 Short circuit date formatting if we're pass something that 
//						doesn't parse into a date.
//
//	The original versions of lastMod() and takeYear() were taken from 
//	Peter-Paul Koch's CSS and JavaScript tips and tricks site 
//  http://www.quirksmode.org -- to quote Ray Bethel, "Good Stuff!" 
//###################################################################

function lastMod( x) {

	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 ';
	if (daysago == 0) towrite += 'today';
	else if (daysago == 1) towrite += 'yesterday';
	else towrite += daysago + ' ' + unit + ' ago';
	return towrite;
}
// -------------------------------------------------------

function takeYear(theDate) {
	var x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

// -------------------------------------------------------

function putLastModified(theDate) {

	if (!theDate) {
		var x = new Date (document.lastModified);
	} else {
		var x = new Date (theDate);
	}
	var yyyy = x.getYear();
	var mm = (x.getMonth() + 1);
	var dd = x.getDate();
	var hh = x.getHours();
	var nn = x.getMinutes();
	var ss = x.getSeconds();
	if (isNaN( yyyy)) return 'Last updated: ' + theDate;
	
	if (yyyy < 1900) yyyy += 1900;
	if (mm < 10) mm = '0' + mm;
	if (dd < 10) dd = '0' + dd;
	if (hh < 10) hh = '0' + hh;
	if (nn < 10) nn = '0' + nn;
	if (ss < 10) ss = '0' + ss;
		
	return lastMod(x) + " (" + yyyy + '-' + mm + '-' + dd + ' ' + hh + ':' + nn + ':' + ss + ")";
}

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	function getOBID(theID) {

		if( document.getElementById) {
			this.obj = document.getElementById(theID);
			this.style = document.getElementById(theID).style;
		} else if( document.all) {
			this.obj = document.all[theID];
			this.style = document.all[theID].style;
		} else if( document.layers) {
			this.obj = document.layers[theID];
			this.style = document.layers[theID];
		}
	}

function putLastModifiedById( idSource, idDestination) {
	
		var DHTML = (document.getElementById || document.all || document.layers);
		if( !DHTML) return;
		var oSource 			= new getOBID( idSource);
		if (!oSource) return;
		var oDestination 	= new getOBID( idDestination);
		if (!oDestination) return;

		var dlmRaw = oSource.obj.innerHTML;
/*
		var dlmAry = dlmRaw.split( " ");
		var dlmMod = dlmAry[1] + ' ' + dlmAry[2];
		dlmMod = dlmMod.replace( /\-/, " ");
		dlmMod = dlmMod.replace( /\-/, ",");
		dlmMod = putLastModified( dlmMod );
*/
		dlmMod = putLastModified( dlmRaw );
		oDestination.obj.innerHTML = dlmMod.replace(" 00:00:00", "");
} 