// Common javascript functions to work with dates and times
// Version 0.9 - 21Jan2010
// Copyright Air Cargo Management Group 2010
// Alan Hedge

// Calculate current years duration from a fixed starting year
function yearsDuration (startYear)
	{	var dateNow=new Date();
	return dateNow.getFullYear()-startYear; }


// Extend the Number type to express any positive whole number as ordinal text.
// All other numbers return null.
Number.prototype.ordinal = function () {
   var digRoot=new Array();
   var decRoot=new Array();

   	digRoot[0]='zeroth';
	digRoot[1]='first';
	digRoot[2]='second';
	digRoot[3]='third';
	digRoot[4]='fourth';
	digRoot[5]='fifth';
	digRoot[6]='sixth';
	digRoot[7]='seventh';
	digRoot[8]='eighth';
	digRoot[9]='ninth';
	digRoot[10]='tenth';
	digRoot[11]='eleventh';
	digRoot[12]='twelfth';
	digRoot[13]='thirteenth';
	digRoot[14]='fourteenth';
	digRoot[15]='fifteenth';
	digRoot[16]='sixteenth';
	digRoot[17]='seventeenth';
	digRoot[18]='eighteenth';
	digRoot[19]='nineteenth';
	
   	decRoot[0]='';
	decRoot[1]='';
	decRoot[2]='twen';
	decRoot[3]='thir';
	decRoot[4]='for';
	decRoot[5]='fif';
	decRoot[6]='six';
	decRoot[7]='seven';
	decRoot[8]='eigh';
	decRoot[9]='nine';
   
	if (this<0 || this%1 > 0) return null;
	else if (this<20) return digRoot[this];
	else if (this<100)
		return (this % 10 == 0) ?  decRoot[this/10]+'tieth' :
	 		decRoot[(this-this%10)/10]+'ty-'+digRoot[this % 10];
	else return this+(
   				(this % 10 == 1 && this % 100 != 11) ? 'st' :
   				(this % 10 == 2 && this % 100 != 12) ? 'nd' :
    			(this % 10 == 3 && this % 100 != 13) ? 'rd' : 'th'
    			);
	}
	
// Return pretty text of current date and time, equivalent to
// "dddd, mmmm d, yyyy" for short month names and "dddd, mmm. d, yyyy"
// for long month names in equivalent Microsoft formatting
function prettyNow () {
	// Array of day names
	var dayNames = new Array( "SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY");
	// Array of month Names
	var monthNames = new Array(
	"JAN. ","FEB. ","MARCH ","APRIL ","MAY ","JUNE ","JULY ","AUGUST ","SEPT. ","OCT. ","NOV. ",			"DEC. ");
	var now = new Date();	
	
return dayNames[now.getDay()] + ",&nbsp;" + monthNames[now.getMonth()] + " " + now.getDate() + ", " + now.getFullYear();
}