var xmlHttp
var id1
var text
var detail_display;

var latitude
var longitude
var ini_address
var zipcode
var ini_city
var ini_state
var marker_str
var oid;
var geocode_index;
var geocode_marker_str,geocode_house_label,geocode_school_label;
//comps
var comp_icon_color,sold_priceArray,latitudeArray,longitudeArray,addressArray,bedsArray,bathsArray,sold_dateArray,year_builtArray, sqftArray, zpidArray, valuationArray, comp_markers,on_mouse_address,dispPrice,zestimateArray, dispsolddate;

var prop_beds, prop_baths, prop_sqft, gbeds, gbaths, gsqft;

//school
var school_addressArray, schoolnameArray ,schooldistArray, schoolAPIArray, schooltypeArray,school_latitudeArray,school_longitudeArray,school_markers,school_on_mouse,school_icon_color;
// this variables are used to store the information about comps/schools which is already being displayed. so when a new comp/school is displayed, the first one is closed with these info
var display= false;
var display_oid ;
var display_lat;
var display_lon ;
var disp_address; 
var disp_zipcode;
var disp_city ;
var disp_state;
var close_oid;
var icon_1;

var ZillowxmlHttp;

var ZILLOW_PID;
var ZILLOWADDR;

/*function school_mymouseover(m)
{
	school_markers[m].openInfoWindowHtml("<TABLE ><TR><TD valign=top width=275px height=20px><Font face=verdana size=2 color=black>"+school_on_mouse[m]+"</FONT></TD></TR></TABLE>");
}
*/function school_mymouseover(m) {
		map.removeOverlay(school_markers[m]);
		school_markers[m].getIcon().image = "http://www.realivent.com/images/icons/pushpin_"+school_icon_color[m]+".png";
	    school_markers[m].getIcon().iconSize= new GSize(18, 25);
		map.addOverlay(school_markers[m]);
        showTooltip(school_markers[m])
      }
//function comp_mymouseover(m)
//	{
		
//	  comp_markers[m].openInfoWindowHtml(on_mouse_address[m]);
//	}
/*function school_mymouseout()
{		
	map.closeInfoWindow();
}
*/
function school_mymouseout(m) {
	map.removeOverlay(school_markers[m]);
		school_markers[m].getIcon().image = "http://www.realivent.com/images/icons/pushpin_"+school_icon_color[m]+".png";
	school_markers[m].getIcon().iconSize= new GSize(12, 20);
	map.addOverlay(school_markers[m]);
	tooltip.style.visibility="hidden";
      }	  
function comp_mymouseover(m) 
{
	if (m!=0)
	{
		map.removeOverlay(comp_markers[m]);
		comp_markers[m].getIcon().image = "http://labs.google.com/ridefinder/images/mm_20_"+comp_icon_color[m]+".png";
	    comp_markers[m].getIcon().iconSize= new GSize(16, 25);
		map.addOverlay(comp_markers[m]);
        //showTooltip(comp_markers[m])
	}
	showTooltip(comp_markers[m])
}
function comp_mymouseout(m)
{
	if (m!=0)
	{
	map.removeOverlay(comp_markers[m]);
	comp_markers[m].getIcon().image = "http://labs.google.com/ridefinder/images/mm_20_"+comp_icon_color[m]+".png";
	comp_markers[m].getIcon().iconSize= new GSize(12, 20);
	map.addOverlay(comp_markers[m]);
	//tooltip.style.visibility="hidden";
	}
	tooltip.style.visibility="hidden";
}	  
//function myclick(i) {
//        gmarkers[i].openInfoWindowHtml(htmls[i]);
 //     }


//function comp_mymouseout()
//	{
		
//	  map.closeInfoWindow();
//	}
	
function school_myclick(m)
	{
	   school_markers[m].openInfoWindowHtml(school_on_mouse[m]);
	}
function comp_myclick(m)
	{
	   comp_markers[m].openInfoWindowHtml(on_mouse_address[m]);
	}
	
	function disp_prop_val_hist_old(m)
	{
	
	var disp_prop_val_html= "";
	
	disp_prop_val_html += "<script src='onboard/zillow_val_history.php'> </script>";
	prop_val_graphDiv = document.getElementById("prop_val_hist");
	prop_val_graphDiv.innerHTML = disp_prop_val_html;
	


	   
	}


function disp_prop_val_hist(zpid, zillowaddr)
{ 


ZILLOWADDR = zillowaddr;


var url="onboard/zillow_val_history.php?zpid="+ zpid;
//alert(url)
//xmlHttp=GetXmlHttpObject(stateChangedPropHist)
//xmlHttp.open("Get", url , true)
//xmlHttp.send(null)

	ZillowxmlHttp=GetXmlHttpRequestObject();

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


} 



function stateChangedPropHist_old() 
{ 

	if (ZillowxmlHttp.readyState==4 || ZillowxmlHttp.readyState=="complete")
	{ 
	document.getElementById("prop_val_hist").innerHTML+=ZillowxmlHttp.responseText;
	
	} 
} 


function stateChangedPropHist()
{
	if (ZillowxmlHttp.readyState==4 || ZillowxmlHttp.readyState=="complete")
	{
		if (ZillowxmlHttp.status == 200)
		{
			try
			{
			document.getElementById("prop_hist_table").style.display="";

			document.getElementById("prop_val_hist_title").innerHTML="Valuation History For: " + ZILLOWADDR;
			document.getElementById("prop_val_hist").innerHTML=ZillowxmlHttp.responseText;	
			
			}
			catch (e)
			{
				alert("Error handling the response" + e.toString());
			}
		}
		else
		{
			alert("There was a problem retrieving the data" + ZillowxmlHttp.statusText);
		}
	}
}

function get_comp_school(pid_array,plat,plon,ptitle,pzip,pstate,pcity, beds, baths, sqft, byaddr)
{
	
	comp_markers = [];
	on_mouse_address =[];
	school_markers = [];
	school_on_mouse = [];
	latitude = plat;
	longitude = plon;
	var lsRegExp = /\+/g;
	var test =  new String();
	test = unescape(ptitle);
	test = unescape(String(test).replace(lsRegExp, " ")); 
	ini_address = test;
	zipcode = pzip;
	//ini_oid = poid;
	comp_id = pid_array[0];
	school_id = pid_array[1];
	ini_city = pcity;
	ini_state = pstate;
	gbeds = parseInt(beds);
	gbaths = parseInt(baths);
	gsqft = parseInt(sqft);
	

	var url_1="onboard/get_zillow_details.php?addr=" + ptitle + "&city=" + city + "&state=" + state + "&zip=" + pzip + "&beds=" + beds+ "&baths=" + baths+ "&sqft=" + sqft;

var url_2 = "Neighborhood/schools_06.php?latitude=" + latitude + "&longitude=" + longitude + "&zipcode=" + zipcode;
	var xmlHttp1=GetXmlHttpRequestObject();
	var xmlHttp2=GetXmlHttpRequestObject();
	
	indicatoroid = "indicator"+oid;
	indi_div = document.getElementById(indicatoroid);
	if (indi_div)
	{
		indi_div.style.display = ""; 
	}


	if (xmlHttp1)
	{
		try
		{
			xmlHttp1.onreadystatechange = function(){ handleCompSchoolRequestStateChange_1(xmlHttp1,comp_id); }
			xmlHttp1.open("GET", url_1 , true)
			//xmlHttp.overrideMimeType('text/');
			xmlHttp1.send(null)
		}
		catch (e)
		{
			alert("Can Not connect to server");
		}
	}
	if (xmlHttp2)
	{
		try
		{
			xmlHttp2.onreadystatechange = function() { handleCompSchoolRequestStateChange_2(xmlHttp2,school_id); }
			xmlHttp2.open("GET", url_2 , true)
			//xmlHttp.overrideMimeType('text/');
			xmlHttp2.send(null)
		}
		catch (e)
		{
			alert("Can Not connect to server");
		}
	}
	
	//map.addControl(new GSmallMapControl());
	//map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(plat,plon), 14);
	icon_1 = new GIcon();
	icon_1.image = "/images/icons/house_blue.png";
	//labs.google.com/ridefinder/images/mm_20_black.png";
	icon_1.shadow = "http://www.realivent.com/images/icons/house_shadow.png";
	icon_1.iconSize = new GSize(26, 34);
	icon_1.shadowSize = new GSize(38, 34);
	icon_1.iconAnchor = new GPoint(6, 20);
	icon_1.infoWindowAnchor = new GPoint(10, 20);
	var marker_str = "<TABLE width=200px height=30px><TR><TD valign=top><FONT face=arial size=2 color=black><strong>"+ini_address+"</strong></FONT><BR></TD></TR></TABLE>";
	mypoint = new GLatLng(plat,plon);
	label = "<TABLE width=250px><TR><TD><FONT face=arial size=2 color=black><strong>"+ini_address+"</strong></FONT></TD></TR></TABLE>";
	var marker = createMarker(mypoint,label,marker_str,icon_1);
	comp_markers[0] = marker;
	//var new_marker = createMarkerNew(mypoint, icon_1, marker_str);
	//map.addOverlay(new_marker);
	
}

function get_comparables(lat,lon,title,zip,poid,state,city, beds, baths, sqft)
{
	//map.clearOverlays();
	comp_markers = [];
	on_mouse_address =[];
	latitude = lat;
	longitude = lon;
	var lsRegExp = /\+/g;
	var test =  new String();
	test = unescape(title);
	test = unescape(String(test).replace(lsRegExp, " ")); 
	ini_address = test;
	zipcode = zip;
	oid=poid
	ini_city = city;
	ini_state = state;
	gbeds = parseInt(beds);
	gbaths = parseInt(baths);
	gsqft = parseInt(sqft);

	
	if (detail_display)
	{
	 temp = document.getElementById(display_oid);
	 temp.innerHTML="";
	}

	prop_hist_tablex = document.getElementById("prop_hist_table");
	if (prop_hist_tablex)
			prop_hist_tablex.style.display="none";

	prop_val_hist_titlex = document.getElementById("prop_val_hist_title");
	if (prop_val_hist_titlex)
     	prop_val_hist_titlex.innerHTML="";
		
	prop_val_histx = document.getElementById("prop_val_hist");
	if (prop_val_histx)
     	prop_val_histx.innerHTML="";


	detail_display="Comps"
	
debugger;

		var url="onboard/get_zillow_details.php?addr=" + title + "&city=" + city + "&state=" + state + "&zip=" + zip + "&beds=" + beds+ "&baths=" + baths+ "&sqft=" + sqft;

	xmlHttp=GetXmlHttpRequestObject();
	indicatoroid = "indicator"+oid;
	indi_div = document.getElementById(indicatoroid);
	if (indi_div)
	{
		indi_div.style.display = ""; 
	}
	if (xmlHttp)
	{
		try
		{
			xmlHttp.onreadystatechange = handleRequestStateChange;
			xmlHttp.open("Get", url , true)
			xmlHttp.send(null)
		}
		catch (e)
		{
			alert("Can Not connect to server");
		}
	}
}

function get_comparables_by_addr(addr, lat,lon,title,zip,poid,state,city, beds, baths, sqft)
{
	//map.clearOverlays();
	comp_markers = [];
	on_mouse_address =[];
	latitude = lat;
	longitude = lon;
	var lsRegExp = /\+/g;
	var test =  new String();
	test = unescape(title);
	test = unescape(String(test).replace(lsRegExp, " ")); 
	ini_address = addr;
	zipcode = zip;
	oid=poid
	ini_city = city;
	ini_state = state;
	gbeds = parseInt(beds);
	gbaths = parseInt(baths);
	gsqft = parseInt(sqft);

	
	if (detail_display)
	{
	 temp = document.getElementById(display_oid);
	 if (temp)
	 	temp.innerHTML="";
	}

	prop_hist_tablex = document.getElementById("prop_hist_table");
	if (prop_hist_tablex)
			prop_hist_tablex.style.display="none";

	prop_val_hist_titlex = document.getElementById("prop_val_hist_title");
	if (prop_val_hist_titlex)
     	prop_val_hist_titlex.innerHTML="";
		
	prop_val_histx = document.getElementById("prop_val_hist");
	if (prop_val_histx)
     	prop_val_histx.innerHTML="";


	detail_display="Comps"
	

	
	var url="onboard/get_zillow_details.php?addr=" + addr + "&city=" + city + "&state=" + state + "&zip=" + zip + "&beds=" + beds+ "&baths=" + baths+ "&sqft=" + sqft;
	
	
	xmlHttp=GetXmlHttpRequestObject();
	indicatoroid = "indicator"+oid;
	indi_div = document.getElementById(indicatoroid);
	if (indi_div)
	{
		indi_div.style.display = ""; 
	}
	if (xmlHttp)
	{
		try
		{
			xmlHttp.onreadystatechange = handleRequestStateChange;
			xmlHttp.open("Get", url , true)
			xmlHttp.send(null)
		}
		catch (e)
		{
			alert("Can Not connect to server");
		}
	}
}

function close_comparables(latitude,longitude,poid,paddress,pzipcode)
{
	close_oid = poid;
	//Remove all overlay for comps/schools
	map.clearOverlays();
	map.setCenter(new GLatLng(lat,lng), 10);
	// Now load original yellow icon for house listing
	icon.image = "http://labs.google.com/ridefinder/images/mm_20_yellow.png";
	icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	icon.iconSize = new GSize(12, 20);
	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);
	for (var i=0; i<listing_markers.length; i++)
	 map.addOverlay(listing_markers[i]);
	var lsRegExp = /\+/g;
	var test =  new String();
	test = unescape(paddress);
	test = unescape(String(test).replace(lsRegExp, " ")); 
	ini_address = test;
	zipcode = pzipcode;
    legendareax = document.getElementById("legendarea");
	if (legendareax)
     	legendareax.innerHTML="";
	
	prop_hist_tablex = document.getElementById("prop_hist_table");
	if (prop_hist_tablex)
			prop_hist_tablex.style.display="none";

	prop_val_hist_titlex = document.getElementById("prop_val_hist_title");
	if (prop_val_hist_titlex)
     	prop_val_hist_titlex.innerHTML="";
		
	prop_val_histx = document.getElementById("prop_val_hist");
	if (prop_val_histx)
     	prop_val_histx.innerHTML="";

	var url="onboard/close_comps.php?latitude=" + latitude + "&longitude=" + longitude+"&address="+ini_address+"&zipcode="+zipcode+"&oid="+ close_oid+"&city="+ini_city+"&state="+ini_state+"&Session_ID="+Session_ID;
	detail_display="";
	addressArray = null;
	sold_priceArray = null;
	latitudeArray = null;
	longitudeArray = null;
	bedsArray = null;
	bathsArray = null;
	sold_dateArray = null;
	year_builtArray = null;
	sqftArray = null;
	zpidArray = null;
	zestimateArray = null;
	
	school_addressArray = null;
	schoolnameArray = null;
	schooldistArray = null;
	schoolAPIArray = null;
	schooltypeArray = null;
	school_latitudeArray = null;
	school_longitudeArray = null;
	school_markers = null;
	school_on_mouse = null;
	school_icon_color  = null;
	
	
	
	xmlHttp = GetXmlHttpRequestObject();
	if (xmlHttp)
	{
		try
		{
			xmlHttp.onreadystatechange = handleRequestStateChange;
			
			//xmlHttp.onreadystatechange = handleRequestStateChange;
			xmlHttp.open("Get", url , true)
			//xmlHttp.overrideMimeType('text/');
			xmlHttp.send(null)
		}
		catch (e)
		{
			alert("Can Not connect to server");
		}
	}
	
}


function get_school_data(platitude,plongitude,title,pzipcode, poid, state, city)
{
	
	//map.clearOverlays();
	school_markers = [];
	school_on_mouse =[];
	latitude = platitude;
	longitude = plongitude;
	zipcode = pzipcode;
	var lsRegExp = /\+/g;
	var test =  new String();
	test = unescape(title);
	test = unescape(String(test).replace(lsRegExp, " ")); 
	ini_address = test;
	oid = poid;
	ini_city = city;
	ini_state = state;
	if (detail_display)
	{
	 temp = document.getElementById(display_oid);
	 if (temp)
		 temp.innerHTML="";
	}
	detail_display="School"
	
	
	var url="Neighborhood/schools_06.php?latitude=" + latitude + "&longitude=" + longitude + "&zipcode=" + zipcode;
	xmlHttp = GetXmlHttpRequestObject();
	indicatoroid = "indicator"+oid;
	indi_div = document.getElementById(indicatoroid);
	if (indi_div)
	{
		indi_div.style.display = ""; 
	}
	if (xmlHttp)
	{
		try
		{
			xmlHttp.onreadystatechange = handleRequestStateChange;
			xmlHttp.open("Get", url , true)
			xmlHttp.send(null)
		}
		catch (e)
		{
			alert("Can Not connect to server");
		}
	}
}
function handleCompSchoolRequestStateChange_1(http_request,poid)
{

	if (http_request.readyState==4)
	{

		if (http_request.status == 200)
		{
			try
			{
				
			 		handleCompSchoolServerResponse(http_request,poid);
					show_on_map_1();
					//(latitude,longitude,latitudeArray,longitudeArray,addressArray,sold_priceArray,bedsArray,bathsArray,sold_dateArray,comp_icon_color);
				
			}
			catch (e)
			{
				alert("Error handling the response" + e.toString());
			}
		}
		else
		{
			alert("There was a problem retrieving the data" + xmlHttp.statusText);
		}
	}
	
}
function handleCompSchoolRequestStateChange_2(http_request2,poid)
{

	if (http_request2.readyState==4)
	{

		if (http_request2.status == 200)
		{
			try
			{
				
			 		handleCompSchoolServerResponse(http_request2,poid);
					show_schools_on_map_1();
					//latitude,longitude,school_latitudeArray,school_longitudeArray,school_addressArray,schoolnameArray,schooldistArray,schooltypeArray,schoolAPIArray,school_icon_color );
			}
			catch (e)
			{
				alert("Error handling the response" + e.toString());
			}
		}
		else
		{
			alert("There was a problem retrieving the data" + xmlHttp2.statusText);
		}
	}
}

function handleRequestStateChange()
{
	if (xmlHttp.readyState==4)
	{
		indicatoroid = "indicator"+oid;
		indi_div = document.getElementById(indicatoroid);
		if (indi_div)
		{
			indi_div.style.display = "none";
		}
		//document.getElementById(indicatoroid).style.display = "none";
		if (xmlHttp.status == 200)
		{
			try
			{
			 	handleServerResponse(oid);
				if (detail_display == "School")
					show_schools_on_map();
				else if (detail_display == "Comps")
					show_on_map();

					

			}
			catch (e)
			{
				alert("Error handling the response" + e.toString());
			}
		}
		else
		{
			alert("There was a problem retrieving the data" + xmlHttp.statusText);
		}
	}
}

function handleCompSchoolServerResponse(http_request,poid)
{
	var type = http_request.getResponseHeader("Content-Type");
	var evenrow;
	
	if (type == "text/xml")
	{
		var xmlResponse = http_request.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;
		evenrow = 1;
		if (firstchild_name == "Noproperties")
		{
			comp_html = "<table width=50% align=center><tr><td style='background:#7FFF00'> No comparable sales data is available for \"" + ini_address + "\"</td></tr></table>";
			myDiv = document.getElementById(poid);
			myDiv.innerHTML = comp_html;
		}
		if ((firstchild_name == "properties") && (poid == "comp_data"))
		{
		indicatoroid = "indicator"+oid;
		indi_div = document.getElementById(indicatoroid);
		if (indi_div)
		{
			indi_div.style.display = ""; 
		}

			addressArray = xmlRoot.getElementsByTagName("address");
			sold_priceArray = xmlRoot.getElementsByTagName("soldprice");
			latitudeArray = xmlRoot.getElementsByTagName("latitude");
			longitudeArray = xmlRoot.getElementsByTagName("longitude");
			bedsArray = xmlRoot.getElementsByTagName("bedrooms");
			bathsArray = xmlRoot.getElementsByTagName("bathrooms");
			sold_dateArray = xmlRoot.getElementsByTagName("solddate");
			year_builtArray = xmlRoot.getElementsByTagName("yearbuilt");
			sqftArray = xmlRoot.getElementsByTagName("sqft");
			zestimateArray = xmlRoot.getElementsByTagName("amount");

	
			var comp_html= "";
			comp_html += "<Table style='font-size:12px; vertical-align:top'> <tr> <td colpan='6'>";
			comp_html += "<tr style='background:#FEF9E4;'><td></td>"+"<td style='text-decoration: underline;' >Address</td><td style='text-decoration: underline;'>Sold Price</td><td align=center style='text-decoration: underline;'>Sold On</td><td style='text-decoration: underline;'>Zestimate</td><td style='text-decoration: underline;'>Beds/  Baths</td><td style='text-decoration: underline;'>Yr Built</td><td style='text-decoration: underline;'>Sq Ft</td></tr>";
			
			
/*			comp_html += "<tr style='background:#FEF9E4;'><td><img src='images/other_logos/zillowlogo_150x40.gif'></td></tr>";
*/	

			
	        comp_icon_color=new Array(addressArray.length);
			on_mouse_address = new Array(addressArray.length);
			dispPrice = new Array(addressArray.length);
			
evenrow = 1;
var min_sqft = 0;
var max_sqft = 10000000;


			for (var i=0; i<addressArray.length; i++)
			{
				var sold_price = sold_priceArray.item(i).firstChild.data
				sold_price = sold_price.replace("$","")
				sold_price = sold_price.replace(/,/g,"")
				var int_sold_price = parseInt(sold_price);
				if (int_sold_price > 0 && int_sold_price <= 350000)
				 comp_icon_color[i] =  "blue";
				else if (int_sold_price > 350000 && int_sold_price <= 700000)
				  comp_icon_color[i] = "red";
				else if (int_sold_price > 700000 && int_sold_price <= 1000000)
				  comp_icon_color[i] = "purple";
				else
				  comp_icon_color[i] = "green";
				 
				comp_html += "<tr align=top>";
				

				if(sqftArray.item(i).firstChild)
				{
					dispsqft = sqftArray.item(i).firstChild.data;
					comp_sqft = parseInt(sqftArray.item(i).firstChild.data);
				}
				else
				{
					dispsqft = "----";
					comp_sqft = 0;
				}

				if(sold_dateArray.item(i).firstChild)
				{
					dispsolddate = sold_dateArray.item(i).firstChild.data;
				}
				else
				{
					dispsolddate = "----";
					comp_sqft = 0;
				}
				


/*				if(evenrow) 
				{
				comp_html += "<tr style='width:100%; background:#F7FEE4;'>";
				}
				else
				{
				comp_html += "<tr style='width:100%; background:#FFFFFF;'>";
				}
*/
                if (i==0)
				{
					comp_html += "<tr style='width:100%; background:#AFEEEE;'>";

				}
				else
				{
					if(evenrow) 
					{
					comp_html += "<tr style='width:100%; background:#F7FEE4;'>";
					}
					else
					{
					comp_html += "<tr style='width:100%; background:#FFFFFF;'>";
					}
				}


				if(year_builtArray.item(i).firstChild){
				var lsRegExp = /\+/g;
	  			var testprice =  new String();
	  			testprice = unescape(sold_priceArray.item(i).firstChild.data);
	  			testprice = unescape(String(testprice).replace(lsRegExp, " ")); 

				//var listPrice = sold_priceArray.item(i).firstChild.data;
				listPrice = testprice.replace(/,/g,"");
				listPrice = listPrice.replace(/$/g,"");
				intPrice = parseInt(listPrice);
				dispPrice[i] = formatPrice(intPrice);
				
				var dispAddrArray = addressArray.item(i).firstChild.data;
				var tmpdispAddr = dispAddrArray.split(",");
				var tmpdispAddr2 = tmpdispAddr[0].split(" ");
				
				var dispAddr = tmpdispAddr2[0] + " " + tmpdispAddr2[1] + " " + tmpdispAddr2[2] ;

                if (i==0)
				{
					comp_html += "<td><img src='/images/icons/house_blue_small.png'></td>"+"<td style='font-size:12px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout("+i+")'"+">"+addressArray.item(i).firstChild.data + "</td><td style='font-size:12px'>" + dispPrice[i] + "</td><td style='font-size:12px' align=center>" + dispsolddate + "</td><td style='font-size:12px' align=center>" + "<a href='javascript:disp_prop_val_hist("+zpidArray.item(i).firstChild.data+",\""+dispAddr+"\")' "+">"+"$"+zestimateArray.item(i).firstChild.data + "</td><td  style='font-size:12px' align=center>"+ bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data+"</td><td style='font-size:12px' align=center>" + year_builtArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + dispsqft + "</td>" ;
				}
				else
				{
					comp_html += "<td><img src='http://labs.google.com/ridefinder/images/mm_20_"+comp_icon_color[i]+".png'></td>"+"<td style='font-size:12px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout("+i+")'"+">"+addressArray.item(i).firstChild.data + "</td><td style='font-size:12px'>" + dispPrice[i] + "</td><td style='font-size:12px' align=center>" + dispsolddate + "</td><td style='font-size:12px' align=center>" + "<a href='javascript:disp_prop_val_hist("+zpidArray.item(i).firstChild.data+",\""+dispAddr+"\")' "+">"+"$"+zestimateArray.item(i).firstChild.data + "</td><td  style='font-size:12px' align=center>"+ bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data+"</td><td style='font-size:12px' align=center>" + year_builtArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + dispsqft + "</td>" ;
				}
				}
				else
				{
				var lsRegExp = /\+/g;
	  			var testprice =  new String();
	  			testprice = unescape(sold_priceArray.item(i).firstChild.data);
	  			testprice = unescape(String(testprice).replace(lsRegExp, " ")); 

				//var listPrice = sold_priceArray.item(i).firstChild.data;
				listPrice = testprice.replace(/,/g,"");
				listPrice = listPrice.replace(/$/g,"");
				intPrice = parseInt(listPrice);
				dispPrice[i] = formatPrice(intPrice);
				var dispAddrArray = addressArray.item(i).firstChild.data;
				var tmpdispAddr = dispAddrArray.split(",");
				var tmpdispAddr2 = tmpdispAddr[0].split(" ");
				
				var dispAddr = tmpdispAddr2[0] + " " + tmpdispAddr2[1] + " " + tmpdispAddr2[2] ;
				if (i==0)
				{
					comp_html += "<td><img src='/images/icons/house_blue_small.png'></td>"+"<td style='font-size:12px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout("+i+")'"+">"+addressArray.item(i).firstChild.data + "</td><td style='font-size:12px'>" + dispPrice[i] + "</td><td style='font-size:12px' align=center>" + dispsolddate + "</td><td style='font-size:12px' align=center>" + "<a href='javascript:disp_prop_val_hist("+zpidArray.item(i).firstChild.data+",\""+dispAddr+"\")' "+">"+"$"+zestimateArray.item(i).firstChild.data + "</td><td  style='font-size:12px' align=center>"+ bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data+"</td><td style='font-size:12px' align=center>" + year_builtArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + "----" + "</td>" ;
					//comp_html +="<td><img src='http://labs.google.com/ridefinder/images/mm_20_"+comp_icon_color[i]+".png'></td>"+ "<td style='font-size:12px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout("+i+")'"+">"+addressArray.item(i).firstChild.data + "</td><td style='font-size:12px'>" + dispPrice[i] + "</td><td  style='font-size:12px' align=center>"+ bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data+"</td><td style='font-size:12px'>" + sold_dateArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + "----" + "</td><td style='font-size:12px'>" + dispsqft + "</td>" ;
				}
				else
				{
					comp_html += "<td><img src='http://labs.google.com/ridefinder/images/mm_20_"+comp_icon_color[i]+".png'></td>"+"<td style='font-size:12px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout("+i+")'"+">"+addressArray.item(i).firstChild.data + "</td><td style='font-size:12px'>" + dispPrice[i] + "</td><td style='font-size:12px' align=center>" + dispsolddate + "</td><td style='font-size:12px' align=center>" + "<a href='javascript:disp_prop_val_hist("+zpidArray.item(i).firstChild.data+",\""+dispAddr+"\")' "+">"+"$"+zestimateArray.item(i).firstChild.data + "</td><td  style='font-size:12px' align=center>"+ bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data+"</td><td style='font-size:12px' align=center>" + year_builtArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + "----" + "</td>" ;
				}

				}
				on_mouse_address[i]="<TABLE><TR><TD valign=top width=150px height=50px><FONT face=arial size=2 color=black><strong>"+addressArray.item(i).firstChild.data+"</strong><BR> Beds: "+bedsArray.item(i).firstChild.data+" Baths: "+bathsArray.item(i).firstChild.data+"<BR>Sold Price: "+dispPrice[i]+"<BR>Sold On: "+dispsolddate+"<BR></FONT></TD></TR></TABLE>";
				//on_mouse_address[i] = addressArray.item(i).firstChild.data;
				comp_html += "</tr>";
				
				if(evenrow == 1) 
				{
				evenrow = 0;
				}
				else
				{
				evenrow = 1;
				}

			}
			comp_html += "</table>";
			myDiv = document.getElementById(poid);
			myDiv.innerHTML = comp_html;
			var comp_html2="";
			comp_html2 = "<td style='font-size:12px; font-weight:bold;'>SALE PRICE&nbsp;</td>";
			
			
			comp_html2 += "<td style='font-size:11px' nowrap='nowrap'><img src='http://labs.google.com/ridefinder/images/mm_20_blue.png'>"+" 0-$350K"+"&nbsp;&nbsp;&nbsp;</td>";
			comp_html2 += "<td style='font-size:11px' nowrap='nowrap'><img src='http://labs.google.com/ridefinder/images/mm_20_red.png' &nbsp;>"+" $350K-$700K"+"&nbsp;&nbsp;&nbsp;</td>";
			comp_html2 += "<td style='font-size:11px' nowrap='nowrap'><img src='http://labs.google.com/ridefinder/images/mm_20_purple.png'>"+" $700K-1M"+"&nbsp;&nbsp;&nbsp;</td>";
			comp_html2 += "<td style='font-size:11px' nowrap='nowrap'><img src='http://labs.google.com/ridefinder/images/mm_20_green.png'>"+" >1M"+"&nbsp;&nbsp;</td>";
			legendareax = document.getElementById("legendarea1");
			legendareax.innerHTML = comp_html2;
			//show_on_map_1(latitude,longitude,latitudeArray,longitudeArray,addressArray,sold_priceArray,bedsArray,bathsArray,sold_dateArray,icon_color);
		} //if (firstchild_name == "properties")
		else if ((firstchild_name == "schools") && (poid == "school_data"))
		{
			
			indicatoroid = "indicator"+oid;
			indi_div = document.getElementById(indicatoroid);
			if (indi_div)
			{
				indi_div.style.display = ""; 
			}

			school_addressArray = xmlRoot.getElementsByTagName("address");
			schoolnameArray = xmlRoot.getElementsByTagName("schoolname");
			schooldistArray = xmlRoot.getElementsByTagName("schooldist");
			schoolAPIArray = xmlRoot.getElementsByTagName("schoolAPI");
			schooltypeArray = xmlRoot.getElementsByTagName("schooltype");
			school_latitudeArray = xmlRoot.getElementsByTagName("sch_latitude");
			school_longitudeArray = xmlRoot.getElementsByTagName("sch_longitude");
			var html= "";
			evenrow=1;
			html += "<Table style='font-size:11px; vertical-align:top'> <tr> <td colpan='5'>";
			//html += "<tr ><td style='text-decoration: underline;'>School</td><td style='text-decoration: underline;'>District</td><td style='text-decoration: underline;'><b>API</b></td><td style='text-decoration: underline;'>Type</td><td style='text-decoration: underline;'>Location</td></tr>";
			html += "<tr style='background:#FEF9E4; font-size:12px;'><td></td><td style='text-decoration: underline;'>School</td><td style='text-decoration: underline;'>District</td><td style='text-decoration: underline; font-weight:bold;'>API</td><td style='text-decoration: underline;'>Type</td></tr>";

	        school_icon_color=new Array(school_addressArray.length);
			school_on_mouse = new Array(school_addressArray.length);
			for (var i=0; i<school_addressArray.length; i++)
			{
				var int_API = parseInt(schoolAPIArray.item(i).firstChild.data);
				if (int_API <=600)
				   school_icon_color[i] = "blue"
				else if ((int_API > 600) && (int_API <= 750))
				   school_icon_color[i] = "green"
				else if ((int_API > 750) && (int_API <= 850))
					school_icon_color[i] = "red"
				else if ((int_API > 850) && (int_API <= 950))
					school_icon_color[i] = "purple"
				else
				   school_icon_color[i] = "teal"
				   
				if(evenrow) 
				{
					
				html += "<tr 'valign=top' style='background:#F7FEE4;'>";
				}
				else
				{
				html += "<tr 'valign=top' style='background:#FFFFFF;'>";
				}



				
				//html += "<td style='font-size:10px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout()'"+">"+schoolnameArray.item(i).firstChild.data + "</td><td style='font-size:10px'>" + schooldistArray.item(i).firstChild.data + "</td><td style='font-size:10px' align=center>"+"<b>"+ schoolAPIArray.item(i).firstChild.data+"</b>"+ "</td><td style='font-size:10px'>"+ schooltypeArray.item(i).firstChild.data+ "</td><td style='font-size:10px'>" + addressArray.item(i).firstChild.data+"</td>" ;
				html += "<td><img src='http://www.realivent.com/images/icons/pushpin_"+school_icon_color[i]+"_small.png'></td>"+"<td style='font-size:12px'>"+"<a href='javascript:school_myclick("+i+")' onmouseover='school_mymouseover("+i+")';  onmouseout='school_mymouseout("+i+")'"+">"+schoolnameArray.item(i).firstChild.data + "</td><td style='font-size:12px'>" + schooldistArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>"+"<b>"+ schoolAPIArray.item(i).firstChild.data+"</b>"+ "</td><td style='font-size:12px'>"+ schooltypeArray.item(i).firstChild.data+ "</td>";
				html += "</tr>";
				school_on_mouse[i]="<TABLE><TR><TD valign=top width=150px height=50px><FONT face=arial size=2 color=black><strong>"+schoolnameArray.item(i).firstChild.data+"</strong><BR> Type: "+schooltypeArray.item(i).firstChild.data+"<BR> District: "+schooldistArray.item(i).firstChild.data+"<BR>API: "+schoolAPIArray.item(i).firstChild.data+"<BR></FONT></TD></TR></TABLE>";
				
				if(evenrow == 1) 
				{
				evenrow = 0;
				}
				else
				{
				evenrow = 1;
				}

				//school_on_mouse[i] = schoolnameArray.item(i).firstChild.data;
			}
			html += "</table>";	    	
			myDiv = document.getElementById(poid);
			myDiv.innerHTML = html;
			var html2="";
			html2 = "<td style='font-size:12px; font-weight:bold;'>API&nbsp;</td>";
			html2 += "<td style='font-size:11px'><img src='http://www.realivent.com/images/icons/pushpin_blue_small.png'>"+" <=600"+"&nbsp;&nbsp;&nbsp;</td>";
			html2 += "<td style='font-size:11px' nowrap='nowrap'><img src='http://www.realivent.com/images/icons/pushpin_green_small.png' &nbsp;>"+" 601-750"+"&nbsp;&nbsp;&nbsp;</td>";
			html2 += "<td style='font-size:11px' nowrap='nowrap'><img src='http://www.realivent.com/images/icons/pushpin_red_small.png'>"+" 751-850"+"&nbsp;&nbsp;&nbsp;</td>";
			html2 += "<td style='font-size:11px' nowrap='nowrap'><img src='http://www.realivent.com/images/icons/pushpin_purple_small.png'>"+" 851-950"+"&nbsp;&nbsp;&nbsp;</td>";
			html2 += "<td style='font-size:11px' nowrap='nowrap'><img src='http://www.realivent.com/images/icons/pushpin_teal_small.png'>"+" >951"+"&nbsp;&nbsp;&nbsp;</td>";
			legendareax = document.getElementById("legendarea");
			legendareax.innerHTML = html2;
		}//  if (firstchild_name == "schools")
	}//(type == "text/xml")
	else
	{
	}
}

function handleServerResponse(oid)
{
	var evenrow;
	

	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 == "Noproperties")
		{
			html = "<table align=center width=50%><tr><td style='background:#7FFF00' nowrap=nowrap> No comparable sales data is available for \"" + ini_address + "\"</td></tr></table>";
			myDiv = document.getElementById(oid);
			myDiv.innerHTML = html;
		}
		if (firstchild_name == "properties")
		{
			//if one comps is open then first close it and then open new
			
			addressArray = xmlRoot.getElementsByTagName("address");
			sold_priceArray = xmlRoot.getElementsByTagName("soldprice");
			latitudeArray = xmlRoot.getElementsByTagName("latitude");
			longitudeArray = xmlRoot.getElementsByTagName("longitude");
			bedsArray = xmlRoot.getElementsByTagName("bedrooms");
			bathsArray = xmlRoot.getElementsByTagName("bathrooms");
			sold_dateArray = xmlRoot.getElementsByTagName("solddate");
			year_builtArray = xmlRoot.getElementsByTagName("yearbuilt");
			sqftArray = xmlRoot.getElementsByTagName("sqft");
			zpidArray =  xmlRoot.getElementsByTagName("zillow_prop_id");
			zestimateArray = xmlRoot.getElementsByTagName("amount");

			
evenrow = 1;
var min_sqft = 0;
var max_sqft = 10000000;


			valuationArray = xmlRoot.getElementsByTagName("valuation");
			
			num_of_addresses = addressArray.length;
			
			if(valuationArray.length != 0 && sqftArray.item(0).firstChild)
			{
			input_addr_beds = parseInt(bedsArray.item(0).firstChild.data);
			input_addr_baths = parseInt(bathsArray.item(0).firstChild.data);
			
			var lsRegExp = /\+/g;

			testsqft = unescape(sqftArray.item(0).firstChild.data);
			testsqft = unescape(String(testsqft).replace(lsRegExp, " ")); 

			tmp_sqft = testsqft.replace(/,/g,"");
			tmp_sqft = parseInt(tmp_sqft);

			input_addr_sqft = tmp_sqft;
					
			if(input_addr_beds != 0) gbeds = input_addr_beds;
			if(input_addr_baths != 0) gbaths = input_addr_baths;
			if(input_addr_sqft != 0) gsqft = input_addr_sqft;



			propDiv = document.getElementById("prop_sqft");
			if(propDiv)
			    propDiv.innerHTML = "Area(Sq. Ft.): "+ input_addr_sqft;
			propDiv = document.getElementById("prop_bedrooms");
			if(propDiv)
			    propDiv.innerHTML = "Bedrooms: "+ input_addr_beds;
			propDiv = document.getElementById("prop_bathrooms");
			if(propDiv)
			    propDiv.innerHTML = "Bathrooms: "+ input_addr_baths;
			propDiv = document.getElementById("prop_valuation");
			
			testvalue = unescape(valuationArray.item(0).firstChild.data);
			testvalue = unescape(String(testvalue).replace(lsRegExp, " ")); 

			valuation = testvalue.replace(/,/g,"");
			valuation = valuation.replace(/$/g,"");
			intValuation = parseInt(valuation);
			//dispValuation = formatPrice(intValuation);
			dispValuation = "$"+valuationArray.item(0).firstChild.data;

			if(propDiv)
			    propDiv.innerHTML = "Current Value Estimate: "+ dispValuation;
				num_of_addresses = addressArray.length - 0;
				
				prop_comps_div_ID = "info"+"000";
				
			prop_beds = input_addr_beds;
			prop_baths = input_addr_baths;
			prop_sqft = input_addr_sqft;
			propDiv = document.getElementById("prop_comps_links");
			if(propDiv)
/*			 propDiv.innerHTML = "<a href=javascript:; onClick='get_comparables_by_addr(ini_address,latitude,longitude,ini_address,zipcode,prop_comps_div_ID,ini_state,ini_city,0,0,0);'>Nearby Recent Sales</a> | <a href=javascript:; onClick='get_school_data(latitude,longitude,ini_address,zipcode,prop_comps_div_ID,ini_state,ini_city);'>Schools</a> | <a target='_blank' href=showGraph.php?latitude="+latitude+"&longitude="+longitude+"&zipcode="+zipcode+"&city="+ini_city+"&state="+ini_state+">Neighborhood</a>";
*/	


		    propDiv.innerHTML = "<a href=javascript:; onClick='get_comparables_by_addr(ini_address,latitude,longitude,ini_address,zipcode,prop_comps_div_ID,ini_state,ini_city,0,0,0);'>Nearby Recent Sales</a> | <span style='background-color:#CCFF99'>Comparable Recent Sales</span> | <a href=javascript:; onClick='get_school_data(latitude,longitude,ini_address,zipcode,prop_comps_div_ID,ini_state,ini_city);'>Schools</a> | <a target='_blank' href=showGraph.php?latitude="+latitude+"&longitude="+longitude+"&zipcode="+zipcode+"&city="+ini_city+"&state="+ini_state+">Neighborhood</a>";
			
				//?latitude="+ latitude+"&longitude=" + longitude + "&zipcode=" + zipcode + "&city=" + ini_city + "&state=" + ini_state">Neighborhood</a>";
				
/*				| <a href="showGraph.php?latitude=" + latitude + "&longitude=" + longitude + "&zipcode=" + zipcode + "&city=" + ini_city + "&state=" + ini_state>Neighborhood</a>';
*/

			}
	
			var html= "";
			html += "<Table width='100%' style='font-size:12px; width=100%'> <tr> ";
			if (oid != "CompSchool")
			{
			html += "<td colpan='6'><a href=javascript:; onClick=close_comparables("+latitude+","+longitude+","+"'"+oid+"'"+","+"'"+escape(ini_address)+"'"+","+zipcode+")>[Close]</a></td><td><img src='images/other_logos/zillowlogo_150x40.gif'></td></tr>";
			
			html += "<tr><td></td><td><a target=_blank style=\'font-size:10px\' href='http://www.zillow.com/corp/Terms.htm'>Subject to Zillow Terms of Use</a></td></tr>";
		

			}
			else 
			{
				html += "</tr>";
			}
			html += "<tr style=' width=100%; background:#FEF9E4;'><td></td>"+"<td style='text-decoration: underline;' >Address</td><td style='text-decoration: underline;'>Sold Price</td><td align=center style='text-decoration: underline;'>Sold On</td><td style='text-decoration: underline;'>Zestimate</td><td style='text-decoration: underline;'>Beds/Baths</td><td style='text-decoration: underline;'>Yr Built</td><td style='text-decoration: underline;'>Sq Ft</td></tr>";
			
			
/*			html += "<tr style='background:#FEF9E4;'><td></td>"+"<td><img src='images/other_logos/zillowlogo_150x40.gif'></td></tr>";
*/
	        comp_icon_color=new Array(addressArray.length);
			on_mouse_address = new Array(addressArray.length);;
			dispPrice = new Array(addressArray.length);
			

			
			for (var i=0; i<num_of_addresses; i++)
			{
				var sold_price = sold_priceArray.item(i).firstChild.data
				sold_price = sold_price.replace("$","")
				sold_price = sold_price.replace(/,/g,"")
				var int_sold_price = parseInt(sold_price);
				if (int_sold_price > 0 && int_sold_price <= 350000)
				 comp_icon_color[i] =  "blue";
				else if (int_sold_price > 350000 && int_sold_price <= 700000)
				  comp_icon_color[i] = "red";
				else if (int_sold_price > 700000 && int_sold_price <= 1000000)
				  comp_icon_color[i] = "purple";
				else
				  comp_icon_color[i] = "green";
				 
				if(sqftArray.item(i).firstChild)
				{
					
					dispsqft = sqftArray.item(i).firstChild.data;
					comp_sqft = parseInt(sqftArray.item(i).firstChild.data);
				}
				else
				{
					dispsqft = "----";
					comp_sqft = 0;
				}
				
				if(sold_dateArray.item(i).firstChild)
				{
					dispsolddate = sold_dateArray.item(i).firstChild.data;
				}
				else
				{
					dispsolddate = "----";
					comp_sqft = 0;
				}

                if (i==0)
				{
//					html += "<tr style='width:100%; background:#87CEEB;'>";
					html += "<tr style='width:100%; background:#AFEEEE;'>";

				}
				else
				{
					if(evenrow) 
					{
						html += "<tr style='width:100%; background:#F7FEE4;'>";
					}
					else
					{
						html += "<tr style='width:100%; background:#FFFFFF;'>";
					}
				}
				

				if(year_builtArray.item(i).firstChild){
				var lsRegExp = /\+/g;
	  			var testprice =  new String();
	  			testprice = unescape(sold_priceArray.item(i).firstChild.data);
	  			testprice = unescape(String(testprice).replace(lsRegExp, " ")); 

				//var listPrice = sold_priceArray.item(i).firstChild.data;
				listPrice = testprice.replace(/,/g,"");
				listPrice = listPrice.replace(/$/g,"");
				intPrice = parseInt(listPrice);
				dispPrice[i] = formatPrice(intPrice);
				
				
				var dispAddrArray = addressArray.item(i).firstChild.data;
				var tmpdispAddr = dispAddrArray.split(",");
				var tmpdispAddr2 = tmpdispAddr[0].split(" ");
				
				var dispAddr = tmpdispAddr2[0] + " " + tmpdispAddr2[1] + " " + tmpdispAddr2[2] ;
				
				//dispAddr = dispAddr.replace(/,/g," ");
                if (i ==0)
				{

					html += "<td><img src='/images/icons/house_blue_small.png'></td>"+"<td style='font-size:12px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout("+i+")'"+">"+addressArray.item(i).firstChild.data + "</td><td style='font-size:12px'>"+dispPrice[i] + "</td><td  style='font-size:12px' align=center>"+ dispsolddate+"</td><td  style='font-size:12px' align=center>"+ "<a href='javascript:disp_prop_val_hist("+zpidArray.item(i).firstChild.data+",\""+dispAddr+"\")' "+">"+"$"+zestimateArray.item(i).firstChild.data+"</td><td style='font-size:12px' align=center>" + bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + year_builtArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + dispsqft + "</td>" ;
				}
				else
				{
					html += "<td><img src='http://labs.google.com/ridefinder/images/mm_20_"+comp_icon_color[i]+".png'></td>"+"<td style='font-size:12px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout("+i+")'"+">"+addressArray.item(i).firstChild.data + "</td><td style='font-size:12px'>"+dispPrice[i] + "</td><td  style='font-size:12px' align=center>"+ dispsolddate+"</td><td  style='font-size:12px' align=center>"+ "<a href='javascript:disp_prop_val_hist("+zpidArray.item(i).firstChild.data+",\""+dispAddr+"\")' "+">"+"$"+zestimateArray.item(i).firstChild.data+"</td><td style='font-size:12px' align=center>" + bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + year_builtArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + dispsqft + "</td>" ;	
				}
				}
				else
				{
				var lsRegExp = /\+/g;
	  			var testprice =  new String();
	  			testprice = unescape(sold_priceArray.item(i).firstChild.data);
	  			testprice = unescape(String(testprice).replace(lsRegExp, " ")); 

				//var listPrice = sold_priceArray.item(i).firstChild.data;
				listPrice = testprice.replace(/,/g,"");
				listPrice = listPrice.replace(/$/g,"");
				intPrice = parseInt(listPrice);
				dispPrice[i] = formatPrice(intPrice);

				var dispAddrArray = addressArray.item(i).firstChild.data;
				var tmpdispAddr = dispAddrArray.split(",");
				var tmpdispAddr2 = tmpdispAddr[0].split(" ");
				
				var dispAddr = tmpdispAddr2[0] + " " + tmpdispAddr2[1] + " " + tmpdispAddr2[2] ;
				if (i == 0)
				{
/*                html +="<td valign=center><img src='/images/icons/house_blue_small.png'></td>"+ "<td style='font-size:12px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout("+i+")'"+">"+addressArray.item(i).firstChild.data + "</td><td style='font-size:12px;'>"+"<a href='javascript:disp_prop_val_hist("+zpidArray.item(i).firstChild.data+",\""+dispAddr+"\")' "+">"+dispPrice[i] + "</td><td  style='font-size:12px' align=center>"+ bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data+"</td><td style='font-size:12px'>" + sold_dateArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + "----" + "</td><td style='font-size:12px'>" + dispsqft + "</td>" ;
*/				
				html += "<td><img src='/images/icons/house_blue_small.png'></td>"+"<td style='font-size:12px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout("+i+")'"+">"+addressArray.item(i).firstChild.data + "</td><td style='font-size:12px'>"+dispPrice[i] + "</td><td  style='font-size:12px' align=center>"+ dispsolddate+"</td><td  style='font-size:12px' align=center>"+ "<a href='javascript:disp_prop_val_hist("+zpidArray.item(i).firstChild.data+",\""+dispAddr+"\")' "+">"+"$"+zestimateArray.item(i).firstChild.data+"</td><td style='font-size:12px' align=center>" + bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + "----" + "</td><td style='font-size:12px' align=center>" + dispsqft + "</td>" ;

				}
				else
				{
/*				html +="<td><img src='http://labs.google.com/ridefinder/images/mm_20_"+comp_icon_color[i]+".png'></td>"+ "<td style='font-size:12px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout("+i+")'"+">"+addressArray.item(i).firstChild.data + "</td><td style='font-size:12px'>"+"<a href='javascript:disp_prop_val_hist("+zpidArray.item(i).firstChild.data+",\""+dispAddr+"\")' "+">"+dispPrice[i] + "</td><td  style='font-size:12px' align=center>"+ bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data+"</td><td style='font-size:12px'>" + sold_dateArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + "----" + "</td><td style='font-size:12px'>" + dispsqft + "</td>" ;
*/				
			html += "<td><img src='http://labs.google.com/ridefinder/images/mm_20_"+comp_icon_color[i]+".png'></td>"+"<td style='font-size:12px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout("+i+")'"+">"+addressArray.item(i).firstChild.data + "</td><td style='font-size:12px'>"+dispPrice[i] + "</td><td  style='font-size:12px'>"+ dispsolddate+"</td><td  style='font-size:12px' align=center>"+ "<a href='javascript:disp_prop_val_hist("+zpidArray.item(i).firstChild.data+",\""+dispAddr+"\")' "+">"+"$"+zestimateArray.item(i).firstChild.data+"</td><td style='font-size:12px' align=center>" + bedsArray.item(i).firstChild.data+ "/" +bathsArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>" + "----" + "</td><td style='font-size:12px' align=center>" + dispsqft + "</td>" ;

				}
				}
				/*
				on_mouse_address[i]="<TABLE><TR><TD valign=top width=210px height=60px><FONT face=verdana size=2 color=black><strong>"+addressArray.item(i).firstChild.data+"</strong><BR> Beds: "+bedsArray.item(i).firstChild.data+"<BR> Baths: "+bathsArray.item(i).firstChild.data+"<BR>Sold Price: "+dispPrice[i]+"<BR>Sold On: "+sold_dateArray.item(i).firstChild.data+"<BR></FONT></TD><TD><script type='text/javascript'"+" src='map/prop_value_history.php?zpid=19791996'"+"></script></TD></TR></TABLE>";
				*/
				
		

/*					on_mouse_address[i]="<TABLE><TR><TD valign=top width=210px height=60px><FONT face=verdana size=2 color=black><strong>"+addressArray.item(i).firstChild.data+"</strong><BR> Beds: "+bedsArray.item(i).firstChild.data+"<BR> Baths: "+bathsArray.item(i).firstChild.data+"<BR>Sold Price: "+dispPrice[i]+"<BR>Sold On: "+sold_dateArray.item(i).firstChild.data+"<BR></FONT></TD><TD><script type='text/javascript' src='prop_value_history.php'></script></TD></TR></TABLE>";
*/


on_mouse_address[i]="<TABLE><TR><TD valign=top width=210px height=60px><FONT face=verdana size=2 color=black><strong>"+addressArray.item(i).firstChild.data+"</strong><BR> Beds: "+bedsArray.item(i).firstChild.data+"<BR> Baths: "+bathsArray.item(i).firstChild.data+"<BR>Sold Price: "+dispPrice[i]+"<BR>Sold On: "+dispsolddate+"<BR></FONT></TD></TR></TABLE>";

				//on_mouse_address[i] = addressArray.item(i).firstChild.data;
				html += "</tr>";
				
				if(evenrow == 1) 
				{
				evenrow = 0;
				}
				else
				{
				evenrow = 1;
				}
			}
			html += "</table>";
	//alert ("myDivComparables_"+latitude);
			//myDiv = document.getElementById("myDivComparables_"+ini_address);
			var lsRegExp = /\+/g;
		var test =  new String();
		test = unescape(oid);
		test = unescape(String(test).replace(lsRegExp, " ")); 
		oid = test;
		    display_oid = oid;
			myDiv = document.getElementById(oid);
			myDiv.innerHTML = html;
			var html2="";
			html2 = "<td style='font-size:12px; font-weight:bold;'>SALE PRICE&nbsp;</td>";
			html2 += "<td style='font-size:11px'><img src='http://labs.google.com/ridefinder/images/mm_20_blue.png'>"+" 0-$350K"+"&nbsp;&nbsp;&nbsp;</td>";
			html2 += "<td style='font-size:11px'><img src='http://labs.google.com/ridefinder/images/mm_20_red.png' &nbsp;>"+" $350K-$700K"+"&nbsp;&nbsp;&nbsp;</td>";
			html2 += "<td style='font-size:11px'><img src='http://labs.google.com/ridefinder/images/mm_20_purple.png'>"+" $700K-1M"+"&nbsp;&nbsp;&nbsp;</td>";
			html2 += "<td style='font-size:11px'><img src='http://labs.google.com/ridefinder/images/mm_20_green.png'>"+" >1M"+"&nbsp;&nbsp;</td>";
			legendareax = document.getElementById("legendarea");
			if (legendareax != null)
				legendareax.innerHTML = html2;
			//show_on_map(latitude,longitude,latitudeArray,longitudeArray,addressArray,sold_priceArray,bedsArray,bathsArray,sold_dateArray,icon_color);
		}
		else if (firstchild_name == "schools")
		{
			
			school_addressArray = xmlRoot.getElementsByTagName("address");
			schoolnameArray = xmlRoot.getElementsByTagName("schoolname");
			schooldistArray = xmlRoot.getElementsByTagName("schooldist");
			schoolAPIArray = xmlRoot.getElementsByTagName("schoolAPI");
			schooltypeArray = xmlRoot.getElementsByTagName("schooltype");
			school_latitudeArray = xmlRoot.getElementsByTagName("sch_latitude");
			school_longitudeArray = xmlRoot.getElementsByTagName("sch_longitude");
			
			evenrow = 1;
			var html= "";
			html += "<Table style='font-size:11px' width=100%> <tr> ";
			if (oid != "CompSchool")
			{
			html += "<td colpan='6'><a href=javascript:; onClick=close_comparables("+latitude+","+longitude+","+"'"+oid+"'"+","+"'"+escape(ini_address)+"'"+","+zipcode+")>[Close]</a></td></tr>";
			}
			else 
			{
				html += "</tr>";
			}
			//html += "<tr ><td style='text-decoration: underline;'>School</td><td style='text-decoration: underline;'>District</td><td style='text-decoration: underline;'><b>API</b></td><td style='text-decoration: underline;'>Type</td><td style='text-decoration: underline;'>Location</td></tr>";
			
/*			html += "<tr style=' width=100%; background:#FEF9E4; font-size:12px;'><td></td><td style='text-decoration: underline;'>School</td><td style='text-decoration: underline;'>District</td><td style='text-decoration: underline; font-weight:bold;'>API</td><td style='text-decoration: underline;'>Type</td><td style='text-decoration: underline;'>Address</td></tr>";
*/
			html += "<tr style=' width=100%; background:#FEF9E4; font-size:12px;'><td></td><td style='text-decoration: underline;'>School</td><td style='text-decoration: underline;'>District</td><td style='text-decoration: underline; font-weight:bold;'>API</td><td style='text-decoration: underline;'>Type</td></tr>";


	        school_icon_color=new Array(school_addressArray.length);
			school_on_mouse = new Array(school_addressArray.length);
			for (var i=0; i<school_addressArray.length; i++)
			{
				var int_API = parseInt(schoolAPIArray.item(i).firstChild.data);
				if (int_API <=600)
				   school_icon_color[i] = "blue"
				else if ((int_API > 600) && (int_API <= 750))
				   school_icon_color[i] = "green"
				else if ((int_API > 750) && (int_API <= 850))
					school_icon_color[i] = "red"
				else if ((int_API > 850) && (int_API <= 950))
					school_icon_color[i] = "purple"
				else
				   school_icon_color[i] = "teal"
				
					if(evenrow) 
					{
					html += "<tr style='width:100%; background:#F7FEE4;'>";
					}
					else
					{
					html += "<tr style='width:100%; background:#FFFFFF;'>";
					}



				//html += "<td style='font-size:10px'>"+"<a href='javascript:comp_myclick("+i+")' onmouseover='comp_mymouseover("+i+")';  onmouseout='comp_mymouseout()'"+">"+schoolnameArray.item(i).firstChild.data + "</td><td style='font-size:10px'>" + schooldistArray.item(i).firstChild.data + "</td><td style='font-size:10px' align=center>"+"<b>"+ schoolAPIArray.item(i).firstChild.data+"</b>"+ "</td><td style='font-size:10px'>"+ schooltypeArray.item(i).firstChild.data+ "</td><td style='font-size:10px'>" + addressArray.item(i).firstChild.data+"</td>" ;
/*				html += "<td><img src='http://www.realivent.com/images/icons/pushpin_"+school_icon_color[i]+"_small.png'></td>"+"<td style='font-size:12px'>"+"<a href='javascript:school_myclick("+i+")' onmouseover='school_mymouseover("+i+")';  onmouseout='school_mymouseout("+i+")'"+">"+schoolnameArray.item(i).firstChild.data + "</td><td style='font-size:12px'>" + schooldistArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>"+"<b>"+ schoolAPIArray.item(i).firstChild.data+"</b>"+ "</td><td style='font-size:12px'>"+ schooltypeArray.item(i).firstChild.data+ "</td><td style='font-size:12px'>" + school_addressArray.item(i).firstChild.data+"</td>" ;
*/				
			html += "<td><img src='http://www.realivent.com/images/icons/pushpin_"+school_icon_color[i]+"_small.png'></td>"+"<td style='font-size:12px'>"+"<a href='javascript:school_myclick("+i+")' onmouseover='school_mymouseover("+i+")';  onmouseout='school_mymouseout("+i+")'"+">"+schoolnameArray.item(i).firstChild.data + "</td><td style='font-size:12px'>" + schooldistArray.item(i).firstChild.data + "</td><td style='font-size:12px' align=center>"+"<b>"+ schoolAPIArray.item(i).firstChild.data+"</b>"+ "</td><td style='font-size:12px'>"+ schooltypeArray.item(i).firstChild.data+ "</td>" ;

				html += "</tr>";
				//on_mouse_address[i] = schoolnameArray.item(i).firstChild.data;
				school_on_mouse[i]="<TABLE width=200px height=60px><TR><TD valign=top ><FONT face=arial size=2 color=black><strong>"+schoolnameArray.item(i).firstChild.data+"</strong><BR> Type: "+schooltypeArray.item(i).firstChild.data+"<BR> District: "+schooldistArray.item(i).firstChild.data+"<BR>API: "+schoolAPIArray.item(i).firstChild.data+"<BR></FONT></TD></TR></TABLE>";
				
				if(evenrow == 1) 
				{
				evenrow = 0;
				}
				else
				{
				evenrow = 1;
				}

			}
			html += "</table>";
	//alert ("myDivComparables_"+latitude);
	    	var lsRegExp = /\+/g;
			var test =  new String();
			test = unescape(oid);
			test = unescape(String(test).replace(lsRegExp, " ")); 
			oid = test;
			display_oid = oid;
			myDiv = document.getElementById(oid);
			myDiv.innerHTML = html;
			var html2="";
			html2 = "<td style='font-size:12px; font-weight:bold;'>API&nbsp;</td>";
			html2 += "<td style='font-size:11px'><img src='http://www.realivent.com/images/icons/pushpin_blue_small.png'>"+" <=600"+"&nbsp;&nbsp;&nbsp;</td>";
			html2 += "<td style='font-size:11px'><img src='http://www.realivent.com/images/icons/pushpin_green_small.png' &nbsp;>"+" 601-750"+"&nbsp;&nbsp;&nbsp;</td>";
			html2 += "<td style='font-size:11px'><img src='http://www.realivent.com/images/icons/pushpin_red_small.png'>"+" 751K-850"+"&nbsp;&nbsp;&nbsp;</td>";
			html2 += "<td style='font-size:11px'><img src='http://www.realivent.com/images/icons/pushpin_purple_small.png'>"+" 851-950"+"&nbsp;&nbsp;&nbsp;</td>";
			html2 += "<td style='font-size:11px'><img src='http://www.realivent.com/images/icons/pushpin_teal_small.png'>"+" >951"+"&nbsp;&nbsp;&nbsp;</td>";
			
			legendareax = document.getElementById("legendarea");
			if (legendareax != null)
				legendareax.innerHTML = html2;
//			show_schools_on_map(latitude,longitude,latitudeArray,longitudeArray,addressArray,schoolnameArray,schooldistArray,schooltypeArray,schoolAPIArray,icon_color );
		}
	}
	else
	{
		var lsRegExp = /\+/g;
		var test =  new String();
		test = unescape(oid);
		test = unescape(String(test).replace(lsRegExp, " ")); 
		oid = test;
		var textResponse = xmlHttp.responseText;
		var html= textResponse;
		   myDiv = document.getElementById(oid);
		 myDiv.innerHTML = html;
	}
	
}


/*function createMarkerNew(point, icon,  str, k) 
	{
	  var lsRegExp = /\+/g;
	  var test =  new String();
	  test = unescape(str);
	  test = unescape(String(test).replace(lsRegExp, " ")); 
	  var marker = new GMarker(point, icon);
	  comp_markers[k] = marker;
	  GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(test);});
	  return marker;
	}*/
function createMarkerNew(point, picon,  str)
{
		var lsRegExp = /\+/g;
	  var test =  new String();
	  test = unescape(str);
	  test = unescape(String(test).replace(lsRegExp, " ")); 
	  var marker = new GMarker(point, picon);
	  GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(test);});
	  return marker;
}
function createMarker(point,name,html,picon) {
        var marker = new GMarker(point,picon);
        // === store the name so that the tooltip function can use it ===
        marker.tooltip = '<div class="tooltip" style="background-color:#CCFF99">'+name+'</div>';
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        //gmarkers[i] = marker;
        //htmls[i] = html;
       // sidebar_html = '<a href="javascript:myclick(' + i + ')" onmouseover="mymouseover('+i+')" onmouseout="mymouseout()">' + name + '</a><br>';
       // i++;
        map.addOverlay(marker);

        //  ======  The new marker "mouseover" and "mouseout" listeners  ======
        GEvent.addListener(marker,"mouseover", function() {
          showTooltip(marker);
        });        
        GEvent.addListener(marker,"mouseout", function() {
		tooltip.style.visibility="hidden"
        });  
		return marker;
      }
function showTooltip(marker) 
{
	
    tooltip.innerHTML = marker.tooltip;
	
		
	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());



	//var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var height=tooltip.clientHeight;
	//var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y));
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
	
	//var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
	pos.apply(tooltip);
	tooltip.style.visibility="visible";
}
	  
function show_on_map_1()
//(lat,lon,lat_array,lon_array,addr_array, soldprice_array,beds_array,baths_array,solddate_array,icon_colorArray)
{
	
		indicatoroid = "indicator"+oid;
		indi_div = document.getElementById(indicatoroid);
		if (indi_div)
		{
			indi_div.style.display = "none";
		}

		icon.iconSize = new GSize(12, 20);
		icon.shadowSize =  new GSize(22, 20);
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		//icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
	    if (latitudeArray)
		{
		for (var j=1; j<latitudeArray.length; j++)
		{
			if(latitudeArray.item(j).firstChild)
			{
				var comp_lat = latitudeArray.item(j).firstChild.data;
			}
			if(longitudeArray.item(j).firstChild)
			{
				var comp_lon = longitudeArray.item(j).firstChild.data;
				mypoint = new GLatLng(comp_lat,comp_lon);
				marker_str  = "<TABLE><TR><TD valign=top width=210px height=60px><FONT face=verdana size=2 color=black><strong>"+addressArray.item(j).firstChild.data+"</strong><BR> Beds: "+bedsArray.item(j).firstChild.data+"<BR> Baths: "+bathsArray.item(j).firstChild.data+"<BR>Sold Price: "+sold_priceArray.item(j).firstChild.data+"<BR>Sold On: "+dispsolddate+"<BR></FONT></TD></TR></TABLE>";
				icon.image = "http://labs.google.com/ridefinder/images/mm_20_"+comp_icon_color[j]+".png";
				//
				label = "<TABLE wifth=300px><TR><TD valign=top nowrap=nowrap><FONT face=sans-serif size=2 color=black><strong>"+addressArray.item(j).firstChild.data+"<BR>Sold Price: "+dispPrice[j]+"</FONT></TD></TR></TABLE>";
				var new_marker = createMarker(mypoint,label,marker_str,icon);
			//
				//var new_marker = createMarkerNew(mypoint, icon, marker_str);
				comp_markers[j] = new_marker;
				//map.addOverlay(new_marker);
			}
		}
		}
}
function show_schools_on_map_1()
//(lat,lon,lat_array,lon_array,addr_array,schoolname_array,schooldist_array,schooltype_array,schoolAPI_array,icon_colorArray)
{

		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(36, 24);
		icon.shadow = "http://www.realivent.com/images/icons/pushpin_shadow.png";

		for (var j=0; j<school_addressArray.length; j++)
		{
			if(school_latitudeArray.item(j).firstChild)
			{
				var comp_lat = school_latitudeArray.item(j).firstChild.data;
			}
			if(school_longitudeArray.item(j).firstChild)
			{
				var comp_lon = school_longitudeArray.item(j).firstChild.data;
				if (comp_lat != 91)
				{
					mypoint = new GLatLng(comp_lat,comp_lon);
					marker_str = "<TABLE><TR><TD valign=top width=200px height=60px><FONT face=verdana size=2 color=black><strong>"+schoolnameArray.item(j).firstChild.data+"</strong><BR> Type: "+schooltypeArray.item(j).firstChild.data+"<BR> District: "+schooldistArray.item(j).firstChild.data+"<BR>API: "+schoolAPIArray.item(j).firstChild.data+"<BR></FONT></TD></TR></TABLE>";
					//icon.image = "http://labs.google.com/ridefinder/images/mm_20_"+icon_colorArray[j]+".png";
					icon.image = "http://www.realivent.com/images/icons/pushpin_"+school_icon_color[j]+".png";
					//
					label = "<TABLE width=200px><TR><TD valign=top nowrap=nowrap><FONT face=sans-serif size=2 color=black><strong>"+schoolnameArray.item(j).firstChild.data+"<BR>API: "+schoolAPIArray.item(j).firstChild.data+"</FONT></TD></TR></TABLE>";
					var new_marker = createMarker(mypoint,label,marker_str,icon);
					//
					//var new_marker = createMarkerNew(mypoint, icon, marker_str);//ABC
					school_markers[j] = new_marker;
					//map.addOverlay(new_marker);//ABC

				}
				else
				{
					var geocoder = new GClientGeocoder();
					geocode_marker_str = "<TABLE width=200px height=60px><TR><TD valign=top><FONT face=verdana size=2 color=black><strong>"+schoolnameArray.item(j).firstChild.data+"</strong><BR> Type: "+schooltypeArray.item(j).firstChild.data+"<BR> District: "+schooldistArray.item(j).firstChild.data+"<BR>API: "+schoolAPIArray.item(j).firstChild.data+"<BR></FONT></TD></TR></TABLE>";
					geocode_school_label = "<TABLE width=200px><TR><TD valign=top nowrap=nowrap><FONT face=sans-serif size=2 color=black><strong>"+schoolnameArray.item(j).firstChild.data+"<BR>API: "+schoolAPIArray.item(j).firstChild.data+"</FONT></TD></TR></TABLE>";
					geocode_index = j;
					geocoder.getLatLng(school_addressArray.item(j).firstChild.data,addSchoolOverlayToMap);
				}
			}
		}
	
}
function show_on_map()
//(lat,lon,lat_array,lon_array,addr_array, soldprice_array,beds_array,baths_array,solddate_array,icon_colorArray)
{
	var label;
       map.clearOverlays();
       map.setCenter(new GLatLng(latitude,longitude), 14);
		
		
		
		// Create our "tiny" marker icon
	 	icon_1 = new GIcon();
		icon_1.image = "/images/icons/house_blue.png";
		icon_1.shadow = "/images/icons/house_shadow.png";
		icon_1.iconSize = new GSize(26, 34);
		icon_1.shadowSize = new GSize(38, 34);
		icon_1.iconAnchor = new GPoint(6, 20);
		icon_1.infoWindowAnchor = new GPoint(10,20);
		var marker_str = "<TABLE width=200px height=30px><TR><TD valign=top><FONT face=arial size=2 color=black><strong>"+ini_address+"</strong></FONT><BR></TD></TR></TABLE>";

        mypoint = new GLatLng(latitude,longitude);
		label = "<TABLE width=250px><TR><TD><FONT face=arial size=2 color=black><strong>"+ini_address+"</strong></FONT></TD></TR></TABLE>";
		var marker = createMarker(mypoint,label,marker_str,icon_1);
		comp_markers[0] = marker
		//var new_marker = createMarkerNew(mypoint, icon_1, marker_str);//ABC
		//map.addOverlay(new_marker);//ABC
		if (latitudeArray)
		{
		var geocoder = new GClientGeocoder();
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		//icon.infoWindowAnchor = new GPoint(1, 5);
		if(valuationArray)
		{
			num_of_markers = latitudeArray.length - 0;
		}
		else
		{
			num_of_markers = latitudeArray.length;
		}
			
		for (var j=1; j<num_of_markers; j++)
		{
			if(latitudeArray.item(j).firstChild){
			var comp_lat = latitudeArray.item(j).firstChild.data;
			}
			if(longitudeArray.item(j).firstChild){
			var comp_lon = longitudeArray.item(j).firstChild.data;
			mypoint = new GLatLng(comp_lat,comp_lon);
			marker_str  = "<TABLE><TR><TD valign=top width=210px height=60px><FONT face=arial size=2 color=black><strong>"+addressArray.item(j).firstChild.data+"</strong><BR> Beds: "+bedsArray.item(j).firstChild.data+"<BR> Baths: "+bathsArray.item(j).firstChild.data+"<BR>Sold Price: "+sold_priceArray.item(j).firstChild.data+"<BR>Sold On: "+dispsolddate+"<BR></FONT></TD></TR></TABLE>";
			
			icon.image = "http://labs.google.com/ridefinder/images/mm_20_"+comp_icon_color[j]+".png";
			label = "<TABLE wifth=300px><TR><TD valign=top nowrap=nowrap><FONT face=sans-serif size=2 color=black><strong>"+addressArray.item(j).firstChild.data+"<BR>Sold Price: "+dispPrice[j]+"</FONT></TD></TR></TABLE>";
			
			
			var marker = createMarker(mypoint,label,marker_str,icon);
			//var new_marker = createMarkerNew(mypoint, icon, marker_str);//ABC
			//comp_markers[j] = new_marker;//ABC
			comp_markers[j] = marker
			//map.addOverlay(new_marker);
			}
			else
			{
				geocode_marker_str  = "<TABLE><TR><TD valign=top width=210px height=60px><FONT face=arial size=2 color=black><strong>"+addressArray.item(j).firstChild.data+"</strong><BR> Beds: "+bedsArray.item(j).firstChild.data+"<BR> Baths: "+bathsArray.item(j).firstChild.data+"<BR>Sold Price: "+sold_priceArray.item(j).firstChild.data+"<BR>Sold On: "+dispsolddate+"<BR></FONT></TD></TR></TABLE>";
		geocode_house_label = "<TABLE width=300px><TR><TD valign=top nowrap=nowrap><FONT face=sans-serif size=2 color=black><strong>"+addressArray.item(j).firstChild.data+"<BR>Sold Price: "+dispPrice[j]+"</FONT></TD></TR></TABLE>";
				geocode_index = j;
				geocoder.getLatLng(addressArray.item(j).firstChild.data,addHouseOverlayToMap);
	


			}

		}
		}
	
	//myMapdiv = document.getElementById("map");
	//myMapdiv.innerHTML = map
}

function show_schools_on_map()
{
		var label;
	    map.clearOverlays();
		if (latitude != 91)
		{
        map.setCenter(new GLatLng(latitude,longitude), 14);
		}
		else
		{
		map.setCenter(new GLatLng(school_latitudeArray.item(0).firstChild.data,school_longitudeArray.item(0).firstChild.data), 12);
		}
		
		
		// Create our "house" marker icon for ini_home
		icon_1 = new GIcon();
		icon_1.iconSize = new GSize(26, 34);
		icon_1.shadowSize = new GSize(38, 34);
		icon_1.image = "http://www.realivent.com/images/icons/house_blue.png";
		icon_1.shadow = "http://www.realivent.com/images/icons/house_shadow.png";
		icon_1.iconAnchor = new GPoint(6, 20);
		icon_1.infoWindowAnchor = new GPoint(10, 20);
		var geocoder = new GClientGeocoder();
		
		marker_str = "<TABLE width=200px height=30px><TR><TD valign=top><FONT face=arial size=2 color=black><strong>"+ini_address+"</strong></FONT><BR></TD></TR></TABLE>";
		label = "<TABLE width=200px><TR><TD><FONT face=arial size=2 color=black><strong>"+ini_address+"</strong></FONT></TD></TR></TABLE>";

		if (latitude != 91)
		{
		mypoint = new GLatLng(latitude,longitude);
		var marker = createMarker(mypoint, label,marker_str,icon_1);
		//map.addOverlay(createMarkerNew(mypoint, icon_1, marker_str));//ABC
		}
		else
		{
			geocoder.getLatLng(ini_address,
										function(point) {
            								if (!point) {
            								} else {
											var marker = new GMarker(point, icon_1);
											GEvent.addListener(marker, "click", function() {
												marker.openInfoWindowHtml(marker_str);});
											map.addOverlay(marker); 
            								}
          											} );
		}
		//now create pushpin icons for school
		
		icon.shadow = "http://www.realivent.com/images/icons/pushpin_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(36, 24);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(1, 5);
		
		for (var j=0; j<school_addressArray.length; j++)
		{
			if(school_latitudeArray.item(j).firstChild)
			{
				var comp_lat = school_latitudeArray.item(j).firstChild.data;
			}
			if(school_longitudeArray.item(j).firstChild)
			{
				var comp_lon = school_longitudeArray.item(j).firstChild.data;
				if (comp_lat != 91)
				{
					mypoint = new GLatLng(comp_lat,comp_lon);
					icon.image = "http://www.realivent.com/images/icons/pushpin_"+school_icon_color[j]+".png";
					marker_str = "<TABLE width=200px height=60px><TR><TD valign=top><FONT face=verdana size=2 color=black><strong>"+schoolnameArray.item(j).firstChild.data+"</strong><BR> Type: "+schooltypeArray.item(j).firstChild.data+"<BR> District: "+schooldistArray.item(j).firstChild.data+"<BR>API: "+schoolAPIArray.item(j).firstChild.data+"<BR></FONT></TD></TR></TABLE>";
					label = "<TABLE width=200px><TR><TD valign=top nowrap=nowrap><FONT face=sans-serif size=2 color=black><strong>"+schoolnameArray.item(j).firstChild.data+"<BR>API: "+schoolAPIArray.item(j).firstChild.data+"</FONT></TD></TR></TABLE>";
					var new_marker = createMarker(mypoint,label,marker_str,icon);
					//var new_marker = createMarkerNew(mypoint, icon, marker_str);//ABC
					school_markers[j] = new_marker;
					//map.addOverlay(new_marker);//ABC
				}
				else
				{
					geocode_marker_str = "<TABLE width=200px height=60px><TR><TD valign=top><FONT face=verdana size=2 color=black><strong>"+schoolnameArray.item(j).firstChild.data+"</strong><BR> Type: "+schooltypeArray.item(j).firstChild.data+"<BR> District: "+schooldistArray.item(j).firstChild.data+"<BR>API: "+schoolAPIArray.item(j).firstChild.data+"<BR></FONT></TD></TR></TABLE>";
					geocode_school_label = "<TABLE width=200px><TR><TD valign=top nowrap=nowrap><FONT face=sans-serif size=2 color=black><strong>"+schoolnameArray.item(j).firstChild.data+"<BR>API: "+schoolAPIArray.item(j).firstChild.data+"</FONT></TD></TR></TABLE>";

					geocode_index = j;
					geocoder.getLatLng(school_addressArray.item(j).firstChild.data,addSchoolOverlayToMap);
		


				}
			}
		}
	
}

function addHouseOverlayToMap(point)
	{
		if (!point) 
	  	{
	  		//alert("address  not found");
		}
		else
		{
			icon.image = "http://www.realivent.com/images/icons/mm_20_"+comp_icon_color[geocode_index]+".png";
			var marker = createMarker(point,geocode_house_label,geocode_marker_str,icon);
			//var marker = createMarkerNew(point,icon,geocode_marker_str);//ABC
			comp_markers[geocode_index]=marker;
			//map.addOverlay(marker);//ABC
		}
	}

function addSchoolOverlayToMap(point)
	{
		if (!point) 
	  	{
	  		//alert("address  not found");
		}
		else
		{
			icon.image = "http://www.realivent.com/images/icons/pushpin_"+school_icon_color[geocode_index]+".png";
			var marker = createMarker(point,geocode_school_label,geocode_marker_str,icon);	//ABC
			//var marker = createMarkerNew(point,icon,geocode_marker_str);	//ABC
			school_markers[geocode_index]=marker;
			//map.addOverlay(marker);//ABC	
		}
	}

function stateChanged() 
{ 

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


function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This example doesn't work in Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
} 

function GetXmlHttpRequestObject()
{
	var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
	alert("This example doesn't work in Opera") 
	return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 

	var strName="Msxml2.XMLHTTP"
	if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
	{
		alert ("in MSIE 5.5");
		strName="Microsoft.XMLHTTP"
	} 
	try
	{ 
		objXmlHttp=new ActiveXObject(strName)
		return objXmlHttp
	} 
	catch(e)
	{ 
		alert("Error. Scripting for ActiveX might be disabled") 
		return 
	} 
} 

if (navigator.userAgent.indexOf("Mozilla")>=0)
{

	objXmlHttp=new XMLHttpRequest();
	return objXmlHttp
}
}

function formatPrice(x) 
{
var price;
if((x >= 0) && (x < 1000000)) {
	price = x/1000;
	var result=Math.round(price*10)/10;
	result = Math.round(result);
	price = "$" + result + "K";
} else if(x>=1000000) {
	price = x/1000000;
	var result=Math.round(price*100)/100;
	//result = Math.round(result);
	//numlength = String(price).length;
	if(result.length > 4) {
		result = result.substr(0,4);
	}
	price = "$" + result + "M";
}
return price;
}


