
    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
    var allPoints = new Object();


	function PointRemarquableCheck (id, num, rue, ville, pays, lat, long) {
	
	this.idPt=id;
	this.numPt=num;
	this.ruePt=rue;
	this.villePt=ville;
	this.paysPt=pays;
	this.latitude=parseFloat(lat);
	this.longitude=parseFloat(long);

	this.idA = function PointRemarquableCheck_idA(){
        return this.idPt;
    }
    this.numA = function PointRemarquableCheck_numA(){
        return this.numPt;
    }
    this.rueA = function PointRemarquableCheck_rueA(){
        return this.ruePt;
    }
    this.villeA = function PointRemarquableCheck_villeA(){
        return this.villePt;
    }
    this.paysA = function PointRemarquableCheck_paysA(){
        return this.paysPt;
    }
    this.longitudeA = function PointRemarquableCheck_longitudeA(){
        return this.longitude;
    }
    this.latitudeA = function PointRemarquableCheck_latitudeA(){
        return this.latitude;
    }
}
    
    
function loadPointsAreAdressesOK(id, num, rue, ville, pays, lat, long){
	var temp=new PointRemarquableCheck(id, num, rue, ville, pays, lat, long);
	allPoints[id]=temp;
	doList(id,id);
}

function doList(label, value){
	var sel = document.getElementById('spotedpoint');
	if(sel.options.length==0)
			loadPointCheck(value);
	sel.options[sel.options.length] = new Option(label, value);
}
    
 function loadPointCheck(id){
if(id!=""){
		var ptDetail = allPoints[id];
			
			document.trajetForm.ruearrivee.value=ptDetail.rueA();
			document.trajetForm.villearrivee.value=ptDetail.villeA();
			document.trajetForm.latitudeArrivee.value=ptDetail.latitudeA();
			document.trajetForm.longitudeArrivee.value=ptDetail.longitudeA();

		
	}else{
	document.trajetForm.ruearrivee.value="";
	document.trajetForm.villearrivee.value="";
	}
}   
function loadPointArr(elemId, id, level){
	loadKids(elemId, id, level, 'spotedPointArrivee', 'loadPointArr');
	if(id!=""){
		ptDetail = allPoints[id];
		// we do this test to make sure we're backward compatible
		// until all rue / ville fields are merged into one on all pages
		if (typeof(document.trajetForm.ruearrivee)=='undefined') {
			document.trajetForm.inputArrivee.value = ptDetail.rueA() + " " + ptDetail.villeA();
			if (typeof(document.trajetForm.arrLocality) != 'undefined') {
				document.trajetForm.arrLocality.value = ptDetail.villeA();
				document.trajetForm.arrThoroughfare.value = ptDetail.rueA();
			}
		} else {
			document.trajetForm.ruearrivee.value=ptDetail.rueA();
			document.trajetForm.villearrivee.value=ptDetail.villeA();
			document.trajetForm.latitudeArrivee.value=ptDetail.latitudeA();
			document.trajetForm.longitudeArrivee.value=ptDetail.longitudeA();
		}
	}else{
		if (typeof(document.trajetForm.ruearrivee)=='undefined') {
			document.trajetForm.inputArrivee.value = "";
		} else {
			document.trajetForm.ruearrivee.value="";
			document.trajetForm.villearrivee.value="";
		}
	}
}


	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.
	}
	function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }
	
	
	
	function loadJs(key,deppoint, arrpoint)
{
	var scr = document.getElementById("callLRV")
	if (scr) {
		scr.parentNode.removeChild(scr);
	}
	var url = contextPath+"/apis/centraleCovoiturage.do?key="+key+"&pointGeoDepart="+deppoint+"&pointGeoArrivee="+arrpoint+"&output=json&callback=showResults";
	eltScript = document.createElement("script");
	eltScript.setAttribute("type", "text/javascript");
	eltScript.setAttribute("src", url);
	
	eltScript.setAttribute("id", "loadedScript1");
	document.getElementsByTagName('head')[0].appendChild(eltScript);
}


function getPoint(latitude, longitude){
	var point = new GLatLng(latitude, longitude);
	return point;
}

function getIcon(style){
	var icon = new GIcon();
	icon.image = contextPath+"/"+style;
	icon.iconSize = new GSize(12, 20);
	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);
	return icon;
}

function handleErrors(doLog){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("Cette adresse n est pas reconnue.\nCode erreur: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("Itineraire impossible a determiner.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("Pour tracer un itineraire, il faut un point de depart et d arrivee.\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("La clef google map est incorrecte. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("Pas d'itineraire possible.\n Error code: " + gdir.getStatus().code);
	    
	   else {
		   var logEnabled = typeof(doLog) == 'undefined' || doLog;
		   if (serverLog && logEnabled) {
			   var errorMsg = gdir.getStatus().code;
			   try {
				   errorMsg = 'Requested directions for: ['+gdir.D.name+'], geocode status code: ['+gdir.getStatus().code+']';
			   } catch (err) {
				   errorMsg += ', InternalCode [002]';
			   }
			   serverLog('gdir', 'error', errorMsg);
		   }
		   alert("Aucun itinéraire en voiture possible entre vos adresses de départ et d'arrivée !");
	   }
	   
	}	
	
function createmarker(lat, long, style){

			var marktemp=new GMarker(new GLatLng(lat, long), {icon:getIcon(style)});
			var infoTabs = [
		  		//new GInfoWindowTab("Profil", "<p style=\"margin-right:0px;\">Enregistrez ce trajet dans votre compte pour voir le profil de ce covoitureur !<p>"),
		 		//new GInfoWindowTab("Trajet", "<p style=\"margin-right:0px;\">Enregistrez ce trajet dans votre compte pour voir le trajet complet de ce covoitureur !</p>")
		 		new GInfoWindowTab("Trajet", "<p style=\"margin-right:0px;\">Enregistrez cette recherche dans votre compte pour contacter ce covoitureur.</p>")
			];
			
		  	GEvent.addListener(marktemp, "click", function() {
				marktemp.openInfoWindowTabsHtml(infoTabs);
			});
return 	marktemp;	
}


