    var map = null;
    var icone = null;
    var icone2 = null;
    var _position = null;
    var circle = null;
    var _rayon = 145;
    var _courantK = 20;
    var fleche = null;
    var _agrandir = 0;
    var TabPoint = new Array();

    /************************************ Script Search2 ********************************************************/
    var Marker0 = null;

   function positionCarte() {
	if (_position==null) map.setCenter(new GLatLng(43.705112,7.262222),11);
	else map.setCenter(_position);
    }

    /************************************ Informations **********************************************************/
    function setRayonPx(nouveau_rayon) {
	_rayon = nouveau_rayon;
    }

    function getRayonPx() {
	return _rayon;
    }

    function getRayon() {
	return _courantK;
    }

    function getXYCentre(coord) {
	if (!circle.isHidden()) {
	  var pointCentre = circle.getPoint();
	  if (coord==0) return pointCentre.lat();
	  if (coord==1) return pointCentre.lng();
	}
	else {
	  var flecheCentre = fleche.getPoint();
	  if (coord==0) return flecheCentre.lat();
	  if (coord==1) return flecheCentre.lng();
	}
    }

    function setPosParam(nouvelle_pos) {
	_position = nouvelle_pos;
    }

    function getPosParam() {
	return _position;
    }


    function agrandir()
    {
        if (_agrandir==0) {

		if (0<TabPoint.length) MarkerCentre();
                else {
		  var Last = document.getElementById("map").style.height;
     		  Last = Last.replace('px','');
		  var H = 2*Last;
		  document.getElementById("map").style.height = H + 'px';

		  var bounds = map.getBounds();
     		  var southWest = bounds.getSouthWest();
     		  var northEast = bounds.getNorthEast();
     		  var lngSpan = northEast.lng() - southWest.lng();
     		  var latSpan = northEast.lat() - southWest.lat();

		  map.panTo(new GLatLng( southWest.lat() + latSpan,southWest.lng() + lngSpan/2));
		  setPosParam(new GLatLng( southWest.lat() + latSpan/2,southWest.lng() + lngSpan/2));
		  circle.setPoint(getPosParam());
		  fleche.setPoint(getPosParam());
		}
		_agrandir = 1 - _agrandir;
	}

    }



   function reduire()
    {
        if (_agrandir==1) {
		if (0<TabPoint.length) MarkerCentre();
                else {
     		  var Last = document.getElementById("map").style.height;
     		  Last = Last.replace('px','');
		  var H = Last/2;
     		  document.getElementById("map").style.height = H +'px';

		  var bounds = map.getBounds();
     		  var southWest = bounds.getSouthWest();
     		  var northEast = bounds.getNorthEast();
     		  var lngSpan = northEast.lng() - southWest.lng();
     		  var latSpan = northEast.lat() - southWest.lat();

		  setPosParam(new GLatLng( southWest.lat(),southWest.lng() + lngSpan/2));
		  map.panTo(getPosParam());
		  circle.setPoint(getPosParam());
		  fleche.setPoint(getPosParam());
		}
		_agrandir = 1 - _agrandir;
	}
    }


    /*********************************** Fonctions basiques **********************************************************/
    function metresToPixels(lat,zoom) {

  	var c = 256 * Math.pow(2,zoom);        // taille du monde en pixels
  	var d = 12756000 * Math.PI;            // circonference de l'equateur
 	var d = d * Math.cos(lat*Math.PI/180); // circonference au niveau du point
	return c/d;                            // pixels par metre en fonction du zoom

    }


    function creaFleche() {
	if (fleche!=null) map.removeOverlay(fleche);
	fleche = new GMarker(getPosParam(),icone2);
	map.addOverlay(fleche);
	if (fleche.isHidden()) fleche.hide();
    }


    function Desactive() {
	if (!circle.isHidden()) {
		circle.hide();
		_courantK = 0;
		fleche.show();
		fleche.setPoint(getPosParam());
	}
	else creaFleche();
    }


    function CreaCercle() {
	if (circle!=null) map.removeOverlay(circle);
	setRayonPx(_courantK * 2000 * metresToPixels(_position.lat(), map.getZoom()));
	<!-- cercle-carto-100.png-->
	<!--  cercle-bleu-250.png  -->
	circle = new EInsert(getPosParam(), "/img/g3/js/cercle-carto-100.png", new GSize(getRayonPx(),getRayonPx()), map.getZoom());
      	map.addOverlay(circle);
      	circle.makeDraggable();
	if (circle.isHidden()) circle.hide();

      	GEvent.addListener(circle, "dragend", function (pt) {
		setPosParam(pt);
		_cercleBouge = 0;
		CentreDessinCarte(1);
		afficheBoutonApCr();
      	});
    }


    function EtendRecherche(k) {
    	$('fcrit').d.value=k;
    	
	if (circle.isHidden() || _courantK!=k) {
		_courantK = k;
		circle.show();
		fleche.hide();
		CreaCercle();
	}
	else creaFleche();

	$('fcrit').chgmap.value='1';
	afficheBoutonApCr();
    }


    function InitDistance(k) {
    	$('fcrit').d.value=k;
    	
	if (_courantK!=k) {
		_courantK = k;
		setPosParam(map.getCenter());
		if (0<k) {
	  	  _courantK = k;
	  	  CreaCercle();
	  	  circle.show();
	  	  fleche.hide();
		}
		else {
		  creaFleche();
	  	  circle.hide();
	  	  fleche.show();
		}
	}
	else {
		setPosParam(map.getCenter());
		if (_courantK>0) {
		  fleche.hide();
		  circle.show();
		}
		else {
		  circle.hide();
		  fleche.show();
		}
	}

	$('fcrit').chgmap.value='1';
    }


    function CentreDessinCarte(mode) {
	var bounds = map.getBounds();
     	var southWest = bounds.getSouthWest();
     	var northEast = bounds.getNorthEast();
     	var lngSpan = northEast.lng() - southWest.lng();
     	var latSpan = northEast.lat() - southWest.lat();

	if (mode==0) {		
		if (_agrandir==0) setPosParam(new GLatLng( southWest.lat() + latSpan/2,southWest.lng() + lngSpan/2));
		else setPosParam(new GLatLng( southWest.lat(),southWest.lng() + lngSpan/2));

		if (!circle.isHidden()) CreaCercle();
		if (!fleche.isHidden()) creaFleche();
	}
	else {
		if (_agrandir==0) map.panTo(getPosParam());
		else {
			var _tmpPoint = new GLatLng(_position.lat() + latSpan/2,_position.lng());
			setPosParam(_tmpPoint);
			map.panTo(_tmpPoint);
		}
	}
    }


    /**************************************** GoogleMap ********************************************/
    function loadGMap() {

      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());


	// Position initialisation de la carte *****************************************************************
	positionCarte();


	/********** Les icônes *******************/
	icone = new GIcon();
	icone.image = "http://labs.google.com/ridefinder/images/mm_20_white.png";
	icone.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	icone.iconSize = new GSize(15, 30);
	icone.shadowSize = new GSize(22, 20);
	icone.iconAnchor = new GPoint(6, 20);
	icone.infoWindowAnchor = new GPoint(5, 1);

	icone2 = new GIcon();
	icone2.image = "http://labs.google.com/ridefinder/images/mm_20_white.png";
	icone2.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	icone2.iconSize = new GSize(12, 20);
	icone2.shadowSize = new GSize(22, 20);
	icone2.iconAnchor = new GPoint(6, 20);
	icone2.infoWindowAnchor = new GPoint(5, 1);


	/******************* Cercle et fleche *************************/
	setPosParam(map.getCenter());
	CreaCercle();
	circle.hide();

	// Creation du pointeur sur centre et initialisation
	creaFleche();


	/***** Evenement GoogleMap **********************************/
	GEvent.addListener(map, "dragend", function(){
		CentreDessinCarte(0);
		$('fcrit').chgmap.value='1';
		afficheBoutonApCr();
	});


	GEvent.addListener(map, "zoomend", function( oldLevel,  newLevel) {
		if (oldLevel!=newLevel) {
		  if (!circle.isHidden()) CreaCercle();
		  if (!fleche.isHidden()) creaFleche();
		}		
	});

	
	/* ssa */ 
	function createMarker(point, number) {  
		var marker = new GMarker(point);

		GEvent.addListener(marker, "click", function() {    
			marker.openInfoWindowHtml("Marker #<b>" + number + "</b>");  
		});

		return marker;
	}
      }

    }


    /****************************************************************************************************************/
    function applique_critere() {
    	//alert("AppliqueCritreres \n" + getXYCentre(0) + "\n" + getXYCentre(1));

	// Redéfini position et redessine de la fléche ou du cercle
	setPosParam(new GLatLng(getXYCentre(0) , getXYCentre(1)));
	circle.setPoint(getPosParam());
	fleche.setPoint(getPosParam());

	// submit
    	var reponsevaleur="none";
		$('fcrit').c1.value=getXYCentre(0);
		$('fcrit').c2.value=getXYCentre(1);
		$('fcrit').submit();
    }



    //]]>
