 var iconBlue = new GIcon(); 
    iconBlue.image = 'images/blue_icon.png';
    iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconBlue.iconSize = new GSize(21, 32);
    iconBlue.shadowSize = new GSize(22, 20);
    iconBlue.iconAnchor = new GPoint(6, 20);
    iconBlue.infoWindowAnchor = new GPoint(5, 1);

    var iconRed = new GIcon(); 
    iconRed.image = 'images/red_icon.png';
    iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconRed.iconSize = new GSize(21, 32);
    iconRed.shadowSize = new GSize(22, 20);
    iconRed.iconAnchor = new GPoint(6, 20);
    iconRed.infoWindowAnchor = new GPoint(5, 1);

    var customIcons = [];
    customIcons["Commercial"] = iconBlue;
    customIcons["Residential"] = iconRed;
	var map;
    var geocoder;

	
    function load() {
      if (GBrowserIsCompatible()) {
		 geocoder = new GClientGeocoder();
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(37.09024,-95.712891), 4);

        GDownloadUrl("mapgenxml.php", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
            var name = markers[i].getAttribute("name");
            var address = markers[i].getAttribute("address");
            var type = markers[i].getAttribute("type");
			var num = markers[i].getAttribute("num");
			var city = markers[i].getAttribute("city");
			var id = markers[i].getAttribute("id");
			
			var rooms = markers[i].getAttribute("rooms");
			var bedrooms = markers[i].getAttribute("bedrooms");
			var bathrooms = markers[i].getAttribute("bathrooms");
			if(rooms == '')
				rooms='N/A'
			if(bedrooms == '')
				bedrooms='N/A'
			if(bathrooms == '')
				bathrooms='N/A'
			
				var price = markers[i].getAttribute("property_price");
				var location = markers[i].getAttribute("location");
				if(location == '')
					location='N/A'
				var property_pic = markers[i].getAttribute("property_pic");
				
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                    parseFloat(markers[i].getAttribute("lng")));
            var marker = createMarker(point, name, address, type,city,location,property_pic,id,rooms,bedrooms,bathrooms,price);
			var sidebarEntryOne = createSidebarEntryFirst(marker, name, address,num);
			document.getElementById('msgPlaceMap').appendChild(sidebarEntryOne);
            map.addOverlay(marker);
          }
        });
      }
    }
	function searchLocations() {	
	var address = document.getElementById('property_address').value;
	var city = document.getElementById('city').value;
	var x;
	if(address != '' && city != '')
		x=address+','+city;
	else if(address == '' && city!='')
		x=city;
	else if(address != '' && city=='')
		x=address;
	else
	{
		document.getElementById('total_records').innerHTML='Please provide address or city to search';
		document.getElementById('msgPlaceMap').innerHTML="";
	}

	geocoder.getLatLng(x, function(latlng) {
		if (!latlng) {
			document.getElementById('total_records').innerHTML='<b>Total Records:</b> 0';
			document.getElementById('msgPlaceMap').innerHTML='"'+ x + '" not found';
		} else {
		  searchLocationsNear(latlng);
		}
	});
}
	function searchLocationsNear(center) {
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(center.lat(),center.lng()), 10);
		var radius = document.getElementById('radius').value;
		var rooms = document.getElementById('rooms').value;
		var bedrooms = document.getElementById('bedrooms').value;
		var bathrooms = document.getElementById('bathrooms').value;
		
		/*alert("lat="+center.lat());
		
		alert("lang="+center.lng());*/
		var price_min = document.getElementById('price_min').value;
		var price_max = document.getElementById('price_max').value;
		var searchUrl = 'mapsearchgenxml.php?lat=' + center.lat() + '&lng=' + center.lng() +'&radius='+radius+'&rooms='+rooms+'&bedrooms='+bedrooms+'&bathrooms='+bathrooms+'&price_min='+price_min+'&price_max='+price_max;
		GDownloadUrl(searchUrl, function(data) {
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName('marker');
			map.clearOverlays();
		
			if (markers.length == 0) {
				document.getElementById('total_records').innerHTML='<b>Total Records:</b> 0';
				document.getElementById('msgPlaceMap').innerHTML='Address not found';
				map.setCenter(new GLatLng(37.09024,-95.712891), 3);
				return;
			}
	   	document.getElementById('msgPlaceMap').innerHTML='';
			for (var i = 0; i < markers.length; i++) {
				var name = markers[i].getAttribute("name");
				var address = markers[i].getAttribute("address");
				var type = markers[i].getAttribute("type");
				var num = markers[i].getAttribute("num");
				
				var city = markers[i].getAttribute("city");
				var location = markers[i].getAttribute("location");
				if(location == '')
					location='N/A'
				var property_pic = markers[i].getAttribute("property_pic");
				var id = markers[i].getAttribute("id");
				
				var rooms = markers[i].getAttribute("rooms");
				var bedrooms = markers[i].getAttribute("bedrooms");
				var bathrooms = markers[i].getAttribute("bathrooms");
				var price = markers[i].getAttribute("property_price");
				
				if(rooms == '')
					rooms='N/A'
				if(bedrooms == '')
					bedrooms='N/A'
				if(bathrooms == '')
					bathrooms='N/A'
				var distance = parseFloat(markers[i].getAttribute('distance'));
				var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
										parseFloat(markers[i].getAttribute("lng")));
				var marker = createMarker(point, name, address, type,city,location,property_pic,id,rooms,bedrooms,bathrooms,price);
				 var sidebarEntry = createSidebarEntry(marker, name, address, distance,num);
				 document.getElementById('msgPlaceMap').appendChild(sidebarEntry);
				map.addOverlay(marker);
			}
	  });
	}

    function createMarker(point, name, address, type,city,location,property_pic,id,rooms,bedrooms,bathrooms,price) {
      var marker = new GMarker(point, customIcons[type]);
      var html = "<div><div style='float:left; display:block;'><a href='property_listing_details.php?property_id="+id+"'><img src='"+property_pic+"' border='0' width='100px' height='72px'></a></div><div style='padding-left:10px; float:left; display:block;'><b><a href='property_listing_details.php?property_id="+id+"'>" + name + "</a></b> <br/><b>Address:</b>" + address +","+location+"<br>"+city+"<br><b>Rooms:</b>"+rooms+", <b>Beds:</b>"+bedrooms+", <b>Baths:</b>"+bathrooms+"<br><b>Price:</b>"+price+" USD</div></div>";
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }
	function createSidebarEntry(marker, name, address, distance,num) {
		document.getElementById("total_records").innerHTML='<b>Total Records:</b>'+num;
		var div = document.createElement('div');
		var html = '<b>' + name + '</b> ';
		div.innerHTML = html;
		div.className = 'left-al';
		div.style.cursor = 'pointer';
		div.style.marginBottom = '5px'; 
		GEvent.addDomListener(div, 'click', function() {
			GEvent.trigger(marker, 'click');
		});
		GEvent.addDomListener(div, 'mouseover', function() {
			div.style.backgroundColor = '#eee';
		});
		GEvent.addDomListener(div, 'mouseout', function() {
			div.style.backgroundColor = '#fff';
		});
		return div;
    }
	function createSidebarEntryFirst(marker, name, address,num)
	{
		document.getElementById("total_records").innerHTML='<b>Total Records:</b>'+num;
		var div = document.createElement('div');
		var html =  name ;
		div.innerHTML = html;
		div.className = 'left-al';
		div.style.cursor = 'pointer';
		div.style.marginBottom = '5px'; 
		GEvent.addDomListener(div, 'click', function() {
			GEvent.trigger(marker, 'click');
		});
		GEvent.addDomListener(div, 'mouseover', function() {
			div.style.backgroundColor = '#eee';
		});
		GEvent.addDomListener(div, 'mouseout', function() {
			div.style.backgroundColor = '#fff';
		});
		return div;
	}

    //]]>
