//
// Version 1.0
//

if( !Date.getFullYear )
{
   Date.prototype.getFullYear = getFullYear;
}

function getFullYear()
{
   var year = this.getYear();
   if (year < 1000) year += 1900;
   return year;
}
//------------------------------------------------------------------------------
//
// Function to return current date as a string.
// Format for returned string is Thursday 1st January 2004
//
// args: dayShort   - number of characters to use in substring
//       monthShort - number of characters to use in substring
//       uppercase  - return uppercase string? true(yes) false(no)
//
// rtns: current date as a string
//
//------------------------------------------------------------------------------
function getToday(dayShort,monthShort,uppercase,addYear)
{
   if( dayShort == undefined || dayShort < 1 || dayShort > 3 )
   {
      dayShort = 0;
   }

   if( monthShort == undefined || monthShort < 1 || monthShort > 3 )
   {
      monthShort = 0;
   }

   if( addYear == undefined || (addYear != true && addYear != false) )
   {
      addYear = true;
   }

   if( uppercase == undefined || (uppercase != false && uppercase != true) )
   {
      uppercase = false;
   }

   //------------------------------------------------------------------------

   var dayOfWeek = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
   var monthOfYear = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
   var today = new Date(), date, day, month, year;
   
   var theDay, theMonth;
   
   theDay = dayOfWeek[today.getDay()];
   theMonth = monthOfYear[today.getMonth()];
   
   if( uppercase )
   {
      theDay = theDay.toUpperCase();
      theMonth = theMonth.toUpperCase();
   }

   day = ( dayShort == 0 ? theDay : theDay.substr(0,dayShort) );
   date = today.getDate();
   date = date + nths(date);
   month = ( monthShort == 0 ? theMonth : theMonth.substr(0,monthShort) );
   year = today.getFullYear();

   if( addYear ) return (day+" "+date+" "+month+" "+year);
   else return (day+" "+date+" "+month);
}

//------------------------------------------------------------------------------
//
// Function to return the ordinal for given date.
//
// args: date    - day of the month
//
// rtns: ordinal - string of "nd", "rd", "st" or "th"
//
//------------------------------------------------------------------------------
function nths(date)
{
   var ordinal = "th";
   
   if( date == 1 || date == 21 || date == 31 )
   {
      ordinal = "st";
   }
   else if( date == 2 || date == 22 )
   {
      ordinal = "nd";
   }
   else if( date == 3 )
   {
      ordinal = "rd";
   }
   
   return ordinal;
}
