// JavaScript Date Functions

function makeTwoDigits( value )
{
	var result;
	if( value <= 9 )
		result = "0" + value;
	else
		result = value;
	return result;
}

function makeDateObj( str )
{
	var d = null;
	var ms = Date.parse( str );
	if( ms > 0 )
		d = new Date( ms );
	return d;
}

function getLastUpdated( str, lang )
{
	var result = "(unknown)";
	var d = makeDateObj( str );
	
	if( d != null )
		if( lang == 'f' )
			result = makeTwoDigits( d.getDate() ) + "-" +
				makeTwoDigits( d.getMonth() + 1 ) + "-" +
				d.getFullYear();
		else
			result = d.getFullYear() + "-" +
				makeTwoDigits( d.getMonth() + 1 ) + "-" +
				makeTwoDigits( d.getDate() );
	return result;
}

function lastUpdated( lang )
{
	if( lang == 'd'  ||  lang == 'D' )
		document.write( "Aktualisiert am: " + getLastUpdated( document.lastModified, 'd' ) );
	if( lang == 'e'  ||  lang == 'E' )
		document.write( "Last updated: " + getLastUpdated( document.lastModified, 'e' ) );
	if( lang == 'f'  ||  lang == 'F' )
		document.write( "Mise au jour le " + getLastUpdated( document.lastModified, 'f' ) );
}

function getCurrentYear()
{
	return new Date().getFullYear();
}

/*
 * HTML will add a space before the <script> tag
 * and after the </script> tag. That space may be
 * undesirable. For example, I want something to appear
 * as 2006-2009, where 2009 is the current year.
 * Hence, the function takes a prefix and a suffix
 * and builds up the desired string without spaces.
 * That is, the call would be
 * 	writeCopyrightYears( "2006-", "" );
 * and the function would return "2006-2009".
 */
function writeCopyrightYears( prefix, suffix )
{
	document.write( prefix + getCurrentYear() + suffix );
}
