/***********************************************************************/
/* twDateLib.js - A JavaScript function library for manipulating dates */
/*         Written by Tony Williams 7th February 2005                  */
/***********************************************************************/


function getDayName(dayNum)
/*******************************************************************************************/
/* A function to get the name of a day from the week day number. Function takes one        */
/*  argument, the week day number, it then returns a string containing the day name.       */
/*******************************************************************************************/
{
var daysOfWeek = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var dayNow = daysOfWeek[dayNum];
return dayNow;
};

function getMonthName(monthNum)
/********************************************************************************************/
/* A function to get the name of the month from the month number. Function takes one        */
/* argument, the month number, it then returns a string containing the month name.          */
/********************************************************************************************/
{
var monthName = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var monthNow = monthName[monthNum];
return monthNow;
};

function addLetters(dateNow)
/********************************************************************************************/
/* A function to concatenate the 'st', 'nd', 'rd' or 'th' to the end of a date. Function    */
/* takes one argument, the date, it then returns a string, the date with extra bit added.   */
/********************************************************************************************/
{
if (dateNow == '1' || dateNow == '21' || dateNow == '31')
{
    dateNow = dateNow + 'st'
}

else if (dateNow == '2' || dateNow == '22')
{
    dateNow = dateNow + 'nd'
}

else if (dateNow == '3' || dateNow == '23')
{
    dateNow = dateNow + 'rd'
}
else
{
    dateNow = dateNow + 'th'
}
return dateNow;
};

function findYear(aDate)
{
var aYear = aDate.getYear();
    if (aYear < 1900) {aYear = aYear + 1900};
return aYear;
};

function printDateToday()
/********************************************************************************************/
/* A function to print today's date to a web page. No argument is required by the function. */
/* The function displays today's date with the day of the week and the month name.          */
/********************************************************************************************/
{
var dateToday = new Date();
var dateNow = addLetters(dateToday.getDate());
var dayNow = getDayName(dateToday.getDay());
var monthNow = getMonthName(dateToday.getMonth());
var yearNow = findYear(dateToday);

document.write(dayNow + ' ' + dateNow + ' ' + monthNow + ' ' + yearNow);
};

function removeLeadingZero(aNumber)
/********************************************************************************************/
/* A function to remove the leading zero from a two digit number. Function takes one        */
/* argument, a number. It then returns the number without leading zeros.                    */
/********************************************************************************************/
{
    if (aNumber.charAt(0) == '0')
    {
    	aNumber = aNumber - aNumber.charAt(0)
    };
return aNumber;
};

function lastUpdate()
/********************************************************************************************/
/* A function to print the date a page was last updated. Function takes no arguments.       */
/* The function displays the last date a page was updated with the day, month and year.     */
/********************************************************************************************/
{
var lastMod = document.lastModified;
var modMonth = lastMod.charAt(0) + lastMod.charAt(1);
var modDate = lastMod.charAt(3) + lastMod.charAt(4);
var modYear = lastMod.charAt(6) + lastMod.charAt(7) + lastMod.charAt(8) + lastMod.charAt(9);

modDate = removeLeadingZero(modDate);
modDate = addLetters(modDate);
modMonth = removeLeadingZero(modMonth);
modMonth = getMonthName(modMonth-1);
document.write('Last updated ' + modDate + ' ' + modMonth + ' ' + modYear);
};

/* Not My JS below */
function doit()
{
var greet="<hr><h4 align='center'><a href='#' onClick='history.go(-1)'>Back to the editor</a></h4>"
document.write( document.editor.fname.value+greet) 
} 