<!-- Begin
/*----------------------------------------------------------------------------------------
|
|	Business Directory Processor Script by Josh Miller @ web@elmiradowntown.com
|	written for the the Elmira Downtown Development @ http://www.elmiradowntown.com
|	and the City of Elmira @ http://www.ci.elmira.ny.us
|		DO NOT USE THIS SCRIPT WITHOUT PERMISSION
-------------------------------------------------------------------------------------------*/ 

function startDirectory(){
	var a=document.location.toString();
	b=a.length;							
	c=a.lastIndexOf("html");				
	c=c+4;	
	var z=a.substring(c,b);
	if( z==""){
		Default()								//DEFAULT DISPLAY
	}
	else{
		state=z.substring(1,3);
		if (state=="vc"){						// VIEW BY CATEGORY 				
			category=z.substring(4,z.length);
			d=category.lastIndexOf('&');
			if(d<0){
				ViewByCategory(category, 0)
			}
			else{
				begin=category.substring(d+1,category.length);		
				category=category.substring(0,d)
				ViewByCategory(category, begin)
			}		
		}
		else if (state=="id"){					// VIEW INDIVIDUAL RECORDS 					
			id=z.substring(4,z.length);
			ViewRecord(id);
		}
		else if (state=="sc"){					// SEARCH FOR NAME, TITLE, DEPARTMENT, OR PHONE NUMBER					
			query=z.substring(4,z.length);
			query=unescape(query);				//unescape the string to eliminate the %20 for spaces
			SearchForQuery(query);
		}
	}
}	//end Start Function

function Default(){
	document.write("<tr><td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=0'><b>Automotive</b></a><br><span class='smalltext'>Dealers, Repair, Parts</span><br></td>");
	document.write("<td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=6'><b>Legal &amp; Financial</b></a><br><span class='smalltext'>Banks, Lawyers, Consultants</span><br></td></tr>");
	document.write("<tr><td valign='top' colspan='4'><img src='pics/dot.gif' width='5' height='5' border='0'></td></tr>");
	document.write("<tr><td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=1'><b>Community &amp;&nbsp;Govt.</b></a><br><span class='smalltext'>Housing, Organizations</span><br></td>");
	document.write("<td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=7'><b>Manufacturing</b></a><br><span class='smalltext'>Factories, Suppliers</span><br></td></tr>");
	document.write("<tr><td valign='top' colspan='4'><img src='pics/dot.gif' width='5' height='5' border='0'></td></tr>");
	document.write("<tr><td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=2'><b>Education &amp; Instruction</b></a><br><span class='smalltext'>Schools, Training</span><br></td>");
	document.write("<td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=8'><b>Repair and Service</b></a><br><span class='smalltext'>Appliance and Home Repair</span><br></td></tr>");
	document.write("<tr><td valign='top' colspan='4'><img src='pics/dot.gif' width='5' height='5' border='0'></td></tr>");	
	document.write("<tr><td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=3'><b>Entertainment &amp; Arts</b></a><br><span class='smalltext'>Arenas, Museums, Sports</span><br></td>");
	document.write("<td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=9'><b>Retail Shopping</b></a><br><span class='smalltext'>Stores, Shops, Boutiques</span><br></td></tr>");
	document.write("<tr><td valign='top' colspan='4'><img src='pics/dot.gif' width='5' height='5' border='0'></td></tr>");
	document.write("<tr><td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=4'><b>Food &amp; Dining</b></a><br><span class='smalltext'>Restaurants, Groceries</span><br></td>");
	document.write("<td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=10'><b>Telecom &amp;&nbsp;Technology</b></a><br><span class='smalltext'>Computers, Copying, Printing</span><br></td></tr>");
	document.write("<tr><td valign='top' colspan='4'><img src='pics/dot.gif' width='5' height='5' border='0'></td></tr>");
	document.write("<tr><td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=5'><b>Health &amp; Medicine</b></a><br><span class='smalltext'>Doctors, Hospitals</span><br></td>");	
	document.write("<td width='5' valign='top'><li></td>");
	document.write("<td width='207' valign='top'><a href='directory.html?vc=11'><b>Travel &amp;&nbsp;Transportation</b></a><br><span class='smalltext'>Buses, Agents</span><br></td></tr>");
	document.write("<tr><td valign='top' colspan='4'><img src='pics/dot.gif' width='5' height='5' border='0'></td></tr>");
	document.write("<tr><td valign='top' colspan='4'><br><a href='directory_submit.html'>Click here</a> to add your downtown business to the directory<br><br>");
	document.write("It is the responsibility of each individual business to keep their directory information current and accurate. &nbsp;EDD and CoE are not responsible for errors in the directory.  Send email to <a href='mail.html'>web@elmiradowntown.com</a> to submit corrections or changes.</td></tr>");
}


function SearchForQuery(q){
	original=q;
	query=original.toLowerCase();								//convert the search string to lowercase
	storeName=new Array();											//create an array to store the index of Business Names that match search criteria
	storeProducts=new Array();										//create an array to store the index of Products and Services that match search criteria
	storeContact=new Array();										//create an array to store the index of Contact Names that match search criteria
	counterName=0;													//set a counter for the storeName array
	counterProducts=0;												//set a counter for the storeProducts array
	counterContact=0;												//set a counter for the storeContact array
	for (i=0; i<biz.length; i++){								//for each business
		temp1=biz[i][bname].toLowerCase();							//set temp1 to the Business Name
		temp2=biz[i][prsvc].toLowerCase();							//set temp2 to the Products and Services
		temp3=biz[i][cname].toLowerCase();							//set temp3 to the Contact Name
		flagName=		temp1.indexOf(query);						//set the flag to the index of the query in the temp variable, if not found, then -1
		flagProducts=	temp2.indexOf(query);						//set the flag to the index of the query in the temp variable, if not found, then -1
		flagContact=	temp3.indexOf(query);						//set the flag to the index of the query in the temp variable, if not found, then -1
		if(flagName>-1){											//if the flag is greater than -1
			storeName[counterName]=i;									//then search term exists in the Business Name and store the business		
			counterName++;
		}
		if(flagProducts>-1){										//if the flag is greater than -1
			storeProducts[counterProducts]=i;							//then search term exists in the Products and Services and store the business		
			counterProducts++;
		}
		if(flagContact>-1){											//if the flag is greater than -1
			storeContact[counterContact]=i;							//then search term exists in the Contact Name and store the business		
			counterContact++;
		}
	}
	storeName.sort(businessSort);
	storeProducts.sort(businessSort);
	storeContact.sort(businessSort);
	printSearchResults(storeName,1)
	printSearchResults(storeProducts,2)
	printSearchResults(storeContact,3)
}	//end function searchForQuery

function printSearchResults(store,search){
	if (search==1){
		Search="Business Names"
	}
	else if (search==2){
		Search="Products and Services"
	}
	else{
		Search="Contact Names"
	}		
	if(store.length==1){
		Result="match"
	}
	else
		Result="matches"
	document.write("<tr><td colspan='2'><span class='dirmatches'><br>Your search returned "+store.length+" "+Result+" for "+Search+":</span></td></tr>");
	document.write("<tr><td><img src='pics/dot.gif' width='250' height='2'></td><td><img src='pics/dot.gif' width='174' height='2'></td></tr>")
	if (store.length!=0){
		document.write("<tr><td colspan='2' bgcolor='#990000'><img src='pics/dot.gif' width='250' height='1'></td></tr>")
		document.write("<tr><td class='dirheader'>Business Name</td><td class='dirheader'>Address</td></tr>")
		document.write("<tr><td colspan='2' bgcolor='#990000'><img src='pics/dot.gif' width='250' height='1'></td></tr>")
	}
	for(i=0;i<store.length;i++){
		document.write("<tr><td colspan='2' bgcolor='#990000'><img src='pics/dot.gif' width='250' height='1'></td></tr>")	
		document.write("<tr><td><a href='directory.html?id="+store[i]+"' class='dirnamelink'>"+biz[store[i]][bname]+"</a></td><td><span class='dirsearch'>"+biz[store[i]][adres]+"</span></td></tr>")
		document.write("<tr><td><span class='dirsearch'>"+biz[store[i]][phone]+"</span></td><td><span class='dirsearch'>Elmira, New York "+biz[store[i]][bzzip]+"</span></td></tr>")
		if(search==3){
			document.write("<tr><td colspan='2'><span class='dirsearch2'>"+biz[store[i]][cname]+", "+biz[store[i]][ctitl]+"</span></td></tr>")
		}
		else{
			document.write("<tr><td colspan='2'><span class='dirsearch2'>"+biz[store[i]][prsvc]+"</span></td></tr>")
		}
	}
	if (search==3){
		document.write("<tr><td colspan='2' bgcolor='#990000'><img src='pics/dot.gif' width='250' height='1'></td></tr>")
		document.write("<tr><td colspan='2' class='dirfooter' align='center'><a href='javascript:history.go(-1);'>Return to Previous Page</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='directory.html'>Directory Listings</a></td></tr>")
		document.write("<tr><td colspan='2' bgcolor='#990000'><img src='pics/dot.gif' width='250' height='1'></td></tr>")
	}
}

function ViewByCategory(category,begin){
	store=new Array();
	counter=0;
	for (i=0;i<biz.length;i++){
		if(biz[i][categ]==category){
			store[counter]=i;
			counter++;
		}		
	}
	store.sort(businessSort);
	if(store.length==0){
		document.write("<tr><td colspan='2'><br><span class='dirmatches'>"+cat[category]+"</span></td></tr>");
		document.write("<tr><td colspan='2'>There are currently no businesses in this category.</td></tr>");
		document.write("<tr><td valign='top' class='dirfooter' align='center'>&nbsp;<a href='javascript:history.go(-1);'>Return to Previous Page</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='directory.html'>Directory Listings</a></td></tr>");

	}
	else{
		if(store.length==1){
			document.write("<tr><td colspan='2'><br><span class='dirmatches'>"+cat[category]+": "+store.length+" Business</span></td></tr>");
		}
		else{
			document.write("<tr><td colspan='2'><br><span class='dirmatches'>"+cat[category]+": "+store.length+" Businesses</span></td></tr>");
		}
		document.write("<tr><td><img src='pics/dot.gif' width='250' height='2'></td><td><img src='pics/dot.gif' width='174' height='2'></td></tr>")
		document.write("<tr><td valign='top' class='dirheader'>Business Name</td><td class='dirheader'>Address</td></tr>")
		document.write("<tr><td valign='top' colspan='2' bgcolor='#990000'><img src='pics/dot.gif' width='250' height='1'></td></tr>")
		ending=parseInt(begin)+10;			
		for(i=begin; ((i<store.length) && (i<ending)); i++){
			document.write("<tr><td valign='top' ><img src='pics/dot.gif' width='250' height='2'></td><td><img src='pics/dot.gif' width='174' height='2'></td></tr>")
			document.write("<tr><td valign='top' ><a href='directory.html?id="+store[i]+"' class='dirnamelink'>"+biz[store[i]][bname]+"</a></td><td><span class='dirsearch'>"+biz[store[i]][adres]+"</span></td></tr>")
			document.write("<tr><td valign='top' ><span class='dirsearch'>"+biz[store[i]][phone]+"</span></td><td><span class='dirsearch'>Elmira, New York "+biz[store[i]][bzzip]+"</span></td></tr>")
			document.write("<tr><td valign='top' colspan='2'><span class='dirsearch2'>"+biz[store[i]][prsvc]+"</span></td></tr>")
			document.write("<tr><td valign='top' colspan='2' bgcolor='#990000'><img src='pics/dot.gif' width='250' height='1'></td></tr>")	
		}
		start=parseInt(begin)
		if((start+10)>store.length){
			document.write("<tr><td class='dirfooter'>Showing results "+ (start+1) +" through "+ (store.length)+" of "+store.length)
		}
		else{
			document.write("<tr><td class='dirfooter'>Showing results "+ (start+1) +" through "+ (start+10)+" of "+store.length)
		}
		document.write("<td class='dirfooter' align='right'>");
		if((start-10) > -1)
			document.write("<a href='directory.html?vc="+category+"&"+(start-10)+"'>Previous</a>&nbsp;&nbsp;")	
		if(store.length>start+11){
			document.write("<a href='directory.html?vc="+category+"&"+(start+10)+"'>Next</a>&nbsp;")
			document.write("&nbsp;</td></tr>");

		}
	document.write("<tr><td colspan='2' bgcolor='#990000'><img src='pics/dot.gif' width='250' height='1'></td></tr>")
	document.write("<tr><td colspan='2' class='dirfooter' align='center'><a href='javascript:history.go(-1);'>Return to Previous Page</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='directory.html'>Directory Listings</a></td></tr>")
	document.write("<tr><td colspan='2' bgcolor='#990000'><img src='pics/dot.gif' width='250' height='1'></td></tr>")
	}
}

function ViewRecord(id){
	document.write("<tr><td><img src='pics/dot.gif' width='20' height='2'></td><td><img src='pics/dot.gif' width='254' height='2'></td><td><img src='pics/dot.gif' width='150' height='2'></td></tr>")
	if(biz[id][bzpic]!=""){
		document.write("<tr><td valign='top' align='center' colspan='3'><img src='bizpics/"+biz[id][bzpic]+"'><br><br></td></tr>");
	}
	document.write("<tr><td valign='top' class='title'colspan='3'>"+biz[id][bname]+"</td></tr>");
	document.write("<tr><td valign='top' bgcolor='#990000'colspan='3'><img src='pics/dot.gif' width='250' height='2'></td></tr>")
	document.write("<tr><td valign='top' colspan ='2' class='title'><table width='274'  cellpadding='2' cellspacing='2' border='0'><tr><td>"+biz[id][adres]+"<br>Elmira, New York "+biz[id][bzzip]+"</td></tr></table></td>");
	if(biz[id][bzfax]!=""){
		document.write("<td class='title'><table width='150'  cellpadding='2' cellspacing='2' border='0'><tr><td align=right>Tel:"+biz[id][phone]+"<br>Fax:"+biz[id][bzfax]+"</td></tr></table></td>");
	}	
	else{
		document.write("<td class='title'><table width='150'  cellpadding='2' cellspacing='2' border='0'><tr><td align=right>Tel:"+biz[id][phone]+"<br><br></td></tr></table></td>");
	}	
	if(biz[id][bzweb]!=""){
		document.write("<tr><td valign='top' class='' colspan='3'>&nbsp;<i><a href='http://"+biz[id][bzweb]+"' target='_blank'>"+biz[id][bzweb]+"</a></i></td></tr>");
	}	
	document.write("<tr><td valign='top'  bgcolor='#990000'colspan='3'><img src='pics/dot.gif' width='250' height='2'></td></tr>")
	document.write("<tr><td valign='top'  class='subheader' colspan='3'>Business Hours</td></tr>");
	document.write("<tr><td>&nbsp;</td><td valign='top' colspan='2'>"+biz[id][hours]+"</td></tr>");
	document.write("<tr><td valign='top'  class='subheader' colspan='3'>Products and Services</td></tr>");
	document.write("<tr><td>&nbsp;</td><td valign='top' colspan='2'>"+biz[id][prsvc]+"</td></tr>");
	if(biz[id][notes]!=""){
		document.write("<tr><td valign='top'  class='subheader' colspan='3'>Other Information</td></tr>");
		document.write("<tr><td>&nbsp;</td><td valign='top' colspan='2'>"+biz[id][notes]+"</td></tr>");
	}
	document.write("<tr><td valign='top'  class='subheader' colspan='3'>Contact</td></tr>");
	document.write("<tr><td>&nbsp;</td><td valign='top' colspan='2'>"+biz[id][cname]+", "+biz[id][ctitl]+"</td></tr>");
	document.write("<tr><td valign='top'  bgcolor='#990000'colspan='3'><img src='pics/dot.gif' width='250' height='1'></td></tr>")
	document.write("<tr><td valign='top' class='dirfooter' colspan='3' align='center'><a href='javascript:history.go(-1);'>Return to Previous Page</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='directory.html'>Directory Listings</a></td></tr>");
	document.write("<tr><td valign='top'  bgcolor='#990000'colspan='3'><img src='pics/dot.gif' width='250' height='1'></td></tr>")

}

function businessSort(A,B){
	//pre: 	A and B are arrays with an index of 0
	//post:	returns 1 if A is bigger than B
	//		returns -1 if A is smaller than B
	//		returns 0 if A is the same as B
	a=biz[A][0]
	b=biz[B][0]
	a=a.toLowerCase();									//set a and b to lowercase for comparison
	b=b.toLowerCase();
	result=new Array()									//store the result of the letter by letter comparison
	for (i=0; i<a.length; i++){							//for each character in the string
		if(a.charCodeAt(i)>b.charCodeAt(i)){			//if the unicode value of a is greater than b
			result[i]=1									//then store 1 in the result array
		}	//end if								
		else if (a.charCodeAt(i)<b.charCodeAt(i)){		//if the unicode value of a is less than b
			result[i]=-1								//then store -1 in the result array
		}	//end else if
		else if (a.charCodeAt(i)==b.charCodeAt(i)){		//if the unicode value of a is the same as b
			result[i]=0									//then store 0 in the result array
		}	//end else if
	}//end for loop
	g=0													//set g to 0 for a counter variable
	flag=0												//set the flag to 0 - assume they are the same word until proven otherwise
	while (flag==0 && g<result.length-1){				//while the flag proves they are still the same, and the result array has values
		test=result[g]									//assign test the value to be tested from the result array
		if(test==-1){									//if the result array is storing -1 then		
			flag=1										//change the flag
			Result=-1									//and store -1 to return to the function
		}	//end if				
		else if (test==1){								//if the result array is storing +1 then
			flag=1										//change the flag
			Result=1									//and store 1 to return to the function
		}	//end if else
		else if (test==0){								//if the result array is storing 0
			flag=0										//do not change the flag- the words may still be the same- check the rest of the result array
		}	//end if else								
		g++
	}	//end while
	if(flag==0){															//if the flag is still 0, the words are similar or the same: eg: Josh and Joshua
		if (a.length-b.length < 0){											//if the length of b is longer, then 
			Result=-1														//store -1 to return to the function
		}	//end if
		else if (b.length-a.length < 0){									//if the length of a is longer
			Result=1														//store 1 to return to the function
		}	//end else if													
		else if (a.length-b.length == 0){									//if the lengths are the same, it is the same word: eg: Josh and Josh
			Result=0														//store 0 to return to the function
		}	//end else if
	}
	return Result;															//return the stored Result to the function
}	//

				
function printCategories(){
	document.write("<form style='display:inline;'>");
	document.write("<select style='font-family: Tahoma; font-size: 8pt; color: #000000; border: 0px solid #000000' onChange='if(this.selectedIndex!=0){ document.location=this.options[this.selectedIndex].value}'> 		");
	document.write("<option>Select a Category</option>");
	for (i=0; i<cat.length; i++){
		document.write("<option value='directory.html?vc=" +i+"'>" +cat[i]+ "</option>");
	}
	document.write("</select>");	
}	//end function printCategories

function searchHandler(){
	a=this.document.all.sc.value;
	a=escape(a);
	b="directory.html?sc="
	document.location=b+a;
}















//-->









