//--------------- LOCALIZEABLE GLOBALS ---------------

var currDate = new Date();
var monthnames = new Array( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var todayString = monthnames[currDate.getMonth()] + " " + currDate.getDate() + ", " + currDate.getFullYear();
var seniorYear = currDate.getFullYear() - 62;

var moCaption = new Array( "June 2012", "July 2012", "August 2012", "September 2012", "October 2012", "November 2012" );
var moMax = new Array( 30, 31, 31, 30, 31, 30 );

// the Sunday1 number is the date on the month calendar for the first Sunday of that month
// if the 1st falls on Sunday, then the value is 1
// if the 1st falls on Monday, then the value is 0 (1 minus 1 = 0)
// if the 1st falls on Tuesday, then the value is -1 (1 minus 2 = -1)
// Sunday is 1; Mon is 0; Tue is -1; Wed is -2; Thu is -3; Fri is -4; Sat is -5

var moSunday = new Array( -4, 1, -2, -5, 0, -3 );
var prev4mo = new Array ( "&laquo; May", 																	// previous month for June is May
						"<a style='cursor:pointer'><span onclick='monthPrev();'>&laquo; Jun</span></a>",	// previous month for July is Jun
						"<a style='cursor:pointer'><span onclick='monthPrev();'>&laquo; Jul</span></a>",	// previous month for Aug  is Jul
						"<a style='cursor:pointer'><span onclick='monthPrev();'>&laquo; Aug</span></a>",	// previous month for Sept is Aug
						"<a style='cursor:pointer'><span onclick='monthPrev();'>&laquo; Sep</span></a>",	// previous month for Oct  is Sep
						"<a style='cursor:pointer'><span onclick='monthPrev();'>&laquo; Oct</span></a>"		// previous month for Nov  is Oct
						);
var next4mo = new Array ( "<a style='cursor:pointer'><span onclick='monthNext();'>Jul &raquo;</span></a>",	// next month for June is Jul 
						 "<a style='cursor:pointer'><span onclick='monthNext();'>Aug &raquo;</span></a>",	// next month for July is Aug
						"<a style='cursor:pointer'><span onclick='monthNext();'>Sep &raquo;</span></a>",	// next month for Aug  is Sep
						"<a style='cursor:pointer'><span onclick='monthNext();'>Oct &raquo;</span></a>",	// next month for Sept is Oct
						"<a style='cursor:pointer'><span onclick='monthNext();'>Nov &raquo;</span></a>",	// next month for Oct  is Nov
						"Dec &raquo;" );																	// next month for Nov  is Dec

var divNames = new Array ( "julyDiv", "julyDiv", "augustDiv", "fallDiv", "fallDiv", "fallDiv" );			// there are only 3 divs for 6 months

var firstMoValue = 5;
var lastMoValue = 10;

var calMonth = firstMoValue;			// Start in June
var calDay = 1;				// on the first

var todayMonth = 0;			// so we can flag today's date on the calendar
var todayDay = 0;

var factList = new Array(
	"Apples are grown in every state in the continental United States, and are grown commercially in 36 states.",
	"Archeologists have found evidence that humans have been enjoying apples since at least 6500 B.C.",
	"It takes energy from 50 leaves to produce one apple.",
	"Planting an apple seed from a particular apple will not produce a tree of that same variety. " +
		"The seed is a cross of the tree the fruit was grown on and the variety that was the cross pollinator.",
	"Apples are a member of the rose family.",
	"Apples have five seed pockets or carpels. Each pocket contains seeds. " + 
		"The number of seeds per carpel is determined by the vigor and health of the plant. Different varieties of apples will have different number of seeds.",
	"A bushel of apples weights about approximately 42 pounds.",
	"Fresh apples float because 25% of their volume is air (thank goodness, or none of us would have ever experienced bobbing for apples!).",
	"Apple varieties range in size from a little larger than a cherry to as large as a grapefruit. " + 
		"There are apples that have an aftertaste of pears, citrus, cinnamon, cloves, coconut, strawberries, grapes and even pineapple!",
	"In 2008, the average U.S. consumer ate an estimated 16.4 pounds of fresh-market apples, " + 
		"and 33.3 pounds of processed apples, for a total of 49.8 pounds of fresh apples and processed apple products.",
	"The apple tree originated in an area between the Caspin and the Black Sea.",
	"Apples were introduced to New York by the European settlers who brought seeds with them in the 1600s.",
	"The apple is the official state fruit of Rhode Island, New York, Washington, and West Virginia.",
	"The apple blossom (Pyrus coronaria) is the official state flower of Arkansas and Michigan.",
	"About 2,500 known varieties of apples are grown in the United States. More than 7,500 are grown worldwide. " + 
		"Here at Harvest TIme Orchards, we grow 12 different varieties of apples PLUS 2 different kinds of cherries!",
	"Nearly 100 varieties of apples are grown commercially in the United States, but a total of 15 popular varieties account for over 90% of production.",
	"Apples are a source of dietary fiber and essential vitamins and minerals.",
	"A medium apple contains no fat and only 80 calories! Apples are also thought to help reduce the risk of heart disease, cancer, stroke, type 2 diabetes and asthma.",
	"The best apples have a good aroma and are free of skin breaks and bruises.",
	"Handle apples gently to prevent bruising.",
	"Store apples in the refrigerator as soon as possible to slow ripening and maintain flavor; chilled properly, apples can keep anywhere from 4 to 6 weeks.",
	"Apples ripen six to ten times faster at room temperature than if they were refrigerated. " + 
		"For optimal storage, apples should be kept at 35-40 degrees with relative humidity of 80-90%.",
	"Store apples away from strong-smelling foods, to prevent them from absorbing unpleasant odors.",
	"Wash each apple under cool running water and dry with a clean paper towel before eating them.",
	"Slip apples slices and dices into a mixture of one part lemon juice to three parts water, " + 
		"or 100% apple juice with added vitamin C, to slow browning. Eat within 2 hours or refrigerate immediately until use.",
	"COOKS NOTE: One pound of sliced apples equals about 2 3/4 cups; diced, about 3 cups. As a rule, 2 large, 3 medium or 4 small apples equal 1 pound."
	);

//---------------   END LOCALIZEABLE   ---------------

function updateCal() 
{
	var captText = moCaption[calMonth - firstMoValue];
	var monthMax = moMax[calMonth - firstMoValue];

	var calendarTbl = document.getElementById("calendar2");
	
	//  here is how the caption looks:
	//
	//	<a href="../page/calendar/htseason.html?cal=julyDiv">July 2012</a>

	var oldCaption = calendarTbl.caption.innerHTML;
	var indexofAtag = oldCaption.indexOf( ">" );		// find the end of the <A> tag
	
	calendarTbl.caption.innerHTML = oldCaption.substring( 0, indexofAtag + 1 ) + captText + "</a>";
	
	// Do it again to change the DIV name in the string
	
	oldCaption = calendarTbl.caption.innerHTML;
	indexofAtag = oldCaption.indexOf( ">" );
	
	var indexofEqual = oldCaption.lastIndexOf( "=" );
	var oldCaptLen = oldCaption.length;
	
	calendarTbl.caption.innerHTML = oldCaption.substring( 0, indexofEqual + 1) + divNames[calMonth - firstMoValue] + oldCaption.substring( indexofAtag - 1, oldCaptLen );

	var preBtn = document.getElementById("prev");
	var nexBtn = document.getElementById("next");
	
	preBtn.innerHTML = prev4mo[calMonth - firstMoValue];
	nexBtn.innerHTML = next4mo[calMonth - firstMoValue];
	
	var currentDate = moSunday[calMonth - firstMoValue];
	
	for (x = 1; x < 7; x = x + 1)		// start at 1 to skip header row (with S M T W T F S)
	{
		rowHTML = "";
		for (y = 0; y < 7; y = y + 1)
		{
			if (currentDate <= 0 || currentDate > monthMax)
			{
				rowHTML = rowHTML + "<td>&nbsp;</td>";
			}
			else if (todayMonth == calMonth && todayDay == currentDate)
			{
				rowHTML = rowHTML + "<td id='now'>" + currentDate + "</td>";
			}
			else
			{
				rowHTML = rowHTML + "<td>" + currentDate + "</td>";
			}
			currentDate = currentDate + 1;
		}
		
		calendarTbl.rows[x].innerHTML = rowHTML;
	}
	
}

function monthNext()
{
	calMonth = calMonth + 1;
	updateCal();
}

function monthPrev()
{
	calMonth = calMonth - 1;
	updateCal();
}

function setCalToNow()
{
	var thisMonth = currDate.getMonth();
	var thisDay = currDate.getDate();
	
	todayMonth = thisMonth;
	todayDay = thisDay;

	if (thisMonth >= firstMoValue && thisMonth <= lastMoValue)		// Months start at 5
	{
		calMonth = thisMonth;
		calDay = thisDay;
	}
	else
	{
		calMonth = firstMoValue;
		calDay = 1;
	}
	
	updateCal();
}

function scrollposition()
{
	var xPos = 0;
}

// ------------ Display and hide DIV in htseason.html

function swapDiv( turnDivOn ) 
{
	var julDiv = document.getElementById( "julyDiv" );
	var augDiv = document.getElementById( "augustDiv" );
	var sepDiv = document.getElementById( "fallDiv" );
	
	var onDiv = julDiv;
	
	if ( turnDivOn != "" )
	{
		onDiv = document.getElementById( turnDivOn );
	}

   	julDiv.style.display = "none";
	augDiv.style.display = "none";
	sepDiv.style.display = "none";
	
	onDiv.style.display = "block";
} 

function parseURLparams( myParam )
{
	var query = window.location.search.substring(1);	// returns the queary portion of the URL including the ?
	var parms = query.split('&');						// gets the array of substrings split at the symbol
	
	for (var i = 0; i < parms.length; i++) 
	{
		var pos = parms[i].indexOf( '=' );

		if ( pos > 0  && myParam == parms[i].substring( 0, pos )) 
		{
				return parms[i].substring( pos + 1 );;
		}
		return "";
	}
}

function openSeasonCal()
{
	var calDiv = parseURLparams( "cal" );
	
	swapDiv( calDiv );
}

function randomFact()
{
	// get a random integer between 0 and 14
	
	factNumber = 1;
	lastFact = factList.length;
	factNumber = Math.floor(Math.random() * lastFact);
	
	var factDiv = document.getElementById( "fact1" );
	factDiv.innerHTML = factList[factNumber];
}


// ------------ Display and hide DIV in muminfo.html

function swapMum( turnDivOn, maxTab ) 
{
	var onDiv = 0;
	
	var mumDiv = new Array();
	var mumTab = new Array();
	var mumTabA = new Array();

	var i;
	
	// get the tab panel, tab, and id names

	for (i = 0; i < maxTab; i++)
	{
		// get the tab panel names
		
		sectName = "mumDiv" + (i+1);
		mumDiv[i] = document.getElementById( sectName );
	
		// get the tab names

		sectName = "mumTab" + (i+1);
		mumTab[i] = document.getElementById( sectName );

		// get the a ids

		sectName = "mumTab" + (i+1) + "a";
		mumTabA[i] = document.getElementById( sectName );
	}
	
	if ( turnDivOn >= 0 )
		if ( turnDivOn < maxTab )
		{
			onDiv = mumDiv[turnDivOn];
			onTab = mumTab[turnDivOn];
			onTabA = mumTabA[turnDivOn];
		}

	for ( i = 0; i < maxTab; i++ )
	{
	   	mumDiv[i].style.display = "none";
	   	mumTab[i].style.border = "outset";
		mumTab[i].style.backgroundColor = "#696";
		mumTabA[i].style.color = "#FFF";
	}

	mumDiv[turnDivOn].style.display = "block";
	mumTab[turnDivOn].style.border = "inset";
	mumTab[turnDivOn].style.backgroundColor = "#DEEBCC";
	mumTabA[turnDivOn].style.color = "#000";

} 

