var xmlHttp;
var html;
var perPage;
var zoomLevel;
var row2_element_name = [];

var dispTitle = [];
var dispPrice = [];
function getListings(minPrice, maxPrice, beds, baths, proptype, city, state, zip)
{
xmlHttp=GetXmlHttpRequestObject();

var url="getListingData.php?minPrice=" + minPrice + "&maxPrice=" + maxPrice + "&beds=" + beds + "&baths=" + baths + "&proptype=" + proptype + "&city=" + city + "&state=" + state + "&zip=" + zip;

if(!city && !state && !zip)
{
	zoomLevel = 8;
}
else
{
	zoomLevel = 12;
}

if (xmlHttp)
	{
		try
		{
			xmlHttp.onreadystatechange = handleRequestStateChange_listing;
			xmlHttp.open("Get", url , true)
			xmlHttp.send(null)
		}
		catch (e)
		{
			alert("Can Not connect to server");
		}
	}
}

function findHouse(address, city, state, zip)
{
	
 xmlHttp=GetXmlHttpRequestObject();	  
					
var url="plotHouse.php?address=" + address + "&city=" + city + "&state=" + state + "&zip=" + zip;

zoomLevel = 14;

if (xmlHttp)
	{
		try
		{
			xmlHttp.onreadystatechange = handleRequestStateChange_address;
			xmlHttp.open("Get", url , true)
			xmlHttp.send(null)
		}
		catch (e)
		{
			alert("Can Not connect to server");
		}
	}
}

function handleRequestStateChange_address()
{
	if (xmlHttp.readyState==4)
	{
		//alert("readyState=4");
		if (xmlHttp.status == 200)
		{
			try
			{
				//alert("readyStatus=200");
			 	handleServerResponse_showaddress();
			}
			catch (e)
			{
				alert("Error handling the response" + e.toString());
			}
		}
		else
		{
			alert("There was a problem retrieving the data" + xmlHttp.statusText);
		}
	}
}

function handleServerResponse_showaddress()
{
	var type = xmlHttp.getResponseHeader("Content-Type");
	if (type == "text/xml")
	{
		//alert ("xml response");
		var xmlResponse = xmlHttp.responseXML;
		
		if (!xmlResponse || !xmlResponse.documentElement)
	 		throw ("Invalid XML structure at first" + xmlResponse);
		var rootNodeName = xmlResponse.documentElement.nodeName;
		if (rootNodeName == "parsererror") throw ("Invalid XML structure firefox "+ rootNodeName );
		xmlRoot = xmlResponse.documentElement;
		if(xmlRoot.firstChild)
		{
		var firstchild_name = xmlRoot.firstChild.nodeName;
		if (firstchild_name == "listings")
		{
			strnumArray = xmlRoot.getElementsByTagName("strnum");
			strnameArray = xmlRoot.getElementsByTagName("strname");
			strsfxArray = xmlRoot.getElementsByTagName("strsfx");
			cityArray = xmlRoot.getElementsByTagName("city");
			stateArray = xmlRoot.getElementsByTagName("state");
			zipArray = xmlRoot.getElementsByTagName("zip");
			bedsArray = xmlRoot.getElementsByTagName("beds");
			bathsArray = xmlRoot.getElementsByTagName("baths");
			listpriceArray = xmlRoot.getElementsByTagName("listprice");
			titleArray = xmlRoot.getElementsByTagName("title");
			feedlinkArray = xmlRoot.getElementsByTagName("feedlink");
			proptypeArray = xmlRoot.getElementsByTagName("proptype");
			mlsnumArray = xmlRoot.getElementsByTagName("mlsnum");
			latitudeArray = xmlRoot.getElementsByTagName("latitude");
			longitudeArray = xmlRoot.getElementsByTagName("longitude");
			oidArray = xmlRoot.getElementsByTagName("oid");
			imgnameArray = xmlRoot.getElementsByTagName("imgname");
	
	var html1 = "";
	var html2= "";

	for (var i=0; i<cityArray.length; i++)
	{
		
		var lsRegExp = /\+/g;
	  	var testaddr =  new String();
	  	testaddr = unescape(titleArray.item(i).firstChild.data);
	  	testaddr = unescape(String(testaddr).replace(lsRegExp, " ")); 
		dispTitle[i] = testaddr;
		titleArray.item(i).firstChild.data = testaddr;
		
		if(listpriceArray.item(i).firstChild)
		{
			var listPrice = listpriceArray.item(i).firstChild.data;
			listPrice = listPrice.replace(/,/g,"");
			intPrice = parseInt(listPrice);
			dispPrice[i] = formatPrice(intPrice);
			listpriceArray.item(i).firstChild.data = dispPrice[i];
		}
		else
		{
			dispPrice[i] = 'N/A';
		}
		
		if(bedsArray.item(i).firstChild.data == 0)
			dispbeds = 'N';
		else
		 	dispbeds = bedsArray.item(i).firstChild.data;
			
		if(bathsArray.item(i).firstChild.data == 0)
			dispbaths = 'A';
		else
			  dispbaths = bathsArray.item(i).firstChild.data;	  
		if(!(feedlinkArray.item(i).firstChild))
		{
			propDescr = 'http://www.realivent.com/login.php';
		}
		else
		{
			propDescr = feedlinkArray.item(i).firstChild.data;
		}
				 
		if(!(cityArray.item(i).firstChild))
		{
			cityName = 'No City Name Available';
		}
		else
			 cityName = cityArray.item(i).firstChild.data;
		{
		}	  
	  	if(!(stateArray.item(i).firstChild))
		{
		  stateName = 'No State Name Available';
		}
		else
		  stateName = stateArray.item(i).firstChild.data;
			  {
			  }
		
		if(imgnameArray.item(i).firstChild)
		{
			imgpath = imgnameArray.item(i).firstChild.data;
		}
		else
		{
			imgpath = "listing_images/nia.gif";
		}
		
		
		var td1 = "<a target="+"'_blank'"+" href="+propDescr+">"+dispTitle[i] + "</a>";
		var td2 = dispbeds+ "/" +dispbaths;
		var td3 = dispPrice[i];
		var td4= "<a target="+"'_blank'"+" href="+imgpath+"><img width=40 height=20 src="+imgpath+"></a>";
		var temp_oid = "L1R2C1";
		html2 += "<a href=javascript:; onClick=get_comparables("+latitudeArray.item(i).firstChild.data+","+longitudeArray.item(i).firstChild.data+","+"'"+escape(cityName)+"'"+","+zipArray.item(i).firstChild.data+","+"'"+temp_oid+"'"+","+"'"+stateName+"'"+","+"'"+escape(cityName)+"'"+")> Comparables </a>|";
	
		if(zipArray.item(i).firstChild)
		{
			html2 += "<a target="+"'_blank'"+" href=showGraph.php?latitude=" + latitudeArray.item(i).firstChild.data + "&longitude=" + longitudeArray.item(i).firstChild.data + "&zipcode=" + zipArray.item(i).firstChild.data + "&city=" + escape(cityName) + "&state=" + stateName +" > Neighborhood Data </a>|";
		}
		html2 += "<a href=javascript:; onClick=get_school_data("+latitudeArray.item(i).firstChild.data+","+longitudeArray.item(i).firstChild.data+","+"'"+escape(cityName)+"'"+","+zipArray.item(i).firstChild.data+","+"'"+temp_oid+"'"+","+"'"+stateName+"'"+","+"'"+escape(cityName)+"'"+")> Schools </a>|";
		html2 += "<a href=javascript:; onClick=hide_post("+"'"+Session_ID+"'"+","+oidArray.item(i).firstChild.data+")> [Hide] </a></td>";
	}//for loop
	
	if(cityArray.length == 0)
	{
		dispTitle[0] = 'Could not find any results. Please change search parameters.'
		dispTitle[1] = 'No matches found'
		dispbeds = '--';
		dispbaths = '--';
		dispPrice[0] = '---';
		imgpath = '---';

		oidName = '000';
		
		html1 += "<td class='highlight'>" + dispTitle[1] + "</td><td align=center class='highlight'>"+ dispbeds+ "/" +dispbaths+"</td><td align=center class='highlight'>" + dispPrice[0] + "</td><td align=center class='highlight'>"+imgpath+"</td>";
		
		html2 += "<tr id='compsdiv_"+oidName+"' class='highlight' align=center>" + dispTitle[0] + "</tr>";
		
	}
				
			
			if(cityArray.length != 0)
			{
			document.getElementById("L1R1C1").style.display = '';
			var cell = document.getElementById("L1R1C1");
			cell.innerHTML = td1;
			document.getElementById("L1R1C2").style.display = '';
			cell = document.getElementById("L1R1C2");
			cell.innerHTML = td2;
			document.getElementById("L1R1C3").style.display = '';
			cell = document.getElementById("L1R1C3");
			cell.innerHTML = td3;
			document.getElementById("L1R1C4").style.display = '';
			cell = document.getElementById("L1R1C4");
			cell.innerHTML = td4;
			document.getElementById("L1R2C1").style.display = '';
			cell = document.getElementById("L1R2C1");
			cell.innerHTML = html2;
			//tablebody[0].innerHTML = html1;
			legendarea1 = document.getElementById("legendarea");
			//legendarea.innerHTML = "";
show_listings_on_map(latitudeArray,longitudeArray,titleArray,bedsArray,bathsArray,listpriceArray,0,1);
			}
			else
			{
			proplistmsg = document.getElementById("L1R1C1");
			proplistmsg.innerHTML = html1;
			legendarea1 = document.getElementById("legendarea");
			legendarea1.innerHTML = html2;
			}
			
		}
		}
		else
		{
		var html1= "";
		var html2= "";
			
		dispTitle[0] = 'Could not find a home with that address.'
		dispTitle[1] = 'No address found'
		dispbeds = '--';
		dispbaths = '--';
		dispPrice[0] = '---';
		imgpath = '---';
		

		oidName = '000';

		//html1 += "<td class='highlight'>" + dispTitle[1] + "</td><td align=center class='highlight'>"+ dispbeds+ "/" +dispbaths+"</td><td align=center class='highlight'>" + dispPrice[0] + "</td><td align=center class='highlight'>"+imgpath+"</td>";
		
		html2 += "<td class='highlight' align=center>" + dispTitle[0] + "</td>";

			//document.getElementById("L1R1C1").style.color = 'maroon';
			//document.getElementById("L1R1C1").style.background = 'yellow';
			document.getElementById("L1R1C1").style.display = '';
			var cell = document.getElementById("L1R1C1");
			cell.innerHTML = dispTitle[1] ;
			
			//document.getElementById("L1R1C2").style.color = 'maroon';
			//document.getElementById("L1R1C2").style.background = 'yellow';
			document.getElementById("L1R1C2").style.display = '';
			cell = document.getElementById("L1R1C2");
			cell.innerHTML = dispbeds+ "/" +dispbaths;
			//document.getElementById("L1R1C3").style.color = 'maroon';
			//document.getElementById("L1R1C3").style.background = 'yellow';
			document.getElementById("L1R1C3").style.display = '';
			cell = document.getElementById("L1R1C3");
			cell.innerHTML = dispPrice[0];
			//document.getElementById("L1R1C4").style.color = 'maroon';
			//document.getElementById("L1R1C4").style.background = 'yellow';
			document.getElementById("L1R1C4").style.display = '';
			cell = document.getElementById("L1R1C4");
			cell.innerHTML = imgpath;
			//document.getElementById("legendarea").style.background = 'yellow';
			document.getElementById("legendarea").style.color = 'maroon';
			legendarea1 = document.getElementById("legendarea");
			legendarea1.innerHTML = html2;

		}
	}
}

function handleRequestStateChange_listing()
{
	if (xmlHttp.readyState==4)
	{
		//alert("readyState=4");
		if (xmlHttp.status == 200)
		{
			try
			{
				//alert("readyStatus=200");
			 	handleServerResponse_listing();
			}
			catch (e)
			{
				alert("Error handling the response" + e.toString());
			}
		}
		else
		{
			alert("There was a problem retrieving the data" + xmlHttp.statusText);
		}
	}
}


function handleServerResponse_listing()
{
	//var dispTitle = [];
	//var dispPrice = [];
	var type = xmlHttp.getResponseHeader("Content-Type");
	if (type == "text/xml")
	{
		//alert ("xml response");
		var xmlResponse = xmlHttp.responseXML;
		
		if (!xmlResponse || !xmlResponse.documentElement)
	 		throw ("Invalid XML structure at first" + xmlResponse);
		var rootNodeName = xmlResponse.documentElement.nodeName;
		if (rootNodeName == "parsererror") throw ("Invalid XML structure firefox "+ rootNodeName );
		xmlRoot = xmlResponse.documentElement;
		var firstchild_name = xmlRoot.firstChild.nodeName;
		if (firstchild_name == "listings")
		{
			strnumArray = xmlRoot.getElementsByTagName("strnum");
			strnameArray = xmlRoot.getElementsByTagName("strname");
			strsfxArray = xmlRoot.getElementsByTagName("strsfx");
			cityArray = xmlRoot.getElementsByTagName("city");
			stateArray = xmlRoot.getElementsByTagName("state");
			zipArray = xmlRoot.getElementsByTagName("zip");
			bedsArray = xmlRoot.getElementsByTagName("beds");
			bathsArray = xmlRoot.getElementsByTagName("baths");
			listpriceArray = xmlRoot.getElementsByTagName("listprice");
			titleArray = xmlRoot.getElementsByTagName("title");
			feedlinkArray = xmlRoot.getElementsByTagName("feedlink");
			proptypeArray = xmlRoot.getElementsByTagName("proptype");
			mlsnumArray = xmlRoot.getElementsByTagName("mlsnum");
			latitudeArray = xmlRoot.getElementsByTagName("latitude");
			longitudeArray = xmlRoot.getElementsByTagName("longitude");
			oidArray = xmlRoot.getElementsByTagName("oid");
			imgnameArray = xmlRoot.getElementsByTagName("imgname");
	
			var html1= "";
			var html2= "";

    		perPage = 10;
			//html= [];
			var no_of_pages = Math.ceil(cityArray.length/perPage);
			html = new Array(no_of_pages);
			for (var page=1; page<no_of_pages; page++)
			{
				
				//html[page][][][] = "";
				var offset = perPage * (page -1);
				var limit = offset+perPage;
				var listing = 1;
				html[page] = new Array(11);
				for (var i=offset; i<limit; i++)
				{
					
	//for (var i=0; i<cityArray.length; i++)
			//{
/*	html += "<tr><td>"+cityArray.item(i).firstChild.data + "</td><td align=center>"+ bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data+"</td><td align=center>" + listpriceArray.item(i).firstChild.data + "</td><td>" + cityArray.item(i).firstChild.data + "</td><tr><td id='compsdiv' colspan=4;>"<a href=javascript:; onClick="get_comparables("+latitudeArray.item(i).firstChild.data+","+longitudeArray.item(i).firstChild.data+","+titleArray.item(i).firstChild.data+","+zipArray.item(i).firstChild.data+","+oidArray.item(i).firstChild.data+","+stateArray.item(i).firstChild.data+","+cityArray.item(i).firstChild.data+")"+"Comparables"+"</a>"</td></tr></tr>";
*/	

					dispTitle[i] = Truncatestr(titleArray.item(i).firstChild.data,35,'...');
					var listPrice = listpriceArray.item(i).firstChild.data;
					listPrice = listPrice.replace(/,/g,"");
					intPrice = parseInt(listPrice);
					dispPrice[i] = formatPrice(intPrice);
		
					if(bedsArray.item(i).firstChild.data == 0)
						dispbeds = 'N';
					else
			  			dispbeds = bedsArray.item(i).firstChild.data;
			
					if(bathsArray.item(i).firstChild.data == 0)
						dispbaths = 'A';
					else
			  			dispbaths = bathsArray.item(i).firstChild.data;
			  
			  
			  		if(!(feedlinkArray.item(i).firstChild))
			  		{
			     		propDescr = 'http://www.realivent.com/login.php';
			  		}
				 	else
				 	{
				 		propDescr = feedlinkArray.item(i).firstChild.data;
				 	}
				 
					if(!(cityArray.item(i).firstChild))
			  		{
				  		cityName = 'No City Name Available';
			  		}
			  		else
			  			cityName = cityArray.item(i).firstChild.data;
			  		{
			  		}
			  
			  		if(!(stateArray.item(i).firstChild))
			  		{
				  		stateName = 'No State Name Available';
			  		}
			  		else
			  		stateName = stateArray.item(i).firstChild.data;
			  		{
			  		}
		
					if(imgnameArray.item(i).firstChild)
					{
						imgpath = imgnameArray.item(i).firstChild.data;
					}
					else
					{
						imgpath = "listing_images/nia.gif";
					}
		
			
					//html[page] += "<tr id='"+"compsdiv_"+oidArray.item(i).firstChild.data+"'>";
					
					//for (var listing=1; listing <=10; listing++)
					//{
						   html[page][listing] = new Array(3);
						   html[page][listing][1] = new Array(5);
							html[page][listing][1][1] = "<a target="+"'_blank'"+" href="+propDescr+">"+dispTitle[i] + "</a>";	
							html[page][listing][1][2] = dispbeds+ "/" +dispbaths;
							html[page][listing][1][3] = dispPrice[i];
							html[page][listing][1][4] = "<a target="+"'_blank'"+" href="+imgpath+"><img width=40 height=20 src="+imgpath+"></a>";
							
							row2_element_name[((page-1)*10)+listing] = "myDivComparables_"+oidArray.item(i).firstChild.data;

                             var temp_oid = "L"+listing+"R2C1";
							 //var temp_oid = 111;
							 html[page][listing][2] = new Array(2);
							//html[page][listing][2][1] = "<a href=javascript:; onClick=get_comparables("+latitudeArray.item(i).firstChild.data+","+longitudeArray.item(i).firstChild.data+","+"'"+escape(cityName)+"'"+","+zipArray.item(i).firstChild.data+","+oidArray.item(i).firstChild.data+","+"'"+stateName+"'"+","+"'"+escape(cityName)+"'"+")> Comparables </a>|";
							html[page][listing][2][1] = "<a href=javascript:; onClick=get_comparables("+latitudeArray.item(i).firstChild.data+","+longitudeArray.item(i).firstChild.data+","+"'"+escape(cityName)+"'"+","+zipArray.item(i).firstChild.data+","+"'"+temp_oid+"'"+","+"'"+stateName+"'"+","+"'"+escape(cityName)+"'"+")> Comparables </a>|";
							
							if(zipArray.item(i).firstChild)
							{
								html[page][listing][2][1] += "<a target="+"'_blank'"+" href=showGraph.php?latitude=" + latitudeArray.item(i).firstChild.data + "&longitude=" + longitudeArray.item(i).firstChild.data + "&zipcode=" + zipArray.item(i).firstChild.data + "&city=" + escape(cityName) + "&state=" + stateName +" > Neighborhood Data </a>|";
							}
							
							html[page][listing][2][1] += "<a href=javascript:; onClick=get_school_data("+latitudeArray.item(i).firstChild.data+","+longitudeArray.item(i).firstChild.data+","+"'"+escape(cityName)+"'"+","+zipArray.item(i).firstChild.data+","+"'"+temp_oid+"'"+","+"'"+stateName+"'"+","+"'"+escape(cityName)+"'"+")> Schools </a>|";
							
							html[page][listing][2][1] += "<a href=javascript:; onClick=hide_post("+"'"+Session_ID+"'"+","+"'"+temp_oid+"'"+")> [Hide] </a></td>";
							listing++;
							
					//}
						
					/*html[page] += "<td><a target="+"'_blank'"+" href="+propDescr+">"+dispTitle[i] + "</td><td align=center>"+ dispbeds+ "/" +dispbaths+"</td><td align=center>" + dispPrice[i] + "</td><td align=center><a target="+"'_blank'"+" href="+imgpath+"><img width=40 height=20 src="+imgpath+"></a></td>";
		
					html[page] += "<tr id="+"compsdiv2_"+oidArray.item(i).firstChild.data+" class='odd' style='border-bottom: thin solid #adbbca'>";
	
					html[page]+= "<td id='"+"myDivComparables_"+oidArray.item(i).firstChild.data+"' colspan=4;>";
		
					html[page] += "<a href=javascript:; onClick=get_comparables("+latitudeArray.item(i).firstChild.data+","+longitudeArray.item(i).firstChild.data+","+"'"+escape(cityName)+"'"+","+zipArray.item(i).firstChild.data+","+oidArray.item(i).firstChild.data+","+"'"+stateName+"'"+","+"'"+escape(cityName)+"'"+")> Comparables </a>|";
	
					if(zipArray.item(i).firstChild)
					{
						html[page] += "<a target="+"'_blank'"+" href=showGraph.php?latitude=" + latitudeArray.item(i).firstChild.data + "&longitude=" + longitudeArray.item(i).firstChild.data + "&zipcode=" + zipArray.item(i).firstChild.data + "&city=" + escape(cityName) + "&state=" + stateName +" > Neighborhood Data </a>|";
					}
	
	
					html[page] += "<a href=javascript:; onClick=get_school_data("+latitudeArray.item(i).firstChild.data+","+longitudeArray.item(i).firstChild.data+","+"'"+escape(cityName)+"'"+","+zipArray.item(i).firstChild.data+","+oidArray.item(i).firstChild.data+","+"'"+stateName+"'"+","+"'"+escape(cityName)+"'"+")> Schools </a>|";
	

					html[page] += "<a href=javascript:; onClick=hide_post("+"'"+Session_ID+"'"+","+oidArray.item(i).firstChild.data+")> [Hide] </a></td>";
		
					html[page]+= "</tr>";
		
					html[page]+= "</tr>";*/
				}
			}
			i = limit;
			var last_page_listing = cityArray.length-limit;
			html[page] = new Array(last_page_listing);
			page_orig = page - 1;
			listing_orig = listing;
			listing =1;
			while (i< cityArray.length)
			{
			//html[page] = new Array(1);
			dispTitle[i] = Truncatestr(titleArray.item(i).firstChild.data,35,'...');
			var listPrice = listpriceArray.item(i).firstChild.data;
			listPrice = listPrice.replace(/,/g,"");
			intPrice = parseInt(listPrice);
			dispPrice[i] = formatPrice(intPrice);
		
			if(bedsArray.item(i).firstChild.data == 0)
				dispbeds = 'N';
			else
				dispbeds = bedsArray.item(i).firstChild.data;
			
			if(bathsArray.item(i).firstChild.data == 0)
				dispbaths = 'A';
			else
				dispbaths = bathsArray.item(i).firstChild.data;
			  
			if(!(feedlinkArray.item(i).firstChild))
			{
				propDescr = 'http://www.realivent.com/login.php';
			}
			else
			{
				propDescr = feedlinkArray.item(i).firstChild.data;
			}
			if(!(cityArray.item(i).firstChild))
			{
				cityName = 'No City Name Available';
			}
			else
				cityName = cityArray.item(i).firstChild.data;
			{
			}
			if(!(stateArray.item(i).firstChild))
			{
				stateName = 'No State Name Available';
			}
			else
		  		stateName = stateArray.item(i).firstChild.data;
	  		{
			}
			if(imgnameArray.item(i).firstChild)
			{
				imgpath = imgnameArray.item(i).firstChild.data;
			}
			else
			{
				imgpath = "listing_images/nia.gif";
			}
			//html[page] += "<tr id='"+"compsdiv_"+oidArray.item(i).firstChild.data+"'>";
			//for (var listing=1; listing <=10; listing++)
			//{             
							html[page][listing] = new Array(2);
							html[page][listing][1] = new Array(4);
							html[page][listing][1][1] = "<a target="+"'_blank'"+" href="+propDescr+">"+dispTitle[i] + "</a>";	
							html[page][listing][1][2] = dispbeds+ "/" +dispbaths;
							html[page][listing][1][3] = dispPrice[i];
							html[page][listing][1][4] = "<a target="+"'_blank'"+" href="+imgpath+"><img width=40 height=20 src="+imgpath+"></a>";
							
							row2_element_name[((page_orig-1)*10)+listing_orig] = "myDivComparables_"+oidArray.item(i).firstChild.data;
							temp_oid = "L"+listing+"R2C1";
							html[page][listing][2] = new Array(1);
							html[page][listing][2][1] = "<a href=javascript:; onClick=get_comparables("+latitudeArray.item(i).firstChild.data+","+longitudeArray.item(i).firstChild.data+","+"'"+escape(cityName)+"'"+","+zipArray.item(i).firstChild.data+","+"'"+temp_oid+"'"+","+"'"+stateName+"'"+","+"'"+escape(cityName)+"'"+")> Comparables </a>|";
							
							if(zipArray.item(i).firstChild)
							{
								html[page][listing][2][1] += "<a target="+"'_blank'"+" href=showGraph.php?latitude=" + latitudeArray.item(i).firstChild.data + "&longitude=" + longitudeArray.item(i).firstChild.data + "&zipcode=" + zipArray.item(i).firstChild.data + "&city=" + escape(cityName) + "&state=" + stateName +" > Neighborhood Data </a>|";
							}
							
							html[page][listing][2][1] += "<a href=javascript:; onClick=get_school_data("+latitudeArray.item(i).firstChild.data+","+longitudeArray.item(i).firstChild.data+","+"'"+escape(cityName)+"'"+","+zipArray.item(i).firstChild.data+","+"'"+temp_oid+"'"+","+"'"+stateName+"'"+","+"'"+escape(cityName)+"'"+")> Schools </a>|";
							
							html[page][listing][2][1] += "<a href=javascript:; onClick=hide_post("+"'"+Session_ID+"'"+","+"'"+temp_oid+"'"+")> [Hide] </a></td>";
							
					//}
		             listing++;
					 listing_orig++;
			//html[page] += "<tr id="+"compsdiv2_"+oidArray.item(i).firstChild.data+" class='odd' style='border-bottom: thin solid #adbbca'>";
	
		
			i++;
			}
	
			if(cityArray.length == 0)
			{
				dispTitle[0] = 'Could not find any results. Please change search parameters.'
				dispTitle[1] = 'No matches found'
				dispbeds = '--';
				dispbaths = '--';
				dispPrice[0] = '---';
				imgpath = '---';
		

				oidName = '000';
		
			
		/* html += "<tr id='compsdiv_000' class='highlight'>"; */
		/* html += "<td class='highlight' align=center>" + dispTitle[0] + "</td>"; */
		
		/* html += "<tr id='compsdiv_"+oidName+"' class='highlight' align=center>" + dispTitle[0] + "</tr>";
		*/
				html1 += "<td class='highlight'>" + dispTitle[1] + "</td><td align=center class='highlight'>"+ dispbeds+ "/" +dispbaths+"</td><td align=center class='highlight'>" + dispPrice[0] + "</td><td align=center class='highlight'>"+imgpath+"</td>";
		/* html += "</tr>"; */
		
				html2 += "<tr id='compsdiv_"+oidName+"' class='highlight' align=center>" + dispTitle[0] + "</tr>";
		/* html+= "</tr>"; */
		
			}
	
	/*
			
			*/
			
			
			if(cityArray.length != 0)
			{
				write_listing(1,no_of_pages,0);
	//		proptable = document.getElementById("propbrowse");
	//		tablebody = proptable.getElementsByTagName("tbody");
	//		tablebody[0].innerHTML = html;
	//		legendarea = document.getElementById("legendarea");
	//		legendarea.innerHTML = "";

	//		show_listings_on_map(latitudeArray,longitudeArray,titleArray,bedsArray,bathsArray,dispPrice);
			}
			else
			{
				proplistmsg = document.getElementById("proplistmsg");
				proplistmsg.innerHTML = html1;
				legendarea = document.getElementById("legendarea");
				legendarea.innerHTML = html2;
			}
		}
	}
	else
	{
		var textResponse = xmlHttp.responseText;
		pagelinktableDiv = document.getElementById("pagelinktable");
		pagelinktableDiv.innerHTML = textResponse;
	}
	
}
function write_listing(current_page,total_pages,poffset)
{
	proptable = document.getElementById("propbrowse");
	var first_row_id, second_row_id;
	var col_id;
	var td_cell;
	//tablebody = proptable.getElementsByTagName("tbody");
	//tablebody[0].innerHTML = html[current_page];
	//firstRow = document.getElementById("L1R1");
	//firstRowfirstcol= document.getElementById("L1R1C1");
	//firstRowfirstcol.innerHTML = "<a target="+"'_blank'"+" href="+"prpdesc"+">"+"Nimisha";
	var listing_limit;
	var test = html[current_page].length;
	if (test < 11)
	 	listing_limit = html[current_page].length-1
	else
	  	listing_limit = 10
	var listingRow;
	for (listingRow=1; listingRow<=listing_limit; listingRow++)
	{
		first_row_id = "L"+listingRow+"R1";
		
		
	  for (var listingCol=1;  listingCol<=4; listingCol++)
	  {
		  col_id = first_row_id+"C" + listingCol;
		  td_cell =  document.getElementById(col_id);
		  document.getElementById(col_id).style.display = '';
		  td_cell.innerHTML = html[current_page][listingRow][1][listingCol];
	  }
	  second_row_id = "L"+listingRow+"R2";
	  row_element = document.getElementById(second_row_id);
	  col_id = second_row_id+"C1";
	  td_cell =  document.getElementById(col_id);
	  //td_cell.setAttribute("id",row2_element_name[listingRow]);
	  document.getElementById(col_id).style.display = '';
	  td_cell.innerHTML = html[current_page][listingRow][2][1];
	}
	//alert("listing = " + listingRow);
	if (listingRow < 11)
	{
		for (var m=listingRow; m<=10; m++)
		{
		 	first_row_id = "L"+m+"R1";
		 	for (var n=1; n<=4; n++)
		 	{
		 		col_id = first_row_id+"C" + n;
				//td_cell =  document.getElementById(col_id);
				//td_cell.innerHTML = "";
				document.getElementById(col_id).style.display = 'none';	
		 	}
			second_row_id = "L"+m+"R2";
			col_id = second_row_id+"C1";
			//td_cell =  document.getElementById(col_id);
			//td_cell.innerHTML = "";
			document.getElementById(col_id).style.display = 'none';
		}
	}
	
	legendarea1 = document.getElementById("legendarea");
	legendarea1.innerHTML = "";
	show_listings_on_map(latitudeArray,longitudeArray,titleArray,bedsArray,bathsArray,dispPrice,poffset,perPage);
	//show_listings_on_map(latitudeArray,longitudeArray,titleArray,bedsArray,bathsArray,proptypeArray,poffset,perPage);
	url = "page_link_new.php?pageNum="+current_page+"&total_pages="+total_pages+"&offset="+poffset;
	xmlHttp=GetXmlHttpRequestObject();	  

	if (xmlHttp)
	{
		try
		{
			xmlHttp.onreadystatechange = handleRequestStateChange_listing;
			xmlHttp.open("Get", url , true)
			xmlHttp.send(null)
		}
		catch (e)
		{
			alert("Can Not connect to server");
		}
	}
}

function show_listings_on_map(lat_array,lon_array,title_array,beds_array,baths_array,dispPrice,offset,no_listing_perpage)
{
	    map2 = new GMap2(document.getElementById("maparea"));
		map2.clearOverlays();
		map2.addControl(new GSmallMapControl());
		map2.addControl(new GMapTypeControl());
		map2.addControl(new GOverviewMapControl());

		
		map2.setCenter(new GLatLng(lat_array.item(offset).firstChild.data,lon_array.item(offset).firstChild.data), zoomLevel);	
		
		// Create our "tiny" marker icon
		var icon1 = new GIcon();
		icon1.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";
		icon1.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon1.iconSize = new GSize(12, 20);
		icon1.shadowSize = new GSize(22, 20);
		icon1.iconAnchor = new GPoint(6, 20);
		icon1.infoWindowAnchor = new GPoint(5, 1);
		var geocoder = new GClientGeocoder();
		
		
		if (lat_array.item(offset).firstChild.data != 91)
		{
		mypoint = new GLatLng(lat_array.item(offset).firstChild.data,lon_array.item(offset).firstChild.data);
		map2.addOverlay(createMarkernew(mypoint, icon1, title_array.item(offset).firstChild.data));
		}
		
		var icon2 = new GIcon();
		icon2.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		icon2.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon2.iconSize = new GSize(12, 20);
		icon2.shadowSize = new GSize(22, 20);
		icon2.iconAnchor = new GPoint(6, 20);
		icon2.infoWindowAnchor = new GPoint(5, 1);
		icon2.iconSize = new GSize(12, 20);
		limit = offset+no_listing_perpage;
		if (limit >= title_array.length)
		 limit = title_array.length
		 
		//for (var j=0; j<title_array.length; j++)
		for (var j=offset; j<limit; j++)
		{
			if(lat_array.item(j).firstChild){
			var comp_lat = lat_array.item(j).firstChild.data;
			}
			if(lon_array.item(j).firstChild){
			var comp_lon = lon_array.item(j).firstChild.data;
			if (comp_lat != 91)
			{
				
			marker_str  = "<TABLE><TR><TD valign=top width=210px height=60px><FONT face=verdana size=2 color=black><strong>"+title_array.item(j).firstChild.data+"</strong><BR> Beds: "+beds_array.item(j).firstChild.data+"<BR> Baths: "+baths_array.item(j).firstChild.data+"<BR>List Price: "+dispPrice[j]+"<BR></FONT></TD></TR></TABLE>";
				
			mypoint = new GLatLng(comp_lat,comp_lon);
			map2.addOverlay(createMarkernew(mypoint, icon2, marker_str));
			}
			}
		}
	
}

function createMarkernew(point, icon,  str) 
	{
	  var lsRegExp = /\+/g;
	  var test =  new String();
	  test = unescape(str);
	  test = unescape(String(test).replace(lsRegExp, " ")); 
	  var marker = new GMarker(point, icon);
	  GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(test);});
	  return marker;
	}

function Truncatestr (str, length, trailing) 
{
      // take off chars for the trailing
      length-=trailing.length;
      if (str.length > length) 
      {
         // string exceeded length, truncate and add trailing dots
		 res = str.substr(0,length)+trailing;
		 return res;
      } 
      else 
      { 
         // string was already short enough, return the string
         res = str; 
      }
  
      return res;
}
/*function get_all_cities()
{ 
//id1=insert
//alert(insert)
//zip = document.getElementById("cities").value

var url="workers/get_cities.php"

xmlHttp=GetXmlHttpObject(stateChanged_cities)
xmlHttp.open("Get", url , true)
xmlHttp.send(null)


} 

function close_cities()
{ 
//id1=insert
//alert(insert)
//zip = document.getElementById("cities").value

var url="workers/close_cities.php"

xmlHttp=GetXmlHttpObject(stateChanged_cities)
xmlHttp.open("Get", url , true)
xmlHttp.send(null)


} 

function stateChanged_cities() 
{ 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	document.getElementById("cities").innerHTML=xmlHttp.responseText 
	//alert(xmlHttp.responseText);
	} 
} 
*/
