// JavaScript Document

/*These functions help us to calculate the 1st Wednesday of the every month */


/*makes sure that the script is working properly after Y2k*/
function y2k(number) { return (number < 1000) ? number + 1900 : number; }


/*determine the day of the week from the input*/
function DayOfWeek(day,month,year) {
    var a = Math.floor((14 - month)/12);
    var y = year - a;
    var m = month + 12*a - 2;
    var d = (day + y + Math.floor(y/4) - Math.floor(y/100) +
             Math.floor(y/400) + Math.floor((31*m)/12)) % 7;
    return d + 1;
}

/*makes the various arrays for months and months of the year*/
function makeArray()    {
    this[0] = makeArray.arguments.length;
    for (i = 0; i<makeArray.arguments.length; i++)
        this[i+1] = makeArray.arguments[i];
}

var daysofmonth   = new makeArray( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var daysofmonthLY = new makeArray( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var monthsofyear = new makeArray('January','February','March','April','May','June','July','August','September','October','November','December');

function LeapYear(year) {
    if ((year/4)   != Math.floor(year/4))   return false;
    if ((year/100) != Math.floor(year/100)) return true;
    if ((year/400) != Math.floor(year/400)) return false;
    return true;
}

/*Determines the date from the nth day of the month   */
/*nth is the specific number (1st,2nd,3rd,4th) */
/*weekday is the actual weekeday (Monday=2, Tuesday=3, Wednesday=4,etc.) */
function NthDay(nth,weekday) {
    var today = new Date();
var thisYear = y2k(today.getYear());
var thisMonth = today.getMonth();
var thisDay = today.getDay();
var actDate = today.getDate();
var theDay;
thisMonth++;


    if (thisMonth == 11) thisYear++; 
	
	if (nth > 0) 
		if (weekday > thisDay) {
			theDay = (nth-1)*7 + 1 + (7 + weekday - DayOfWeek((nth-1)*7 + 1,thisMonth,thisYear))%7;
			if (theDay < actDate) {
				thisMonth++;
				theDay = (nth-1)*7 + 1 + (7 + weekday - DayOfWeek((nth-1)*7 + 1,thisMonth,thisYear))%7;
			}
		}
		else 
			thisMonth++;
			theDay = (nth-1)*7 + 1 + (7 + weekday - DayOfWeek((nth-1)*7 + 1,thisMonth,thisYear))%7;
	
	return monthsofyear[thisMonth]+' '+theDay + Nths(theDay)  ;
}

/* Adds the appropriate ending to the number*/
function Nths(day) { 
    if (day == 1 || day == 21 || day == 31) return 'st';
    if (day == 2 || day == 22) return 'nd';
    if (day == 3 || day == 23) return 'rd';
    return 'th';
}

