  var circle;
	var centerMarker;
	var circleUnits;
	var map;
	var geocoder = null;
    var nbdebiens;
    
    
    /*******************************************
    *	CrŽe la map et le geocoder et fait 
    *	appel ˆ chercher().
    *******************************************/
    function initialize(longitude,latitude,inidice_zoom) {
    	
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(longitude,latitude),inidice_zoom);
 		map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
		geocoder = new GClientGeocoder();
		nbdebiens=0;
    	chercher(geocoder,map);
    	  }
    }
    
    /*******************************************
    *	teste une adresse et Žcrit Oui ou Non 
    *	(ˆ intŽgrer avec du code php)
    *******************************************/
    function verifbien(){
    	var adresse = $('map_addresse').value;
    	var codepostal = $('map_codepostal').value;
    	var ville=$('map_ville').value;
    	var achercher = adresse+' '+codepostal+' '+ville;
		var geocoder = new GClientGeocoder();
		var inputfound = '<input type="hidden" class="cases" name="map_found" value="';
		var inputfound2 = '"/>';
		var inputlatlng = '<input type="hidden" class="cases" name="map_latlng" value="';
		
		
		if (geocoder) {
          geocoder.getLatLng(
            achercher,
            function(point) {
              if (!point) {
              	//console.log("non");
                $('bienfound').innerHTML="Non"; 
                $('bienfound').innerHTML+= inputfound+'0'+inputfound2;
                $('bienfound').innerHTML+= inputlatlng+'(0,0)'+inputfound2;
              } else {
              	//console.log("oui");
            	$('bienfound').innerHTML="Oui";
            	$('bienfound').innerHTML+= inputfound+'1'+inputfound2;
            	$('bienfound').innerHTML+= inputlatlng+point+inputfound2;
           	  }
		    }
    	  );
      	}
      	
      	// Reste ˆ entrer les infos dans la base
    	
    }
  
  	/*******************************************
    *	Recupere la ville et appelle drawCircle() 
    *	(ˆ intŽgrer avec du code php)
    *******************************************/
  	function callCircle(){
  		situerlaville(geocoder,map);
  		
  		setTimeout(function(){ 
  			centerMarker=$('villerayon').retrieve('pointVille'); 
  			//console.log(centerMarker, $('villerayon').retrieve('pointVille')); 
  			drawCircle();
  		}, 500);
    	
  	}
  
  	/*******************************************
    *	Permet d'associer un evenement au click 
    *	sur la map
    *******************************************/
  	function aroundlistenner(address, map){
  	 var retour=null;
  	 GEvent.addListener(map,"click", function(overlay, latlng) {     
		  if (latlng) { 
		  	//centerMarker = latlng;
		  	//drawCircle();
		  	/*
			var myHtml = "Vous tes ˆ cette coordonnŽe : " + map.fromLatLngToDivPixel(latlng);
			map.openInfoWindow(latlng, myHtml);
			*/
		  }
		});
		

  		
  	}
      
    /*******************************************
    *	Permet de placer un marqueur sur la map
    *	sur la map
    *******************************************/
    function showAddress(geocoder,map,address,titre,accroche,telephone,fax,email,societe/*,latlng*/) {
    //var lien = "<a href=\""+message+"\" title=\""+titre+"\" >Voir ce bien</a>";
    //var image = "<a href=\""+message+"\" title=\""+titre+"\"><img src=\""+wwwroot+"upload/"+ img +"\" alt=\""+titre+"\" /></a>";
	//var prixa = "<b>"+prix+"</b>"; 
	//lien = "<table><tr><td>"+ image + "</td><td style=\"padding-left:3px;\"> <h2>"+lien +"</h2>" +accroche+ "<br />"+prixa+"</td></tr></table>";
    //console.log(accroche);
    var lien = "<table><tr><td></td><td style=\"padding-left:3px;\"><h2 class=\"titre_produit\" style=\"padding:0\">" +societe+ "</h2>";
    if(address != ""){
	    lien = lien+address;
	}
	if(telephone != ""){
    	lien = lien+"<br />T&eacute;l : "+telephone;
    }
    if(fax != ""){
    	lien = lien+"<br />Fax : "+fax;
    }
    if(email != ""){
    	lien = lien+"<br />Email : "+email;
   	}
    lien = lien+"</td></tr></table>";
      aroundlistenner(address, map);
     /* if (latlng!=""){
      	//console.log(latlng);
      	place_marqueur(latlng,prix,number,lien,address);
      } else {*/
		  if (geocoder) {
			geocoder.getLatLng(
			  address,
			  function(point) {
				if (!point) {
				  //alert(address + " introuvable !");
				} else {
					//console.log(point);
					place_marqueur(point,lien,address);	
				}
			  });    
				  
				
			  }
			
		  /*}*/
      }
    

	/*******************************************
    *	Place un marqueur associe a une icone
    *	sur la map
    *******************************************/
	function place_marqueur(point,lien,address){
	
		//var simapicon = new GIcon();	
		
		/*if (monprix<300000) simapicon.image = "images/simapicon_green.gif";
		else if ((monprix>=300000)&&(monprix<400000)) simapicon.image = "images/simapicon_blue.gif";
		else if (monprix>=400000) simapicon.image = "images/simapicon_purple.gif";
		
		else simapicon.image = "images/simapicon.gif";
		simapicon.iconSize = new GSize(40, 46);
		simapicon.iconAnchor = new GPoint(20, 46);
		simapicon.infoWindowAnchor = new GPoint(5, 1);
		*/
		//markerOptions = { icon:simapicon };
	 
	  var marker = new GMarker(point/*, markerOptions*/);
	  //marker.value = number;
	  /*if (
			($('param1').value=='1')&&(monprix<300000)
			||($('param2').value=='1')&&((monprix>=300000)&&(monprix<400000))
			||($('param3').value=='1')&&(monprix>=400000)
		) {
			 map.addOverlay(marker);
			 nbdebiens++;
			 afficher_nb_biens(nbdebiens);
			}*/
	  	map.addOverlay(marker);
		nbdebiens++;
		GEvent.addListener(marker,"click", function() {
		var myHtml = "<br/>" + address; 
		marker.openInfoWindowHtml(lien,myHtml);
		}
		);
	}
	

	/*******************************************
    *	Affiche le nombre de biens sur la map
    *	(ˆ intŽgrer avec du code php)
    *******************************************/
	function afficher_nb_biens(nbdebiens){
		creerRequete();
		var url = 'scripts/geoloc_biens.php?nb='+nbdebiens;
		requete.open('GET', url, true);
		
		requete.onreadystatechange = function() {
			if(requete.readyState == 4) {
				if(requete.status == 200) {
					$('nbdebiens').innerHTML = requete.responseText;
				}
			}
		};
		
		requete.send(null);
	
	}
	
	
	/*******************************************
    *	Change la valeur d'une checkbox
    *	(ˆ intŽgrer avec du code php)
    *******************************************/
	function changeValeur(param){
		if ($(param).value == '0')
			$(param).value = '1';
		else if ($(param).value == '1')
			$(param).value = '0';
		initialize();
	}
	
	/*******************************************
    *	Trace un cercle sur la map
    *	(ˆ intŽgrer avec du code php)
    *******************************************/
	function drawCircle() {
		var oRadius = document.getElementById('radiusInput');
		oRadius.value = oRadius.value ? oRadius.value : 500;
		
		if (oRadius.value.match(/[^\d.]/)) {
			alert("Entrez une valeur en km.");
			return;
		}
		if (oRadius.value > 9999) {
		}
	
		circleRadius = oRadius.value;
		
		doDrawCircle();
	}
	
	
	function doDrawCircle(){
	
		if (circle) {
			map.removeOverlay(circle);
		}
	
	
		if (centerMarker) {
			map.setCenter(centerMarker)
		}
		else {
			centerMarker = new GMarker(map.getCenter(),{draggable:true});
			GEvent.addListener(centerMarker,'dragend',drawCircle)
			map.addOverlay(centerMarker);
		}
	
		var center = map.getCenter();
	
		var bounds = new GLatLngBounds();
		
		var circlePoints = Array();
	
		with (Math) {
			
			var d = circleRadius/6378.8;	// radians
				
			var lat1 = (PI/180)* center.lat(); // radians
			var lng1 = (PI/180)* center.lng(); // radians
	
			for (var a = 0 ; a < 361 ; a++ ) {
				var tc = (PI/180)*a;
				var y = asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc));
				var dlng = atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(y));
				var x = ((lng1-dlng+PI) % (2*PI)) - PI ; // MOD function
				var point = new GLatLng(parseFloat(y*(180/PI)),parseFloat(x*(180/PI)));
				circlePoints.push(point);
				bounds.extend(point);
			}
	
			if (d < 1.5678565720686044) {
				circle = new GPolygon(circlePoints, '#89313C', 2, 1, '#89313C', 0.25);	
			}
			else {
				circle = new GPolygon(circlePoints, '#000000', 2, 1);	
			}
			map.addOverlay(circle); 
	
			map.setZoom(map.getBoundsZoomLevel(bounds));
		}
	}

	
	var retourville = null;
	
	/*******************************************
    *	Geolocalise une ville sur la map et stocke la latlng
    *	(ˆ intŽgrer avec du code php)
    *******************************************/
	function situerlaville(geocoder,map){
		var ville = $('villerayon').value;		
		
		if (geocoder) {
          geocoder.getLatLng(
            ville,
            function(point) {
              if (!point) {
                //alert(ville + " introuvable !");
              	$('villerayon').store('pointVille', null);
              } else {
            	$('villerayon').store('pointVille', point);
           	  }
		    }
    	  );
      }
    }    
    
    
    /*******************************************
    *	Recupere les infos dans la page et appelle showAddress()
    *	(ˆ intŽgrer avec du code php)
    *******************************************/    
	function chercher(geocoder,map){
		var accroches = $$('.accroche');
		//var latlngs = $$('.latlng');
		var addresses = $$('.address');
		var telephone = $$('.telephone');
		var email = $$('.email');
		var fax = $$('.fax');
		var societe = $$('.societe');
		//var links = $$('.link');
		var titres = $$('.titre');
		//var imgs = $$('.img');
		//var prixs = $$('.prix');
		var i=0;
		addresses.each(function(adre){
			//if (prixs[i].value!=""){
				//showAddress(geocoder,map,adre.value,i+1,links[i].value,titres[i].value,imgs[i].value,prixs[i].value,accroches[i].value/*,latlngs[i].value*/);
				showAddress(geocoder,map,adre.value,titres[i].value,accroches[i].value,telephone[i].value,fax[i].value,email[i].value,societe[i].value/*,latlngs[i].value*/);
			/*}
			else {
			 	//console.log("Bien ignorŽ");
			}*/
			i++;
		});
		
		

	}
      
