
/* Preload images script */
var myimages=new Array()

function preloadimages(){
	for (i=0;i<preloadimages.arguments.length;i++){
		myimages[i]=new Image();
		myimages[i].src=preloadimages.arguments[i];
	}
}


/* The path of images to be preloaded inside parenthesis: (Extend list as desired.) */
preloadimages("eventdata/PrevYrOff40x40.jpg","eventdata/PrevYrOn40x40.jpg","eventdata/PrevMoOff40x40.jpg","eventdata/PrevMoOn40x40.jpg","eventdata/NextYrOff40x40.jpg","eventdata/NextYrOn40x40.jpg","eventdata/NextMoOff40x40.jpg","eventdata/NextMoOn40x40.jpg");


/***************************************************************************************
	JavaScript Calendar - Digital Christian Design
	//Script featured on and available at JavaScript Kit: http://www.javascriptkit.com
	// Functions
		changedate(): Moves to next or previous month or year, or current month depending on the button clicked.
		createCalendar(): Renders the calander into the page with links for each to fill the date form filds above.
			
***************************************************************************************/

var thisDate = 1;							// Tracks current date being written in calendar
var wordMonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var today = new Date();							// Date object to store the current date
var todaysDay = today.getDay() + 1;					// Stores the current day number 1-7
var todaysDate = today.getDate();					// Stores the current numeric date within the month
var todaysMonth = today.getUTCMonth() + 1;				// Stores the current month 1-12
var todaysYear = today.getFullYear();					// Stores the current year
var monthNum = todaysMonth;						// Tracks the current month being displayed
var yearNum = todaysYear;						// Tracks the current year being displayed
var firstDate = new Date(String(monthNum)+"/1/"+String(yearNum));	// Object Storing the first day of the current month
var firstDay = firstDate.getUTCDay();					// Tracks the day number 1-7 of the first day of the current month
var lastDate = new Date(String(monthNum+1)+"/0/"+String(yearNum));	// Tracks the last date of the current month
var numbDays = 0;
var calendarString = "";
var eastermonth = 0;
var easterday = 0;


function changedate(buttonpressed) {
	if (buttonpressed == "prevyr") yearNum--;
	else if (buttonpressed == "nextyr") yearNum++;
	else if (buttonpressed == "prevmo") monthNum--;
	else if (buttonpressed == "nextmo") monthNum++;
	else  if (buttonpressed == "return") { 
		monthNum = todaysMonth;
		yearNum = todaysYear;
	}

	if (monthNum == 0) {
		monthNum = 12;
		yearNum--;
	}
	else if (monthNum == 13) {
		monthNum = 1;
		yearNum++
	}

	lastDate = new Date(String(monthNum+1)+"/0/"+String(yearNum));
	numbDays = lastDate.getDate();
	firstDate = new Date(String(monthNum)+"/1/"+String(yearNum));
	firstDay = firstDate.getDay() + 1;
	createCalendar();

	var object=document.getElementById('selectevents');
	object.innerHTML = "";

	return;
}


function easter(year) {
// feed in the year it returns the month and day of Easter using two GLOBAL variables: eastermonth and easterday
var a = year % 19;
var b = Math.floor(year/100);
var c = year % 100;
var d = Math.floor(b/4);
var e = b % 4;
var f = Math.floor((b+8) / 25);
var g = Math.floor((b-f+1) / 3);
var h = (19*a + b - d - g + 15) % 30;
var i = Math.floor(c/4);
var j = c % 4;
var k = (32 + 2*e + 2*i - h - j) % 7;
var m = Math.floor((a + 11*h + 22*k) / 451);
var month = Math.floor((h + k - 7*m + 114) / 31);
var day = ((h + k - 7*m +114) % 31) + 1;
eastermonth = month;
easterday = day;
}


function createCalendar() {
	calendarString = '';
	var daycounter = 0;
	//
	// 
	calendarString += '<table class=\"caltab\">';
	calendarString += '<tr>';
	calendarString += '<td class=\"calcel_button\"><a href=\"#\" onMouseOver=\"document.PrevYr.src=\'..\/..\/styles\/calendar\/PrevYrOn40x40\.jpg\';\" onMouseOut=\"document.PrevYr.src=\'..\/..\/styles\/calendar\/PrevYrOff40x40\.jpg\';\" onClick=\"changedate(\'prevyr\')\"><img name=\"PrevYr\" src=\"..\/..\/styles\/calendar\/PrevYrOff40x40\.jpg\" width=\"40\" height=\"40\" border=\"0\" alt=\"Prev Yr\"\/><\/a><\/td>';
	calendarString += '<td class=\"calcel_button\"><a href=\"#\" onMouseOver=\"document.PrevMo.src=\'..\/..\/styles\/calendar\/PrevMoOn40x40\.jpg\';\" onMouseOut=\"document.PrevMo.src=\'..\/..\/styles\/calendar\/PrevMoOff40x40\.jpg\';\" onClick=\"changedate(\'prevmo\')\"><img name=\"PrevMo\" src=\"..\/..\/styles\/calendar\/PrevMoOff40x40\.jpg\" width=\"40\" height=\"40\" border=\"0\" alt=\"Prev Mo\"\/><\/a><\/td>';
	calendarString += '<td class=\"calcel_title\" colspan=\"3\"><b>' + wordMonth[monthNum-1] + '&nbsp;&nbsp;' + yearNum + '<\/b><\/td>';
	calendarString += '<td class=\"calcel_button\"><a href=\"#\" onMouseOver=\"document.NextMo.src=\'..\/..\/styles\/calendar\/NextMoOn40x40\.jpg\';\" onMouseOut=\"document.NextMo.src=\'..\/..\/styles\/calendar\/NextMoOff40x40\.jpg\';\" onClick=\"changedate(\'nextmo\')\"><img name=\"NextMo\" src=\"..\/..\/styles\/calendar\/NextMoOff40x40\.jpg\" width=\"40\" height=\"40\" border=\"0\" alt=\"Next Mo\"\/><\/a><\/td>';
	calendarString += '<td class=\"calcel_button\"><a href=\"#\" onMouseOver=\"document.NextYr.src=\'..\/..\/styles\/calendar\/NextYrOn40x40\.jpg\';\" onMouseOut=\"document.NextYr.src=\'..\/..\/styles\/calendar\/NextYrOff40x40\.jpg\';\" onClick=\"changedate(\'nextyr\')\"><img name=\"NextYr\" src=\"..\/..\/styles\/calendar\/NextYrOff40x40\.jpg\" width=\"40\" height=\"40\" border=\"0\" alt=\"Next Yr\"\/><\/a><\/td>';
	calendarString += '<\/tr>';
	calendarString += '<tr>';
	calendarString += '<td class=\"calcel_day\">Sun<\/td>';
	calendarString += '<td class=\"calcel_day\">Mon<\/td>';
	calendarString += '<td class=\"calcel_day\">Tue<\/td>';
	calendarString += '<td class=\"calcel_day\">Wed<\/td>';
	calendarString += '<td class=\"calcel_day\">Thu<\/td>';
	calendarString += '<td class=\"calcel_day\">Fri<\/td>';
	calendarString += '<td class=\"calcel_day\">Sat<\/td>';
	calendarString += '<\/tr>';

	thisDate == 1;

	for (var i = 1; i <= 6; i++) {
		calendarString += '<tr>';
		for (var x = 1; x <= 7; x++) {
			daycounter = (thisDate - firstDay)+1;
			thisDate++;
			if ((daycounter > numbDays) || (daycounter < 1)) {
				calendarString += '<td class=\"calcel_noday\">&nbsp;<\/td>';
			} else {
				if (checkevents(daycounter,monthNum,yearNum,i,x) || ((todaysDay == x) && (todaysDate == daycounter) && (todaysMonth == monthNum))){
					if ((todaysDay == x) && (todaysDate == daycounter) && (todaysMonth == monthNum)) {
						calendarString += '<td class=\"calcel_curday\"><a href=\"javascript:showevents(' + daycounter + ',' + monthNum + ',' + yearNum + ',' + i + ',' + x + ')\">' + daycounter + '<\/a><\/td>';
					}
 					else calendarString += '<td class=\"calcel_eventday\"><a href=\"javascript:showevents(' + daycounter + ',' + monthNum + ',' + yearNum + ',' + i + ',' + x + ')\">' + daycounter + '<\/a><\/td>';
				} else {
					calendarString += '<td class=\"calcel_noevent\">' + daycounter + '<\/td>';
				}
			}
		}
		calendarString += '<\/tr>';
	}

	calendarString += '<tr><td class=\"calcel_footer\" colspan=\"7\"><a href=\"javascript:changedate(\'return\')\"><b>Show Current Date<\/b><\/a><\/td><\/tr><\/table>';

	var object=document.getElementById('calendar');
	object.innerHTML= calendarString;
	thisDate = 1;
}


function checkevents(day,month,year,week,dayofweek) {
var numevents = 0;
var floater = 0;

	for (var i = 0; i < events.length; i++) {
		if (events[i][0] == "W") {
			if ((events[i][2] == dayofweek)) numevents++;
		}
		else if (events[i][0] == "Y") {
			if ((events[i][2] == day) && (events[i][1] == month)) numevents++;
		}
		else if (events[i][0] == "F") {
			if ((events[i][1] == 3) && (events[i][2] == 0) && (events[i][3] == 0) ) {
				easter(year);
				if (easterday == day && eastermonth == month) numevents++;
			} else {
				floater = floatingholiday(year,events[i][1],events[i][2],events[i][3]);
				if ((month == 5) && (events[i][1] == 5) && (events[i][2] == 4) && (events[i][3] == 2)) {
					if ((floater + 7 <= 31) && (day == floater + 7)) {
						numevents++;
					} else if ((floater + 7 > 31) && (day == floater)) numevents++;
				} else if ((events[i][1] == month) && (floater == day)) numevents++;
			}
		}
		else if ((events[i][2] == day) && (events[i][1] == month) && (events[i][3] == year)) {
			numevents++;
		}
	}

	if (numevents == 0) {
		return false;
	} else {
		return true;
	}
}


function showevents(day,month,year,week,dayofweek) {
var theevent = "";
var floater = 0;
var eventcount = 0;
var emitentry = 0;

	theevent += '<div class="caled_header">Events on: ' + month +'/'+ day +'/'+ year + '</div>';

	for (var i = 0; i < events.length; i++) {
		// First we'll process recurring events (if any):
		if (events[i][0] != "") {
			if (events[i][0] == "D") {
			}
			if (events[i][0] == "W") {
				if ((events[i][2] == dayofweek)) {
					emitentry = 1;
				}
			}
			if (events[i][0] == "M") {
			}
			if (events[i][0] == "Y") {
				if ((events[i][2] == day) && (events[i][1] == month)) {
					emitentry = 1;
				}
			}
			if (events[i][0] == "F") {
				if ((events[i][1] == 3) && (events[i][2] == 0) && (events[i][3] == 0) ) {
					if ((easterday == day) && (eastermonth == month)) {
						emitentry = 1;
					} 
				} else {
					floater = floatingholiday(year,events[i][1],events[i][2],events[i][3]);

					if ((month == 5) && (events[i][1] == 5) && (events[i][2] == 4) && (events[i][3] == 2)) {
						if ((floater + 7 <= 31) && (day == floater + 7)) {
							emitentry = 1;
						} else if ((floater + 7 > 31) && (day == floater)) {
							emitentry = 1;
						}
					} else if ((events[i][1] == month) && (floater == day)) {
						emitentry = 1;
					}
				}
			}
		}
		// Now we'll process any One Time events happening on the matching month, day, year:
		else if ((events[i][2] == day) && (events[i][1] == month) && (events[i][3] == year)) {
			emitentry = 1;
		}

		if( 1 == emitentry) {
			emitentry = 0;
			eventcount += 1;
/*
			theevent += '<div class="caled_entry"><div class="caled_etype">' + events[i][10] + '</div>';
			theevent += '<div class="caled_title">' + events[i][6] + '</div>';
			if(events[i][9] == ""){
				theevent += '<div class="caled_venue">' + events[i][8] + '</div>';
			}
			else{
				theevent += '<div class="caled_venue"><a href="' + events[i][9] + '">' + events[i][8] + '</a></div>';
			}
			theevent += '<div class="caled_description">' + events[i][7] + '</div></div>';

*/

			theevent += '<div class="caled_entry"><div class="caled_etype">' + events[i][10] + '</div>';
			theevent += '<div class="caled_title">' + events[i][6] + '</div>';
					
			theevent += '<div class="caled_ekind">' + events[i][5] + '</div>';
			if(events[i][9] == ""){
				theevent += '<div class="caled_venue">' + events[i][1] + '/' + events[i][2] + '/' + events[i][3] + ': ' + events[i][8];
			}
			else{
				theevent += '<div class="caled_venue">' + events[i][1] + '/' + events[i][2] + '/' + events[i][3] + ': <a href="' + events[i][9] + '">' + events[i][8] + '</a>';
			}
						// Contact	[11]	ContactEmail [12]	ContactPhone [13]
			if( "" != events[i][11]) { // There is a contact for the event
				if( "" != events[i][12]) { // There is a contact email for the event
					theevent += '<br/><div class="caled_contact"> Contact: <a href="mailto:' + events[i][12] + '">' + events[i][11] + '</a>';
				}
				else {
					theevent += '<br/><div class="caled_contact"> Contact: ' + events[i][11];
				}
				if( "" != events[i][13]) { // There is a contact phone for the event
					theevent += ', Phone: ' + events[i][13];
				}
				theevent += '</div>';
			}
			theevent += '</div>';
			theevent += '<div class="caled_description">' + events[i][7] + '</div></div>';
		}
	}
	if (eventcount == 0) {
		theevent += '<div class="caled_footer">No events to show.</div>'
	}
	else {
		theevent += '<div class="caled_footer">' + eventcount + ' event(s) for the day.</div>'
	}

	var object=document.getElementById('selectevents');
	object.innerHTML= theevent;

}


/*
	This function will display events matching a query based on the following parameters:
		eventtype which is one of: Dressage, Eventing, Driving, Equestrian (blank and Other are not used)
		eventkind which is one of: AShow, BShow, Clinic, Deadline, Holliday (blank and Other are not used)
		scope which is either 'M' or 'Y' which denotes the period to consider
	If eventtype or eventkind is left blank it is assumed that any value will do. Thus, keeping both
	blank, one can search for any event either in the month or the year.
*/
function showethismonth(month,year,eventtype,eventkind,scope) {
var theevent = "";
var floater = 0;
var eventcount = 0;
var emitentry = 0;

	theevent += '<div class="caled_header">Events this month:</div>';

	for (var j = 0; j < 2; j++) {
		for (var i = 0; i < events.length; i++) {
			if( ((0 == j) && ((events[i][4] == "EI") || (events[i][4] == "WCDEA") || (events[i][4] == "LPSDC"))) || ((1 == j) && ((events[i][4] != "EI") && (events[i][4] != "WCDEA") && (events[i][4] != "LPSDC")))) {
				if( "" != eventtype){	// eventtype is fixed
					if( "" != eventkind) {	// eventtype and eventkind are fixed
						if(((events[i][10] == eventtype) && (events[i][5] == eventkind)) && ((('M' == scope) && (events[i][1] == month) && (events[i][3] == year)) || (('Y' == scope) && (events[i][3] == year)))){
							emitentry = 1;
						}
					}
					else {	// eventkind is wild, eventtype is fixed
						if((events[i][10] == eventtype) && ((('M' == scope) && (events[i][1] == month) && (events[i][3] == year)) || (('Y' == scope) && (events[i][3] == year)))){
							emitentry = 1;
						}
					}
				}
				else {	// eventtype is wild
					if( "" != eventkind) {	// eventtype is wild and eventkind is fixed
						if((events[i][5] == eventkind) && ((('M' == scope) && (events[i][1] == month) && (events[i][3] == year)) || (('Y' == scope) && (events[i][3] == year)))){
							emitentry = 1;
						}
					}
					else {	// eventtype and eventkind are wild
						if((('M' == scope) && (events[i][1] == month) && (events[i][3] == year)) || (('Y' == scope) && (events[i][3] == year))){
							emitentry = 1;
						}
					}
				}
				if( 1 == emitentry) {
					eventcount += 1;
					emitentry = 0;
					if( 0 == j) {
						theevent += '<div class="caled_entry"><div class="caled_etype">' + events[i][10] + ' <b>(' + events[i][4] + ')</b></div>';
					}
					else {
						theevent += '<div class="caled_entry"><div class="caled_etype">' + events[i][10] + '</div>';
					}
					if(events[i][9] == "") {
						theevent += '<div class="caled_title">' + events[i][6] + '</div>';
					}
					else {
						theevent += '<div class="caled_title"><a href="' + events[i][9] + '">' + events[i][6] + ' (click for details)</a></div>';
					}

					theevent += '<div class="caled_ekind">' + events[i][5] + '</div>';

					if(events[i][8] == ""){
						theevent += '<div class="caled_venue">' + events[i][1] + '/' + events[i][2] + '/' + events[i][3];
					}
					else {
						theevent += '<div class="caled_venue">' + events[i][1] + '/' + events[i][2] + '/' + events[i][3] + ' at ' + events[i][8];
					}

						// Contact	[11]	ContactEmail [12]	ContactPhone [13]
					if( "" != events[i][11]) { // There is a contact for the event
						if( "" != events[i][12]) { // There is a contact email for the event
/*
																<a href="mailto:ei-webmaster@equestriansinstitute.org">Peter Larsen</a>
*/
							theevent += '<br/><div class="caled_contact"> Contact: <a href="mailto:' + events[i][12] + '">' + events[i][11] + '</a>';
						}
						else {
							theevent += '<br/><div class="caled_contact"> Contact: ' + events[i][11];
						}
						if( "" != events[i][13]) { // There is a contact phone for the event
							theevent += ', Phone: ' + events[i][13];
						}
						theevent += '</div>';
					}
					theevent += '</div>';
					theevent += '<div class="caled_description">' + events[i][7] + '</div></div>';
				}
			}
		}
	}

	if (eventcount == 0) {
		theevent += '<div class="caled_footer">No events to show.</div>'
	}
	else {
		theevent += '<div class="caled_footer">' + eventcount + ' event(s) for the month.</div>'
	}

	var object=document.getElementById('selectevents');
	object.innerHTML= theevent;
}

/*
	This function will display events matching a query based on the following parameters:
		eventtype which is one of: Dressage, Eventing, Driving, Equestrian (blank and Other are not used)
		eventkind which is one of: AShow, BShow, Clinic, Deadline, Holliday (blank and Other are not used)
		scope which is either 'M' or 'Y' which denotes the period to consider
	If eventtype or eventkind is left blank it is assumed that any value will do. Thus, keeping both
	blank, one can search for any event either in the month or the year.
*/

function showeupcoming(eventtype,eventkind) {
/* month,year,scope: are taken out and undefined */
var theevent = "";
var floater = 0;
var eventcount = 0;
var emitentry = 0;
var iscurrent = 0;
var showeventsmax = 6;
var showeventsexceeded = false;
var iseievent = false;

/*
	if( "" != eventtype){
		if( "" != eventkind)
			theevent += '<div class="caled_header">Upcoming ' + eventtype + ' ' + eventkind + ' :</div>';
		else
			theevent += '<div class="caled_header">Upcoming ' + eventtype + ' :</div>';
	}
	else{
		if( "" != eventkind)
			theevent += '<div class="caled_header">Upcoming ' + eventkind + ' :</div>';
		else
			theevent += '<div class="caled_header">Upcoming Events:</div>';
	}
*/


	for (var j = 0; j < 2; j++) {
		for (var i = 0; i < events.length; i++) {
			iscurrent = 0;
			if( todaysYear == events[i][3]) {
				if( todaysMonth == events[i][1]) {
						/* Let's try and replace 14 with 28 days into the future */
					if( (todaysDate <= parseInt(events[i][2])) && (todaysDate + 60) > parseInt(events[i][2])) {
						iscurrent=1;	/* Within 14 days */
					}
				}
				else {
						/* Let's try and replace 14 with 28 days into the future */
					if( ((todaysMonth + 1) == events[i][1]) && ((31 - todaysDate + parseInt(events[i][2])) <= 60)) {
						iscurrent=1;	/* Within 14 days, next month */
					}
				}
			}
			else {
						/* Let's try and replace 14 with 28 days into the future */
				if( ((todaysYear + 1) == events[i][3]) && ( 12 == todaysMonth) && ((31 - todaysDate + parseInt(events[i][2])) <= 60)) {
					iscurrent=1;	/* Within 14 days, next year */
				}
			}

			/* Currently does not show next years events */
 
			iseievent = false;
			if( ((0 == j) && ((events[i][4] == "EI") || (events[i][4] == "WCDEA") || (events[i][4] == "LPSDC"))) || ((1 == j) && ((events[i][4] != "EI") && (events[i][4] != "WCDEA") && (events[i][4] != "LPSDC")))) {
				if( (0 == j) && ((events[i][4] == "EI") || (events[i][4] == "WCDEA") || (events[i][4] == "LPSDC"))) {
					iseievent = true;
				}
/* *** */
				if( "" != eventtype){	// eventtype is fixed
					if( "" != eventkind) {	// eventtype and eventkind are fixed
						if(( 1 == iscurrent) && (events[i][10] == eventtype)){
							if(events[i][5] == eventkind){
								emitentry = 1;
							}
							if((eventkind == "Shows") && ((events[i][5] == "AShow") || (events[i][5] == "Show(NR)"))){
								emitentry = 1;
							}
						}
					}
					else {	// eventkind is wild, eventtype is fixed
						if(( 1 == iscurrent) && (events[i][10] == eventtype)){
							emitentry = 1;
						}
					}
				}
				else {	// eventtype is wild
					if( "" != eventkind) {	// eventtype is wild and eventkind is fixed
						if( 1 == iscurrent){
							if(events[i][5] == eventkind){
								emitentry = 1;
							}
							/*
							else theevent += "MIS:" + events[i][5];
							*/
				
							if( (eventkind == "Shows") && ((events[i][5] == "AShow") || (events[i][5] == "Show(NR)"))){
								emitentry = 1;
							}
							/*
							else theevent += "MIS:" + events[i][5];
							*/
						}
					}
					else {	// eventtype and eventkind are wild
						if( 1 == iscurrent){
							emitentry = 1;
						}
					}
				}
				if( 1 == emitentry) {
					eventcount += 1;
					emitentry = 0;
					if( !showeventsexceeded){
						if(events[i][9] == ""){
							if( iseievent){
								theevent += '<div class="calevent_current_ei">'+events[i][1]+'/'+events[i][2]+': <a href="http://www.equestriansinstitute.org/wroot09/einews/calendar/calendar.html">EI: ' + events[i][6] + '</a>';
							}
							else{
								theevent += '<div class="calevent_current">'+events[i][1]+'/'+events[i][2]+': <a href="http://www.equestriansinstitute.org/wroot09/einews/calendar/calendar.html">' + events[i][6] + '</a>';
							}
						}
						else{
							if( iseievent){
								theevent += '<div class="calevent_current_ei">'+events[i][1]+'/'+events[i][2]+': <a href="' + events[i][9] + '">EI: ' + events[i][6] + '</a>';
							}
							else{
								theevent += '<div class="calevent_current">'+events[i][1]+'/'+events[i][2]+': <a href="' + events[i][9] + '">' + events[i][6] + '</a>';
							}
						}
						theevent += '</div>';
					}
					if( eventcount >= showeventsmax){
						showeventsexceeded = true;
					}
				}
/* *** */
			}
		}
	}
/*
	if (showeventsexceeded) {
		theevent += '</br><div class="calevent_current"><a href="http://www.equestriansinstitute.org/wroot09/einews/calendar.html">' + (eventcount - showeventsmax) + ' More events ...</a></div>';
	}
*/
	if (eventcount == 0) {
		theevent += '<div class="caled_footer">No events to show.</div>'
	}
	else {
		theevent += '<div class="caled_footer"><a href="http://www.equestriansinstitute.org/wroot09/einews/calendar/calendar.html">' + eventcount + ' Upcoming Events ...</a></div>'
	}

	var object=document.getElementById('currentevents');
	object.innerHTML= theevent;
}


function floatingholiday(targetyr,targetmo,cardinaloccurrence,targetday) {
// Floating holidays/events of the events.js file uses:
//	the Month field for the Month (here it becomes the targetmo field)
//	the Day field as the Cardinal Occurrence  (here it becomes the cardinaloccurrence field)
//		1=1st, 2=2nd, 3=3rd, 4=4th, 5=5th, 6=6th occurrence of the day listed next
//	the Year field as the Day of the week the event/holiday falls on  (here it becomes the targetday field)
//		1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thurday, 6=Friday, 7=Saturday
//	example: "F",	"1",	"3",	"2", = Floating holiday in January on the 3rd Monday of that month.
//
// In our code below:
// 	targetyr is the active year
// 	targetmo is the active month (1-12)
// 	cardinaloccurrence is the xth occurrence of the targetday (1-6)
// 	targetday is the day of the week the floating holiday is on
//		0=Sun; 1=Mon; 2=Tue; 3=Wed; 4=Thu; 5=Fri; 6=Sat
//		Note: subtract 1 from the targetday field if the info comes from the events.js file
//
// Note:
//	If Memorial Day falls on the 22nd, 23rd, or 24th, then we add 7 to the dayofmonth to the result.
//
// Example: targetyr = 2052; targetmo = 5; cardinaloccurrence = 4; targetday = 1
//	This is the same as saying our floating holiday in the year 2052, is during May, on the 4th Monday
//
var firstdate = new Date(String(targetmo)+"/1/"+String(targetyr));	// Object Storing the first day of the current month.
var firstday = firstdate.getUTCDay();	// The first day (0-6) of the target month.
var dayofmonth = 0;	// zero out our calendar day variable.

	targetday = targetday - 1;

	if (targetday >= firstday) {
		cardinaloccurrence--;	// Subtract 1 from cardinal day.
		dayofmonth = (cardinaloccurrence * 7) + ((targetday - firstday)+1);
	} else {
		dayofmonth = (cardinaloccurrence * 7) + ((targetday - firstday)+1);
	}
return dayofmonth;
}

