var fullMonthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var abbrevMonthArray = new Array("Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
var abbrevDayArray = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
var abbrevDaysOfWeekInit = new Array("S", "M", "T", "W", "TR", "F", "S");

function beefcakeCalcDayOfYear() { // Calculates the day of the year between 1 and 365
	var dateVar = new Date();
	var Y = dateVar.getYear(), M = dateVar.getMonth(), D = dateVar.getDate()
	var seasonStartYear = Y;
	if (M < 08) { seasonStartYear--; } // BEEFCAKE_REVISIT --> HARDCODED to start in september every season.
	var doy = (Date.UTC(Y,M,D) - Date.UTC(seasonStartYear,08,01)) / 864e5; // BEEFCAKE_REVISIT --> Set to first day of season (note months from 0 to 11)
	if (doy < 1 || doy > 365) {
		alert ("Please send the webmaster email, tell him you saw this message, and let him know that one of his javascript functions isn't working properly.  Y = " + Y + " M = " + M + " D = " + D + " DOY = " + doy);
	}
	
	return doy;
}

function beefcakeMod(X, Y) { // Standard Mod Function
	return X - Math.floor(X/Y)*Y;
}

function beefPlayerNumOfDay() { // Determine the player of the day
	return ( beefcakeMod(beefcakeCalcDayOfYear(), arrayNames.length) );
}

function beefcakeGetPlayerAge() {
	var currDate = new Date();
	var birthDate = arrayDOB[beefPlayerNumOfDay()];
	
	var yearsDiff = currDate.getYear() - birthDate.getYear();
	if (currDate.getMonth() == birthDate.getMonth()) {
		if (currDate.getDate() < birthDate.getDate()) {
			yearsDiff--;
		}
	}
	else if (currDate.getMonth() > birthDate.getMonth()) {
		// Do Nothing, it's all good
	}
	else { // (currDate.getMonth() < birthDate.getMonth())
		yearsDiff--;
	}
	return yearsDiff-1900;
}
													  

function beefcakeGetMonthName() { // What's the current date?
	var dateVariable = new Date();
	return fullMonthArray[dateVariable.getMonth()]
}

function beefcakeDaysInMonth(year, month) {
	return 32 - new Date(year, month, 32).getDate();
}

// See schedule.js for irwinGetGameIndex function
<!-- beefcakebeefcake -->
function beefcakeGameChange(theGame) {
	var text = "";
	text = '<img src="imagesOpposingTeams/Beefcakes' + schedArrayVs[theGame] + '.jpg"><br><b>' + abbrevDayArray[schedArrayDate[theGame].getDay()] + ' ' + abbrevMonthArray[schedArrayDate[theGame].getMonth()] + ' ' + schedArrayDate[theGame].getDate() + ', ' + schedArrayTime[theGame] + '<br><I>@</I>' + schedArrayLoc[theGame] + ' vs. ' + schedArrayVs[theGame] + "</b>";
	gameDisplay.innerHTML = text;
	//window.event.cancelBubble = true; //BEEFCAKE_REVISIT --> Became an error after calling the "init" function.
}

function beefcakeGenerateCalendar() { // Auto Generate the Calendar based on current month, etc
	var currDateTime = new Date();
	var dateVar = new Date(currDateTime.getYear(), currDateTime.getMonth(), 01, 00, 00, 00);
	var currDayOfWeek = dateVar.getDay();
	var lastDayOfMonth = beefcakeDaysInMonth(dateVar.getYear(), dateVar.getMonth());
	var gameIndex = -1;
	var i=0, j=0, k=1;
	var maxDaysForSixCalendarRows = 35; // This is from 7 days per week times 5 rows (as opposed to needing a sixth).

	// NEW:  The days of the week
	document.write("<tr>");
	for (i=0; i<7; i++) {
		document.write("<td id=\"divBeefcakeScheduletd0\"><B><div>" + abbrevDaysOfWeekInit[i] + "</div></B></td>");
	}
	document.write("</tr><tr>");
	for (i=0; i<42; i++) {
		// When i travels through the sixth row, but we only need five for this month, do nothing
		if (lastDayOfMonth - 1 + currDayOfWeek < maxDaysForSixCalendarRows & i >= maxDaysForSixCalendarRows) {
			// Do Nothing
		}
		// For blank grids (leading or trailing blanks surrounding the 29-to-31 days of the month
		else if (i < currDayOfWeek | i > (lastDayOfMonth - 1 + currDayOfWeek)) {
			document.write("<td>&nbsp</td>");
		}
		// Default:  All days in the month (that may or may not have an event)
		else {
			gameIndex = beefcakeGetGameIndex(new Date(dateVar.getYear(), dateVar.getMonth(), k));
			// Nothing
			if (gameIndex == -1) {
				document.write("<td id=\"divBeefcakeScheduletd1\"><div>" + k + "</div></td>");
			}
			// Feis
			else if (schedArrayHomeAway[gameIndex] == "Away") {
				document.write("<td id=\"divBeefcakeScheduletd2\"><a onMouseOver=\"beefcakeGameChange(" + gameIndex + ");\"><B>" + k + "</B></a></td>");
			}
			// Performance
			else if (schedArrayHomeAway[gameIndex] == "Home") {
				document.write("<td id=\"divBeefcakeScheduletd3\"><a onMouseOver=\"beefcakeGameChange(" + gameIndex + ");\"><B>" + k + "</B></a></td>");
			}
			else { alert("Javascript error detected.  Please notify the webmaster of this message:  Error 01"); }
			
			k++;
			
			// Jump to next row at end of 7 days
			if (beefcakeMod(i,7) == 6) {
				document.write("</tr>");
				if (i<maxDaysForSixCalendarRows) { document.write("<tr>"); }
			} // end if beefcakeMod()
		} // end else (default)
	} // end for loop
	
	
	gameIndex = beefcakeGetGameIndex(new Date(currDateTime.getYear(), currDateTime.getMonth(), currDateTime.getDate()));
	if(gameIndex>=0)
	{
			beefcakeGameChange(gameIndex);
	}
	
} // end function

function beefcakeReWriteCalendar(selectedDate) {
	var text = "<table cellpadding=\"0\" cellspacing=\"2\" border=\"0\" width=\"164\" id=\"divBeefcakeSchedule\">";
	var tempText = "";
	var displayDate = new Date(selectedDate);
	var currDateTime = new Date(displayDate.getYear(), displayDate.getMonth(), displayDate.getDate(), 00, 00, 00); // Use input --> Diff than last function
	var dateVar = new Date(currDateTime.getYear(), currDateTime.getMonth(), 01, 00, 00, 00);
	var currDayOfWeek = dateVar.getDay();
	var lastDayOfMonth = beefcakeDaysInMonth(dateVar.getYear(), dateVar.getMonth());
	var gameIndex = -1;
	var i=0, j=0, k=1;
	var maxDaysForSixCalendarRows = 35; // This is from 7 days per week times 5 rows (as opposed to needing a sixth).

	// NEW:  The days of the week
	text += "<TR>";
	for (i=0; i<7; i++) {
		tempText = "<td id=\"divBeefcakeScheduletd0\"> <B> <div>" + abbrevDaysOfWeekInit[i] + "</div> </B> </td>";
		text += tempText;
	}
	text += "</TR> <TR>";

	for (i=0; i<42; i++) {
		// When i travels through the sixth row, but we only need five for this month, do nothing
		if (lastDayOfMonth - 1 + currDayOfWeek < maxDaysForSixCalendarRows & i >= maxDaysForSixCalendarRows) {
			// Do Nothing
		}
		// For blank grids (leading or trailing blanks surrounding the 29-to-31 days of the month
		else if (i < currDayOfWeek | i > (lastDayOfMonth - 1 + currDayOfWeek)) {
			text += "<td>&nbsp</td>";
		}
		// Default:  All days in the month (that may or may not have an event)
		else {
			gameIndex = beefcakeGetGameIndex(new Date(dateVar.getYear(), dateVar.getMonth(), k));
			// Nothing
			if (gameIndex == -1) {
				text += "<td id=\"divBeefcakeScheduletd1\"><div>" + k + "</div></td>";
			}
			// Feis
			else if (schedArrayHomeAway[gameIndex] == "Away") {
				text += "<td id=\"divBeefcakeScheduletd2\"> <a onMouseOver=\"beefcakeGameChange(" + gameIndex + ");\"> <b>" + k + "</b> </a> </td>";
			}
			// Performance
			else if (schedArrayHomeAway[gameIndex] == "Home") {
				text += "<td id=\"divBeefcakeScheduletd3\"> <a onMouseOver=\"beefcakeGameChange(" + gameIndex + ");\"> <b>" + k + "</b> </a> </td>";
			}
			else { alert("Javascript error detected.  Please notify the webmaster of this message:  Error 02"); }
			
			k++;
			
			// Jump to next row at end of 7 days
			if (beefcakeMod(i,7) == 6) {
				text += "</TR>";
				if (i<maxDaysForSixCalendarRows) { text += "<TR>"; }
			} // end if beefcakeMod()
		} // end else (default)
	} // end for loop
	
	text += "</table>";

	calendarDisplay.innerHTML = text;
	window.event.cancelBubble = true; // BEEFCAKE_REVISIT --> Not sure what this does
	//alert(text);
}


function beefcakeGetTargetDate() { //BEEFCAKE_REVISIT --> Bad coding, clean up later...
	var currDate = new Date();
	var returnDate = new Date("September 23 22:00 2007"); // BEEFCAKE_REVISIT --> Hardcoded = bad
	var i = 0;
	for (i = 0; i < 365; i++) {
		if (!schedArrayBEEFCAKE_REVISITfix[i] | schedArrayBEEFCAKE_REVISITfix[i] < currDate) {
			// Do Nothing
		} else {
			return schedArrayBEEFCAKE_REVISITfix[i];
		}
	}
	return returnDate;
}

function beefcakeTEMP(zzz) {
// document.write(arrayNumbers[zzz], ", ", arrayNames[zzz], ", ", arrayPositions[zzz], ", ", arrayHeights[zzz], ", ", arrayWeights[zzz], ", ", arrayCity[zzz], ", ", arrayDOB[zzz].getYear(), ", ", arrayDOB[zzz].getMonth(), ", ", arrayDOB[zzz].getDate())
}














function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



















//-->
// JavaScript Document
