var csel_month,csel_year,sel_section,totaldays,thefirst,ctoday,tmp,cstart_month,cstart_year,wishlist_flag,listactiveswap='';
var strhistory = '';
var calendar_mode = 'FULL';  //FULL or LIST mode

var defaultperformance = 1;  //defaults to first perforamce date when set to 1

var month_name=new Array(12);
month_name[0]="January"
month_name[1]="February"
month_name[2]="March"
month_name[3]="April"
month_name[4]="May"
month_name[5]="June"
month_name[6]="July"
month_name[7]="August"
month_name[8]="September"
month_name[9]="October"
month_name[10]="November"
month_name[11]="December"

var days_of_week=new Array(7);
days_of_week[0]="Sun"
days_of_week[1]="Mon"
days_of_week[2]="Tue"
days_of_week[3]="Wed"
days_of_week[4]="Thurs"
days_of_week[5]="Fri"
days_of_week[6]="Sat"

var fullname_dow=new Array(7);
fullname_dow[0]="Sunday"
fullname_dow[1]="Monday"
fullname_dow[2]="Tuesday"
fullname_dow[3]="Wednesday"
fullname_dow[4]="Thursday"
fullname_dow[5]="Friday"
fullname_dow[6]="Saturday"

//used for sort featured
var sortlistitem = new Array();
var listitem = new Array();
var li_index = 0;
var cal_sortby = 'Date';


sel_section = 'all';
wishlist_flag = 1;
purchased_flag = 1;
ctoday = new Date();
cstart_month = ctoday.getMonth(); //static -do not change the name of this variable as it is used elsewhere
cstart_year = ctoday.getFullYear(); 

csel_month = ctoday.getMonth();
csel_year = ctoday.getFullYear();
function daysInMonth(nmonth,nyear) 
{
	var m = [31,28,31,30,31,30,31,31,30,31,30,31];
	if (nmonth != 2) return m[nmonth - 1]; //check for leap year
	if (nyear%4 != 0) return m[1];
	if (nyear%100 == 0 && nyear%400 != 0) return m[1];
	return m[1] + 1;
}

function fc_setvars()
{
	thefirst = new Date((csel_month+1) + '/01/' + csel_year);
	sel_dayofweek = thefirst.getDay();
	totaldays = daysInMonth(csel_month+1,csel_year);
}
function changeMonthYear(newMonth,newYear)
{
	csel_year = newYear;
	csel_month = newMonth;
	createCookie("Month", csel_month, 1);
	createCookie("Year", csel_year, 1);
	createCookie("Section", sel_section, 1);
	fc_setvars();
	setHeading();
	setMonthHeading();
}

function swapMode()
{ 
	calendar_mode = document.frmSort.calCalview.options[document.frmSort.calCalview.selectedIndex].value;
	if (calendar_mode == 'FULL')
	{
		drawFullCalendar();
	}
	else if (calendar_mode == 'LIST')
	{
		var strSearch = document.getElementById('calSearch').value;
		drawListCalendar(strSearch.toLowerCase());
	}
	else 
	{
		window.location = calendar_mode;
	
/*
		switch(sel_section)
		{
			case "POPS":
				window.location = "/bso/mods/complete_season.jsp?id=bcat12400012";
				break;

			case "Tanglewood":
				window.location = "/bso/mods/complete_season.jsp?id=bcat12400010";
				break;

			case "BSO":
			case" Symphony":
			default:
				window.location = "/bso/mods/complete_season.jsp?id=bcat12400014";
				break;
		}
		//window.location = "/bso/mods/complete_season.jsp";
*/
	}
}

function setHeading()
{
	var tmp = document.getElementById("cal_heading");
	tmp.innerHTML = '<span class="calMonth">' + month_name[csel_month] + '</span> <a href="javascript:undefined" onclick="cstart_year--;changeMonthYear(' + csel_month + ',' + (csel_year-1) + ');initCalendar();">&lt;</a> <span class="calYear">' + csel_year + '</span> <a href="javascript:undefined" onclick="cstart_year++;changeMonthYear(' + csel_month + ',' + (csel_year+1) + ');initCalendar();">&gt;</a>';
}

function ajaxGrab()
{
	/*from the 1st of the start month to the 1st of the end month - handles nov & dec */
	var startmonth = csel_month+1;
	var endmonth = csel_month+2;
	var endyear = cstart_year;
	var startyear = cstart_year;
	
	if (endmonth > 12) 
	{
		endmonth = endmonth - 12;
		endyear++;
	}
	if (startmonth > 12)
	{
		startmonth = startmonth - 12;
		startyear++;
	}
	if (cstart_month > csel_month)
	{
		startyear++;
		endyear++;
	}
	var strident = '-'+startmonth+startyear+endmonth+endyear+'-';
	if (strhistory.indexOf(strident)==-1)
	{
		strhistory += '-'+startmonth+startyear+endmonth+endyear+'-';
		grabEventsFC(startmonth,startyear,endmonth,endyear,'fc');
	} else {
		drawCalendar();
	}
}

function drawFilter()
{
	var tmp;
	tmp = document.getElementById("cal_filter");
	
	tmp.innerHTML = '<table cellpadding="0" cellspacing="0" border="0"><tr>'+
	'<td><span class="calMonth">Filter by:</span></td><td>&nbsp;</td>'+
	'<td><input checked type="checkbox" onclick="((purchased_flag==1) ? purchased_flag=0 : purchased_flag=1);drawCalendar();">&nbsp;</td><td><img name="calbso" src="/images/mc_purchased.gif" border="0" alt="Purchased" /></td><td>&nbsp;</td>'+
	'<td><input checked type="checkbox" onclick="((wishlist_flag==1) ? wishlist_flag=0 : wishlist_flag=1);drawCalendar();">&nbsp;</td><td><img name="calbso" src="/images/mc_wishlist.gif" border="0" alt="Wishlist" /></td><td>&nbsp;</td>'+
	'<td><input checked type="checkbox">&nbsp;</td><td><img name="calbso" src="/images/mc_suggestion.gif" border="0" alt="Suggestion" /></td>'+
	'</tr></table>';	
}


function drawHeader()
{

	createCookie("Section", sel_section, 1);

	if (cal_loggedin == "false")
		drawFilter();
	
	var bsoover,popsover,twover,shover,allover,fullsel,listsel,tmp;
	bsoover = '';
	popsover = '';
	twover = '';
	shover = '';
	allover = '';
	fullsel = '';
	listsel = '';
	
	if (calendar_mode == 'FULL')
		fullsel = ' selected';
	else
		listsel = ' selected';
		
	if (sel_section == 'BSO')
		bsoover = '-over';
	else if (sel_section == 'POPS')
		popsover = '-over';
	else if (sel_section == 'Tanglewood')
		twover = '-over';
	else if (sel_section == 'Symphony')
		shover = '-over';
	else
		allover = '-over';
		
	tmp = document.getElementById("calendar_cat_header");
	
	tmp.innerHTML = '<table cellpadding="0" cellspacing="0" border="0"><tr>'+
	'<td><a href="javascript:undefined" onmouseout="changeImages(\'calbso\', \'/images/calendar_bso' + bsoover + '.gif\');" onmouseover="changeImages(\'calbso\', \'/images/calendar_bso-over.gif\');" onclick="sel_section=\'BSO\';drawHeader();drawCalendar();"><img name="calbso" src="/images/calendar_bso' + bsoover + '.gif" border="0" alt="BSO" /></a></td>'+
	'<td><a href="javascript:undefined" onmouseout="changeImages(\'calpops\', \'/images/calendar_pops' + popsover + '.gif\');" onmouseover="changeImages(\'calpops\', \'/images/calendar_pops-over.gif\');" onclick="sel_section=\'POPS\';drawHeader();drawCalendar();"><img name="calpops" src="/images/calendar_pops' + popsover + '.gif"  border="0" alt="POPS" /></a></td>'+
	'<td><a href="javascript:undefined" onmouseout="changeImages(\'caltanglewood\', \'/images/calendar_tw' + twover + '.gif\');" onmouseover="changeImages(\'caltanglewood\', \'/images/calendar_tw-over.gif\');" onclick="sel_section=\'Tanglewood\';drawHeader();drawCalendar();"><img name="caltanglewood" src="/images/calendar_tw' + twover + '.gif" border="0" alt="TANGLEWOOD" /></a></td>'+
	'<td><a href="javascript:undefined" onmouseout="changeImages(\'calsymphony\', \'/images/calendar_sh' + shover + '.gif\');" onmouseover="changeImages(\'calsymphony\', \'/images/calendar_sh-over.gif\');" onclick="sel_section=\'Symphony\';drawHeader();drawCalendar();"><img name="calsymphony" src="/images/calendar_sh' + shover + '.gif" border="0" alt="SYMPHONY" /></a></td>'+
	'<td><a href="javascript:undefined" onmouseout="changeImages(\'calall\', \'/images/calendar_view' + allover + '.gif\');" onmouseover="changeImages(\'calall\', \'/images/calendar_view-over.gif\');" onclick="sel_section=\'all\';drawHeader();drawCalendar();"><img name="calall" src="/images/calendar_view' + allover + '.gif" border="0" alt="" /></a></td>'+
	'</tr></table>';
}

function setMonthHeading()
{
	var tmpStr,monthCount,yearCount,tmp;
	
	monthCount = cstart_month;
	yearCount = cstart_year;
	
	tmp = document.getElementById("cal_month_heading");
	tmpStr = '<table class="calMonths" cellpadding="1" cellspacing="1" border="0"><tr>';
	
	for (var i = 0; i< 12;i++)
	{
		tmpStr += '<td valign="top" align="center">';
		if (csel_month == monthCount)
			tmpStr += '<b>' + month_name[monthCount].substr(0,3).toUpperCase() + '</b>&nbsp;&nbsp;<br><img src="/images/active_breadcrumb.gif" alt="">';
		else
			tmpStr += '<a href="javascript:undefined" class="calMonths" onclick="changeMonthYear(' + monthCount + ',' + yearCount + ');ajaxGrab();setMonthHeading();">' + month_name[monthCount].substr(0,3).toUpperCase() + '</a>';
		tmpStr += '&nbsp;&nbsp;</td>';
		
		if (monthCount == 11)
		{
			monthCount = 0;
			yearCount++;
		}
		else
			monthCount++;
	}
	
	tmpStr += '<tr></table>';
	tmp.innerHTML = tmpStr;
}

function calStartRow()
{
	return '<tr><td width="1" class="bgSeperator"><img src="/images/transpix.gif" height="20" alt="" border="0" width="1"/></td>';
}

function calDrawDay(content,sel)
{
	if (sel==1)
		return '<td valign="top" align="right" class="calNOW"><div class="calDateCell">' + content + '</div></td><td width="1" class="bgSeperator"></td>';
	else
		return '<td valign="top" align="right"><div class="calDateCell">' + content + '</div></td><td width="1" class="bgSeperator"></td>';
}
function calDrawDay2(content,sel)
{
	if (sel==1)
		return '<td valign="top" align="left" class="calNOW"><div class="calCell">' + content + '</div></td><td width="1" class="bgSeperator"></td>';
	else
		return '<td valign="top" align="left"><div class="calCell">' + content + '</div></td><td width="1" class="bgSeperator"></td>';
}
function calDrawSeparator(colspan)
{
	return '<tr><td colspan="' + colspan + '" class="bgSeperator"></td></tr>';
}

function drawFullCalendar()
{
	var strOut='',strRow1='',strRow2='',strRow3='';
	var weekmax = 7;
	var daycount = 1;
	var eventtoday = 0;

	fc_setvars();

	strOut += '<tr>';
	for (var i=0;i<15;i++)
	{
		strOut += '<td width="1"><img src="/images/transpix.gif" height="1" alt="" border="0" width="' + (((i % 2)==0) ? 1 : 75) + '"/></td>';
	}
	strOut += '</tr>' + calDrawSeparator(15);
	
	strOut += calStartRow(); //start listing days of the week
	for (i=0;i<7;i++)
	{
		strOut += '<td valign="top" align="right" width="75"><div class="calDayCell">' + days_of_week[i] + '</div></td><td width="1" class="bgSeperator"></td>';
	}
	strOut += '</tr>'; //end row
	
	for (daycount=1; daycount <= totaldays;)
	{
		if ((totaldays-daycount) < 6)
			weekmax = totaldays - daycount + 1;
		
		for (i=0;i<weekmax;i++)
		{
			if (ctoday.getMonth() == csel_month)
				eventtoday = isEventToday(daycount);
			if (i <= sel_dayofweek)
			{	
				if (sel_dayofweek == i)
				{
					sel_dayofweek = -1; //this happens once per xml load, reset when section is clicked
					strRow1 += calDrawDay(daycount,eventtoday);
					strRow2 += drawEvent(daycount,eventtoday);
					strRow3 += calDrawDay2('',eventtoday);
					daycount++;
				}
				else
				{
					strRow1 += calDrawDay('&nbsp',eventtoday);
					strRow2 += calDrawDay2('',eventtoday);
					strRow3 += calDrawDay2('',eventtoday);
				}
			}
			else
			{
				strRow1 += calDrawDay(daycount,eventtoday);
				strRow2 += drawEvent(daycount,eventtoday);
				strRow3 += calDrawDay2('',eventtoday);
				daycount++;
			}
		}
		strOut += calDrawSeparator(15) + calStartRow() + strRow1 + '</tr>' + calStartRow() + strRow2 + '</tr>' + calStartRow() + strRow3 + '</tr>' + calDrawSeparator(15);
		
		strRow1 = '';
		strRow2 = '';
		strRow3 = '';
	}
	
	strOut = '<table cellpadding="0" cellspacing="0" border="0" width="530">' + strOut + '</table>';
	tmp = document.getElementById("cal_days");
	tmp.innerHTML = strOut;
}

function isEventToday(eventDay)
{
	if ((ctoday.getDate() == eventDay) && (ctoday.getMonth() == csel_month) && (ctoday.getFullYear() == csel_year))
		return 1;
	else
		return 0;
}

arCache = new Array();
arCacheList = new Array();

function drawEvent(daycount,eventtoday)
{
	var strtemp,strtemp2,selectionType;
	var divcounter = '';
	var timeSlots=new Array('','','','','','','','','','','','','','','','','');  //day header and 7am to 11pm
	var strloc1 = '';
	var strloc2 = '';
	var pid = 0;
	var strid = daycount + '/' + (thefirst.getMonth()+1) + '/' + thefirst.getFullYear();
	var strdiv = '';
	strEventID = 'title_event_fc' + strid + divcounter; //grab from hidden div
	
	while(document.getElementById(strEventID) != null)
	{
		objevent = document.getElementById(strEventID);
		selectionType = findSection(objevent.innerHTML);
		
		if (arCache['pid_event_fc' + strid + divcounter])
		{ 
			strTime = arCache['timeod_event_fc' + strid + divcounter];
			strloc1 = arCache['location_event_fc' + strid + divcounter];
			strloc2 = arCache['citystate_event_fc' + strid + divcounter];
			pid =     arCache['pid_event_fc' + strid + divcounter];
		} else {
			strTime = document.getElementById('timeod_event_fc' + strid + divcounter).innerHTML;
			strloc1 = document.getElementById('location_event_fc' + strid + divcounter).innerHTML;
			strloc2 = document.getElementById('citystate_event_fc' + strid + divcounter).innerHTML;
			pid = document.getElementById('pid_event_fc' + strid + divcounter).innerHTML;
			
			arCache['timeod_event_fc' + strid + divcounter] = strTime;
			arCache['location_event_fc' + strid + divcounter] = strloc1;
			arCache['citystate_event_fc' + strid + divcounter] = strloc2;
			arCache['pid_event_fc' + strid + divcounter] = pid;
		}
		
		nTimeslot = setTimeSlot(strTime);
		
		strtemp='';
		if (((ctoday.getMonth() < csel_month) && (ctoday.getFullYear() <= csel_year)) ||
		((ctoday.getDate() <= daycount) && (ctoday.getMonth() <= csel_month) && (ctoday.getFullYear() <= csel_year))) {
			if (wishlist_flag == 1)
				if (wishlist.indexOf('-' + pid + '-') != -1)
					strtemp = '<br><img src="/images/mc_wishlist.gif"><br><img src="/images/transpix.gif" width="1" height="2" alt="spacer" />';
		}
		strtemp2='';
		if (purchased_flag == 1)
			if (purchased.indexOf('-' + pid + '-') != -1)
				strtemp2 = '<br><img src="/images/mc_purchased.gif">';
		
		if(sel_section != 'all')
		{
			if (selectionType == 'BSO' && sel_section == 'BSO') {
				defaultperformance = 0;
				//timeSlots[nTimeslot] += '<div class="cal' + selectionType + '"><span class="callink"><a href="/bso/mods/perf_detail.jsp;jsessionid=' + sessionid + '?pid=' + pid + '"><b>' + objevent.innerHTML + '</b><br>' + strloc1 + '<br>' + strloc2 + '<br>' + strTime + '</a>' + strtemp + strtemp2 + '</span></div>';
				timeSlots[nTimeslot] += '<div class="cal' + selectionType + '"><span class="callink"><a href="/bso/mods/perf_detail.jsp?pid=' + pid + '"><b>' + objevent.innerHTML + '</b><br>' + strloc1 + '<br>' + strloc2 + '<br>' + strTime + '</a>' + strtemp + strtemp2 + '</span></div>';
			} else if (selectionType == 'POPS' && sel_section == 'POPS'){
				defaultperformance = 0;
				//timeSlots[nTimeslot] += '<div class="cal' + selectionType + '"><span class="callink"><a href="/bso/mods/perf_detail.jsp;jsessionid=' + sessionid + '?pid=' + pid + '"><b>' + objevent.innerHTML + '</b><br>' + strloc1 + '<br>' + strloc2 + '<br>' + strTime + '</a>' + strtemp + strtemp2 + '</span></div>';
				timeSlots[nTimeslot] += '<div class="cal' + selectionType + '"><span class="callink"><a href="/bso/mods/perf_detail.jsp?pid=' + pid + '"><b>' + objevent.innerHTML + '</b><br>' + strloc1 + '<br>' + strloc2 + '<br>' + strTime + '</a>' + strtemp + strtemp2 + '</span></div>';
			} else if (selectionType == 'TW' && sel_section == 'Tanglewood'){
				defaultperformance = 0;
				//timeSlots[nTimeslot] += '<div class="cal' + selectionType + '"><span class="callink"><a href="/bso/mods/perf_detail.jsp;jsessionid=' + sessionid + '?pid=' + pid + '"><b>' + objevent.innerHTML + '</b><br>' + strloc1 + '<br>' + strloc2 + '<br>' + strTime + '</a>' + strtemp + strtemp2 + '</span></div>';
				timeSlots[nTimeslot] += '<div class="cal' + selectionType + '"><span class="callink"><a href="/bso/mods/perf_detail.jsp?pid=' + pid + '"><b>' + objevent.innerHTML + '</b><br>' + strloc1 + '<br>' + strloc2 + '<br>' + strTime + '</a>' + strtemp + strtemp2 + '</span></div>';
			} else if (selectionType == 'SH' && sel_section == 'Symphony'){
				defaultperformance = 0;
				//timeSlots[nTimeslot] += '<div class="cal' + selectionType + '"><span class="callink"><a href="/bso/mods/perf_detail.jsp;jsessionid=' + sessionid + '?pid=' + pid + '"><b>' + objevent.innerHTML + '</b><br>' + strloc1 + '<br>' + strloc2 + '<br>'  + strTime + '</a>' + strtemp + strtemp2 + '</span></div>';
				timeSlots[nTimeslot] += '<div class="cal' + selectionType + '"><span class="callink"><a href="/bso/mods/perf_detail.jsp?pid=' + pid + '"><b>' + objevent.innerHTML + '</b><br>' + strloc1 + '<br>' + strloc2 + '<br>'  + strTime + '</a>' + strtemp + strtemp2 + '</span></div>';
			}
		}
		else
		{
			defaultperformance = 0;
			//timeSlots[nTimeslot] += '<div class="cal' + selectionType + '"><span class="callink"><a href="/bso/mods/perf_detail.jsp;jsessionid=' + sessionid + '?pid=' + pid + '"><b>' + objevent.innerHTML + '</b><br>' + strloc1 + '<br>' + strloc2 + '<br>' + strTime + '</a>' + strtemp + strtemp2 + '</span></div>';
			timeSlots[nTimeslot] += '<div class="cal' + selectionType + '"><span class="callink"><a href="/bso/mods/perf_detail.jsp?pid=' + pid + '"><b>' + objevent.innerHTML + '</b><br>' + strloc1 + '<br>' + strloc2 + '<br>' + strTime + '</a>' + strtemp + strtemp2 + '</span></div>';
		}
		if(divcounter == '') 
			divcounter = 1;
		
		divcounter++;
		strEventID = 'title_event_fc' + strid + divcounter;
	}
	if (divcounter == '')
	{
		return calDrawDay2('',eventtoday);
	}
	else
	{
		strtemp = ''; //we're reusing this variable - it's not related to the above code
		for (var i = 0;i<17;i++)
			strtemp += timeSlots[i];
		return calDrawDay2(strtemp,eventtoday);
	}
}

function setTimeSlot(strTime)
{
	
	switch (strTime.substr(0,2) + strTime.substr(strTime.length-2,2))
	{
		case "7:AM":
			return 0;
		case "8:AM":
			return 1;
		case "9:AM":
			return 2;
		case "10AM":
			return 3;
		case "11AM":
			return 4;
		case "12PM":
			return 5;
		case "1:PM":
			return 6;
		case "2:PM":
			return 7;
		case "3:PM":
			return 8;
		case "4:PM":
			return 9;
		case "5:PM":
			return 10;
		case "6:PM":
			return 11;
		case "7:PM":
			return 12;
		case "8:PM":
			return 13;
		case "9:PM":
			return 14;
		case "10PM":
			return 15;
		case "11PM":
			return 16;
	}
}
function findSection(strSearch)
{
	if (strSearch.indexOf('>bso<') > -1)
		return 'BSO';
	else if (strSearch.indexOf('>pops<') > -1)
		return 'POPS';
	else if (strSearch.indexOf('>tanglewood<') > -1)
		return 'TW';
	else if (strSearch.indexOf('>symphony<') > -1)
		return 'SH';
}

function drawListSpacer()
{
	return '<tr><td width="1"><img src="/images/transpix.gif" height="1" alt="" border="0" width="13"/></td>' +
	'<td width="1"><img src="/images/transpix.gif" height="1" alt="" border="0" width="57"/></td>' +
	'<td width="1"><img src="/images/transpix.gif" height="1" alt="" border="0" width="170"/></td>' +
	'<td width="1"><img src="/images/transpix.gif" height="1" alt="" border="0" width="82"/></td>' +
	'<td width="1"><img src="/images/transpix.gif" height="1" alt="" border="0" width="104"/></td>' +
	'<td width="1"><img src="/images/transpix.gif" height="1" alt="" border="0" width="68"/></td>' +
	'<td width="1"><img src="/images/transpix.gif" height="1" alt="" border="0" width="39"/></td></tr>';
}
function drawListCalendar(strSearch)
{

	var strOut='';
	var strTemp = '';
	var weekmax = 7;
	var daycount = 1;
	var lastday = '';
	fc_setvars();
	if (strSearch == 'search') strSearch = '';

	
	//used for sort
	cal_sortby = document.frmSort.sortby.options[document.frmSort.sortby.selectedIndex].value;
	sortlistitem = null;
	sortlistitem = new Array();
	li_index = 0;
	
	for (daycount=1; daycount <= totaldays;)
	{
		if ((totaldays-daycount) < 6)
			weekmax = totaldays - daycount + 1;
		
		for (i=0;i<weekmax;i++)
		{
			if (i <= sel_dayofweek)
			{	
				if (sel_dayofweek == i)
				{
					sel_dayofweek = -1; //this happens once per xml load, reset when section is clicked
					fillListEvents(daycount,strSearch,i);	
					daycount++;
				}
			}
			else
			{
				fillListEvents(daycount,strSearch,i);	
				daycount++;
			}
		}
	}
	
	sortlistitem.sort(compareItems);
	
	var i = 0;
	if(typeof sortlistitem[i] != 'undefined')
		lastday = sortlistitem[i][2];
	while(typeof sortlistitem[i] != 'undefined')
	{
		if (lastday != sortlistitem[i][2]) //day changed
		{
			while (strTemp.indexOf('listactiveswap') != -1)
				strTemp = strTemp.replace('listactiveswap',listactiveswap);
			
			strOut += wrapinDay(lastday,strTemp);
			lastday = sortlistitem[i][2];
			strTemp = '';
			if (listactiveswap == '')
				listactiveswap = 'listactive';
			else
				listactiveswap = '';
		}
		
		strTemp += listitem[sortlistitem[i][0]];
		i++;
	}
	//do one last time
	if (i != 0)
	{
		while (strTemp.indexOf('listactiveswap') != -1)
			strTemp = strTemp.replace('listactiveswap',listactiveswap);
		strOut += wrapinDay(lastday,strTemp);
	}		
	
	if (strOut == '')
		strOut = '<tr><td colspan="7" height="100" valign="middle" align="center"><span class="listContent">Your search returned no results.</span></td></tr>'; //search returned no results
	
	strOut = calDrawSeparator(7) + drawListSpacer() + strOut;
	strOut = '<table cellpadding="0" cellspacing="0" border="0" width="530">' + strOut + '</table>';
	
	tmp = document.getElementById("cal_days");
	tmp.innerHTML = strOut; 
}

function drawCompleteSeason(strSearch)
{

	var strOut='';
	var strTemp = '';
	var weekmax = 7;
	var daycount = 1;
	var lastday = '';
	fc_setvars();
	if (strSearch == 'search') strSearch = '';

	
	//used for sort
	cal_sortby = 'Date'; 
		//document.frmSort.sortby.options[document.frmSort.sortby.selectedIndex].value;
	sortlistitem = null;
	sortlistitem = new Array();
	li_index = 0;
	for (daycount=1; daycount <= totaldays;)
	{
		if ((totaldays-daycount) < 6)
			weekmax = totaldays - daycount + 1;
		
		for (i=0;i<weekmax;i++)
		{
			if (i <= sel_dayofweek)
			{	
				if (sel_dayofweek == i)
				{
					sel_dayofweek = -1; //this happens once per xml load, reset when section is clicked
					fillListEventsCS(daycount,strSearch,i);	
					daycount++;
				}
			}
			else
			{
				fillListEventsCS(daycount,strSearch,i);	
				daycount++;
			}
		}
	}
	
	sortlistitem.sort(compareItems);
	
	var i = 0;
	if(typeof sortlistitem[i] != 'undefined')
		lastday = sortlistitem[i][2];
	while(typeof sortlistitem[i] != 'undefined')
	{
		if (lastday != sortlistitem[i][2]) //day changed
		{
			while (strTemp.indexOf('listactiveswap') != -1)
				strTemp = strTemp.replace('listactiveswap',listactiveswap);
			
			strOut += wrapinDay(lastday,strTemp);
			lastday = sortlistitem[i][2];
			strTemp = '';
			if (listactiveswap == '')
				listactiveswap = 'listactive';
			else
				listactiveswap = '';
		}
		
		strTemp += listitem[sortlistitem[i][0]];
		i++;
	}
	//do one last time
	if (i != 0)
	{
		while (strTemp.indexOf('listactiveswap') != -1)
			strTemp = strTemp.replace('listactiveswap',listactiveswap);
		strOut += wrapinDay(lastday,strTemp);
	}		
	
	if (strOut == '')
		strOut = '<tr><td colspan="7" height="100" valign="middle" align="center"><span class="listContent">Your search returned no results.</span></td></tr>'; //search returned no results
	
	strOut = calDrawSeparator(7) + drawListSpacer() + strOut;
	strOut = '<table cellpadding="0" cellspacing="0" border="0" width="530">' + strOut + '</table>';
	
	tmp = document.getElementById("cal_days");
	tmp.innerHTML = strOut; 
}

function wrapinDay(strDate, strContent)
{
	var tmpDate = new Date(strDate);
	return '<tr><td colspan="7" class="' +  listactiveswap + '"><img src="/images/transpix.gif" height="20" alt="" border="0" width="1"/></td></tr>' +
	'<tr><td valign="top" align="left" class="' +  listactiveswap + '"></td><td valign="top" align="left" colspan="6" class="' +  listactiveswap + '"><span class="listHead">' + month_name[tmpDate.getMonth()] + ' ' + tmpDate.getDate() + ', ' + fullname_dow[tmpDate.getDay()] + '</span></td></tr>' +
	'<tr><td colspan="7" class="' +  listactiveswap + '"><img src="/images/transpix.gif" height="4" alt="" border="0" width="1"/></td></tr>' +
	strContent + '<tr><td colspan="7" class="' +  listactiveswap + '"><img src="/images/transpix.gif" height="20" alt="" border="0" width="1"/></td></tr>' +
	calDrawSeparator(7);
}
function fillListEvents(daycount,strSearch,nDOW)
{
	var strtemp = '';
	var strloc1 = '';
	var strloc2 = '';
	var selectionType;
	var divcounter = '';
	var strpid = '';
	
	var strid = daycount + '/' + (thefirst.getMonth()+1) + '/' + thefirst.getFullYear();
	
	strEventID = 'title_event_fc' + daycount + '/' + (thefirst.getMonth()+1) + '/' + thefirst.getFullYear() + divcounter;
	
	while(document.getElementById(strEventID) != null)
	{
		objevent = document.getElementById(strEventID);
		
		if (objevent.innerHTML.toLowerCase().indexOf(strSearch) != -1)
		{
			
			selectionType = findSection(objevent.innerHTML);

			if (arCacheList['pid_event_fc' + strid + divcounter])
			{ 
				strTime = arCacheList['timeod_event_fc' + strid + divcounter];
				strloc1 = arCacheList['location_event_fc' + strid + divcounter];
				strloc2 = arCacheList['citystate_event_fc' + strid + divcounter];
				strpid =     arCacheList['pid_event_fc' + strid + divcounter];
			} else {
				strTime = document.getElementById('timeod_event_fc' + strid + divcounter).innerHTML;
				strloc1 = document.getElementById('location_event_fc' + strid + divcounter).innerHTML;
				strloc2 = document.getElementById('citystate_event_fc' + strid + divcounter).innerHTML;
				strpid = document.getElementById('pid_event_fc' + strid + divcounter).innerHTML;
				
				arCacheList['timeod_event_fc' + strid + divcounter] = strTime;
				arCacheList['location_event_fc' + strid + divcounter] = strloc1;
				arCacheList['citystate_event_fc' + strid + divcounter] = strloc2;
				arCacheList['pid_event_fc' + strid + divcounter] = strpid;
			}

/*
			strTime = document.getElementById('timeod_event_fc' + strid + divcounter).innerHTML;
			strloc1 = document.getElementById('location_event_fc' + strid + divcounter).innerHTML;
			strloc2 = document.getElementById('citystate_event_fc' + strid + divcounter).innerHTML;
			strpid = document.getElementById('pid_event_fc' + strid + divcounter).innerHTML;
*/			
			if(sel_section != 'all')
			{
				if (selectionType == 'BSO' && sel_section == 'BSO') {
					drawListItem(strTime,objevent.innerHTML,sel_section,strloc1,strloc2,strpid,daycount);
				} else if (selectionType == 'POPS' && sel_section == 'POPS'){
					drawListItem(strTime,objevent.innerHTML,sel_section,strloc1,strloc2,strpid,daycount);
				} else if (selectionType == 'TW' && sel_section == 'Tanglewood'){
					drawListItem(strTime,objevent.innerHTML,sel_section,strloc1,strloc2,strpid,daycount);
				} else if (selectionType == 'SH' && sel_section == 'Symphony'){
					drawListItem(strTime,objevent.innerHTML,sel_section,strloc1,strloc2,strpid,daycount);
				}
			}
			else
			{
				drawListItem(strTime,objevent.innerHTML,convertSectionAbb(selectionType),strloc1,strloc2,strpid,daycount);
			}
		}
		if(divcounter == '') 
			divcounter = 1;
		
		divcounter++;
		strEventID = 'title_event_fc' + daycount + '/' + (thefirst.getMonth()+1) + '/' + thefirst.getFullYear() + divcounter;
	}
}

function fillListEventsCS(daycount,strSearch,nDOW)
{
	var strtemp = '';
	var strloc1 = '';
	var strloc2 = '';
	var selectionType;
	var divcounter = '';
	var strprice = '';
	var strensemble = '';
	var strpid = '';
	var strprgnote = '';
	var strid = daycount + '/' + (thefirst.getMonth()+1) + '/' + thefirst.getFullYear();
	
	strEventID = 'title_event_fc' + daycount + '/' + (thefirst.getMonth()+1) + '/' + thefirst.getFullYear() + divcounter;
	
	while(document.getElementById(strEventID) != null)
	{
		objevent = document.getElementById(strEventID);
		
		if (objevent.innerHTML.toLowerCase().indexOf(strSearch) != -1)
		{
			
			selectionType = findSection(objevent.innerHTML);

			/*
			if (arCacheList['pid_event_fc' + strid + divcounter])
			{ 
				strTime = arCacheList['timeod_event_fc' + strid + divcounter];
				strloc1 = arCacheList['location_event_fc' + strid + divcounter];
				strloc2 = arCacheList['citystate_event_fc' + strid + divcounter];
				strpid =     arCacheList['pid_event_fc' + strid + divcounter];
			} else {
			*/
				strTime = document.getElementById('timeod_event_fc' + strid + divcounter).innerHTML;
				strloc1 = document.getElementById('location_event_fc' + strid + divcounter).innerHTML;
				strloc2 = document.getElementById('citystate_event_fc' + strid + divcounter).innerHTML;
				
				strprice = document.getElementById('price_event_fc' + strid + divcounter).innerHTML;
				strensemble = document.getElementById('ensembles_event_fc' + strid + divcounter).innerHTML;
				strprgnote = document.getElementById('programnotes_event_fc' + strid + divcounter).innerHTML;
				strpid = document.getElementById('pid_event_fc' + strid + divcounter).innerHTML;
				
				arCacheList['timeod_event_fc' + strid + divcounter] = strTime;
				arCacheList['location_event_fc' + strid + divcounter] = strloc1;
				arCacheList['citystate_event_fc' + strid + divcounter] = strloc2;
				arCacheList['ensembles_event_fc' + strid + divcounter] = strensemble;
				arCacheList['price_event_fc' + strid + divcounter] = strprice;
				arCacheList['programnotes_event_fc' + strid + divcounter] = strprgnote;
				arCacheList['pid_event_fc' + strid + divcounter] = strpid;
			/*}*/

/*
			strTime = document.getElementById('timeod_event_fc' + strid + divcounter).innerHTML;
			strloc1 = document.getElementById('location_event_fc' + strid + divcounter).innerHTML;
			strloc2 = document.getElementById('citystate_event_fc' + strid + divcounter).innerHTML;
			strpid = document.getElementById('pid_event_fc' + strid + divcounter).innerHTML;
*/			
			if(sel_section != 'all')
			{
				if (selectionType == 'BSO' && sel_section == 'BSO') {
					drawListItemCS(strTime,objevent.innerHTML,sel_section,strloc1,strloc2,strprgnote,strprice,strensemble,strpid,daycount);
				} else if (selectionType == 'POPS' && sel_section == 'POPS'){
					drawListItemCS(strTime,objevent.innerHTML,sel_section,strloc1,strloc2,strprgnote,strprice,strensemble,strpid,daycount);
				} else if (selectionType == 'TW' && sel_section == 'Tanglewood'){
					drawListItemCS(strTime,objevent.innerHTML,sel_section,strloc1,strloc2,strprgnote,strprice,strensemble,strpid,daycount);
				} else if (selectionType == 'SH' && sel_section == 'Symphony'){
					drawListItemCS(strTime,objevent.innerHTML,sel_section,strloc1,strloc2,strprgnote,strprice,strensemble,strpid,daycount);
				}
			}
			else
			{
				drawListItemCS(strTime,objevent.innerHTML,convertSectionAbb(selectionType),strloc1,strloc2,strprgnote,strprice,strensemble,strpid,daycount);
			}
		}
		if(divcounter == '') 
			divcounter = 1;
		
		divcounter++;
		strEventID = 'title_event_fc' + daycount + '/' + (thefirst.getMonth()+1) + '/' + thefirst.getFullYear() + divcounter;
	}
}

function convertSectionAbb(strTemp)
{
	if (strTemp == 'BSO') {
		return 'BSO';
	} else if (strTemp == 'POPS'){
		return 'POPS';
	} else if (strTemp == 'TW'){
		return 'Tanglewood';
	} else if (strTemp == 'SH'){
		return 'Symphony Hall';
	}
}

function drawListItemCS(strTime,strText,strSection,strLocation1,strLocation2,strPrgNote,strPrice,strEnsemble,pid,daycount)
{
	if (strSection == null) strSection = "";
	
	listitem[li_index] = '<tr class="listactiveswap"><td valign="top" align="left" class=""></td>' +
	'<td valign="top" colspan="2" align="left" class=""><span class="listContent">' + strTime + '<br/><span class="listContent' + strSection.toUpperCase() + '">' + strSection + '</span><br/>' + strLocation1 +'<br/>' + strLocation2 + '<br/>' + strPrice + '<br/></span><br/></td>' +
	'<td valign="top" colspan="2" align="left" class=""><span class="listContent">' + strEnsemble + '</span></td>' +
	'<td valign="top" colspan="2" align="left" class=""><span class="listContent">' + strPrgNote + '</span></td></tr>';
	
	if (cal_sortby == 'Title')
		sortlistitem[li_index] = new Array(li_index,strText,(thefirst.getMonth()+1) + '/' + daycount + '/' + thefirst.getFullYear());
	else if(cal_sortby == 'Venue')
		sortlistitem[li_index] = new Array(li_index,strLocation1,(thefirst.getMonth()+1) + '/' + daycount + '/' + thefirst.getFullYear());
	else if (cal_sortby == 'Location')
		sortlistitem[li_index] = new Array(li_index,strLocation2,(thefirst.getMonth()+1) + '/' + daycount + '/' + thefirst.getFullYear());
	else if (cal_sortby == 'Date')
	{
		var tmpDate = new Date((thefirst.getMonth()+1) + '/' + daycount + '/' + thefirst.getFullYear() + ' ' + strTime);
		sortlistitem[li_index] = new Array(li_index,tmpDate.getTime(),(thefirst.getMonth()+1) + '/' + daycount + '/' + thefirst.getFullYear());
	}
	li_index++;
}
function drawListItem(strTime,strText,strSection,strLocation1,strLocation2,pid,daycount)
{
	if (strSection == null) strSection = "";
	
	listitem[li_index] = '<tr class="listactiveswap"><td valign="top" align="left" class=""></td>' +
	'<td valign="top" align="left" class=""><span class="listContent">' + strTime + '</span></td>' +
	//'<td valign="top" align="left" class=""><span class="listContent"><a href="/bso/mods/perf_detail.jsp;jsessionid=' + sessionid + '?pid=' + pid + '">' + strText + '</a></span></td>' +
	'<td valign="top" align="left" class=""><span class="listContent"><a href="/bso/mods/perf_detail.jsp?pid=' + pid + '">' + strText + '</a></span></td>' +
	'<td valign="top" align="left" class=""><span class="listContent' + strSection.toUpperCase() + '">' + strSection + '</span></td>' +
	'<td valign="top" align="left" class=""><span class="listContent">' + strLocation1 + '</span></td>' +
	'<td valign="top" align="left" class=""><span class="listContent">' + strLocation2 + '</span></td>' +
	//'<td valign="top" align="left" class=""><a href="/bso/mods/seatsel.jsp;jsessionid=' + sessionid + '?prevPage=PerformanceDetails&pid=' + pid + '"><img src="/images/tix.gif" alt="Tix" border="0"/></a></td></tr>';
	'<td valign="top" align="left" class=""><a href="/bso/mods/seatsel.jsp?prevPage=PerformanceDetails&pid=' + pid + '"><img src="/images/tix.gif" alt="Tix" border="0"/></a></td></tr>';
	
	if (cal_sortby == 'Title')
		sortlistitem[li_index] = new Array(li_index,strText,(thefirst.getMonth()+1) + '/' + daycount + '/' + thefirst.getFullYear());
	else if(cal_sortby == 'Venue')
		sortlistitem[li_index] = new Array(li_index,strLocation1,(thefirst.getMonth()+1) + '/' + daycount + '/' + thefirst.getFullYear());
	else if (cal_sortby == 'Location')
		sortlistitem[li_index] = new Array(li_index,strLocation2,(thefirst.getMonth()+1) + '/' + daycount + '/' + thefirst.getFullYear());
	else if (cal_sortby == 'Date')
	{
		var tmpDate = new Date((thefirst.getMonth()+1) + '/' + daycount + '/' + thefirst.getFullYear() + ' ' + strTime);
		sortlistitem[li_index] = new Array(li_index,tmpDate.getTime(),(thefirst.getMonth()+1) + '/' + daycount + '/' + thefirst.getFullYear());
	}
	li_index++;
}

function compareItems(a1, a2) {
   return a1[1] < a2[1] ? -1 :
          a1[1] > a2[1] ? 1 : 0;
}


function onkey(){
    if (event.keyCode == 13){ 
        searchEvents(0);
	}
	return;
} 

function searchEvents(ndropdown)
{
	listactiveswap='';

	var strSearch = document.getElementById('calSearch').value;
	calendar_mode = 'LIST';
	drawListCalendar(strSearch.toLowerCase());
	document.frmSort.calCalview.selectedIndex = 1;
}
function initCalendar()
{
	
	if (readCookie("Section")!= null)
	{
		sel_section = readCookie("Section");
	}
	if (readCookie("Year")!= null && readCookie("Month")!= null)
	{
		defaultperforamnce = 0;
		csel_year = parseInt(readCookie("Year"));
		csel_month = parseInt(readCookie("Month"));
	}


	if (calendar_mode != 'EMPTY')
	{
		drawHeader();
		setHeading();
		setMonthHeading();
		ajaxGrab();
	}
}

function pullInFilters()
{
	if(document.getElementById('wishlist_events') != null)
	{
		wishlist = document.getElementById('wishlist_events').innerHTML;
	}	
	if(document.getElementById('purchased_events') != null)
	{
		purchased = document.getElementById('purchased_events').innerHTML;
	}
}

function drawCalendar()
{
	pullInFilters();
	if (calendar_mode == 'FULL')
	{
		drawFullCalendar();
		if (cookieset==false)
		{
			if (defaultperformance == 1) 
			{
				sel_section = 'all';
				drawHeader();
				drawFullCalendar();
			}
			if (defaultperformance == 2)
			{
				var newmonth = csel_month+1;
				var newyear = csel_year;
				if ((newmonth - 12) > 0)
				{
					newmonth = newmonth - 12;
					newyear++;
				}
				
				changeMonthYear(newmonth,newyear);
				ajaxGrab();
				setMonthHeading();
			}
		}
		defaultperformance = 0;
	}
	else if (calendar_mode == 'LIST')
	{
		var strSearch = document.getElementById('calSearch').value;
		drawListCalendar(strSearch.toLowerCase());
	}
	else 
	{
		drawCompleteSeason('search');
	}
	
	
}


/***********************************/
function createCookie(name,value,days) {
	/*
	if (min) {
		var date = new Date();
		date.setTime(date.getTime()+(min*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	if (hours) {
		var date = new Date();
		date.setTime(date.getTime()+(hours*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	*/
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*4*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
