    var map;
    var geocoder;
    var myPano;
    var gdir;
    var addressMarker;



    function initialize() {
    var mapOptions = {googleBarOptions : {style : "new",resultList: document.getElementById("searchwell"),adsOptions : {
	                client: "pub-8586823648395186",channel: "2706656745",adsafe: "low",language: "fr"}
	            						 }
          			 }
      //map = new GMap2(document.getElementById("map_canvas"));
      map = new GMap2(document.getElementById("map_canvas"), mapOptions);
      map.setMapType(G_HYBRID_MAP);
      //map.setMapType(G_SATELLITE_MAP);
      map.setUIToDefault();
      if (name != ""){
      gdir = new GDirections(map, document.getElementById("directions"));
      GEvent.addListener(gdir, "load", onGDirectionsLoad);
      GEvent.addListener(gdir, "error", handleErrors);
      //setDirections("San Francisco", "Mountain View", "en_US");
      }
      

      
            // Enable the additional map types within
            //the map type collection
      //map.enableRotation();
      
      map.setCenter(new GLatLng(42.345573,-71.098326), depth);
      // map.setUIToDefault();
	  //   var pos = new GControlPosition(G_ANCHOR_DOWN_RIGHT, new GSize(10,1));
	  // map.addControl(new GScaleControl(), pos);
      map.enableGoogleBar();
      geocoder = new GClientGeocoder();
      //var fenwayPark = new GLatLng(42.345573,-71.098326);
	  // panoramaOptions = { latlng:fenwayPark };
	  // myPano = new GStreetviewPanorama(document.getElementById("pano"), panoramaOptions);
	  // GEvent.addListener(myPano, "error", handleNoFlash);

    }

function handleNoFlash(errorCode) {
      if (errorCode == FLASH_UNAVAILABLE) {
        alert("Error: Flash doesn't appear to be supported by your browser");
        return;
      }
    }


    // addAddressToMap() is called when the geocoder returns an
    // answer.  It adds a marker to the map with an open info window
    // showing the nicely formatted version of the address and the country code.
    function addAddressToMap(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        //alert("Sorry, we were unable to geocode that address");
        //var node = document.getElementById('message');
	//node.innerHTML('<p>Sorry, we were unable to geocode that address</p>');

          var txt = "Sorry, we were unable to geocode that address";
	  var node = document.getElementById('message');
	  var newNode = document.createElement('p');
	  newNode.appendChild(document.createTextNode(txt));
	  node.appendChild(newNode);
	  
	        } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        map.addOverlay(marker);
        panoramaOptions = { latlng:point };
		myPano = new GStreetviewPanorama(document.getElementById("pano"), panoramaOptions);
		GEvent.addListener(myPano, "error", handleNoFlash);

        map.setCenter(point, depth);
        if (name != ""){ marker.openInfoWindowHtml(name + place.address + '<br>' );}
      }
    }

    // showLocation() is called when you click on the Search button
    // in the form.  It geocodes the address entered into the form
    // and adds a marker to the map at that location.
    function showLocation() {
      var address = document.forms[0].q.value;
      geocoder.getLocations(address, addAddressToMap);
    }

   // findLocation() is used to enter the sample addresses into the form.
    function findLocation(address) {
      document.forms[0].q.value = address;
      showLocation();
    }
    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}
	
	
