	
	/*-------------fonction qui nous permet de faire afficher l'indicateur de chargement lorsqu'on passe par de l'ajax--------------------------------------*/
	/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
	/*var myGlobalHandlers = {
		onCreate: function(){
				//$('loader').setStyle({display: 'block'});
		 },
		onComplete: function(){
				//$('loader').setStyle({display: 'none'});
				alert(i + " erreurs ");
		 }
	};
	Ajax.Responders.register(myGlobalHandlers);
	*/
	/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
	
	function findGeocode(address,une_enseigne,une_adresse,une_suite_adresse,address2,un_id_magasin) {
		var type_requete = 'json_short'; // json_all ou json_short
		var url = '../../../templates/1/ajax/proxy.php';
		// appel du proxy et affichage des points
		new Ajax.Request(url,{
			method: 'post',
			asynchronous : true,
			parameters : { 
				adresse : address, 
				adresse2 : address2,
				id_magasin : un_id_magasin,
				type_requete : type_requete
			},
			evalJSON : true,
			onComplete : function(transport) {	
				if(type_requete == 'json_all'){
					//récuperation du code 
					var code_retour = transport.responseJSON.Status.code;
					
					//aucune reponse trouvé!!!
					if(code_retour==602){
						i++;
						//$('erreur_gmap').insert({after: '<p>Impossible de géolocaliser : ' + address + ' ou ' + address2 + '</p>'});
					}else{
						if(code_retour==200){ //reponse ok!!!
							//récuperation des coordonnées gps							
							var place = transport.responseJSON.Placemark[0];
							var point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);

							// création du marker
							var marker = createMarker(point, une_enseigne, une_adresse, une_suite_adresse, MonIcon, un_id_magasin);
							map.addOverlay(marker);
							return marker;
						}	
					}
				}else{
					if(type_requete == "json_short"){
						//récuperation des valeurs recus google maps
						var code_retour = transport.responseJSON.statut;
						var latitude = transport.responseJSON.latitude;
						var longitude = transport.responseJSON.longitude;
						
						//aucune reponse trouvé!!!
						if(code_retour==602){
							i++;
							//$('erreur_gmap').insert({after: '<p>Impossible de géolocaliser : ' + address + ' ou ' + address2 + '</p>'});
						}else{
							if(code_retour==200){ //reponse ok!!!
								//récuperation des coordonnées gps							
								var point = new GLatLng(latitude,longitude);

								// création du marker
								var marker = createMarker(point, une_enseigne, une_adresse, une_suite_adresse, MonIcon, un_id_magasin);
								map.addOverlay(marker);
								return marker;
							}	
						}
					}	
				}
			}
		});
	}
	
	//placer un point sur tournon sur rhone : (45.06867131826394, 4.830894470214844)
	//faire afficher une infobulle stylée
	function createMarker(point, name, address,suite_address, type, id_magasin) {
	  var marker = new GMarker(point, type);
		GEvent.addListener(marker, 'click', function() {
			var maxContentDiv = document.createElement('div');
			maxContentDiv.innerHTML = 'Chargement...'
			marker.openInfoWindowHtml("<table><tr><td>" + name +"</td><tr><td>" + address + "</td></tr><tr><td></td></tr><tr><td>" + suite_address + "</table>");
				//{,maxContent: maxContentDiv, 
				// maxTitle: "Mini Fiche : "}
			var iw = map.getInfoWindow();
			
			
			//on met à jour l'id du magasin :
			
			$('id_magasin').value = id_magasin;
			
			//on fait afficher le formulaire de contact du magasin
			$('block_form_magasin').style.display = 'block';
			
			map.setCenter(point, 12);
			
			/*
			GEvent.addListener(iw, "maximizeclick", function() {
				GDownloadUrl("minifiche.php", function(data) { //attention l'url doit etre sur le meme site sinon ca ne passe pas... les données retournées sont dans data.
					maxContentDiv.innerHTML = data; //un ptit coup d'ajax pour recuperer les infos d'une page
				});
			  });
			 */
			GEvent.addListener(iw, "restoreend", function() {
				//GDownloadUrl("http://www.cotedor-tourisme.com", function(data) {
					//alert('petit');
					//document.getElementById('navmap').style.display='';
				//});
			});
			
			GEvent.addListener(iw, "closeclick", function() {
				$('block_form_magasin').style.display = 'none';
				$('id_magasin').value = 0;
				//GDownloadUrl("http://www.cotedor-tourisme.com", function(data) {
					// document.getElementById('navmap').style.display='';
				//});
			});
		});
	  
		//--- infoalt
		/*
		var infoalt = new InfoAlt(marker,name,4);
		marker.infoalt = infoalt;
		map.addOverlay(infoalt);
		GEvent.addListener(marker,'mouseover',function(){
		this.infoalt.show();
		});
		GEvent.addListener(marker,'mouseout',function(){
		this.infoalt.hide();
		});
		//FIN --- infoalt
		
		*/
	  return marker;
	}
	
	function InfoAlt(marker, text, padding){
		this.marker_ = marker;
		this.text_ =  text;
		this.padding_ = padding;
	}
	
	InfoAlt.prototype.remove = function(){
		this.div_.parentNode.removeChild(this.div_);
	}

	InfoAlt.prototype.copy = function(){
		return new InfoAlt(this.marker_,this.text_,this.padding_);
	}

	InfoAlt.prototype.redraw = function(force){
		if (!force) return;
		var markerPos = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
		var iconAnchor = this.marker_.getIcon().iconAnchor;
		var xPos = Math.round(markerPos.x - this.div_.clientWidth / 2);
		var yPos = markerPos.y - iconAnchor.y - this.div_.clientHeight - this.padding_;
		this.div_.style.top = yPos + 'px';
		this.div_.style.left = xPos + 'px';
	}

	InfoAlt.prototype.show = function(){
		this.div_.style.visibility = 'visible';
	}

	InfoAlt.prototype.hide = function(){
		this.div_.style.visibility = 'hidden';
	}
