// JavaScript Document

/*********************************************************************/
/*  This script will diplay the date [mmmm/dd] for the next Chapter  */
/*  Meeting of the Baltimore H.O.G. Chapter, which occurs on the     */
/*  first Thursday of each month.                                    */
/*                                                                   */
/*  Created by Jason Grundman (my 1st javascript) 12/27/2007         */
/*********************************************************************/

/* Declare an array to supply the Month names as text. */
	
	var monthName = new Array();
	monthName[0] = "January";
	monthName[1] = "February";
	monthName[2] = "March";
	monthName[3] = "April";
	monthName[4] = "May";
	monthName[5] = "June";
	monthName[6] = "July";
	monthName[7] = "August";
	monthName[8] = "September";
	monthName[9] = "October";
	monthName[10] = "November";
	monthName[11] = "December";
	
/* Declare common variables to be used through the script. */
	
	var now = new Date();
	var currDate = now.getDate();
	var firstOfMonth = new Date();
	firstOfMonth.setDate(1);
	var firstDay = firstOfMonth.getDay();

/* Declare an array to determine the number of days to add 
when 'firstOfMonth' is not the first Thursday. */
	
	var wkDay = new Array();
	wkDay[0] = 4;
	wkDay[1] = 3;
	wkDay[2] = 2;
	wkDay[3] = 1;
	wkDay[4] = 0;
	wkDay[5] = 6;
	wkDay[6] = 5;
	
/* Set the Meeting date [dd] for the current month. If the 1st is
not on a Thursday, refer to the wkDay array to find how many
days to add to get there */
	
	var currMtgDate = new Date();
	currMtgDate.setDate(1 + (wkDay[firstDay]));
	
/*Set the Meeting date [dd] for next month by adding 4 or 5 weeks
to the current meeting date. The date has to be 
between the 1st and 7th of the upcoming month, so if 4 weeks is
not enough, then add a total of five weeks. */

	var nextMtgDate = new Date();
	nextMtgDate.setDate(currMtgDate.getDate() + 28);
	if (nextMtgDate.getDate() > 7) {
		nextMtgDate.setDate(currMtgDate.getDate() + 35);
	}

/* Determine a date suffix to be added for
readability (i.e. 31st, 22nd, 3rd, 12th). */

	function dateSuffix(intDate) {
		switch (intDate) {
			case 1 || 21 ||31:
				var strSuffix = "st";
				break;
			case 2 ||22:
				var strSuffix = "nd";
				break;
			case 3 || 23:
				var strSuffix = "rd";
				break;
			default:
				var strSuffix = "th";
		}
		return strSuffix;
	}

/* Determine which of the Meeting dates will be the next to occur, based on 
today's date, and output the correct option as text (ex: "Thursday, Januray 3rd"). */
	
	function getMtgDate() {
		
		if (currDate <= currMtgDate.getDate()) {
			var mtgDate = ("Thursday, " + monthName[currMtgDate.getMonth()] + 
				" " + currMtgDate.getDate() + dateSuffix(currMtgDate.getDate()));
			return mtgDate;
		}
		else {
			var mtgDate = ("Thursday, " + monthName[nextMtgDate.getMonth()] + 
				" " + nextMtgDate.getDate() + dateSuffix(nextMtgDate.getDate()));
			return mtgDate;
		}
	}

	  document.write (getMtgDate());
	
	
	

