//<![CDATA[
this.mal = null
this.geocoder = null

function load(point) {
  if (GBrowserIsCompatible()) {
    this.marker = null;
    this.map = new GMap2(document.getElementById("map"));
    this.map.setCenter(new GLatLng(47.0, 3.0), 5);
    this.map.addControl(new GSmallMapControl());
    this.map.addControl(new GMapTypeControl());
    this.map.enableScrollWheelZoom();
    this.geocoder = new GClientGeocoder();

    if (point)
    {
      map.setCenter(point, 5);
      this.marker = new GMarker(point, {draggable: true});
      map.addOverlay(this.marker);
    }

    var myEventListener = GEvent.bind(this.map, "click", this, function(marker,latlng) {
      if (this.marker == null) {
	if (latlng) {
	  this.marker = new GMarker(latlng, {draggable: true});
	  this.map.addOverlay(this.marker)
	}
      } else {
	GEvent.removeListener(myEventListener);
      }
    }); 
  }
}

function fillAddress(address) {
  if (this.geocoder && this.marker) {
    this.geocoder.getLocations(this.marker.getLatLng(), function(response) {
      if(response && response.Status.code == 200)
	{
	  place = response.Placemark[0];
	  address.value = place.address;
	}
    });
  }
}
function showAddress(address) {
  if (this.geocoder) {
    this.geocoder.getLatLng(
		       address,
		       function(point) {
      if (point) {
	this.map.setCenter(point, 15);
	if (this.marker != null)
	  {
	    this.map.removeOverlay(this.marker);    
	  }
	this.marker = new GMarker(point, {draggable: true});
	this.map.addOverlay(this.marker)
	  
      }
    }
		       );
  }
}

function validateForm(form) {
  if (this.marker == null)
    {
      alert("Vous devez positionner le marqueur en cliquant sur la carte");
      return(false);
    }
  if (form.animal.value == "empty")
    {
      alert("Vous devez specifier l'espèce de l'animal");
      return(false);
    }
  if (form.status.value == "empty")
    {
      alert("Vous devez specifier si l'animal a ete perdu ou trouvé");
      return(false);
    }
  if (form.email.value == "")
    {
      alert("Vous devez specifier une adresse email valide");
      return(false);
    }
  if (form.email.value != form.email2.value)
    {
      alert("Les deux emails ne concordent pas");
      return(false);
    }
  if (form.email.value == "root@localhost")
    {
      alert("Fred, mets TON email, boulet! :D");
      return(false);
    }
  if (form.author.value == "")
    {
      alert("Vous devez specifier un nom ou un pseudonyme");
      return(false);
    }

  latlng = this.marker.getLatLng(); 
  form.lat.value = latlng.lat(); 
  form.lng.value = latlng.lng(); 
  return(true);
}


//]]>
