//
    var map;
    var geocoder;

    function load() {
      if (GBrowserIsCompatible()) {
        geocoder = new GClientGeocoder();
        map = new GMap2(document.getElementById('map'));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(40, -100), 4);
      }
	  else alert("This browser is not compatible with Google Maps.");
    }

   function searchLocations() {
	   var zipcode = document.getElementById('zipcode').value;
	   if (zipcode == '') {
		   alert("Please enter a zipcode.");
		   return;
	   }
	   
     //var address = document.getElementById('addressInput').value;
     geocoder.getLatLng(zipcode, function(latlng) {
       
	if (!latlng) {
         alert(zipcode + ' not found');
       } else {
		   
         searchLocationsNear(latlng);
       }
     });
   }

   function searchLocationsNear(center) {
     var radius = document.getElementById('radiusSelect').value;
     
	 var searchUrl = 'php/'+'phpsqlsearch_genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
	 //alert('b');
	 //alert(String(radius));
	 //alert(searchUrl);
	 
     
	 GDownloadUrl(searchUrl, function(data) {
	
       var xml = GXml.parse(data);
	   var markers = xml.documentElement.getElementsByTagName('marker');
       map.clearOverlays();
	   //alert(String(data));
		//alert(String(markers.length));
       var sidebar = document.getElementById('sidebar');
       sidebar.innerHTML = '';
       if (markers.length == 0) {
         sidebar.innerHTML = 'No results found.';
         map.setCenter(new GLatLng(40, -100), 4);
		 
         return;
       }
		
       
       var bounds = new GLatLngBounds();
       for (var i = 0; i < markers.length; i++) {
         var name = markers[i].getAttribute('name');
         var address = markers[i].getAttribute('address');
         var city = markers[i].getAttribute('city');
         var state = markers[i].getAttribute('state');
         var country = markers[i].getAttribute('country');
         var zip = markers[i].getAttribute('zip');
         var phone = markers[i].getAttribute('phone');
         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, city, state, country, zip, phone);
         map.addOverlay(marker);
         var sidebarEntry = createSidebarEntry(marker, name, address, city, state, country, zip, phone, distance);
         sidebar.appendChild(sidebarEntry);
		 
         bounds.extend(point);
       }
       map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
     });
   }

    function createMarker(point, name, address, city, state, country, zip, phone) {
      var marker = new GMarker(point);
      //var html = '<b>' + name + '</b> <br/>' + address;
	  
      var html = '<div style="font-family:Helvetica, Lucida Grande, Geneva, Verdana, Arial, sans-serif; color: #8e0064; font-size: 12px;"><b>' + name + '</b> <br/>' + address + '<br/>' + city + ', '+ state + ' '+zip+ '</br>'+ phone+'</div>';
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }

    function createSidebarEntry(marker, name, address, city, state, country, zip, phone, distance) {
      var div = document.createElement('div');
      var html = '<b>' + name + '</b> (' + distance.toFixed(1) + ')<br/>' + address + '<br/>' + city + ', '+ state + ' '+zip+ '</br>'+ phone;
      div.innerHTML = html;
	  
	  //div.className = "bodylinks";
	  
	  
      div.style.width = '373px';	// had to set it explicitly because of IE  subtract scroll bar wideth *********************
	  div.style.width = '355px';
	  
	  div.style.fontFamily =  'Helvetica, Lucida Grande, Geneva, Verdana, Arial, sans-serif';  
	  div.style.color = '8e0064'; 
	  div.style.fontSize = '12px'; 
	  //div.style.lineHeight = '18px'; 
	  //div.style.textDecoration = none; 
	  //div.style.fontWeight = normal;  
	  //div.style.textAlign = left; 
	  //div.style.marginRight = '20px';
		
	  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;
    }

  
