//<![CDATA[
  var cptDemo = 0;
  var cptNbRech = 0;

  function ouvreBulle(adresse, country, marker, lat, lng)
  {
    if (adresse == null)
    {
      marker.openInfoWindowHtml('Votre recherche :<BR /><B>Latitude : </B>'+ lat +'<BR /><B>Longitude : </B>'+ lng);
    }
    else
    {
      if (adresse == 3)
      {
        marker.openInfoWindowHtml('<A href="http://netkom.com/"><IMG src="image/logo-netkom.gif" /></A><BR /><B>' + country);
      }
      else if (adresse < 3)
      {
        marker.openInfoWindowHtml('<B>' + country + '</B><BR><B>Latitude : </B>'+ lat +'<BR><B>Longitude : </B>'+ lng);
      }
      else
      {
        marker.openInfoWindowHtml(adresse +'<BR><B>Code Pays :</B> '+ country +'<BR><B>Latitude : </B>'+ lat +'<BR><B>Longitude : </B>'+ lng);
      }
    }
  }

  function ville ()
  {
    if (cptDemo <= 3)
    {
      var point = new GLatLng(tabDemo[cptDemo]['lat'], tabDemo[cptDemo]['long']);
      var marker = new GMarker(point, {draggable: false});
      MyMap.panTo(point);
      MyMap.addOverlay(marker);
      window.setTimeout(function(){ ouvreBulle (cptDemo, tabDemo[cptDemo]['ville'], marker, tabDemo[cptDemo]['lat'], tabDemo[cptDemo]['long']);}, 1000);
      window.setTimeout("cptDemo++", 1500);
      window.setTimeout("ville()" , 3500);
    }
  }

  function load() {
    if (GBrowserIsCompatible())
    {
      tabDemo = new Array(4);
      tabDemo[0] = new Array('lat', 'long', 'ville');
      tabDemo[0]['lat'] = 40.757929;
      tabDemo[0]['long'] = -73.985506;
      tabDemo[0]['ville'] = 'New York';
      tabDemo[1] = new Array('lat', 'long', 'ville');
      tabDemo[1]['lat'] = 51.500152;
      tabDemo[1]['long'] = -0.126236;
      tabDemo[1]['ville'] = 'Londre';
      tabDemo[2] = new Array('lat', 'long', 'ville');
      tabDemo[2]['lat'] = 55.755786;
      tabDemo[2]['long'] = 37.617633;
      tabDemo[2]['ville'] = 'Moscou';
      tabDemo[3] = new Array('lat', 'long', 'ville');
      tabDemo[3]['lat'] = 45.935701;
      tabDemo[3]['long'] = 4.721435;
      tabDemo[3]['ville'] = 'Anse';
      MyMap = new GMap2(document.getElementById('cadreCarte'), { size : new GSize(730, 200) });
      MyMap.setCenter(new GLatLng(45.935701, 4.721435), 2);
      MyMap.disableDragging();
      window.setTimeout("ville()", 1500);
    }
    else
    {
      alert("Désolé, mais votre navigateur n'est pas compatible avec Google Maps");
    }
  }


  function finGlisseMarker(adresse, country, marker)
  {
    var centre = marker.getPoint();
    var chaineCentre = centre.toString();
    var tabPoint = chaineCentre.split(",");
    var lat = "";
    var lng = "";
    var lat = tabPoint[0].replace("(", "");
    var lng = tabPoint[1].replace(")", "");
    window.setTimeout(function(){MyMap.panTo(new GLatLng(lat, lng));}, 1000);
    ouvreBulle(adresse, country, marker, lat, lng);
  }

        
  function defCarte(adresse, country, point)
  {
    document.getElementById("cadreResultat").innerHTML = '<DIV id="resultat"></DIV><BR />';
    MyMap.addControl(new GLargeMapControl());
    MyMap.addControl(new GMapTypeControl());
    MyMap.addControl(new GOverviewMapControl());
    MyMap.addControl(new GScaleControl());
    MyMap.addControl(new google.maps.LocalSearch({ resultList : document.getElementById("resultat")}),
                     new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(0,-30)));
    var marker = new GMarker(point, {draggable: true});
    GEvent.addListener(marker, "click", function() { finGlisseMarker(adresse, country, marker); });
    GEvent.addListener(marker, "dragstart", function() { MyMap.closeInfoWindow(); });
    GEvent.addListener(marker, "dragend", function() { finGlisseMarker(adresse, country, marker); });
    MyMap.addOverlay(marker);
    finGlisseMarker(adresse, country, marker);
    MyMap.setCenter(point);
    var adresse = null;
  }

  function verifAdresse(response) {
    if (!response || response.Status.code != 200) {
      alert("Désolé, nous ne pouvons gélocalisé cette addresse. \n         Vérifier son orthographe");
    }
    else 
    {
      champOk(cptNbRech);
      place = response.Placemark[0];
      var adresse = place.address;
      var country = place.AddressDetails.Country.CountryNameCode;
      point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
      defCarte(adresse, country, point);
    }
  }

  function champOk()
  {
    if (cptNbRech == 0) //premiere recherche
    {
      MyMap = new GMap2(document.getElementById("cadreCarte"), { size : new GSize(730, 400) });
      MyMap.setCenter(new GLatLng(45.935701, 4.721435), 2);
      MyMap.setZoom(8);
    }
    else //autre recherche
    {
      var zoom = MyMap.getZoom();
      MyMap.setZoom(zoom);
    }
    cptNbRech++;
  }

  function recherche()
  {
    if (cptDemo <= 3)
    {
      alert("Veuiller patienter pendant le chargement de la page, Merci");
    }
    else
    {
      var lat = document.getElementById("lat").value;
      var lng = document.getElementById("lng").value;
      var adresse = document.getElementById("adresse").value;
      if (adresse == "" && lat == "" && lng == "")
      {
        alert("Vous devez renseignier l'une ou l'autre partie du formulaire");
      }
      else if (adresse != "" && (lat != "" | lng != ""))
      {
        alert("Vous ne devez renseignier que l'une ou l'autre partie du formulaire");
      }
      else if (adresse == "" && (lat == "" || lng == ""))
      {
        alert("Vous devez renseignier les deux champs latitude et longitude");
      }
      else
      {
        if (adresse != '')  //recherche d une addresse
        {
          geocoder = new GClientGeocoder();
          geocoder.getLocations(adresse, verifAdresse);
        }
        else   // recherche de coordonnee
        {
          if (isNaN(lat) || isNaN(lng))
          {
            alert("La latitude est un nombre compris entre 90 et -90 \n                  La longitude entre -180 et 180\nex: Latitude:45.935701 longitude:4.721435 ");
          }
          else
          {
            champOk(cptNbRech);
            var point = new GLatLng(lat,lng);
            defCarte(null, null, point);
          }
        }
      }
    }
  }
//]]>
