// JavaScript Document
	var map;
    var geocoder;
    var address;
	var radius;
 
    function initialize() {
      map = new GMap2(document.getElementById("Karte"));
      map.setCenter(new GLatLng(51.158348,10.441211),6);
      map.setUIToDefault();
      GEvent.addListener(map, "click", getAddress);
      geocoder = new GClientGeocoder();
    }
    
    function getAddress(overlay, latlng) {
      if (latlng != null) {
        address = latlng;
        geocoder.getLocations(latlng, showAddress);
      }
    }
 
    function showAddress(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Status Code:" + response.Status.code);
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(
        '<b>Address:</b>' + place.address + '<br>' +
        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
      }
	  for (var i = 0; i <= 2; i++) {
			if(document.forms[1].radius[i].checked == true) {
				radius=document.forms[1].radius[i].value;
			}
	  }
	  window.location = "http://www.fabrikverkauf-adressen.de/fabrikverkauf_geo2.php?lat_nahe=" + place.Point.coordinates[1] + "&lng_nahe=" + place.Point.coordinates[0] + "&radius=" + radius + "&location=" + document.forms[1].location.value;
    }
	function addAddressToMap(response) {
      if (!response || response.Status.code != 200) {
        alert("Adresse kann nicht gefunden werden");
      } else {
        map.clearOverlays();
		place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
		marker = new GMarker(point);
		map.addOverlay(marker);
		map.setCenter(point, 10);
		for (var i = 0; i <= 2; i++) {
			if(document.forms[1].radius[i].checked == true) {
				radius=document.forms[1].radius[i].value;
			}
	    }
		window.location = "http://www.fabrikverkauf-adressen.de/fabrikverkauf_geo2.php?lat_nahe=" + place.Point.coordinates[1] + "&lng_nahe=" + place.Point.coordinates[0] + "&radius=" + radius + "&location=" + document.forms[1].location.value;
      }
    }
	function showLocation() {
      /*for (var i = 0; i <= 2; i++) {
			if(document.forms[1].radius[i].checked == "checked") {
				radius=document.forms[1].radius[i].value;
			}
	  }*/
	  var address = document.forms[1].location.value + ', de';
      geocoder.getLocations(address, addAddressToMap);
    }
