<!-- Begin
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------
|	Community Calendar Script by Josh Miller
|	written for the City of Elmira @ http://www.cityofelmira.net
|	*free to use as long as header remains*
|	
|	start()						: call this function from the Calendar Page
|	previewer(num,StartDate)	: this function stores events num days from the StartDate
|	search(word)				: this function searches the Title and Description of each event for word
|	monthNavigator(mo,yr)		: this function shows all events from the Month and Year passed as mo and yr
|	dayNavigator(dy,mo,yr)		: this function shows all events from the specified day passed as dy, mo, and yr
|	drawCalendar(m,y)			: this function sets up the tables for the Calendar and calls the FillCalendar function to fill the Calendar
|	FillCalendar(m,y)			: this function fills in the Calendar with the dates after calling the CheckDate function
|	checkDate(d,m,y)			: this function checks the Date to see if the date is today, prints the date and its links
|	drawSearchTools()			: this function prints the Month dropdown and Search Field
|	searchEvents()				: this function takes the input from the search field and calls the search function
|	goToMonth()					: this function takes the input from the dropdown and calls the monthNavigator function
|	compareDates(it,that)		: this function takes two Date objects, it and that, and compares then- returning True if the dates are the same
|	precedeDates(it,that)		: this function takes two Date objects, it and that, and returns True if it occurs before that
|	sortDates(a,b)				: this function sorts the dates in an array
|	printEvent(id)				: this function prints a single event by its id
|	printEvents()				: this function prints the events in the store array
|	sendEvent(id)				: this function opens a window to send an event using AspMail
|	indexPreview()				: call this function from the Index Page for the "This Week's Events" feature
|	getWeekDay(weekday)			: this function accepts 0-6 and returns the corresponding Day of the Week
|	getMonth(month)				: this function accepts 0-11 and returns the corresponding month
|	addZero(x)					: this function accepts a number (x) and adds a zero to the front of it if less than 10: e.g. 5 becomes 05
|	stringInit()				: this function is used by the links array to link to information in a website	
-------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ 
today=new Date();						//get Today's date and store in today
currentDate=today.getDate();			//get Today's numerical date
currentDay=today.getDay();				//get Today's weekday
currentMonth=today.getMonth();			//get Today's month
currentYear=today.getYear();			//get Today's year
if (navigator.appName == "Netscape"){	//adjust for Netscape's weird handling of dates...
	currentYear=(1900+currentYear)
}
firstflag=0;lastflag=0;					//flags to find the first and last days of the month
weekcounter=0;daycounter=0;				//variables to count the weeks and days in a month
previewWidth=190;						//the width of the preview table

//------------------------------------START---------------------------------------------------------------------------------------------------------------------

function start(){										//function to call within the html page
	stringInit();
	calendarInit();
	var url=document.location.toString();				//parse the url to determine the state requested
	urlLength=url.length;							
	y=url.lastIndexOf("html");				
	y=y+4;	
	var params=url.substring(y,urlLength);
	if( params==""){									//if no state, then display the next month of events
		previewer(14, today);
	}
	else{
		state=params.substring(1,3);				
		if (state=="id"){								//if the state is id, then print the event with the id
			id=params.substring(4,params.length);
			printEvent(id)
		}
		else if (state=="pv"){							//if the state is preview, then preview the number of days requested
			preview=params.substring(4,params.length);
			a=preview.lastIndexOf("&start=");
			previewDays=preview.substring(0,a)
			previewStart=preview.substring(a+7,preview.length)
			startDate=new Date();
			y=previewStart.substring(0,4);
			m=parseInt(previewStart.substring(4,6)-1);
			d=previewStart.substring(6,8);
			startDate=new Date(y,m,d);
			previewer(previewDays,startDate);
		}
		else if (state=="sc"){								//if the state is search, then call the search function
			wordIndex=params.lastIndexOf("&submit=Search")
			if(wordIndex > 0){
				word=params.substring(4,params.length-14);
			}
			else{
				word=params.substring(4,params.length);
			}
			word=word.replace("+","%20")
			word=unescape(word)							
			search(word);
		}
		else if(state=="mo"){								//if the state is month navigator, then call the navigate function

			yr=params.substring(4,params.length-2)
			mo=params.substring(8,params.length);
			monthNavigator(mo,yr);
		}
		else if(state=="dy"){								//if the state is day navigator, then call the navigate function
			yr=params.substring(4,params.length-4)
			mo=params.substring(8,params.length-2);
			dy=params.substring(10,params.length);
			dayNavigator(dy,mo,yr);
		}
	}
}//end start function


//------------------------------------PREVIEW A SPECIFIC NUMBER OF DAYS FROM TODAY---------------------------------------------------------------------------------------------------------------------

function previewer(num, StartDate){
	yC=StartDate.getYear(); if (navigator.appName == "Netscape"){yC=(1900+yC)}
	drawCalendar(StartDate.getMonth(),yC)
	numb=num;							//The number of days to preview
	numb++;
	test=new Array();					//Create an array to hold the dates of the preview period
	store=new Array();					//Create an array to hold the index of the events in the edate[] array to be printed
	counter=0;							//Use a counter to increment the store array
	Day=StartDate.getDate();
	Month=StartDate.getMonth();
	Year=StartDate.getYear();
	if (navigator.appName == "Netscape"){	//adjust for Netscape's weird handling of dates...
		Year=(1900+Year)
	}
	for(i=0; i<numb; i++){												//for (Today) and each of the next preview days
		test[i]=new Date(Year,Month,Day+i);								
	}
	for (i=0; i<test.length; i++){							//for each date in the test array
		testDate=test[i];									//assign testDate the value of the date in the test array
		for(j=0;j<edate.length;j++){							//then for each value in the date array
			temp=new Date(edate[j]);							//assign it to temp
			if (compareDates(testDate,temp)){					//and then compare the two dates- if they are the same
				store[counter]=j;counter++;							//then store that event in the store array and increment the counter
			}//end if 
		}//end inner for loop
	}//end outer for loop
	header="Upcoming Events"
	document.write("<tr><td class='calendarTitle'>"+header+"</td></tr>");
	printEvents()
	document.write("<tr><td class='eventDate'>&nbsp;</td></tr>");
	LastDate=new Date(Year, Month, Day+numb);
	StartDay=addZero(LastDate.getDate());
	StartMonth=addZero(LastDate.getMonth()+1);
	StartYear=LastDate.getYear(); if (navigator.appName == "Netscape"){StartYear=(1900+StartYear)}
	StartingDate=StartYear.toString()+StartMonth.toString()+StartDay.toString();
	document.write("<tr><td><a href='calendar.html?pv=14&start="+StartingDate+"'><b>More Upcoming Events</b></a></td></tr>");
}//end previewer function


//------------------------------------SEARCH EVENTS FOR A KEYWORD---------------------------------------------------------------------------------------------------------------------

function search(word){
	var url=document.location.toString();
	if (url.indexOf("blossom")< 0){
		drawCalendar(currentMonth,currentYear)
	}
	original=word
	word=original.toLowerCase();								//convert the search string to lowercase
	store=new Array();											//create an array to store the index of events that match search criteria
	counter=0;													//set a counter for the store array
	toDay=new Date(currentYear,currentMonth,currentDate);		//create a Date to eliminate all events prior to this date
	for(i=0;i<edate.length;i++){									//then for each value in the date array
		temp=title[i].toLowerCase();							//store the title in temp in lower case
		temp2=edesc[i].toLowerCase();							//store the description in temp2 in lower case
		flag=temp.indexOf(word);								//set flag=to the index of the search term in the title- if not there then flag is -1
		flag2=temp2.indexOf(word);								//set flag2=to the index of the search term in the description- if not there then flag2 is -1 
		if ((flag >-1) || (flag2>-1)){							//if the flags are not -1 (meaning the seach term is found in the event)				
			tempDate=edate[i];									//assign tempDate the value of the event's Date
			if (!precedeDates(tempDate,toDay)){ 				//if the date of the event does not precede today, then
				store[counter]=i;								//then store that event in the store array
				counter++;										//and increment the counter
			}//end if
		}//end if 
	}//end outer for loop
	if (store.length==1)
		matches=store.length+" match"
	else
		matches=store.length+" matches"

	document.write("<tr><td colspan='2'><span  class='searchResults'>Search for: </span><span  class='searchWord'>"+original+"</span><span  class='searchResults'> returned "+matches+"</span><br><br></td></tr>");
	printEvents()
}//end search function


//------------------------------------PRINT ALL EVENTS IN A SPECIFIED MONTH---------------------------------------------------------------------------------------------------------------------

function monthNavigator(mo,yr){
	month=mo-1;
	drawCalendar(month,yr)
	test=new Array();store=new Array();counter=0;
	for(i=0; i<32; i++){
		test[i]=new Date(yr,month,i);
	}
	for (i=0; i<test.length; i++){
		testDate=test[i];
		for(j=0;j<edate.length;j++){
			temp=new Date(edate[j]);
			if (compareDates(testDate,temp)){
				testMonth=temp.getMonth();
				if (testMonth==month){
					store[counter]=j;counter++;
				}
			}
		}
	}
	header="Events for "+getMonth(month)+" "+yr
	document.write("<tr><td class='calendarTitle'>"+header+"</td></tr>");
	printEvents()
}//end monthNavigatorfunction


//------------------------------------PRINT ALL EVENTS IN A SPECIFIED DAY---------------------------------------------------------------------------------------------------------------------

function dayNavigator(dy,mo,yr){
	month=mo-1;	;day=dy
	drawCalendar(month,yr)
	store=new Array();counter=0;
	testDate=new Date(yr,month,dy);
	for(j=0;j<edate.length;j++){
		temp=new Date(edate[j]);
		if (compareDates(testDate,temp)){
			testMonth=temp.getMonth();
			if (testMonth==month){
				store[counter]=j;counter++;
			}
		} 
	}
	header="Events for "+getMonth(month)+" "+parseInt(day)+", "+yr
	document.write("<tr><td class='calendarTitle'>"+header+"</td></tr>");
	printEvents()
}//end dayNavigator function


//------------------------------------DRAW AND FILL THE INTERACTIVE CALENDAR---------------------------------------------------------------------------------------------------------------------

function drawCalendar(m,y){
	document.write("<tr><td>")
	document.write("<table border='0' cellpadding='2' cellspacing='0'><tr><td>")
	document.write("<table border='0' cellpadding='0' cellspacing='0' class='calendarborder'>")
	if(m==0){
		document.write("<tr class='monthheader'><td colspan='7' align='center'>")
		document.write("<a href='calendar.html?mo="+(parseInt(y)-1)+addZero(m+1)+"' class='monthheader' title='Last Year'><<</a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+(parseInt(y)-1)+"12"+"' class='monthheader' title='Last Month'><</a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+y+addZero(m+1)+"' class='monthheader' title='This Month\'s Events'>"+getMonth(m)+"&nbsp;"+y+"</a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+y+addZero(m+2)+"' class='monthheader' title='Next Month'>></a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+(parseInt(y)+1)+addZero(m+1)+"' class='monthheader' title='Next Year'>>></a>")
		document.write("</td><tr>")
	}
	else if (m==11){
		document.write("<tr class='monthheader'><td colspan='7' align='center'>")
		document.write("<a href='calendar.html?mo="+(parseInt(y)-1)+addZero(m+1)+"' class='monthheader' title='Last Year'><<</a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+y+addZero(m)+"' class='monthheader' title='Last Month'><</a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+y+addZero(m+1)+"' class='monthheader' title='This Month\'s Events'>"+getMonth(m)+"&nbsp;"+y+"</a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+(parseInt(y)+1)+"01"+"' class='monthheader' title='Next Month'>></a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+(parseInt(y)+1)+addZero(m+1)+"' class='monthheader' title='Next Year'>>></a>")
		document.write("</td><tr>")
	}
	else{
		document.write("<tr class='monthheader'><td colspan='7' align='center'>")
		document.write("<a href='calendar.html?mo="+(parseInt(y)-1)+addZero(m+1)+"' class='monthheader' title='Last Year'><<</a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+y+addZero(m)+"' class='monthheader' title='Last Month'><</a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+y+addZero(m+1)+"' class='monthheader' title='This Month\'s Events'>"+getMonth(m)+"&nbsp;"+y+"</a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+y+addZero(m+2)+"' class='monthheader' title='Next Month'>></a>&nbsp;&nbsp;")
		document.write("<a href='calendar.html?mo="+(parseInt(y)+1)+addZero(m+1)+"' class='monthheader' title='Next Year'>>></a>")
		document.write("</td><tr>")
	}
	document.write("<tr class='weekheader'><td align='middle' class='weekheader'>S</td><td align='middle' class='weekheader'>M</td><td align='middle' class='weekheader'>T</td><td align='middle' class='weekheader'>W</td><td align='middle' class='weekheader'>T</td><td align='middle' class='weekheader'>F</td><td align='middle' class='weekheader'>S</td></tr>")
	for(i=0; i<6; i++){
		document.write("<tr>")
		for(j=0; j<7; j++){
			document.write("<td align='middle' class='calendardays'>&nbsp;"+FillCalendar(m,y)+"&nbsp;</td>")
		}
		document.write("</tr>")
	}
	document.write("</table>")
	document.write("</td><td valign='bottom'>");drawSearchTools();document.write("</td></tr></table>")
	document.write("<br></td></tr>")
}//end drawCalendar function

function FillCalendar(m,y){
	FirstoftheMonth=new Date();FirstoftheMonth.setDate(1);FirstoftheMonth.setMonth(m);FirstoftheMonth.setYear(y)
	DayoftheFirst=FirstoftheMonth.getDay()
	ToDay=new Date();ToDay.setMonth(m);ToDay.setYear(y);ToDay.setDate(daycounter)
	ToMorrow=new Date(ToDay);ToMorrow.setDate(daycounter+1);
	weekcounter++;
	if (weekcounter%7==0){weekcounter=0;}
	daycounter++;
	if (weekcounter==DayoftheFirst && firstflag==0){firstflag=1;daycounter=0;return "";}
	else if (firstflag==0){return ""}
	else{
		if (ToMorrow.getMonth()==FirstoftheMonth.getMonth()){
			return checkDate(daycounter, m, y)
		}
		else{
			if(lastflag==0){
				lastflag=1;return checkDate(daycounter, m, y);
			}
			else{return ""}
		}
	}
}//end FillCalendar function

function checkDate(d,m,y){
	todayflag=0;
	m;
	test=new Date();test.setDate(d);test.setMonth(m);test.setYear(y);
	Today=new Date();Today.setDate(currentDate);Today.setMonth(currentMonth);Today.setYear(currentYear)
	if(compareDates(Today,test)){todayflag=1;}
	store=new Array();counter=0;
	for(a=0;a<edate.length;a++){
		temp=new Date(edate[a]);
		if (compareDates(test,temp)){
			testMonth=temp.getMonth();
			if (testMonth==m){
				store[counter]=a;counter++;
			}
		}
	}
	if(store.length<1){
		if(todayflag==1){return "<span class='calendartoday'>"+d+"</span>"}
		else{return d}}
	else{
		if(todayflag==1){return "<b><a href='calendar.html?dy="+y+addZero(m+1)+addZero(d)+"' class='calendartoday' title='Show Events for Today'>"+d+"</b></a>"}
		else{return "<a href='calendar.html?dy="+y+addZero(m+1)+addZero(d)+"' class='calendardays' title='Show Events for "+getMonth(m)+"&nbsp;"+d+", "+y+"'>"+d+"</a>"}
	}
}//end checkDate function

function drawSearchTools(){
	document.write("<table border='0' cellpadding='0' cellspacing='0'><tr><td>")
	document.write("<tr><td><span class='searchBar'>Select a Month and Year:</span><br><select id='monthSelector' size='1'>")
	for (m=0; m<12; m++){
		if(m==currentMonth){document.write("<option value='"+ addZero(parseInt(m+1)) +"' selected>"+getMonth(m)+"</option>")}
		else{document.write("<option value='"+ addZero(parseInt(m+1)) +"'>"+getMonth(m)+"</option>")}
	}
	document.write("</select>&nbsp;<select id='yearSelector' size='1'>")
	document.write("<option value='"+(currentYear-2)+"'>"+(currentYear-2)+"</option>")
	document.write("<option value='"+(currentYear-1)+"'>"+(currentYear-1)+"</option>")
	document.write("<option value='"+(currentYear)+"' selected>"+(currentYear)+"</option>")
	document.write("<option value='"+(currentYear+1)+"'>"+(currentYear+1)+"</option>")
	document.write("<option value='"+(currentYear+2)+"'>"+(currentYear+2)+"</option>")
	document.write("</select>")
	document.write("&nbsp;<input type='submit' name='submit' value='Go' onClick='goToMonth();'></td></tr>")
	document.write("<tr><td>")
	document.write("<form><span class='searchBar'><br>Search for Events:</span><br><input type='text' name='sc' value='' size='30'>&nbsp;<input type='submit' name='submit' value='Search' onClick='searchEvents();'>");
	document.write("</td></tr>")
	document.write("<tr><td class='smalltext'><a href='../index/calendar_submit.html'>>submit your event</a></form></td></tr></table>")
}//end drawSearchTools function

function searchEvents(){
	a=document.all.sc.value;a=escape(a);
	b="../index/calendar.html?sc="
	document.location=b+a;
}//end searchEvents function

function goToMonth(){
	document.location="calendar.html?mo="+document.getElementById('yearSelector').value+document.getElementById('monthSelector').value
}//end goToMonth function


//------------------------------------COMPARISON AND SORTING FUNCTIONS---------------------------------------------------------------------------------------------------------------------

function compareDates(it,that){
	//pre: it and that are valid JavaScript Date Objects
	//post: returns True if the dates are the same and False if they are not
	thisDate=it.getDate();
	thisMonth=it.getMonth();
	thisYear=it.getYear();
	thatDate=that.getDate();
	thatMonth=that.getMonth();
	thatYear=that.getYear();
	return ( (thisDate==thatDate) && (thisMonth==thatMonth) && (thisYear==thatYear) );
}//end compareDate function

function precedeDates(it,that){
	//pre: it and that are valid JavaScript Date Objects
	//post: returns True if it precedes that in linear time
	//      returns False if it and that are the same day
	//	    returns False if it occurs after that
	thisDate=it.getDate();thisMonth=it.getMonth();thisYear=it.getYear();
	thatDate=that.getDate();thatMonth=that.getMonth();thatYear=that.getYear();
	if((thisYear-thatYear)>0){return false;}
	else if ((thisYear-thatYear)<0){return true;}
	else{
		if ((thisMonth-thatMonth)>0){return false;}
		else if ((thisMonth-thatMonth)<0){return true;}
		else{if ((thisDate-thatDate)>0){return false;}else if ((thisDate-thatDate)<0){return true;}else{return false;}}
	}
}//end precedeDates function

function sortDates(a,b){
	//pre: a and b are the indexes of dates in the date array
	it=edate[a];that=edate[b];	
	thisDate=it.getDate();thisMonth=it.getMonth();thisYear=it.getYear();
	thatDate=that.getDate();thatMonth=that.getMonth();thatYear=that.getYear();
	if((thisYear-thatYear)>0){return 1;}
	else if ((thisYear-thatYear)<0){return -1;}
	else{
		if ((thisMonth-thatMonth)>0){return 1;}
		else if ((thisMonth-thatMonth)<0){return -1;}
		else{if ((thisDate-thatDate)>0){return 1;}else if ((thisDate-thatDate)<0){return -1}else{return 0}}
	}
}//end sortDates function


//------------------------------------OUTPUT FUNCTIONS---------------------------------------------------------------------------------------------------------------------

function printEvent(id){
	DAY=edate[id].getDate();
	WEEKDAY=getWeekDay(edate[id].getDay());
	MONTH=getMonth(edate[id].getMonth());
	YEAR=edate[id].getYear();
	if (navigator.appName == "Netscape"){
		YEAR=(1900+YEAR)
	}
	drawCalendar(edate[id].getMonth(),YEAR)
	dateOfEvent=WEEKDAY+", "+MONTH+" "+DAY+", "+YEAR;
	document.write("<tr><td class='calendarTitle'>"+title[id]+"</td></tr>");
	document.write("<tr><td class='eventDate'>&nbsp;"+dateOfEvent+"</td></tr>");
	document.write("<tr><td><br></td></tr>");
	document.write("<tr><td class='eventDesc'>"+edesc[id]+"</td></tr>");
	document.write("<tr><td><table cellpadding='0' cellspacing='0' border='0'><tr><td class='eventContact' width='10'>&nbsp;</td><td class='eventContact' valign='top' width='1'>»</td><td class='eventContact'>"+cntct[id]+"</td></tr>");
	if(links[id]!=""){
		document.write("<tr><td class='eventLinks'>&nbsp;</td><td class='eventLinks' colspan='2'>"+links[id]+"</td></tr>");
	}
	document.write("<tr><td class='eventLinks'>&nbsp;</td><td class='eventLinks' colspan='2'><a href='calendar.html?sc="+title[id]+"' title='Click here to find other occurrences of this event'>»find other occurrences of this event</a></td></tr>");
	document.write("<tr><td class='eventLinks'>&nbsp;</td><td class='eventLinks' colspan='2'><a href='javascript:sendEvent(" +id+ ")' title='Click here to email a link to this event to a friend'>»email this event to a friend</a></td></tr>");
	document.write("<tr><td class='eventLinks'>&nbsp;</td><td class='eventLinks' colspan='2'><a href='javascript:print()' title='Click here to print this event'>»print this event</a></td></tr></table></td></tr>");
	document.write("<td><br></td></tr>");
	document.write("<tr><td class='eventDate'>&nbsp;</td></tr>");
}

function printEvents(){
	if (store.length==0){
		document.write("<tr><td colspan='2' class='noevents'><br>No Upcoming Events Found<br><br></td></tr>");	}//end if
	else{
		store.sort(sortDates);
		for (i=0;i<store.length;i++){
			eventDate=new Date();eventDate=edate[store[i]];
			DAY=eventDate.getDate();		
			WEEKDAY=getWeekDay(eventDate.getDay());
			MONTH=getMonth(eventDate.getMonth());
			YEAR=eventDate.getYear();
			if (navigator.appName == "Netscape"){
				YEAR=(1900+YEAR)
			}
			lastEvent=new Date("January 1,1970")
			if(i>0){
				lastEvent=edate[store[i-1]]
			}
		dateOfEvent=WEEKDAY+", "+MONTH+" "+DAY+", "+YEAR;
		document.write("<tr>")
		if(!compareDates(lastEvent,edate[store[i]])){
			document.write("<td class='eventDate'>&nbsp;"+dateOfEvent+"</td></tr>");
			document.write("<tr><td><br></td></tr>");
		}
		document.write("<tr><td><a href='../index/calendar.html?id="+store[i]+"' title='Click to view this event' class='eventTitle'>"+title[store[i]]+"</a></td></tr>");
		document.write("<tr><td class='eventDesc'>"+edesc[store[i]]+"</td></tr>");
		document.write("<tr><td><table cellpadding='0' cellspacing='0' border='0'><tr><td class='eventContact' width='10'>&nbsp;</td><td class='eventContact' valign='top' width='1'>»</td><td class='eventContact'>"+cntct[store[i]]+"</td></tr>");
		if(links[store[i]]!=""){
			document.write("<tr><td class='eventLinks'>&nbsp;</td><td class='eventLinks' colspan='2'>"+links[store[i]]+"</td></tr>");
		}
		document.write("<tr><td class='eventLinks'>&nbsp;</td><td class='eventLinks' colspan='2'><a href='javascript:sendEvent(" +store[i]+ ")' title='Click here to email a link to this event to a friend'>»email this event to a friend</a></td></tr></table></td></tr>");
		document.write("<td><br></td></tr>");
		}//end for
	}//end else
}//end printEvents function

function sendEvent(id){
	DAY=edate[id].getDate();
	Weekday=edate[id].getDay();
	WEEKDAY=getWeekDay(Weekday);
	Month=edate[id].getMonth();
	MONTH=getMonth(Month);
	YEAR=edate[id].getYear();
	if (navigator.appName == "Netscape"){
		YEAR=(1900+YEAR)
	}
	dateOfEvent=WEEKDAY+", "+MONTH+" "+DAY+", "+YEAR;
        Linkwindow=window.open("", "sendwin", "height=460,width=365,toolbar=no,scrollbars=no,menubar=no										");
        Linkwindow.document.write(" 	<head><title>Email Event</title>        															");
        Linkwindow.document.write(" 	<LINK rel='stylesheet' type='text/css' href='http://www.cityofelmira.net/_elmira.css'>				");
        Linkwindow.document.write(" 	<style>td{font-family:tahoma; font-size:10pt; color:#000000;}</style></head>        				");
        Linkwindow.document.write(" 	<body  background='http://www.cityofelmira.net/index/pics/bg.gif' bgcolor='#FFFFFF' leftmargin='0' marginwidth='2' topmargin='0' marginheight='0'>	");
        Linkwindow.document.write("		<span class='title'>Email this Event to a Friend</span><br>        									");
       	Linkwindow.document.write("		&nbsp;&nbsp;&nbsp;<a href='http://www.cityofelmira.net/index/calendar.html?id="+id+"' target='_blank' class='linktosend'>"+title[id]+"</a>   		");
        Linkwindow.document.write("		<form method='get' action='../scripts/sendevent.asp' name='mail'>			");
        Linkwindow.document.write("		<input type='hidden' value='" +title[id]+ "' name='eventTitle'>        								");
        Linkwindow.document.write("		<input type='hidden' value='" +dateOfEvent+ "' name='eventDate'>        							");
        Linkwindow.document.write("		<input type='hidden' value='http://www.cityofelmira.net/index/calendar.html?id="+id+"' name='link'> 	");
        Linkwindow.document.write("		<table border='0'>        																			");
        Linkwindow.document.write("		<tr><td>Recipient's Name:</td><td><input type='text' name='toname'></td></tr>        				");
        Linkwindow.document.write("		<tr><td>Recipient's Email:</td><td><input type='text' name='to'></td></tr>        					");
        Linkwindow.document.write("		<tr><td>Your Name:</td><td><input type='text' name='fromname'></td></tr>        					");
        Linkwindow.document.write("		<tr><td>Your Email Address:</td><td><input type='text' name='replyto'></td></tr>       				");
        Linkwindow.document.write("		<td colspan='2'>Your Message:<br><textarea type='text' name='message' wrap='virtual' rows='10' cols='40'></textarea></td></tr>	");
        Linkwindow.document.write("		<tr><td colspan='2' align='center'><input type='submit' value='Send Mail'>&nbsp;&nbsp;<input type='reset' value='Clear'><br>	");
        Linkwindow.document.write("		<a href='javascript:close()'>Close this window</a>        											");
        Linkwindow.document.write("		<br><br><span class='text'>Copyright © City of Elmira</span>										");
        Linkwindow.document.write("		</td></tr></table>        																			");
        Linkwindow.document.write("		</form></body></html>        																		");
        Linkwindow.document.close();		//if user does not close, the previous window, close it and then recreate it
        Linkwindow.document.focus();		//bring the new window to the front
        self.name="main"
}//end sendEvent function


//------------------------------------INDEX PAGE PREVIEWER----------------------------------------------------------------------------------------

function indexPreview(){
	stringInit();
	calendarInit();
	week=7;								//The number of days in a week
	test=new Array();					//Create an array to hold the dates of the next week or month
	store=new Array();					//Create an array to hold the index of the events in the date[] array to be printed
	counter=0;							//Use a counter to increment the store array
	for(i=0; i<week; i++){											//for (Today) and each of the next six days
		test[i]=new Date(currentYear,currentMonth,currentDate+i);		//store the Date in the test array
	}
	for (i=0; i<test.length; i++){								//for each date in the test array
		testDate=test[i];											//assign testDate the value of the date in the test array
		for(j=0;j<edate.length;j++){									//then for each value in the date array
			temp=new Date(edate[j]);									//assign it to temp
			if (compareDates(testDate,temp)){						//and then compare the two dates- if they are the same
				store[counter]=j;									//then store that event in the store array
				counter++;											//and increment the counter
			}//end if 
		}//end inner for loop
	}//end outer for loop
	if (store.length==0){
		document.write("<span class='previewTitle'>No Upcoming Events This Week<br><a href='../index/calendar.html'>Click here for this month's events</a></span>");
	}//end if
	else{
		store.sort(sortDates);
		document.write("<table width='"+previewWidth+"' cellpadding='0' cellspacing='0' border='0'>")
		for (i=0;i<store.length;i++){
			eventDate=new Date();eventDate=edate[store[i]];
			lastEvent=new Date("January 1,1970")
			if(i>0){
				lastEvent=edate[store[i-1]]
			}
			if (compareDates(eventDate, today)){dayOfEvent="Today" }
			else {dayOfEvent=getWeekDay(eventDate.getDay()) }
		
			if(!compareDates(lastEvent,edate[store[i]])){
				document.write("<tr><td class='previewWeekday'>"+dayOfEvent+"</td></tr>");
			}
			document.write("<tr><td class='previewList'><a href='../index/calendar.html?id="+store[i]+"' title='Click to view this event' class='previewList'>"+title[store[i]]+"</a></td></tr>");
		}//end for
		document.write("<tr><td class='previewList'><b><a href='../index/calendar.html' title='Click here for more Events in the Community Calendar'>More Upcoming Events</a><b></td></tr>");
		document.write("</table>");
	}//end else
}//end function


//------------------------------------HELPER FUNCTIONS---------------------------------------------------------------------------------------------------------------------

function getWeekDay(weekday){
	switch (weekday){
		case 0: return "Sunday";
		case 1: return "Monday";
		case 2: return "Tuesday";
		case 3: return "Wednesday";
		case 4: return "Thursday";
		case 5: return "Friday";
		case 6: return "Saturday";
		default:return "Error";
	}//end switch statement
}//end getWeekday function

function getMonth(month){
	switch (month){
		case 0: return "January";
		case 1: return "February";
		case 2: return "March";
		case 3: return "April";
		case 4: return "May";
		case 5: return "June";
		case 6: return "July";
		case 7: return "August";
		case 8: return "September";
		case 9: return "October";
		case 10:return "November";
		case 11:return "December";
		default:return "Error";
	}//end switch statement
}//end getMonth function

function addZero(x){
	if(x<10){return "0"+x}
	else{return x}
}//end addZero function


//------------------------------------TEXT STRINGS---------------------------------------------------------------------------------------------------------------------

function stringInit(){
arena=				"<a href='../about/attractions.html#arena'>»more about the First Arena...</a>"
ec=					"<a href='../about/attractions.html#ec'>»more about Elmira College Theatre...</a>"
clemens=			"<a href='../about/attractions.html#clemens'>»more about the Clemens Center...</a>"
tagsevents=			"<a href='../about/attractions.html#tagsevents'>»more about Tags...</a>"
heights=			"<a href='../about/attractions.html#heights'>»more about the Heights Theater...</a>"

ecsports=			"<a href='../about/attractions_sports.html#ecsports'>»more about Elmira College Sports...</a>"
pioneers=			"<a href='../about/attractions_sports.html#pioneers'>»more about the Elmira Pioneers...</a>"
jackals=			"<a href='../about/attractions_sports.html#jackals'>»more about the Elmira Jackals...</a>"
speedrome=			"<a href='../about/attractions_sports.html#speedrome'>»more about the Chemung Speedrome...</a>"

wingsofeagles=		"<a href='../about/attractions_museums.html#wingsofeagles'>»more about the Wings of Eagles Museum...</a>"
soaring=			"<a href='../about/attractions_museums.html#soaring'>»more about the Soaring Museum...</a>"
cchs=				"<a href='../about/attractions_museums.html#cchs'>»more about the Chemung Valley History Museum...</a>"
tanglewood=			"<a href='../about/attractions_museums.html#tanglewood'>»more about Tanglewood Nature Center...</a>"
livinghistory=		"<a href='../about/attractions_museums.html#livinghistory'>»more about the Chemung Valley Living History Center...</a>"


countyfair=			"<a href='../about/attractions_annual.html#countyfair'>»more about the Chemung County Fair...</a>"
strongkids=			"<a href='../about/attractions_annual.html#strongkids'>»more about Strong Kids, Safe Kids...</a>"
wisnermarket=		"<a href='../about/attractions_annual.html#wisnermarket'>»more about Wisner Market...</a>"
brandpark=			"<a href='../about/attractions_annual.html#brandpark'>»more about the Brand Park Summer Concerts...</a>"
summercohesion=		"<a href='../about/youth.html#summercohesion'>»more on the Summer Cohesion Program, see the Youth Activities page</a>."

communitydays=		"<a href='http://www.bigflatsny.gov/recreation/communitydays.html' target='_blank'>»more about Big Flats Community Days...</a>"
edd=				"<a href='http://www.elmiradowntown.com' target='_blank'>»more from Elmira Downtown Development</a>"
}

// End -->