/* from the page http://www.xs4all.nl/~ppk/js/lastmod.html */

function lastMod(documentDate)
{
	var x = new Date (documentDate);
	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 'on ' + documentDate;
	if (Year < Year2 && daysago > 180)
	{
		if (Year + 1 < Year2)
		{
			howlong = (Year2 - Year) + ' years ago';
		}
		else
		{
			howlong = 'last year';
		}
	}
	else if (Month != Month2 && daysago > 28)
	{
		if (Year < Year2)
		{
			Month2 += 12;
		}

		if (Month + 1 < Month2)
		{
			numMonths = Month2 - Month;
			howlong = numMonths + ' months ago';
		}
		else
		{
			howlong = 'last month';
		}
	}
	else if (daysago > 14)
	{
		howlong = Math.round(daysago/7) + ' weeks ago';
	}
	else
	{
		howlong = daysago + ' days ago';
	}
	if (daysago == 0) towrite = 'today';
	else if (daysago == 1) towrite = 'yesterday';
	else towrite = howlong + ', on ' + documentDate;
	return towrite;
}


function takeYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}
