function initialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
	map.addControl(new GLargeMapControl());
    map.setCenter(new GLatLng(38, -98), 4);
	message = document.getElementById("message");
	message.innerHTML ='Please enter either a (1) <b>Postal Code</b> (2) <b>City and State</b> or (3) <b>Full Address</b> and <b>click the "Find Dealers"</b> button to find Grex Power Tools dealers within a <b>50 mile</b> radius from your location.';
  }
}
 
function finddealers(){

  document.getElementById("map_img").setAttribute("class","map_bot");
  document.getElementById("map_img").setAttribute("className","map_bot");
  
  var location = document.getElementById('location').value;
  
  var url="map.php5";
  url=url+"?location=" + location;
  url=url+"&sid="+Math.random();
  
  map.clearOverlays();
  GDownloadUrl(url, function(data, responseCode) {
    var xml = GXml.parse(data);
    var markers = xml.documentElement.getElementsByTagName("marker");
	if (markers.length == 0){
	  map.setCenter(new GLatLng(38, -98), 4);
	  message.innerHTML = '<div class="red">There are currently no Grex Grex Power Tools dealers within a 50 mile radius from your location. In the meantime, please visit one of our online dealers or contact us for other options. Thank you.</div>';
	}
	else {
	message.innerHTML ='Please enter either a (1) <b>Postal Code</b> (2) <b>City and State</b> or (3) <b>Full Address</b> and <b>click the "Find Dealers"</b> button to find Grex Power Tools dealers within a <b>50 mile</b> radius from your location.';
    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 zip = markers[i].getAttribute("zip");
	  var phone = markers[i].getAttribute("phone");
	  var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
	  var marker = createMarker(point, name, address, city, state, zip, phone);
	  map.addOverlay(marker);
    }
	
	var geocoder = new GClientGeocoder();
    geocoder.getLatLng(location, function(latlng) {map.setCenter(latlng, 8);});
    }
  });


 
}

function createMarker(point, name, address, city, state, zip, phone) {
  var marker = new GMarker(point);
  var html = "<b>" + name + "</b> <br/>" + address + "<br/>" + city + ", " + state + " " + zip + "<br/>" + phone;
  GEvent.addListener(marker, 'click', function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}