var tourCalendarKeys = {
	eventClass: '0',
	eventId: '1',
	dateStart: '2',
	dateEnd: '3',
	descriptionHtml: '4',
	eventType: '5',
	timeStart: '6',
	timeEnd: '7',
	displayDate: '8'
};
var tourCalendar = [
	['Bike','DalBike','10/15/07','10/31/07','<a href="http://www.ms150.org/dallas/register/">Early Bird Registration</a>: $15','Registration'],
	['Bike','HouBike, DalBike, SABike','10/20/07','10/21/07','<a href="http://biketothebeach.ms150.org/btb/">Valero MS 150: San Antonio to Corpus Christi</a>','Recommended Ride, Tour Event'],
	['Bike','DalBike','11/1/07','1/31/08','<a href="http://www.ms150.org/dallas/register/">Registration Fee</a>: $25','Registration'],
	['Bike','HouBike','11/4/07','11/4/07','<a href="http://www.tourdedoughnut.com">Tour de Doughnut</a>','Recommended Ride'],
	['Bike','HouBike','11/10/07','11/10/07','<a href="http://www.novemberfestmetriccentury.org">Novemberfest Metric Century</a>','Recommended Ride'],
	['Bike','HouBike','11/18/07','11/18/07','<a href="http://www.ftbendliteracy.org">Bike the Bend Ride for Literacy</a>','Recommended Ride'],
	['Bike','HouBike','1/27/08','1/27/08','<a href="http://www.jvgolddusters.com">Frost Bike 50</a>','Recommended Ride'],
	['Bike','DalBike','2/1/08','3/31/08','<a href="http://www.ms150.org/dallas/register/">Registration Fee</a>: $50','Registration'],
	['Bike','HouBike','2/2/08','2/2/08','<a href="http://www.kingwoodfillies.org">Bike Through the Forest</a>','Recommended Ride'],
	['Bike','HouBike','2/9/08','2/9/08','<a href="http://www.tx.ducks.org">Ducks Unlimited Ride</a>','Recommended Ride'],
	['Bike','HouBike','2/10/08','2/10/08','<a href="http://www.teamwestu.org">The West U Warm Up</a>','Recommended Ride'],
	['Bike','HouBike','2/16/08','2/16/08','<a href="http://www.bulldogbikeride.com">The Bulldog Bike Ride</a>','Recommended Ride'],
	['Bike','HouBike','2/17/08','2/17/08','<a href="http://www.teamwestend.org">Wild West End Ride</a>','Recommended Ride'],
	['Bike','HouBike','2/23/08','2/23/08','<a href="http://www.humblelionsclub.com">Humble Lions Ride</a>','Recommended Ride'],
	['Bike','HouBike','2/24/08','2/24/08','<a href="http://www.hillhopper.org">Tri-County Hill Hopper</a>','Recommended Ride'],
	['Bike','HouBike','3/1/08','3/1/08','<a href="http://www.gatorride.org">Gator Ride</a>','Recommended Ride'],
	['Bike','HouBike','3/1/08','3/1/08','<a href="http://www.pedalthrupines.org">Pedal Thru the Pines</a>','Recommended Ride'],
	['Bike','DalBike','3/1/08','3/1/08','100 Club Ride<br />Ride and packet pick up for 100 Club members<br />Location and Time TBD','100 Club Event'],
	['Bike','DalBike','3/1/08','5/2/08','Bike Inspections<br />All riders must have their bikes inspected by an <a href="http://dallas.ms150.org/dallas/riding/official_bike_stores.asp">official bike store</a>.','Tour Event'],
	['Bike','HouBike','3/2/08','3/2/08','<a href="http://www.southernelite.org/Spring%20Breakaway%202008/Spring2008.htm">Sun &amp; Ski Sports Spring Breakaway</a>','Recommended Ride'],
	['Bike','HouBike','3/8/08','3/8/08','<a href="http://magnoliamiles.org/">Magnolia Miles</a>','Recommended Ride'],
	['Bike','HouBike','3/8/08','3/8/08','<a href="http://www.spiritreins.org">Spokes n\' Spurs</a>','Recommended Ride'],
	['Bike','DalBike','3/8/08','3/8/08','Kick-Off Party and Training Ride<br />Location and Time TBD','Tour Event'],
	['Bike','HouBike','3/9/08','3/9/08','<a href="http://cocyclingclassic.com/">The Continental Airlines Cycling Classic</a>','Recommended Ride'],
	['Bike','HouBike','3/15/08','3/15/08','<a href="http://www.houstonspecialevents.org">Guaranty Bank Tour de Houston</a>','Recommended Ride'],
	['Bike','HouBike','3/16/08','3/16/08','<a href="http://www.pearlandcyclingclub.org">The Great Escape Bike Ride</a>','Recommended Ride'],
	['Bike','HouBike','3/22/08','3/22/08','<a href="http://www.katyramchallenge.com">Katy Ram Challenge</a>','Recommended Ride'],
	['Bike','HouBike','3/29/08','3/29/08','<a href="http://www.fortbendisd.com/foundation">The Schlumberger Fort Bend Education Expedition</a>','Recommended Ride'],
	['Bike','HouBike','3/29/08','3/29/08','<a href="http://www.rosedaleride.org">The Rosedale Ride</a>','Recommended Ride'],
	['Bike','HouBike','3/30/08','3/30/08','<a href="http://www.northwestcyclingclub.com">Bluebonnet Express</a>','Recommended Ride'],
	['Bike','DalBike','10/13/07','10/13/07','<a href="http://www.paluxypedal.com/index.html">Paluxy Pedal</a>','Recommended Ride'],
	['Bike','DalBike','10/20/07','10/20/07','<a href="http://www.kiwaniscrazykicker.com">Kiwanis Crazy Kicker</a>','Recommended Ride'],
	['Bike','DalBike','11/17/07','11/17/07','<a href="http://www.DentonBreakfastKiwanis.org">25th Anniversary Denton Breakfast Kiwanis Club Denton Turkey Roll</a>','Recommended Ride'],
	['Bike','DalBike','02/02/08','02/02/08','<a href="http://www.visitlongviewtx.com/fyf/">Freeze Your Fanny</a>','Recommended Ride'],
	['Bike','DalBike','03/15/08','03/15/08','<a href="http://www.abilenetx.com/Recreation/documents/BikeRaceEntryForm.pdf">Steam & Wheels</a>','Recommended Ride'],
	['Bike','DalBike','03/29/08','03/29/08','<a href="http://www.rideforheroes.org">Moritz Chevrolet Ride for Heroes</a>','Recommended Ride'],
	['Bike','DalBike','03/29/08','03/29/08','<a href="http://www.sspilotclub.org">Spring Fever Ride</a>','Recommended Ride'],
	['Bike','DalBike','4/1/08','4/27/08','<a href="http://www.ms150.org/dallas/register/">Registration Fee</a>: $75','Registration'],
	['Bike','HouBike','4/5/08','4/5/08','<a href="http://www.campforall.org">Camp For All Hilltop Ride</a>','Recommended Ride'],
	['Bike','HouBike','4/5/08','4/5/08','<a href="http://www.hccac.org/howhelp/pedalpower/index.html">Pedal Power Wildflower Ride</a>','Recommended Ride'],
	['Bike','HouBike','4/6/08','4/6/08','<a href="http://www.spacerace.org">The Space Race</a>','Recommended Ride'],
	['Bike','DalBike','4/9/08','4/9/08','<a href="http://dallas.ms150.org/dallas/packet_pick-up.asp">Packet Pick-Up</a> - Plano Cycling<br />Riders can turn in their waiver forms and pick up their t-shirts, Champs bandanas, and rider packets<br /><a href="http://maps.google.com/maps?q=605+18th+St,+Plano,+TX+75074,+USA&ie=UTF8&z=17&iwloc=addr&om=1">Map and Directions</a>','Packet Pick-Up'],
	['Bike','DalBike','04/05/08','04/05/08','<a href="http://www.tourdallas.org">Tour Dallas</a>','Recommended Ride'],
	['Bike','DalBike','04/12/08','04/12/08','<a href="http://www.greaterdallasbicyclists.com">Lancaster Country Ride</a>','Recommended Ride'],
	['Bike','HouBike','4/12/08','4/13/08','<a href="http://www.ms150.org/ms150/">BP MS 150: Houston to Austin</a>','Tour Event'],
	['Bike','HouBike','4/26/08','4/26/08','<a href="http://www.brookwoodcommunity.org" alt="">Brookwood Spirit Rally</a>','Recommended Ride'],
	['Bike','DalBike, SABike','4/12/08','4/13/08','<a href="http://www.ms150.org/ms150/">BP MS 150: Houston to Austin</a>','Recommended Ride, Tour Event'],
	['Bike','DalBike','4/16/08','4/16/08','<a href="http://dallas.ms150.org/dallas/packet_pick-up.asp">Packet Pick-Up</a> - Fort Worth - Bicycles Inc<br />Riders can turn in their waiver forms and pick up their t-shirts, Champs bandanas, and rider packets<br /><a href="http://maps.google.com/maps?q=5125+Old+Granbury+Rd,+Fort+Worth,+TX+76133,+USA&ie=UTF8&z=17&iwloc=addr&om=1">Map and Directions</a>','Packet Pick-Up'],
	['Bike','DalBike','4/17/08','4/17/08','Team Captain\'s Logistic Meeting - National MS Society Office<br /><br /><a href="http://maps.google.com/maps?q=2105+Luna+Rd,+Carrollton,+TX+75006,+USA&ie=UTF8&z=17&iwloc=addr&om=1">Map and Directions</a>','Team Event'],
	['Bike','DalBike','04/19/08','04/19/08','<a href="http://www.cruisindehood.com">Cruisin\' de Hood</a>','Recommended Ride'],
	['Bike','DalBike','04/20/08','04/20/08','<a href="http://www.planobicycle.org/pba/index.php?option=com_events&task=view_detail&agid=82&year=2008&month=04&day=20&Itemid=27" alt="">EDS</a>','Recommended Ride'],
	['Bike','DalBike','4/21/08','4/21/08','Volunteer Training Night<br />6pm - 8pm, location TBD','Volunteer Event'],
	['Bike','DalBike','4/24/08','4/24/08','Volunteer Training Night<br />6pm - 8pm, location TBD','Volunteer Event'],
	['Bike','DalBike','4/25/08','4/25/08','<a href="http://dallas.ms150.org/dallas/packet_pick-up.asp">Packet Pick-Up</a> - Richardson Bike Mart<br />Riders can turn in their waiver forms and pick up their t-shirts, Champs bandanas, and rider packets<br /><a href="http://maps.google.com/maps?q=1451+W+Campbell+Rd,+Richardson,+TX+75080,+USA&ie=UTF8&z=17&iwloc=addr&om=1">Map and Directions</a>','Packet Pick-Up'],
	['Bike','DalBike','04/26/08','04/26/08','<a href="http://www.germanfest.net/bike.htm">Muenster Germanfest Metric Century</a>','Recommended Ride'],
	['Bike','DalBike','4/28/08','5/2/08','After April 28, new registrants must pay the <a href="http://www.ms150.org/dallas/register/">registration fee and minimum pledge</a>: $375','Registration'],
	['Bike','DalBike','4/30/08','4/30/08','<a href="http://dallas.ms150.org/dallas/packet_pick-up.asp">Packet Pick-Up</a> - MS Office','PPU'],
	['Bike','DalBike','5/2/08','5/2/08','Sam\'s Club MS 150 Expo<br />Last chance to pick up your <a href="http://dallas.ms150.org/dallas/packet_pick-up.asp">rider packet</a>. Check out our vendor booths<br /><a href="http://embassysuites1.hilton.com/en_US/es/hotel/DALFSES-Embassy-Suites-Dallas-Frisco-Hotel-Convention-Center-Spa-Texas/index.do">Hotel Website</a>','Tour Event, Packet Pick-Up'],
	['Bike','HouBike, SABike','5/3/08','5/4/08','<a href="http://dallas.ms150.org/">SAM\'S CLUB MS 150: Frisco to Fort Worth</a>','Recommended Ride, Tour Event'],
	['Bike','DalBike','5/3/08','5/4/08','<a href="http://dallas.ms150.org/">SAM\'S CLUB MS 150: Frisco to Fort Worth</a>','Tour Event'],
	['Bike','HouBike','5/17/08','5/17/08','<a href="http://www.pedalingtheprairie.org" alt="">Pedaling the Prairie</a>','Recommended Ride'],
	['Bike','HouBike','6/8/08','6/8/08','<a href="http://www.alvintexas.org" alt="">Tour de Braz</a>','Recommended Ride'],
	['Bike','HouBike','6/21/08','6/21/08','<a href="http://www.animalalliancetx.org/events.htm">Paws and Puddles Bike Ride</a>','Recommended Ride'], 
	['Bike','DalBike','7/24/08','7/24/08','Awards Party<br />Celebration of the 2008 Sam\'s Club Bike Tour<br />6:30pm - 9:00pm at <a href="http://www.lonestarpark.com/">Lone Star Park</a>','Tour Event']
];

function formatCalendarRow(cellArray)
{
	var retStr = '';
	var item = '';
	while(cellArray.length > 0)
	{
		item = cellArray.shift();
		if(item=='')
			retStr += '<td>&nbsp;</td>';
		else
			retStr += '<td>'+item+'</td>';
	}
	
	return '<tr onmouseover="calItemHighLight(this,1);" onmouseout="calItemHighLight(this,0);" class="">'+retStr+'</tr>'
}
function formatTwoDates(dateStart,dateEnd)
{
	var noBrSt = '<nobr>';
	var noBrEnd = '</nobr>';
	var retStr = '';
	if(dateStart.equals(dateEnd))
	{
		retStr = dateStart.format('EE, MM/dd/yyyy');
	}
	else
	{
		retStr = noBrSt+dateStart.format('EE') + '-' + dateEnd.format('EE')+','+noBrEnd+' ';
		if(dateStart.format('yyyy') != dateEnd.format('yyyy'))
		{
			retStr += noBrSt+dateStart.format('MM/dd/yyyy')+'-'+dateEnd.format('MM/dd/yyyy')+noBrEnd;
		}
		else if(dateStart.format('MM') != dateEnd.format('MM'))
		{
			retStr += noBrSt+dateStart.format('MM/dd')+'-'+dateEnd.format('MM/dd')+dateEnd.format('/yyyy')+noBrEnd;
		}
		else
		{
			retStr += noBrSt+dateStart.format('MM/')+dateStart.format('dd')+'-'+dateEnd.format('dd')+dateEnd.format('/yyyy')+noBrEnd;
		}
	}

	return retStr
}

function buildTourCalendar(eventType,domObj,displayPast,eventId,eventClass,displayColsArray)
{
	var filterArguments = {
		eventType:0,
		eventClass:4,
		eventId:3
	}
	if(displayColsArray == null || displayColsArray.length == 0)
		displayColsArray = ['displayDate','descriptionHtml','eventType'];
	var displayItem = true;
	var alertFilter = new Array();
	for(key in filterArguments)
	{
		if(arguments[filterArguments[key]] == '')
			delete filterArguments[key];
	}
	var contentAccumulatorReturn = "";
	var contentAccumulatorFuture = "";
	var contentAccumulatorPast = "";
	var dateToday = new Date();
	var dateStart = new Date();
	var dateEnd = new Date();
	for(var i = 0; i < tourCalendar.length; i++)
	{
		startStr = tourCalendar[i][tourCalendarKeys['dateStart']];
		endStr = tourCalendar[i][tourCalendarKeys['dateEnd']];
		tourCalendar[i][tourCalendarKeys['dateStart']] = new Date();
		tourCalendar[i][tourCalendarKeys['dateStart']].setTime(Date.parseString(startStr,'M/d/y'));
		tourCalendar[i][tourCalendarKeys['dateEnd']] = new Date();
		tourCalendar[i][tourCalendarKeys['dateEnd']].setTime(Date.parseString(endStr,'M/d/y'));
		tourCalendar[i][tourCalendarKeys['displayDate']] = formatTwoDates(tourCalendar[i][tourCalendarKeys['dateStart']],tourCalendar[i][tourCalendarKeys['dateEnd']]);
	}
	futureItemsArray = new Array();
	pastItemsArray = new Array();
	dontDisplayItemsArray = new Array();
	for(var i = 0; i < tourCalendar.length; i++)
	{
		displayItem = true;
		tourCalendarItem = tourCalendar[i];
		for(key in filterArguments)
		{
			if(tourCalendarItem[tourCalendarKeys[key]].match(arguments[filterArguments[key]]) == null)
				displayItem = false;
		}
		displayArray = [];
		for(var k = 0; k < displayColsArray.length; k++)
		{
			displayArray.push(tourCalendar[i][tourCalendarKeys[displayColsArray[k]]]);
		}
		if(displayItem)
		{
			if(tourCalendar[i][tourCalendarKeys['dateStart']].isAfter(dateToday))
			{
				futureItemsArray.push(displayArray);
			}
			else
			{
				pastItemsArray.push(displayArray);
			}
		}
		else
		{
			dontDisplayItemsArray.push(displayArray);
		}
	}
	contentAccumulatorReturn = '';
	contentAccumulatorDontDisplay = '';
	contentAccumulatorFuture = '';
	contentAccumulatorPast = '';
	if(futureItemsArray.length > 0)
	{
		contentAccumulatorFuture += '<h2>Upcoming:</h2><table>';
		while(futureItemsArray.length > 0) contentAccumulatorFuture += formatCalendarRow(futureItemsArray.shift());
		contentAccumulatorFuture += '</table>';
	}
	if(pastItemsArray.length > 0 && (displayPast == 'before'||displayPast == 'after'))
	{
		contentAccumulatorPast += '<h2>Past:</h2><table>';
		while(pastItemsArray.length > 0) contentAccumulatorPast += formatCalendarRow(pastItemsArray.shift());
		contentAccumulatorPast += '</table>';
		if(displayPast == 'before')
		{
			contentAccumulatorReturn = contentAccumulatorPast;
			contentAccumulatorPast = '';
		}
	}
	contentAccumulatorReturn += contentAccumulatorFuture+contentAccumulatorPast;
	domObj.innerHTML = contentAccumulatorReturn;
}

