//<![CDATA[
    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(43.891310, -85.521614), 6);
		
      }
    }

   function searchLocations() {
     var address = document.getElementById('addressInput').value;
     geocoder.getLatLng(address, function(latlng) {
       if (!latlng) {
         alert(address + ' not found');
       } else {
         searchLocationsNear(latlng);
       }
     });
   }
   //$var = geocoder.getLatLng(address)

   function searchLocationsNear(center) {
     var radius = document.getElementById('radiusSelect').value;
     var searchUrl = 'http://mildmi.org/includes/gmaps_genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;		 
     GDownloadUrl(searchUrl, function(data) {
       var xml = GXml.parse(data);
       var markers = xml.documentElement.getElementsByTagName('marker');
       map.clearOverlays();

       var sidebar = document.getElementById('sidebar');
       sidebar.innerHTML = '';
       if (markers.length == 0) {
         sidebar.innerHTML = 'No results found.';
          map.setCenter(new GLatLng(43.891310, -85.521614), 6);
         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 Phone = markers[i].getAttribute('Phone');
		 var Website = markers[i].getAttribute('Website');
		 var city = markers[i].getAttribute('city');
		 var state = markers[i].getAttribute('state');
		 var zip = markers[i].getAttribute('zip');
         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, Phone, Website, city, state, zip);
         map.addOverlay(marker);
         var sidebarEntry = createSidebarEntry(marker, name, address, distance, Phone, Website, city, state, zip);
         sidebar.appendChild(sidebarEntry);
         bounds.extend(point);
       }
       map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
     });
   }
     //var x = hello.goobye;
    function createMarker(point, name, address, Phone, Website, city, state, zip) {
      var marker = new GMarker(point);
	   
	  //THIS IS WEHRE YOU CAN CHANGE WINDOW INFORMATION!	   
      //var html = '<div style="width: 325px; height: 110px;"> <b>' + name + '</b> <br />' + 'Address: ' +  address + '<br />' + 'Phone: ' + Phone + '<br />' + 'Web Site: ' + Website + '<br /></a></div>' ;
			var html = '<b>' + name + '</b> <br />' + address + '<br />' + city + ' ' + state + ' ' + zip + '<br /><br />' + Phone + '<br />' + '<a href="' + Website + '" target="_blank">' + Website + '</a>' ;
      GEvent.addListener(marker, 'click', function() {
		
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }

    function createSidebarEntry(marker, name, address, distance, Phone, Website, city, state, zip) {
      var div = document.createElement('div');
      //var html = '<b>' + name + '</b> (' + distance.toFixed(1) + ')<br/>' + address;
			var html = '<div style="background: #44A2FF; padding: 5px;"><b>' + name + '</b> <br />' + address + '<br />' + city + ' ' + state + ' ' + zip + '<br />' + Phone + '<br />' + '<a href="' + Website + '" target="_blank">' + Website + '</a></div>'
      div.innerHTML = html;
      div.style.cursor = 'pointer';
	  //div.style.height = '100px';  //changes height of each sidebar entry
	  div.style.width = '200px';
	  //div.style.fontSize = '15px';
	  div.style.backgroundColor = '44A2FF';
      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 = '44A2FF';
      });
      return div;
    }
    //]]>
