var dates = [
	// BeginDate			|EndDate(Same if One Day)|Name of Event
	[new Date("Mar 16 2007"),new Date("Mar 18 2007"),"Spring Musical"],
	[new Date("Mar 23 2007"),new Date("Mar 28 2007"),"New York Trip"],
	[new Date("Apr 14 2007"),new Date("Apr 14 2007"),"Hersey Contest"],
	[new Date("Apr 21 2007"),new Date("Apr 21 2007"),"Plainfield Festival"],
	[new Date("May 05 2007"),new Date("May 05 2007"),"Superstate"],
	[new Date("May 17 2007"),new Date("May 17 2007"),"Spring Concert"],
	[new Date("May 20 2007"),new Date("May 20 2007"),"Jazz Concert"],
	[new Date("Jun 02 2007"),new Date("Jun 02 2007"),"Graduation"]
];

var repertoire = [
//    Band   Year    Piece Title		   Author / arr.
	["Jazz", 2007, "Frosty The Snow Man", "Lowden, Bob"],
	["Jazz", 2006, "Autumn Leaves",	"Kosma / Mercer, arr. Blair" ],
	["Jazz", 2006, "Bill Bailey's Back","arr. Peter Blair"],
	["Jazz", 2006, "Killer Joe", "Golson / arr. Higgins"],
	["Jazz", 2006, "One O'Clock Jump", "Basie / arr. Taylor"],
	["Jazz", 2006, "Straight No Chaser", "Monk, T. / arr. Taylor"],
	["Jazz", 2005, "Almost Cried", "Duke Ellington / Strayhorn"],
	["Jazz", 2005, "Birdland", "Joseph Zawinul / Higgins"],
	["Jazz", 2005, "Blue Rondo Ala Turk", "Dave Brubeck / Custer"],
	["Jazz", 2005, "Frosty The Snow Man", "Bob Lowden"],
	["Jazz", 2005, "It Don't Mean Thing", "Duke Ellington / Mills", "With the Vocal Jazz Choir"],
	["Jazz", 2005, "On The Prowl!", "Les Sabina"],
	["Jazz", 2005, "Radio Active", "Les Sabina"],
	["Jazz", 2005, "Since I Fell For You", "Buddy Johnson / Wolpe"],
	["Jazz", 2004, "Cut to the Chase", "Barton, Larry"],
	["Jazz", 2004, "In the Mood", "Garland, Joe"],
	["Jazz", 2004, "I Remember Clifford", "Golson, Benny / Nestico"],
	["Jazz", 2004, "Malaguena", "Lecuona, Ernesto, arr. Kerchner"],
	["Jazz", 2004, "Mercy, Mercy, Mercy", "Zawinul, Josef / Jennings"],
	["Jazz", 2004, "Never No Lament", "Ellington, Duke, arr. Berger"],
	["Jazz", 2004, "Oclupaca", "Ellington, Duke, arr. Berger"],
	
	["Symphonic", 2007, "Festivo", "Nelhybel, Vaclav"],
	["Symphonic", 2007, "Folk Song Suite", "Vaughn Williams, Ralph"],
	["Symphonic", 2007, "Sleigh Ride", "Anderson, Leroy"],
	["Symphonic", 2007, "Stars and Stripes for Christmas", ""],
	["Symphonic", 2007, "With Pleasure", "Sousa, J. P."],
	["Symphonic", 2006, "Caccia and Chorale","Williams, Clifton"],
	["Symphonic", 2006, "Carmina Burana","Orff / arr. Krance"],
	["Symphonic", 2006, "Fortress","Ticheli, Frank"],
	["Symphonic", 2006, "Hounds of Spring","Reed, Alfred"],
	["Symphonic", 2006, "Impressions of Japan","Barnes, James"],
	["Symphonic", 2006, "March: Untitled","Sousa, J.P. / arr. Brion and Schissel"],
	["Symphonic", 2006, "Night Dances","Yurko, Bruce"],
	["Symphonic", 2006, "Prelude, Siciliano, and Rondo","Arnold, Malcom / arr. Paynter"],
	["Symphonic", 2006, "Serenade","Bourgeios, Derek "],
	["Symphonic", 2006, "Sleigh Ride", "Anderson, Leroy"],
	["Symphonic", 2006, "Sorcery Suite, Mvt. V","Barnes, James"],
	["Symphonic", 2006, "Stars in a Velvety Sky","Clarke, Herbert L.", "Andrea Smith, Euphonium"],
	["Symphonic", 2006, "Vesuvius","Ticheli, Frank"],
	["Symphonic", 2005, "Bolero", "Maurice Ravel / Bocook"],
	["Symphonic", 2005, "Cloudsplitter", "Strommen, Carl "],
	["Symphonic", 2005, "Dedicatory Overture", "Williams, Clifton"],
	["Symphonic", 2005, "Dialogues", "Sweeney, Michael"],
	["Symphonic", 2005, "Greensleeves", "Reed, Alfred"],
	["Symphonic", 2005, "Havendance", "Holsinger, David"],
	["Symphonic", 2005, "Sun Dance", "Ticheli, Frank"],
	["Symphonic", 2005, "Loch Lomond", "Ticheli, Frank"],
	["Symphonic", 2005, "Russian Easter Overture", "Nicoli Rimsky-Korsakov / Bocook"],
	["Symphonic", 2005, "Semper Fidelis", "J. P. Sousa/Custer"],
	["Symphonic", 2005, "Their Blossoms Down", "Hazo, Samuel"],
	["Symphonic", 2005, "Vigor", "OLoughlin, Sean"],

	["WindE", 2005, "Hands Up!", "Andrew Boysen Jr."],
	["WindE", 2005, "Concerto for Oboe and Band", "Domenico Cimarosa/Boom", "(Jaimie Duff, Oboe)"],
	["WindE", 2005, "Persistence of Time", "Jim Colonna"],
	["WindE", 2005, "Variations on a Shaker Melody", "Aaron Copland"],
	["WindE", 2005, "Irish Trilogy", "Larry Daehn"],
	["WindE", 2005, "Spoon River", "Percy Grainger / Sheldon"],
	["WindE", 2005, "Each Time You Tell Their Story", "Samuel Hazo", "Mr. David Oldham, Narrator"],
	["WindE", 2005, "Jupiter", "Gustav Holst / Curnow"],
	["WindE", 2005, "Avenue X", "Jonathon Newman", "Commissioned"],
	["WindE", 2005, "Procession of the Nobles", "Nicoli Rimsky-Korsakov / Leidzen"],
	["WindE", 2005, "Black Horse Troop", "J. P. Sousa"],
	["WindE", 2005, "Stars and Stripes Forever", "J. P. Sousa", "With Choir"],
	["WindE", 2005, "Allerseelen", "Richard Strauss / Fennell"],
	["WindE", 2005, "Ascendance", "Robert Thurston"],
	["WindE", 2005, "Sleigh Ride", "Leroy Anderson"],
	["WindE", 2005, "Sleep", "Eric Whitacre", "With Choir"],

	["Concert", 2007, "Christmas at the Movies","Moss, John"],
	["Concert", 2007, "On A Hymnsong of Philip Bliss","Holsinger, David"],
	["Concert", 2007, "Orion","Van der Roost, Jan"],
	["Concert", 2007, "Westridge Overture","Barnes, James"],
	["Concert", 2006, "A+","Duffy, Thomas"],
	["Concert", 2006, "The Carolers","Curnow, Jim"],
	["Concert", 2006, "Celtic Suite","Del Borgo, Elliot"],
	["Concert", 2006, "Courtly Airs and Dances","Nelson, Ron"],
	["Concert", 2006, "For the New Day Arison","Baront, Steven"],
	["Concert", 2006, "Ginger Marmalade","Benson, Warren"],
	["Concert", 2006, "Invicta","Swearingen, James"],
	["Concert", 2006, "Prelude and Fugue in Bb Major","Bach / Moehlmann"],
	["Concert", 2006, "Shenandoah","Ticheli, Frank"],
	["Concert", 2006, "Three Ayres from Gloucester","Stuart, Hugh"],
	["Concert", 2006, "Tribal Quest","O'loughlin, Sean"],
	["Concert", 2005, "Celebration Point", "Bullock, Jack"],
	["Concert", 2005, "Christmas on a Snowy Night", "Moss, John"],
	["Concert", 2005, "Days of Glory", "OLoughlin, Sean"],
	["Concert", 2005, "Portraits", "Colonna, Jim"],
	["Concert", 2005, "Prairie Songs", "La Plante, Pierre"],
	["Concert", 2005, "Rhythm of the Winds", "Erickson, Frank"],
	["Concert", 2005, "Sunrise Song", "Barrett, Rolland"],
	["Concert", 2005, "Urban Scenes", "Boysen, Andrew Jr."],
	["Concert", 2005, "Washington Post March", "J. P. Sousa/Balent"],
	["Concert", 2005, "With Quiet Courage", "Daehn, Larry"],

	
	["Marching",2006, "Celtic Legends",""],
	["Marching",2005, "Cirque Du Soleil",'"La Nouba"'],
	["Marching",2004, "Ragtime",""],
	["Marching",2003, "Tower of Power",""]
	
];

links = [

	["Concert","concert.html"],
	["Symphonic","symphonic.html"],
	["Jazz","jazz.html"],
	["Pep","pep.html"],
	["Marching","marching.html"],
	["Calendar","calendar.html"],
	["Repertoire","repertoire.html"],
	["Plainfield Band Boosters","http://www.plainfieldbandboosters.org/"]
		 
];


//BEGIN Code no one should edit unless they know what they're doing.

var now = new Date();

function searchChange(){
	var songList = new Array();
	var found = false;
	for(var i=0;i<repertoire.length;i++)
		if(repertoire[i][0] == document.form1.sbBand.value)
			songList.push(repertoire[i][1]);
	var uniqueYears = new Array();
	
	for(var i=0;i<songList.length;i++)
	{
		for(var j=0;j<uniqueYears.length;j++)
			if(songList[i] == uniqueYears[j])
				found = true;
		if(!found)uniqueYears.push(songList[i]);
		found=false;
	}
		document.form1.sbYear.length = 0;
	for(var i=0;i<uniqueYears.length;i++)
		document.form1.sbYear.options[i] = new Option(uniqueYears[i], uniqueYears[i], false,false);	
}
function mysortfn(a,b) {
return(b-a);
}
function loadSearch(){
	var uniqueYears = new Array();
	var found = false;
	for(var i=0;i<repertoire.length;i++)
	{
		for(var j=0;j<uniqueYears.length;j++)
			if(repertoire[i][1] == uniqueYears[j])
				found = true;
		if(!found)uniqueYears.push(repertoire[i][1]);
		found=false;
	}
	
	
	for(var i=0;i<uniqueYears.length;i++)
		document.form1.sbYear.options[i] = new Option(uniqueYears[i], uniqueYears[i], false,false);
	
	var uniqueBands = new Array();
	for(var i=0;i<repertoire.length;i++)
	{
		for(var j=0;j<uniqueBands.length;j++)
			if(repertoire[i][0] == uniqueBands[j])
				found = true;
		if(!found)uniqueBands.push(repertoire[i][0]);
		found=false;
	}	
	
	

	for(var i=0;i<uniqueBands.length;i++)
	document.form1.sbBand.options[i] = new Option(uniqueBands[i], uniqueBands[i], false,false);

	searchChange();	
	
}
function searchRepertoire()
{
	document.getElementById("repertoire").innerHTML = getRepertoire(document.form1.sbBand.value,document.form1.sbYear.value);
	}
	


function handleRepertoire(band,year){
document.getElementById("repertoire").innerHTML = "<b>Performed Pieces, "+year+":</b><br /><a href='javascript:handleRepertoire(\""+band+"\","+(year-1)+")'>Previous Year</a> - ";
document.getElementById("repertoire").innerHTML+="<a href='javascript:handleRepertoire(\""+band+"\","+(year+1)+")'>Next Year</a><br />"+getRepertoire(band, year);
}
function handleTextSearch(){
	document.getElementById('repertoire').innerHTML = searchText(document.form1.sbText.value);
}
function searchText(searchString){
	
var searchResults = new Array();
	for(var i=0; i<repertoire.length;i++)
		for(var j=0; j<repertoire[i].length;j==0?j+=2:j++)
			if(repertoire[i][j].toLowerCase().indexOf(searchString.toLowerCase()) !=-1){searchResults.push(repertoire[i]);break;}
		
var uniqueYears = new Array();
	for(var i=0; i<searchResults.length;i++){
		found=false;
		for(var j=0;j<uniqueYears.length;j++)
			if(searchResults[i][1] == uniqueYears[j])
				found=true;
		if(!found)uniqueYears.push(searchResults[i][1]);
	}

	uniqueYears.sort(mysortfn);
	
var uniqueBands = new Array();
	for(var i=0; i<searchResults.length;i++){
		found=false;
		for(var j=0;j<uniqueBands.length;j++)
			if(searchResults[i][0] == uniqueBands[j])
				found=true;
		if(!found)uniqueBands.push(searchResults[i][0]);
	}

var output = "";
var currentBand = "";
	for(var i=0; i<uniqueYears.length;i++){
		var currentBand = "";
		output+="<b>"+uniqueYears[i]+"</b><br />";
		for(var k=0; k<uniqueBands.length;k++){		
			for(var j=0; j<searchResults.length;j++)
				if(searchResults[j][1] == uniqueYears[i])
						if(searchResults[j][0] == uniqueBands[k]){
							if(currentBand!= uniqueBands[k]){
								output+="&nbsp;&nbsp;<b>"+uniqueBands[k]+"</b><br />";
								currentBand=uniqueBands[k];
							}
							output+=searchResults[j][2]+" - "+searchResults[j][3]+"<br />";
						}
		}
	}
return output;
}

function getRepertoire(band, year){	
	var output="";
	for(var i=0; i<repertoire.length;i++)
		if(repertoire[i][0]== band)
			if(repertoire[i][1] == year) {
				output+= repertoire[i][2]+ " - " +repertoire[i][3]+"<br />";
				if(repertoire[i][4] != null)
					output+= "&nbsp;&nbsp;&nbsp;" + repertoire[i][4]+"<br />";}
			if(output.length == 0)
	output+="No entries found for the "+band+" band of "+year+".";
return output;	
}


function events(month){
	var temp = new Array();
	for(var i;i<dates.length;i++)
		if (dates[i][0].getMonth() == month)temp.push(dates[i]);
	return temp;
}

function toMonth(integer){
switch(integer)
{
case 0:return "Jan ";
case 1:return "Feb ";
case 2:return "Mar ";
case 3:return "Apr ";
case 4:return "May ";
case 5:return "Jun ";
case 6:return "Jul ";
case 7:return "Aug ";
case 8:return "Sep ";
case 9:return "Oct ";
case 10:return "Nov ";
case 11:return "Dec ";
}
}
function handleCalendar(date){
	date = new Date(date);	
	document.getElementById('calendar').innerHTML = calendar(date,true);
	}
function calendar(date,useSpecialDay) {
  // If no parameter is passed use the current date.
  if(date == null){date = new Date();useSpecialDay=true;}
  var lastMonth = new Date(date);
  var nextMonth = new Date(date);
  lastMonth.setMonth((lastMonth.getMonth()-1)%12);
  nextMonth.setMonth((nextMonth.getMonth()+1)%12);
  day = date.getDate();
  month = date.getMonth();
  year = date.getFullYear();

  months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
  days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
  this_month = new Date(year, month, 1);

  first_week_day = this_month.getDay();
  days_in_this_month = Math.round(((new Date(year, month + 1, 1)).getTime() - this_month.getTime()) / (1000 * 60 * 60 * 24));

  calendar_html = '<table align="center" class="Calendar">';
  calendar_html += '<tr>';
  calendar_html += "<td><a href='javascript:handleCalendar(\""+lastMonth+"\")'>Last Month</a></td>";
  calendar_html += '<td colspan="5" align="center">' + months[month] + ' ' + year + '</td>';
  calendar_html += "<td><a href='javascript:handleCalendar(\""+nextMonth+"\")'>Next Month</a></td></tr>";
  calendar_html += '<tr  align="center">';

  for(da = 0; da < days.length;da++)
  	calendar_html += '<td style="height:20px;">'+days[da]+'</td>';
  
 if(0<first_week_day) calendar_html += '</tr><tr valign="top" >';
  
  for(week_day = 0; week_day < first_week_day; week_day++) 
    calendar_html += '<td></td>';

  week_day = first_week_day;
  for(day_counter = 1; day_counter <= days_in_this_month; day_counter++) {
    week_day %= 7;
    if(week_day == 0) calendar_html += '</tr><tr valign="top">';
    if(day == day_counter&&useSpecialDay)  calendar_html += '<td><b>' + day_counter + '</b>';
    else      				calendar_html += '<td> ' + day_counter;
	
	for(var i = 0; i<dates.length;i++)
	{
		if( ( dates[i][0].valueOf() <= (new Date(year,month,day_counter)).valueOf() ) && ( dates[i][1].valueOf() >= (new Date(year,month,day_counter)).valueOf() ) )
			calendar_html+=' '+dates[i][2];
	}
	
	
	calendar_html += '</td>';
    week_day++;
  }

  calendar_html += '</tr></table>';

  return calendar_html;
}


function upcoming(number){
	if(number==null)number=5;

	var output = "Upcoming Dates:<br>";
	var counter = 0,selectedDates=0;
	while(selectedDates<number)
	{
		if(now<dates[counter][0])
		{
			output+=("<b>"+toMonth(dates[counter][0].getMonth())+dates[counter][0].getDate());
			if(dates[counter][0].valueOf()!=dates[counter][1].valueOf())
			output += (" - "+ toMonth(dates[counter][1].getMonth())+dates[counter][1].getDate());
			output += ("</b><br>"+dates[counter][2]+"<br>");
			selectedDates++;
		}
		if(++counter>=dates.length)	return output;
	}
	return output;
}


function navigation(){
	var temp = "";
	for(var i=0;i<links.length;i++)
		temp+= "<a href='"+links[i][1]+"'>"+links[i][0]+"</a><br />";
        temp+= "<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\"></script><script type=\"text/javascript\">_uacct = \"UA-631338-2\";urchinTracker();</script>";
	return temp;
}