var map = null;
var geocoder = null;

    function geocoder_init(adress,i) {
      if (GBrowserIsCompatible()) {
       if(map==null) {map = new GMap2(document.getElementById("mapgeocoder"));
         map.setCenter(new GLatLng(44.091007,6.231478),7);
        geocoder = new GClientGeocoder();};var h=$('geocodesub_'+i).getCoordinates();h.top-=300;h.left-=500;
		$('mapgeo').setStyles({'top':h.top+'px','left':h.left+'px'});
		if(adress!='' && adress!=' false') {showAddress(adress+', France',i);} else {alert('adresse incomplète');};
		
      }
    }

    function showAddress(address,i) {
      if (geocoder) {

        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " non trouvée");
            } else {
              map.setCenter(point, 13);  map.clearOverlays();
			  var marker=new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address+'<br />'+point.x+','+point.y+'<br /><a href="#" onclick="getgeocode('+point.x+','+point.y+','+i+');return false;"> Cliquer ici pour valider ces valeurs <br />et renseigner la latitude et la longitude correspondant &agrave; l'+"'"+'adresse fournie</a>');
            }
          }
        );
      }
    }
function addAddressToMap(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("\"" + address + "\" non trouvée "+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(place.address + '<br>' +point+ 
      '<b>Code pays :</b> ' + place.AddressDetails.Country.CountryNameCode+'<br /><b>Pr&eacute;cision : </b>'+response.Accuracy+'<br /><a href="#" onclick="getgeocode('+point.y+','+point.x+','+i+');return false;">Cliquer ici pour valider ces valeurs <br />et renseigner la latitude et la longitude correspondant &agrave; l'+"'"+'adresse fournie</a>');return 1;
  }
}
function getgeocode(x,y,i) {
    $('geocode_'+i).value=x+','+y;
  $('mapgeo').setStyle('display','none');
  };
