var countries=new Array();
var flags=new Array();
var categories=new Array();
var origSectors=["Apparel, Textile, Shoes, Accessories","Aviation, Transportation, Warehousing","Banking","Communications, Media, Entertainment","Export/Import","Finance, Insurance","Food, Restaurants","IT, High Tech","Manufacturing","Professional Services","Public Administration","Hospitality, Tourism ","Retail","Wholesale, B2B"];
var sectors=["Apparel, Textile, Shoes, Accessories","Aviation, Transportation, Warehousing","Banking","Communications, Media, Entertainment","Export/Import","Finance, Insurance","Food, Restaurants","IT, High Tech","Manufacturing","Professional Services","Public Administration","Hospitality, Tourism ","Retail","Wholesale, B2B"];
var numberOfEmployees=["1-5 Employees","6-50 Employees","51-99 Employees","100-499 Employees","500-999 Employees","1000+ Employees"]
var regions=["Africa","Asia","Caribbean","Europe","Scandinavia"];
var filter_category="";
var filter_country="";
var filter_sector="";
var filter_name="";
var filter_description="";
var resultsPerPage=20;
var theSpans=new Array();
var itemCount=0;
var nameIndex=0;
var salutation=1;
var first_name=2;
var middle_name=3;
var last_name=4;
var contact_title=5;
var street_address=6;
var city=7;
var state=8;
var zip=9;
var phone=10;
var fax=11;
var email=12;
var website=13;
var countryStarts=14;
var numCountries=5;
var descriptionIndex=19;
var locationTypeStarts=20;
var locationTypeLength=3;
var numLocations=23;
var numEmployeesStarts=24;
var sectorStarts=30;
var sectorOther=44;
var categoryIndex=45;

function countriesContains(newEntry){
	for(var j=0;j<countries.length;j++){
		if(countries[j].toLowerCase()==newEntry.toLowerCase()){
			return(true);
		}
	}
	return(false);
}
function categoriesContains(newEntry){
	for(var j=0;j<categories.length;j++){
		if(categories[j]==newEntry){
			return(true);
		}
	}
	return(false);
}
function sectorsContains(newEntry){
	for(var j=0;j<sectors.length;j++){
		if(sectors[j]==newEntry){
			return(true);
		}
	}
	return(false);
}

function writeDropdowns(){
	for(var i=0;i<dir_list.length;i++){
		for(var j=0;j<numCountries;j++){
			var countryIndex=countryStarts+j;
			if(dir_list[i][countryIndex].length>0&&!countriesContains(dir_list[i][countryIndex])){
				countries[countries.length]=dir_list[i][countryIndex];
			}
		}
	}
	for(var i=0;i<dir_list.length;i++){
		if(dir_list[i][categoryIndex].length>0&&!categoriesContains(dir_list[i][categoryIndex])){
			categories[categories.length]=dir_list[i][categoryIndex];
		}
	}
	for(var i=0;i<dir_list.length;i++){
		if(dir_list[i][sectorOther].length>0&&!sectorsContains(dir_list[i][sectorOther])){
			sectors[sectors.length]=dir_list[i][sectorOther];
		}
	}
	countries=countries.sort();
	for(var i=0;i<countries.length;i++){
		if(isNotRegion(countries[i])){
			flags[flags.length]=findFlag(countries[i]);
		}
	}
	categories=categories.sort();
	sectors=sectors.sort();
	document.write('<span class="flagsTitle">Search for:</span><br><br>');
	document.write('<table cellpadding="0" cellspacing="0" border="0" width="484"><tr><Td class="searchLabel" width="136">Category</Td>');
	document.write('<td class="searchField" width="326"><select style="width:326px;" class="textbox" name="categorySelect" id="categorySelect">');
	document.write('<option value=""> - All - </option>');
	for(var i=0;i<categories.length;i++){
		document.write('<option value="'+categories[i]+'">'+categories[i]+'</option>');
	}
	document.write('</select></td></tr><tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>');
	document.write('<tr><Td class="searchLabel" width="136">Country</Td><td class="searchField" width="326"><select style="width:326px;" class="textbox" name="countrySelect" id="countrySelect">');
	document.write('<option value=""> - All - </option>');
	for(var i=0;i<countries.length;i++){
		document.write('<option value="'+countries[i]+'">'+countries[i]+'</option>');
	}
	document.write('</select></td></tr><tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>');
	document.write('<tr><Td class="searchLabel" width="136">Industry Sector</Td><td class="searchField" width="326"><select style="width:326px;" class="textbox" name="sectorSelect" id="sectorSelect">');
	document.write('<option value=""> - All - </option>');
	for(var i=0;i<sectors.length;i++){
		document.write('<option value="'+sectors[i]+'">'+sectors[i]+'</option>');
	}
	document.write('</select></td></tr><tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>');
	document.write('<tr><Td class="searchLabel" width="136">Company Name</Td><td class="searchField" width="326"><input type="text" style="width:326px;" class="textbox" name="nameField" id="nameField"></td></tr>');
	document.write('<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>');
	document.write('<tr><Td class="searchLabel" width="136">Description</Td><td class="searchField" width="326"><input type="text" style="width:326px;" class="textbox" name="descriptionField" id="descriptionField"></td></tr>');
	document.write('<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="10" alt="" border="0"></td></tr>');
	document.write('<tr><td colspan="2" align="right"><input type="button" class="search_button" value="Search" style="width:71px;" onClick="writeResults()">&nbsp;<input type="reset" class="search_button" value="Reset" style="width:63px;" onclick="clearResults()"></td></tr>');
	document.write('</table>');
}

function isNotRegion(theCountry){
	for(var k=0;k<regions.length;k++){
		if(theCountry.toLowerCase()==regions[k].toLowerCase()){
			return(false);
		}
	}
	return(true);
}

function findFlag(theCountry){
	for(var j=0;j<flagsSource.length;j++){
		if(theCountry.toLowerCase()==flagsSource[j][1].toLowerCase()){
			return(flagsSource[j]);
		}
	}
	return(["blank",theCountry]);
}

function writeFlagResults(theFlag){
	document.getElementById('resultsSpan').innerHTML='<span class="red">Searching...</span>';
	document.getElementById('resultsSpan').style.display="";
	document.getElementById('flagsTable').style.display="none";
	document.getElementById('detailsSpan').style.display="none";
	document.getElementById('categorySelect').selectedIndex=0;
	document.getElementById('countrySelect').selectedIndex=getFlagIndex(theFlag);
	document.getElementById('sectorSelect').selectedIndex=0;
	document.getElementById('nameField').value="";
	document.getElementById('descriptionField').value="";
	itemCount=0;
	filter_category="";
	filter_country=theFlag;
	filter_sector="";
	filter_name="";
	filter_description="";
	setTimeout(writeResultsText,10);
}

function getFlagIndex(theFlag){
	for(var f=0;f<countries.length;f++){
		if(countries[f].toLowerCase()==theFlag.toLowerCase()){
			return(f+1);
		}
	}
	return(0);
}

function writeResults(){
	document.getElementById('resultsSpan').innerHTML='<span class="red">Searching...</span>';
	document.getElementById('resultsSpan').style.display="";
	document.getElementById('flagsTable').style.display="none";
	document.getElementById('detailsSpan').style.display="none";
	itemCount=0;
	var theField=document.getElementById('categorySelect');
	filter_category=theField.options[theField.selectedIndex].value;
	theField=document.getElementById('countrySelect');
	filter_country=theField.options[theField.selectedIndex].value;
	theField=document.getElementById('sectorSelect');
	filter_sector=theField.options[theField.selectedIndex].value;
	filter_name=document.getElementById('nameField').value;
	filter_description=document.getElementById('descriptionField').value;
	setTimeout(writeResultsText,10);
}

function writeResultsText(){
	if(filter_country.length==0){
		dir_list.sort(sortByCountry);
	}else{
		dir_list.sort();
	}
	var theResults='<table cellspacing="0" cellpadding="0" border="0" width="499">';
	theResults=theResults+'<tr><td><img src="../../includes/site_images/misc/filter_divider499.gif" width="499" height="3" alt="" border="0"></td></tr>';
	theResults=theResults+'<tr><Td><img src="../../includes/site_images/spacers/spacer.gif" width="499" height="10" alt="" border="0"></td></tr>';
	theResults=theResults+'<tr><td><table cellspacing="0" cellpadding="0" border="0" width="100%">';
	theResults=theResults+'<tr><td align="left" class="flagsTitle">Search Results:</td><td align="right" id="linksTop" class="pagination"></td></tr>';
	theResults=theResults+'</table></td></tr><tr><td><img src="../../includes/site_images/spacers/spacer.gif" width="499" height="6" alt="" border="0"></td></tr><tr><td id="resultsTd"></td></tr>';
	theResults=theResults+'<tr><Td><img src="../../includes/site_images/spacers/spacer.gif" width="499" height="5" alt="" border="0"></td></tr>';
	theResults=theResults+'<tr><td><table cellspacing="0" cellpadding="0" border="0" width="100%">';
	theResults=theResults+'<tr><td align="left" class="pagination" id="pagination"></td><td align="right" id="linksBottom" class="pagination"></td></tr>';
	theResults=theResults+'</table></td></tr><tr><td><img src="../../includes/site_images/spacers/spacer.gif" width="499" height="25" alt="" border="0"></td></tr></table>';
	document.getElementById('resultsSpan').innerHTML=theResults;
	if(filter_category.length==0&&filter_country.length==0&&filter_sector.length==0&&filter_name.length<3&&filter_description.length<3){
		var errorMessage='Please enter search terms above';
		if(filter_name.length>0&&filter_name.length<3){
			errorMessage=errorMessage+"<br>You must enter at least 3 characters for the name";
		}
		if(filter_description.length>0&&filter_description.length<3){
			errorMessage=errorMessage+"<br>You must enter at least 3 characters for the description";
		}
		document.getElementById("resultsTd").innerHTML=errorMessage;
		return;
	}else{
		theSpans=getSpans();
		if(itemCount==0){
			document.getElementById('resultsTd').innerHTML="No results found";
		}else{
			showPage(0);
		}
	}
}

function getSpans(){
	var spans=new Array();
	var theString='<table cellspacing="0" cellpadding="0" border="0" width="499">';
	theString=theString+'<tr><td class="resultsTableHeader" width="158">Company Name</td><td class="resultsTableHeader2" width="158">Industry Sector</td><td class="resultsTableHeader2" width="158">Country</td></tr>';
	for(var i=0;i<dir_list.length;i++){
		if(isValid(i)){
			theString=theString+'<tr valign="top"><Td class="resultsEntry"><a href="javascript:showCompany('+i+')" class="resultsLink">'+getName(i)+'</a></Td>';
			var theSectors=getSectors(i);
			if(theSectors.length==0){
				theSectors="&nbsp;";
			}
			theString=theString+'<Td class="resultsEntry2">'+theSectors+'</Td><td class="resultsEntry2">'+getCountries(i)+'</td></tr>';
			itemCount++;
			if(itemCount%resultsPerPage==0){
				theString=theString+'</table>';
				spans[spans.length]=theString;
				theString='<table cellspacing="0" cellpadding="0" border="0" width="499">';
				theString=theString+'<tr><td class="resultsTableHeader" width="158">Company Name</td><td class="resultsTableHeader2" width="158">Industry Sector</td><td class="resultsTableHeader2" width="158">Country</td></tr>';
			}
		}
	}
	if(theString.length>63&&theString.substring(theString.length-8)!="</table>"){
		theString=theString+'</table>';
		spans[spans.length]=theString;
	}
	return(spans);
}

function isValid(theIndex){
	var valid=true;
	if(filter_category.length>0){
		valid=valid&&filter_category==getCategory(theIndex);
	}
	if(filter_country.length>0){
		valid=valid&&checkCountries(theIndex,filter_country);
	}
	if(filter_sector.length>0){
		valid=valid&&checkSectors(theIndex,filter_sector);
	}
	if(filter_name.length>0){
		valid=valid&&getName(theIndex).toLowerCase().indexOf(filter_name.toLowerCase())>-1;
	}
	if(filter_description.length>0){
		valid=valid&&getDescription(theIndex).toLowerCase().indexOf(filter_description.toLowerCase())>-1;
	}
	return(valid);
}

function checkSectors(theIndex, theSector){
	var sectorIndex=-1;
	for(var j=0;j<origSectors.length;j++){
		if(theSector==origSectors[j]){
			sectorIndex=j;
		}
	}
	if(sectorIndex!=-1){
		return(dir_list[theIndex][(sectorIndex+sectorStarts)].toLowerCase()=="y");
	}else{
		return(dir_list[theIndex][sectorOther]==theSector);
	}
}

function showPage(pageNumber){
	document.getElementById('resultsTd').innerHTML=theSpans[pageNumber];
	var theLinks=""
	if(pageNumber>0){
		theLinks=theLinks+'<a href=javascript:showPage('+(pageNumber-1)+') class="pageLink">&lt; Previous '+resultsPerPage+'</a>';
	}
	if(pageNumber<theSpans.length-1){
		if(theLinks.length>0){
			theLinks=theLinks+" | ";
		}
		theLinks=theLinks+'<a href=javascript:showPage('+(pageNumber+1)+') class="pageLink">Next '+resultsPerPage+' &gt;</a>';
	}
	document.getElementById('linksTop').innerHTML=theLinks;
	document.getElementById('linksBottom').innerHTML=theLinks;
	var thePage="<b>Page:</b> "+(pageNumber+1)+" of "+theSpans.length;
	document.getElementById('pagination').innerHTML=thePage;
}

function clearResults(){
	document.getElementById('resultsSpan').style.display="none";
	document.getElementById('detailsSpan').style.display="none";
	document.getElementById('flagsTable').style.display="";
	document.getElementById('resultsSpan').innerHTML="";
	document.getElementById('categorySelect').selectedIndex=0;
	document.getElementById('countrySelect').selectedIndex=0;
	document.getElementById('sectorSelect').selectedIndex=0;
	document.getElementById('nameField').value="";
	document.getElementById('descriptionField').value="";
	filter_category="";
	filter_country="";
	filter_sector="";
	filter_name="";
	filter_description="";
}

function writeFlags(){
	var minCol=parseInt(flags.length/3);
	var remainder=flags.length%minCol;
	document.write('<br><span class="flagsTitle">Select a Country:</span><br><br>');
	document.write('<table cellspacing="0" cellpadding="0" border="0" width="498">');
	var theCountryName="";
	var col2Spacer=0;
	if(remainder>0){
		col2Spacer=1;
	}
	for(var i=0;i<minCol;i++){
		theCountryName='"'+flags[i][1]+'"';
		document.write('<tr valign="top"><td width="16" class="flagsImage"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink"><img src="../../includes/site_images/flags/'+flags[i][0].toLowerCase()+'.gif" width="16" height="11" border="0" alt="'+flags[i][0]+'"></a></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+flags[i][1]+'</a></td>');
		var col2=i+minCol+col2Spacer;
		var col3=i+minCol*2+remainder;
		theCountryName='"'+flags[col2][1]+'"';
		document.write('<td width="16" class="flagsImage"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink"><img src="../../includes/site_images/flags/'+flags[col2][0].toLowerCase()+'.gif" width="16" height="11" border="0" alt="'+flags[col2][0]+'"></a></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+flags[col2][1]+'</a></td>');
		theCountryName='"'+flags[col3][1]+'"';
		document.write('<td width="11" class="flagsEntry"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink"><img src="../../includes/site_images/flags/'+flags[col3][0].toLowerCase()+'.gif" width="16" height="11" border="0" alt="'+flags[col3][0]+'"></a></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+flags[col3][1]+'</a></td></tr>');
	}
	if(remainder==1){
		theCountryName='"'+flags[minCol][1]+'"';
		document.write('<tr valign="top"><td width="16" class="flagsImage"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink"><img src="../../includes/site_images/flags/'+flags[minCol][0].toLowerCase()+'.gif" width="16" height="11" border="0" alt="'+flags[minCol][0]+'"></a></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+flags[minCol][1]+'</a></td><td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150">&nbsp;</td><td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150">&nbsp;</td></tr>');
	}
	if(remainder==2){
		theCountryName='"'+flags[minCol][1]+'"';
		document.write('<tr valign="top"><td width="16" class="flagsImage"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink"><img src="../../includes/site_images/flags/'+flags[minCol][0].toLowerCase()+'.gif" width="16" height="11" border="0" alt="'+flags[minCol][0]+'"></a></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+flags[minCol][1]+'</a></td>');
		var col2=minCol*2+1;
		theCountryName='"'+flags[col2][1]+'"';
		document.write('<td width="16" class="flagsImage"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink"><img src="../../includes/site_images/flags/'+flags[col2][0].toLowerCase()+'.gif" width="16" height="11" border="0" alt="'+flags[col2][0]+'"></a></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+flags[col2][1]+'</a></td><td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150">&nbsp;</td></tr>');
	}
	document.write('<tr><td colspan="6"><img src="../../includes/site_images/spacers/spacer.gif" width="498" height="11" border="0" alt=""></td></tr>');
	document.write('<tr><td colspan="6"><span class="flagsTitle">Choose a Region:</span></td></tr>');
	document.write('<tr><td colspan="6"><img src="../../includes/site_images/spacers/spacer.gif" width="498" height="14" border="0" alt=""></td></tr>');
	minCol=parseInt(regions.length/3);
	if(minCol==1){
		remainder=regions.length-3;
	}else{
		remainder=regions.length%minCol;
	}
	col2Spacer=0;
	if(remainder>0){
		col2Spacer=1;
	}
	for(var i=0;i<minCol;i++){
		theCountryName='"'+regions[i]+'"';
		document.write('<tr valign="top"><td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+regions[i]+'</a></td>');
		var col2=i+minCol+col2Spacer;
		var col3=i+minCol*2+remainder;
		theCountryName='"'+regions[col2]+'"';
		document.write('<td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+regions[col2]+'</a></td>');
		theCountryName='"'+regions[col3]+'"';
		document.write('<td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+regions[col3]+'</a></td></tr>');
	}
	if(remainder==1){
		theCountryName='"'+regions[minCol]+'"';
		document.write('<tr valign="top"><td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+regions[minCol]+'</a></td><td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150">&nbsp;</td><td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150">&nbsp;</td></tr>');
	}
	if(remainder==2){
		theCountryName='"'+regions[minCol]+'"';
		document.write('<tr valign="top"><td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+regions[minCol]+'</a></td>');
		var col2=minCol*2+1;
		theCountryName='"'+regions[col2]+'"';
		document.write('<td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150"><a href=\'javascript:writeFlagResults('+theCountryName+')\' class="flagsLink">'+regions[col2]+'</a></td><td width="16" class="flagsImage"><img src="../../includes/site_images/spacers/spacer.gif" width="16" height="11" border="0" alt=""></td><td class="flagsEntry" width="150">&nbsp;</td></tr>');
	}
	document.write('<tr><td colspan="6"><img src="../../includes/site_images/spacers/spacer.gif" width="498" height="50" border="0" alt=""></td></tr>');
	document.write('</table>');
}
function backToResults(){
	document.getElementById('detailsSpan').style.display="none";
	document.getElementById('resultsSpan').style.display="";
}

function showCompany(theIndex){
	var theCompany="";
	theCompany=theCompany+'<img src="../../includes/site_images/misc/filter_divider499.gif" width="499" height="3" alt="" border="0">';
	theCompany=theCompany+'<table cellspacing="0" cellpadding="0" border="0" width="484">';
	theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="14" alt="" border="0"></td></tr>';
	theCompany=theCompany+'<tr><td colspan="2"><a href="javascript:backToResults()" class="pageLink">&lt; Go Back to Search Results</a></td></tr>';
	theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="11" alt="" border="0"></td></tr>';
	theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Company Name</td><td class="detailsText" width="319">'+getName(theIndex)+'</td></tr>';
	if(getContact(theIndex).length>0){
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
		theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Contact</td><td class="detailsText" width="319">'+getContact(theIndex)+'</td></tr>';
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
		theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Contact Title</td><td class="detailsText" width="319">'+getContactTitle(theIndex)+'</td></tr>';
	}
	if(getAddress(theIndex).length>0){
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
		theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Address</td><td class="detailsText" width="319">'+getAddress(theIndex)+'</td></tr>';
		if(getLocationType(theIndex).length>0){
			theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
			theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">This location is</td><td class="detailsText" width="319">'+getLocationType(theIndex)+'</td></tr>';
		}
	}
	if(getPhone(theIndex).length>0){
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
		theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Phone</td><td class="detailsText" width="319">'+getPhone(theIndex)+'</td></tr>';
	}
	if(getFax(theIndex).length>0){
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
		theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Fax</td><td class="detailsText" width="319">'+getFax(theIndex)+'</td></tr>';
	}
	if(getEmail(theIndex).length>0){
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
		theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Email</td><td class="detailsText" width="319">'+getEmail(theIndex)+'</td></tr>';
	}
	if(getWebsite(theIndex).length>0){
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
		theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Web site</td><td class="detailsText" width="319">'+getWebsite(theIndex)+'</td></tr>';
	}
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
	theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Parent Country</td><td class="detailsText" width="319">'+getCountries(theIndex)+'</td></tr>';
	if(getNYCLocations(theIndex).length>0){
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
		theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Locations in NYC</td><td class="detailsText" width="319">'+getNYCLocations(theIndex)+'</td></tr>';
	}
	if(getNYCEmployees(theIndex).length>0){
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
		theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Employees in NYC</td><td class="detailsText" width="319">'+getNYCEmployees(theIndex)+'</td></tr>';
	}
	if(getDescription(theIndex).length>0){
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
		theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Business Service Description</td><td class="detailsText" width="319">'+getDescription(theIndex)+'</td></tr>';
	}
	if(getSectors(theIndex).length>0){
		theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="4" alt="" border="0"></td></tr>';
		theCompany=theCompany+'<tr valign="top"><Td class="searchLabel" width="136">Industry Sector</td><td class="detailsText" width="319">'+getSectors(theIndex)+'</td></tr>';
	}
	theCompany=theCompany+'<tr><td colspan="2"><img src="../../includes/site_images/spacers/spacer.gif" width="484" height="100" alt="" border="0"></td></tr>';
	theCompany=theCompany+'</table>';
	document.getElementById('detailsSpan').innerHTML=theCompany;
	document.getElementById('resultsSpan').style.display="none";
	document.getElementById('detailsSpan').style.display="";
}
function getContact(theIndex){
	var theContact="";
	if(dir_list[theIndex][salutation].length>0){
		theContact=dir_list[theIndex][salutation];
	}
	if(dir_list[theIndex][first_name].length>0){
		if(theContact.length>0){
			theContact=theContact+" ";
		}
		theContact=theContact+dir_list[theIndex][first_name];
	}
	if(dir_list[theIndex][middle_name].length>0){
		if(theContact.length>0){
			theContact=theContact+" ";
		}
		theContact=theContact+dir_list[theIndex][middle_name];
	}
	if(dir_list[theIndex][last_name].length>0){
		if(theContact.length>0){
			theContact=theContact+" ";
		}
		theContact=theContact+dir_list[theIndex][last_name];
	}
	//theContact=toTitleCase(theContact);
	return(theContact);
}
function getContactTitle(theIndex){
	return(dir_list[theIndex][contact_title]);
}
function getAddress(theIndex){
	var theAddress="";
	if(dir_list[theIndex][street_address].length>0){
		theAddress=theAddress+dir_list[theIndex][street_address];
		if(dir_list[theIndex][city].length>0||dir_list[theIndex][state].length>0||dir_list[theIndex][zip].length>0){
			theAddress=theAddress+"<br>";
		}
	}
	if(dir_list[theIndex][city].length>0){
		theAddress=theAddress+dir_list[theIndex][city];
		if(dir_list[theIndex][state].length>0){
			theAddress=theAddress+", ";
		}else if(dir_list[theIndex][zip].length>0){
			theAddress=theAddress+" ";
		}
	}
	if(dir_list[theIndex][state].length>0){
		theAddress=theAddress+dir_list[theIndex][state];
		if(dir_list[theIndex][zip].length>0){
			theAddress=theAddress+" ";
		}
	}
	if(dir_list[theIndex][state].length>0){
		theAddress=theAddress+dir_list[theIndex][zip];
	}
	return(theAddress);
}
function getPhone(theIndex){
	return(dir_list[theIndex][phone]);
}
function getFax(theIndex){
	return(dir_list[theIndex][fax]);
}
function getEmail(theIndex){
	return(dir_list[theIndex][email]);
}
function getWebsite(theIndex){
	var theWebsite="";
	var theUrl=""
	var theLink="";
	if(dir_list[theIndex][website].length>0&&dir_list[theIndex][website]!="n/a"&&dir_list[theIndex][website]!="na"){
		theWebsite=dir_list[theIndex][website];
		if(theWebsite.indexOf("http://")==-1){
			theUrl="http://"+theWebsite;
		}else{
			theUrl=theWebsite;
			theWebsite=theWebsite.substr(7);
		}
		theLink='<a href="http://www.nyc.gov/cgi-bin/exit.pl?url='+theUrl+'" class="resultsLink">'+theWebsite+'</a>';
	}else if(dir_list[theIndex][website]=="n/a"||dir_list[theIndex][website]=="na"){
		theLink="n/a";
	}
	return(theLink);
}
function getNYCLocations(theIndex){
	return(dir_list[theIndex][numLocations]);
}
function getLocationType(theIndex){
	var theLocationType=""
	if(dir_list[theIndex][locationTypeStarts].toLowerCase()=="y"){
		theLocationType="Corporate Office";
	}
	if(dir_list[theIndex][(locationTypeStarts+1)].toLowerCase()=="y"){
		if(theLocationType.length>0){
			theLocationType=theLocationType+"<br>";
		}
		theLocationType=theLocationType+"Retail";
	}
	if(dir_list[theIndex][(locationTypeStarts+2)].length>0){
		if(theLocationType.length>0){
			theLocationType=theLocationType+"<br>";
		}
		theLocationType=theLocationType+dir_list[theIndex][(locationTypeStarts+2)];
	}
	return(theLocationType);
}
function getNYCEmployees(theIndex){
	var numEmployees="";
	for(var e=0;e<numberOfEmployees.length;e++){
		if(dir_list[theIndex][(numEmployeesStarts+e)].toLowerCase()=="y"){
			numEmployees=numberOfEmployees[e];
		}
	}
	return(numEmployees);
}
function getCategory(theIndex){
	return(dir_list[theIndex][categoryIndex]);
}
function getName(theIndex){
	return(dir_list[theIndex][nameIndex]);
}
function getDescription(theIndex){
	return(dir_list[theIndex][descriptionIndex]);
}
function checkCountries(theIndex, theCountry){
	theCountry=theCountry.replace(/'/,"&#39;")
	var matchCountry=false;
	for(var j=0;j<numCountries;j++){
		var countryIndex=countryStarts+j;
		matchCountry=matchCountry||(theCountry.toLowerCase()==dir_list[theIndex][countryIndex].toLowerCase())
	}
	return(matchCountry);
}
function getSectors(theIndex){
	var theSectors="";
	for(var j=0;j<origSectors.length;j++){
		if(dir_list[theIndex][(sectorStarts+j)].toLowerCase()=='y'){
			if(theSectors.length>0){
				theSectors=theSectors+"<br>";
			}
			theSectors=theSectors+origSectors[j];
		}
	}
	if(dir_list[theIndex][sectorOther].length>0){
		if(theSectors.length>0){
			theSectors=theSectors+"<br>";
		}
		theSectors=theSectors+dir_list[theIndex][sectorOther];
	}
	return(theSectors);
}

function getCountries(theIndex){
	var theCountries="";
	for(var j=0;j<numCountries;j++){
		var countryIndex=countryStarts+j;
		if(dir_list[theIndex][countryIndex].length>0){
			if(theCountries.length>0){
				theCountries=theCountries+"<br>";
			}
			theCountries=theCountries+dir_list[theIndex][countryIndex];
		}
	}
	if(theCountries.length==0){
		theCountries="&nbsp;";
	}
	return(theCountries);
}

function toTitleCase(theString){
	var cased="";
	var splits=theString.toLowerCase().split(" ");
	for(var c=0;c<splits.length;c++){
		cased=cased+splits[c].substr(0,1).toUpperCase()+splits[c].substr(1);
		if(c<splits.length-1){
			cased=cased+" ";
		}
	}
	return(cased);
}

function sortByCountry(a,b){
	var x = a[countryStarts].toLowerCase();
	var y = b[countryStarts].toLowerCase();
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
