function resete(text,id,depart) {
  if (text == depart)
  {
    var cible = eval(document.getElementById(id));
    cible.value = '';
  }
}///////////////////////////////////////////////////////////////////////////////

function commonload() {
  
  if (GBrowserIsCompatible()) {
    geocoder = new GClientGeocoder();
    geocoder.setBaseCountryCode('FR');
    map = new GMap2(document.getElementById("map"));
    map.enableContinuousZoom();
    map.enableDoubleClickZoom();
    /*GEvent.addListener(map, "moveend", function() {
      var center = map.getCenter();
      var zoom = map.getZoom();
      var msg = center.toString()+" :: "+zoom;
      document.getElementById("message").innerHTML = msg;
    });*/
    map.addControl(new GLargeMapControl());
  }
}///////////////////////////////////////////////////////////////////////////////

function bindInfoWindow(marker, map, infoWindow, html) {
  google.maps.event.addListener(marker, 'click', function() {
    infoWindow.setContent(html);
    infoWindow.open(map, marker);
  });
}


function downloadUrl(url, callback) {
  var request = window.ActiveXObject ?
      new ActiveXObject('Microsoft.XMLHTTP') :
      new XMLHttpRequest;

  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      request.onreadystatechange = doNothing;
      callback(request.responseText, request.status);
    }
  };

  request.open('GET', url, true);
  request.send(null);
}

function parseXml(str) {
  if (window.ActiveXObject) {
    var doc = new ActiveXObject('Microsoft.XMLDOM');
    doc.loadXML(str);
    return doc;
  } else if (window.DOMParser) {
    return (new DOMParser).parseFromString(str, 'text/xml');
  }
}

function doNothing() {}



function centre() {
  var position = map.getCenter();
  marker.setPosition(position);
  remplilatlng(marker.getPosition());
  charge("/inc/checkshop.php?lat="+marker.getPosition().lat()+"&lng="+marker.getPosition().lng(),"checkshop");
}///////////////////////////////////////////////////////////////////////////////

function fadresse(adresse,zoom) {
  if (arguments.length == 1) var zoom = 16;
  var cp = adresse.match(/[0-9]{5}/);
  if (cp) { 
    cp = cp[0];
    cp = cp.substr(0,2);
    var cible = eval(document.getElementById('dept'));
    cible.value = cp;
  }
  
  showAddress(adresse,zoom,1)
}///////////////////////////////////////////////////////////////////////////////

function showAddress(address,zoom,auto) {
    if (address == '') {
        alert('Veuillez préciser une adresse !');
        return;
    }
    address = address.replace('\n',' ');
    if (arguments.length == 1) var zoom = 11;
    if (geocoder) {
        geocoder.geocode( { 'address': address, 'region':'fr', 'language':'fr'}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                charge("/inc/checkshop.php?lat="+results[0].geometry.location.lat()+"&lng="+results[0].geometry.location.lng(),"checkshop"); 
                map.setZoom(zoom);
                marker.setPosition(results[0].geometry.location);
                remplilatlng(results[0].geometry.location);
                //centre();
                /*var marker = new google.maps.Marker({
                map: map, 
                position: results[0].geometry.location
                });*/
            } else {
                if (!auto) alert("Erreur : " + status);
            }
        });
    }
        
    
    /*
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          if (!auto) alert(address + " non trouvé!");
        } else {    
          charge("/inc/checkshop.php?lat="+point.lat()+"&lng="+point.lng(),"checkshop");    //?lat="+point.lat()+"&lng="+point.lng()
          map.setCenter(point, zoom);
          if (zoom == 16) { 
            centre();
            remplilatlng(point);
          }
          //var marker = new GMarker(point);
          //map.addOverlay(marker);
          //marker.openInfoWindowHtml(address);
        }
      }
    );
    }*/
}///////////////////////////////////////////////////////////////////////////////

function remplilatlng(point) {
  //var point = marker.getPoint();
  var lat = point.lat();
  var lng = point.lng();
  var ciblelat = eval(document.getElementById('lat'));
  var ciblelng = eval(document.getElementById('lng'));
  ciblelat.value = lat;
  ciblelng.value = lng;
}



function montre(quoi) {
	cible = eval(document.getElementById(quoi));
	cible.style.display = "inline";
}///////////////////////////////////////////////////////////////////////////////
function cache(quoi) {
	cible = eval(document.getElementById(quoi));
	cible.style.display = "none";
}///////////////////////////////////////////////////////////////////////////////

function montre2(quoi) {
	cible = eval(document.getElementById(quoi));
	cible.style.visibility = "visible";
}///////////////////////////////////////////////////////////////////////////////
function cache2(quoi) {
	cible = eval(document.getElementById(quoi));
	cible.style.visibility = "hidden";
}///////////////////////////////////////////////////////////////////////////////

function changepays(quoi) {
  //alert(quoi);
  if (quoi == 0) montre2('selectdept');
  else cache2('selectdept');
}///////////////////////////////////////////////////////////////////////////////

// A TextualZoomControl is a GControl that displays textual "Zoom In"
// and "Zoom Out" buttons (as opposed to the iconic buttons used in
// Google Maps).

// We define the function first
function AddControl() {
}

function ajouteAddControl() {
	// To "subclass" the GControl, we set the prototype object to
	// an instance of the GControl object
	AddControl.prototype = new GControl();
	
	// Creates a one DIV for each of the buttons and places them in a container
	// DIV which is returned as our control element. We add the control to
	// to the map container and return the element for the map class to
	// position properly.
	AddControl.prototype.initialize = function(map) {
	  var container = document.createElement("div");
	
	  var zoomInDiv = document.createElement("div");
	  this.setButtonStyle_(zoomInDiv);
	  container.appendChild(zoomInDiv);
	  zoomInDiv.appendChild(document.createTextNode("Géolocaliser l'adresse"));
	  GEvent.addDomListener(zoomInDiv, "click", function() {
			showAddress(eval(document.getElementById('adresse')).value,16);
	  });
	
	  var zoomOutDiv = document.createElement("div");
	  this.setButtonStyle_(zoomOutDiv);
	  container.appendChild(zoomOutDiv);
	  zoomOutDiv.appendChild(document.createTextNode("Centrer le marqueur"));
	  GEvent.addDomListener(zoomOutDiv, "click", function() {
			centre();
	  });
	
	  map.getContainer().appendChild(container);
	  return container;
	}
	
	// By default, the control will appear in the top left corner of the
	// map with 7 pixels of padding.
	AddControl.prototype.getDefaultPosition = function() {
	  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
	}
	
	// Sets the proper CSS for the given button element.
	AddControl.prototype.setButtonStyle_ = function(button) {
	  button.style.color = "#000000";
	  button.style.backgroundColor = "white";
	  button.style.font = "small Arial";
	  button.style.border = "1px solid black";
	  button.style.padding = "2px";
	  button.style.marginBottom = "3px";
	  button.style.textAlign = "center";
	  //button.style.width = "6em";
	  button.style.cursor = "pointer";
	}
}///////////////////////////////////////////////////////////////////////////////

/*
var map = new GMap2(document.getElementById("map"));
map.addControl(new TextualZoomControl());
map.setCenter(new GLatLng(37.441944, -122.141944), 13);
*/

////////////////////////////////////////////////////////////////////////////////

function charge(url, target) {
	//target = "droite";
	//url = 'contenu.php?'+url;
  //document.getElementById(target).innerHTML = 'Chargement...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {chargeplus(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}///////////////////////////////////////////////////////////////////////////////  

function chargeplus(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML="Erreur:\n"+req.statusText;
    }
  }
}///////////////////////////////////////////////////////////////////////////////










/*
var iconv = new GIcon();
  iconv.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";
  iconv.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
  iconv.iconSize = new GSize(12, 20);
  iconv.shadowSize = new GSize(22, 20);
  iconv.iconAnchor = new GPoint(6, 20);
  iconv.infoWindowAnchor = new GPoint(5, 1);
////////////////////////////////////////////////////////////////////////////////

var iconr = new GIcon();
  iconr.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
  iconr.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
  iconr.iconSize = new GSize(12, 20);
  iconr.shadowSize = new GSize(22, 20);
  iconr.iconAnchor = new GPoint(6, 20);
  iconr.infoWindowAnchor = new GPoint(5, 1);
////////////////////////////////////////////////////////////////////////////////
*/  
