//------------------------------------------------------------------------------------- declaration de moultes variables
var access_path = "library/map_module/";
var j_name=" day(s) ";
var h_name=" hr(s) ";
var m_name=" min(s) ";
var embarquement = 0.004167;
//
var type1 = "Smart'Airport"
var type2 = "Smart'Airfield"
var type3 = "Smart'OffRoad"
//
var map;
var coords_from = new GClientGeocoder();
var gdir1;
var centerLatitude = 56.3;
var centerLongitude = 10.6191666666667;
var startZoom = 3;
var circleArray = new Array();	//Tableau qui contient les cercles deja dessine
var all_airports= new Array();
var all_airports_from= new Array();
var all_airports_grid= new Array();
var coords_departure;
var max_in_grid = 15;

var nb_airports_from = 0;

//
var radius1h=410;
var radius1_5h=730;
var radius2h=1050;
var radius3h=2580;
var circleArray = new Array();	//Tableau qui contient les cercles deja dessine
var seqments=40;
var lineColor = /*"#d95121"*/null;
var lineWidth = 1;
var lineOpacity = null;
var circleFillColor = /*"#d95121"*/null;
var circleOpacity = null;
//
var marker_airport_selected_from;
var marker_from; // a
//
var distance_max_search = 500;
var max_airports = 11;
var adding_from = new Array();

var airport_from = new Array();
//
var t_entier;
var t_heures;
var t_minutes;
var t_jour;
var t_secondes;
//
var time_travel_from;
var time_travel_flight;
var time_travel_total;
//
var temp_id;
var temp_address;
var temp_car_h;
var temp_car_m;
//------------------------------------------------------------------------------------- objets icones
// b_a
var icon_3_0 = new GIcon();
icon_3_0.image = access_path+'images/3_0.png';
icon_3_0.iconSize = new GSize(17, 25);
icon_3_0.iconAnchor = new GPoint(9, 25);
icon_3_0.infoWindowAnchor = new GPoint(5, 1);
// b_a
var icon_3_1 = new GIcon();
icon_3_1.image = access_path+'images/3_1.png';
icon_3_1.iconSize = new GSize(17, 25);
icon_3_1.iconAnchor = new GPoint(9, 25);
icon_3_1.infoWindowAnchor = new GPoint(5, 1);
// b_b
var icon_3_2 = new GIcon(); 
icon_3_2.image = access_path+'images/3_2.png';
icon_3_2.iconSize = new GSize(17, 25);
icon_3_2.iconAnchor = new GPoint(9, 25);
icon_3_2.infoWindowAnchor = new GPoint(5, 1);
// b_c
var icon_3_3 = new GIcon();
icon_3_3.image = access_path+'images/3_3.png';
icon_3_3.iconSize = new GSize(17, 25);
icon_3_3.iconAnchor = new GPoint(9, 25);
icon_3_3.infoWindowAnchor = new GPoint(5, 1);
// b_d
var icon_3_4 = new GIcon(); 
icon_3_4.image = access_path+'images/3_4.png';
icon_3_4.iconSize = new GSize(17, 25);
icon_3_4.iconAnchor = new GPoint(9, 25);
icon_3_4.infoWindowAnchor = new GPoint(5, 1);
// n_point
var icon_3_5 = new GIcon(); 
icon_3_5.image = access_path+'images/3_5.png';
icon_3_5.iconSize = new GSize(17, 25);
icon_3_5.iconAnchor = new GPoint(9, 25);
icon_3_5.infoWindowAnchor = new GPoint(5, 1);
// v_1
var icon_0_0 = new GIcon(); 
icon_0_0.image = access_path+'images/0_0.png';
icon_0_0.iconSize = new GSize(17, 25);
icon_0_0.iconAnchor = new GPoint(9, 25);
icon_0_0.infoWindowAnchor = new GPoint(5, 1);
// v_2
var icon_0_1 = new GIcon(); 
icon_0_1.image = access_path+'images/0_1.png';
icon_0_1.iconSize = new GSize(17, 25);
icon_0_1.iconAnchor = new GPoint(9, 25);
icon_0_1.infoWindowAnchor = new GPoint(5, 1);
// v_3
var icon_0_2 = new GIcon(); 
icon_0_2.image = access_path+'images/0_2.png';
icon_0_2.iconSize = new GSize(17, 25);
icon_0_2.iconAnchor = new GPoint(9, 25);
icon_0_2.infoWindowAnchor = new GPoint(5, 1);
// f_1
var icon_1_0 = new GIcon(); 
icon_1_0.image = access_path+'images/1_0.png';
icon_1_0.iconSize = new GSize(17, 25);
icon_1_0.iconAnchor = new GPoint(9, 25);
icon_1_0.infoWindowAnchor = new GPoint(5, 1);
// f_2
var icon_1_1 = new GIcon(); 
icon_1_1.image = access_path+'images/1_1.png';
icon_1_1.iconSize = new GSize(17, 25);
icon_1_1.iconAnchor = new GPoint(9, 25);
icon_1_1.infoWindowAnchor = new GPoint(5, 1);
// f_3
var icon_1_2 = new GIcon(); 
icon_1_2.image = access_path+'images/1_2.png';
icon_1_2.iconSize = new GSize(17, 25);
icon_1_2.iconAnchor = new GPoint(9, 25);
icon_1_2.infoWindowAnchor = new GPoint(5, 1);
// r_1
var icon_2_0 = new GIcon(); 
icon_2_0.image = access_path+'images/2_0.png';
icon_2_0.iconSize = new GSize(17, 25);
icon_2_0.iconAnchor = new GPoint(9, 25);
icon_2_0.infoWindowAnchor = new GPoint(5, 1);
// r_2
var icon_2_1 = new GIcon(); 
icon_2_1.image = access_path+'images/2_1.png';
icon_2_1.iconSize = new GSize(17, 25);
icon_2_1.iconAnchor = new GPoint(9, 25);
icon_2_1.infoWindowAnchor = new GPoint(5, 1);
// r_3
var icon_2_2 = new GIcon(); 
icon_2_2.image = access_path+'images/2_2.png';
icon_2_2.iconSize = new GSize(17, 25);
icon_2_2.iconAnchor = new GPoint(9, 25);
icon_2_2.infoWindowAnchor = new GPoint(5, 1);
//
var marker_array = new Array();
//
//var type_icons = new Array();
//type_icons[0] = new Array(icon_v_1, icon_v_2, icon_v_3);
//type_icons[1] = new Array(icon_f_1, icon_f_2, icon_f_3);
//type_icons[2] = new Array(icon_r_1, icon_r_2, icon_r_3);
//type_icons[3] = new Array(icon_n_point, icon_b_a, icon_b_b, icon_b_c, icon_b_d);
//------------------------------------------------------------------------------------- fonction d'initialisation
function init(){
	
	combo_to_zero()
	// creation de la map
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.addControl(new GScaleControl());
	map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
	// appel de la fonction de creation du tableau 2 dimensions
	load_combos();
	// a deplacer dans la fonction de creation des chemins
	gdir1 = new GDirections(map, document.getElementById("directions1"));
	GEvent.addListener(gdir1, "error", handleErrors1);
	GEvent.addListener(gdir1, "load", onGDirectionsLoad1);
	//
}
//
function load_combos(){
	// vide le tableau
	all_infos_airport = new Array();
	all_infos_airport_from = new Array();
	// recuperation des marqueurs
	GDownloadUrl(access_path+"phpsqlajax_genxml2.php", function(data) {
	//alert("GG");
		var xml = GXml.parse(data);
		markers = xml.documentElement.getElementsByTagName("marker");
		//
		var actuel = "";
		var old = "";
		by_country = new Array();
		//
		for (var i = 0; i < markers.length; i++) {
			// REDEFINITION DE L'ID ! L'ID DU XML N'EST PAS UTILISE !
			// remplissage des tableaux "all_infos_airport_FROM" et "all_infos_airport_TO" et du normal qui n'est jamais trié
			// BAM 2 dimensions
			all_infos_airport[i] = new Array();
			// remplissage du tableau // 0 = id // 1 = name // 2 = country
			// 3 = lat // 4 = lng // 5 = distance (renseignee plus tard, dans les duplicatas) // 6 = type_num
			all_infos_airport[i][0] = i;
			all_infos_airport[i][1] = markers[i].getAttribute("name");
			all_infos_airport[i][2] = markers[i].getAttribute("country");
			all_infos_airport[i][3] = markers[i].getAttribute("lat");
			all_infos_airport[i][4] = markers[i].getAttribute("lng");
			all_infos_airport[i][5] = 0;
			all_infos_airport[i][6] = markers[i].getAttribute("type_num");
			all_infos_airport[i][7] = markers[i].getAttribute("zone_num");
			//----------------------------------------------------------------------------------- remplissage d'un tableau, aéroport par pays
			// !!!!!!!!! REMPLACER "COUNTRY"" PAR "COUNTRY_NAME"" QUAND LA BDD SERA RENSEIGNEE !!!!!!!!! faire les changements adéquats dans les listes au dessus et dans la page phpsqlajax_genxml2.php ET DANS LES FUNCTIONS PLUS HAUT load_combo12_grille et load_combo22_grille
		}
		all_infos_airport_from = all_infos_airport;
		//alert(all_infos_airport);
		launchtest();
	});	
}
//------------------------------------------------------------------------------------- Lance la fonction de la check box, pour afficher ou masquer les aéroports
function launchtest(eteindre) {
	if(eteindre) {
		document.button_airports.remove_airport.checked = false;
	}
	var checkbox=document.button_airports.remove_airport.checked;
	if(checkbox==false){
	//efface les cercles bleus si il y en a
		
		if (circleArray.length>0){
			for (k=0; k<circleArray.length; k++) {		
				map.removeOverlay(circleArray[k]);
			}
			circleArray = new Array();
		}
		//Efface tout les aéroports affichés au depart
		if(all_airports.length>0) {	
			for (i=0;i<=all_airports.length; i++) {
				if(all_airports[i]){
					map.removeOverlay(all_airports[i]);
				}
			}
			all_airports = new Array();
		}
	} else if (checkbox==true){
		// création du tableau à envoyer a init_all_airports
		var actu_to_send = new Array();
		for(var i = 0; i < markers.length; i++) {
		//for(var i = 0; i < 10; i++) {
			if(markers[i].getAttribute("type_num") == "1") {
				actu_to_send[actu_to_send.length] = i;
			}
		}
		//alert(actu_to_send.length);
		//appel le fonction de base pout afficher les aéroports
		init_all_airports(actu_to_send, "all_airports");
	}
}
//------------------------------------------------------------------------------------- création des markers + event pour cercles
function createMarker(point, name, city, type_airport, zone_airport,country, oaci, comments, country_name) {
	var icon_actu = "icon_"+(type_airport-1)+"_"+(zone_airport-1);
	var marker = new GMarker(point, this[icon_actu]);
	var html = 	'<div class="infobulle">'
				+ city + ' - <b>' + name + '</b> - ' + country_name + ' - '+ this["type"+type_airport]
				+ '<br /><br />COMMENTS<br />'
				+ '<i>'+ comments +'</i>'
				+ '<br /><br />'
				//+ '<img src="'+access_path+'images/'+(type_airport-1)+"_"+(zone_airport-1)+'.png">'
				+ '</div>';
	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(html);
		//if(1==5) {
		drawmap(point, radius1h);// affichage du cercle
		drawmap(point, radius1_5h);// affichage du cercle
		drawmap(point, radius2h);// affichage du cercle
		drawmap(point, radius3h);// affichage du cercle
		//}
	});
	return marker;
}
//------------------------------------------------------------------------------------- lance l'affichage des aeroports contenus dans le tableau recu
function init_all_airports(table_to_add, array_to_save) {
	//alert("HOHO  "+array_to_save);
	//function add_one(ajoute_num) {
	//if(ajoute_num < table_to_add.length) {
	//recupere la valeur contenue dans le tableau recu - utilise cette valeur pour piocher dans le tableau "markers"
	//	val = table_to_add[ajoute_num];
	//for(var val = 0; val<table_to_add.length;val++) {
	// VIDE LE TABLEAU (varie entre ALL AIRPORTS et ALL AIRPORTS FROM)
	if(this[array_to_save].length > 0) {
		for(var t = 0; t<this[array_to_save].length; t++) {
			map.removeOverlay(this[array_to_save][t]);
		}
		this[array_to_save] = new Array();
	}
	//efface les cercles bleus si il y en a
		
		if (circleArray.length>0){
			for (k=0; k<circleArray.length; k++) {		
				map.removeOverlay(circleArray[k]);
			}
			circleArray = new Array();
		}
	var val = 0;
	while(val<table_to_add.length) {
		actu_num = table_to_add[val];
		// Name
		var name = markers[actu_num].getAttribute("name");
		// Country
		var country = markers[actu_num].getAttribute("country");
		// City
		var city = markers[actu_num].getAttribute("city");
		// OACI
		var oaci = markers[actu_num].getAttribute("oaci");
		// COMMENTS
		var comments = markers[actu_num].getAttribute("comments");
		// COUNTRY_NAME
		var country_name = markers[actu_num].getAttribute("country_name");
		// Type
		var type_airport = markers[actu_num].getAttribute("type_num");
		var zone_airport = markers[actu_num].getAttribute("zone_num");
		// Point (coordonnees)
		var point = new GLatLng(parseFloat(markers[actu_num].getAttribute("lat")), parseFloat(markers[actu_num].getAttribute("lng")));
		// Marker
		//alert(point+" / "+name+" / "+city+" / "+type_airport+" / "+zone_airport+" / "+country+" / "+oaci);
		var marker = createMarker(point, name, city, type_airport, zone_airport, country, oaci, comments, country_name);
		//
		this[array_to_save].push(marker);
		//
		map.addOverlay(marker)
		//
		val++;
	}
	//add_one(ajoute_num+1);
	//} else {
	//sort de la boucle
	//}
	//}
	//
	//add_one(0);
}
//------------------------------------------------------------------------------------- add listener pour point DEPARTURE
function add_listener(latlng, markerHTML, type_airport, zone_airport){
	var icon_actu = "icon_"+(type_airport-1)+"_"+(zone_airport-1);
	//alert(type_airport+" ////////// "+(type_airport-1)+" / "+zone_airport);
	var marker = new GMarker(latlng, this[icon_actu]);
	GEvent.addListener(marker, 'click', function(){
		marker.openInfoWindowHtml(markerHTML);
	});
	return marker;
}
//------------------------------------------------------------------------------------- drawmap
function drawmap(point, radius) {
	
	//Permet d'effacer les cercles dessine
	if (circleArray.length>3){
		for (k=0; k<circleArray.length; k++) {		
			map.removeOverlay(circleArray[k]);
		}
		circleArray = new Array();
	}
	//function draw
	function draw(){
		var givenRad = radius*1;
		var givenQuality = seqments*1;
		var center = point;
		
		drawCircle(center, givenRad, givenQuality, lineColor, lineWidth, lineOpacity, circleFillColor, circleOpacity);
	}	
	//function draw circle
	function drawCircle(center, radius, nodes, liColor, liWidth, liOpa, fillColor, fillOpa) {
		/*calculating kmdegree*/
		var latConv = center.distanceFrom(new GLatLng(center.lat()+0.1, center.lng()))/100;
		var lngConv = center.distanceFrom(new GLatLng(center.lat(), center.lng()+0.1))/100;
		//Loop 
		var points = [];
		var step = parseInt(360/nodes)||10;
		
		for(var i=0; i<=360; i+=step){
			var pint = new GLatLng(center.lat() + (radius/latConv * Math.cos(i * Math.PI/180)), center.lng() + (radius/lngConv * Math.sin(i * Math.PI/180)));
			points.push(pint);
		}
		fillColor = fillColor||liColor||"#0055ff";
		liWidth = liWidth||1;
		//
		var poly = new GPolygon(points,liColor,liWidth,liOpa,fillColor,fillOpa);
		map.addOverlay(poly);
		circleArray.push(poly); //On enregistre le cercle dans une cellule du tableau

	}
	//fin function draw circle
	draw(point);
}
//
function vide_adresse_from(){
	if (document.combos1.adresse_from.value == "No, Street, City, Country") {
		document.combos1.adresse_from.value = "";
	}
}
//
function remp_adresse_from(){
	if (document.combos1.adresse_from.value == "") {
		document.combos1.adresse_from.value = "No, Street, City, Country";
	}
}
//---
function combo_to_zero() {
	if(document.combos1!=null){
		var temp=document.combos1.combo11;
		temp.options[0] = new Option("CHOOSE AN AIRPORT", "");
		temp.options[0].disabled = true;
		temp.options[0].selected = true;
		for (m=temp.options.length-1;m>0;m--){
			temp.options[m]=null
		}
	}
}
//------------------------------------------------------------------------------------- charge la liste des aéroports proches, les affiches sur la map
function load_combo11(){
	// VIDE LA COMBO BOX
	combo_to_zero();
	document.combos1.add_grid.disabled = true;
	//
	// recuperation de l'adresse envoyee dans le champs de texte 1
	sended_adresse_from = document.combos1.adresse_from.value;
	//
	var pointeur1;
	var pointeur2;
	//
	coords_from.getLatLng(sended_adresse_from, function (coord) {
		if(!coord) {
			// previent s'il ne trouve pas la destination
			//alert(sended_adresse_from+ " not found.\nPlease retry.");
		} else {
			coords_departure = coord;
			if(marker_from){
				map.removeOverlay(marker_from);
			}
			//
			var html = '<div><b>DEPARTURE ADDRESS:</b><br />'
			+ sended_adresse_from
			+ '</div>';
			//
			var markerHTML = html;
			//
			map.setCenter(coord, 7);
			current_marker = add_listener(coord, markerHTML, 4, 1);
			map.addOverlay(current_marker);
			marker_from = current_marker;
			// CALCUL LES DISTANCES ENTRE LES AEROPORTS ET L ADRESSE SELECTIONNEE
			pointeur1 = new GLatLng(coord.lat(), coord.lng());
        	for(var i=0; i<all_infos_airport_from.length; i++) {
        		pointeur2 = new GLatLng(all_infos_airport_from[i][3], all_infos_airport_from[i][4]);
        		current_distance = Math.round(pointeur1.distanceFrom(pointeur2)/1000);
        		// renseignement de la distance par rapport a l'adresse
        		all_infos_airport_from[i][5] = current_distance;
         		//
        	}
        	// TRIE LES AEROPORTS
        	//--if(TriTab(all_infos_airport_from,1)){
        		var temp=document.combos1.combo11;
				var ajout_a = 1;
				// vide la table des aéroports les plus proches
				adding_from = new Array();
				for (i=0;i<all_infos_airport_from.length;i++){
					//--if (ajout_a < max_airports && all_infos_airport_from[i][5]<distance_max_search && Number(all_infos_airport_from[i][6]) < 3) {
					if (all_infos_airport_from[i][5]<distance_max_search && Number(all_infos_airport_from[i][6]) < 3) {
						//
						//categories_from[selected][ajout_a-1] = all_infos_airport_from[i][0];
						//
						//alert(all_infos_airport_from[i][0]+" / "+all_infos_airport_from[i][1]);
						//--adding_from.push(all_infos_airport_from[i][0]);
						
						adding_from.push(all_infos_airport_from[i]);
						
						//--temp.options[ajout_a]=new Option(all_infos_airport_from[i][1]+" | "+all_infos_airport_from[i][5]+" km", all_infos_airport_from[i][0])
						ajout_a++;
					}
				}
				
				airport_from = new Array();
				
				TriTab2(adding_from);
				
				nb_airports_from = max_airports;
				if(adding_from.length < max_airports){
					nb_airports_from = adding_from.length;
				}
				
				for (i=0;i<nb_airports_from;i++){
					airport_from.push(adding_from[i][0])
					temp.options[i+1]=new Option(adding_from[i][1]+" | "+adding_from[i][5]+" km", adding_from[i][0])
				}

				
				init_all_airports(airport_from, "all_airports_from");	
				//
        	//}
			// SI LA CASE ALL AIRPORTS EST COCHEE, LA DECOCHE
			if(document.button_airports.remove_airport.checked == true) {
				launchtest(true);
			}
		}
	});
}
//------------------------------------------------------------------------------------- AJOUTE L ADRESSE DANS LA LISTE
function add_address_to_list() {
	var val = all_airports_grid.length;
	all_airports_grid[val] = new Array();
	//
	all_airports_grid[val][0] = temp_id;
	all_airports_grid[val][1] = temp_address;
	all_airports_grid[val][2] = temp_car;
	//
	document.combos1.list_grid.value = "";
	for(var i =0; i< all_airports_grid.length; i++) {
		//
		recup_id = all_airports_grid[i][0];
		recup_name = markers[recup_id].getAttribute("name");
		recup_address = all_airports_grid[i][1];
		//
		document.combos1.list_grid.value += recup_address+" BY "+recup_name;
		document.combos1.list_grid.value += "\n";
	}
	if(val>0) {
		document.combos1.create_grid.disabled = false;
	}
	if((val+1) >=max_in_grid){
		document.combos1.add_grid.disabled = true;
	}
	
}
//------------------------------------------------------------------------------------- CALCUL LE TRAJET, L AFFICHE - PERMET LE CLICK SUR ADD ADDRESS
function load_combo12(selected){
	var sended_adresse_from = document.combos1.adresse_from.value;
	var lat = markers[selected].getAttribute("lat");
	var lng = markers[selected].getAttribute("lng");
	var lat_from = coords_departure.lat();
	var lng_from = coords_departure.lng();
	gdir1.load("from: "+lat_from+","+lng_from+" to: "+lat+","+lng, { "locale": "EN", "preserveViewport": true });
	if (all_airports_grid.length < max_in_grid) {
		document.combos1.add_grid.disabled = false;
	}
	// REMPLIT LES VARIABLES TEMPORAIRES POUR LE REMPLISSAGE DU TABLEAU GRID
	temp_id = selected;
	temp_address = sended_adresse_from;
}
function onGDirectionsLoad1(){
	duration1 = gdir1.getDuration().seconds;
	//
	t_entier = duration1/86400;
	time_travel_from = t_entier;
	//
	t_jours = Math.floor(t_entier);
	t_heures = Math.floor((t_entier-t_jours)*24);
	t_minutes = Math.floor((t_entier-t_jours-t_heures/24)*24*60);
	//document.combos3.temps1.value = t_jours+" jour(s) "+t_heures+" heure(s) "+t_minutes+" minute(s) ";
	//
	document.combos1.car_time.value = "";
	if(t_heures > 0) {
		document.combos1.car_time.value += t_heures+h_name;
	}
	document.combos1.car_time.value += t_minutes+m_name;
	// REMPLIT LES VARIABLES TEMPORAIRES POUR LE REMPLISSAGE DU TABLEAU GRID
	temp_car = time_travel_from;
}
function create_list() {
	//
	var string_grid = "";
	string_grid += "<table class='matable' align='center'>";
	//
	var limite_a = 5;
	var nbr_tables = Math.ceil(all_airports_grid.length/limite_a);
	var reste = all_airports_grid.length-((nbr_tables-1)*limite_a);
	//alert(nbr_tables+" / "+reste);
	//
	for(z=0; z<nbr_tables*limite_a; z+=limite_a) {
	//alert(z);
		//
		string_grid += "<tr><td align='left' class='montd'><table border='1'>";
		
		//
		for(var i=-1; i<all_airports_grid.length; i++) {
			if(((i-1)%2) == 0) {
				var couleur_ligne = "#FFFFFF";
			} else {
				var couleur_ligne = "#DDDDDD";
			}
			for(var y=z-1; y<all_airports_grid.length && y< z+limite_a; y++) {
				// AJOUTE LES TR SI DEBUT
				if(y == (z-1)) {
					string_grid += "<tr>";
				}
				if(i == y && y != z-1) {
					string_grid += "<td bgcolor='#d95121'></td>";
				} else {
					if(i < 0) {
						if(y == (z-1)) {
							string_grid += "<td bgcolor='#d95121'></td>";
						} else {
							// RECUPER LES INFOS
							recup_yd = all_airports_grid[y][0];
							recup_name = markers[recup_yd].getAttribute("name");
							recup_type = markers[recup_yd].getAttribute("type_num");
							recup_zone = markers[recup_yd].getAttribute("zone_num");
							recup_car = all_airports_grid[y][2];
							recup_address = all_airports_grid[y][1];
							var image_name = (recup_type-1)+"_"+recup_zone;
							//
							string_grid += "<td bgcolor='"+couleur_ligne+"'><table class='matable' width='100%'><tr class='montd'><td class='montd'><b>"+recup_address+"<br />BY "+recup_name+"</b></td><td class='montd' align='right'><img src='../map_module/images/"+image_name+".png'></td></tr></table></td>";
						}
					} else {
						// RECUPER LES INFOS
						recup_id = all_airports_grid[i][0];
						recup_name = markers[recup_id].getAttribute("name");
						recup_type = markers[recup_id].getAttribute("type_num");
						recup_zone = markers[recup_id].getAttribute("zone_num");
						recup_address = all_airports_grid[i][1];
						recup_cari = all_airports_grid[i][2];
						var image_name = (recup_type-1)+"_"+(recup_zone-1);
						var save_lat0 = markers[recup_id].getAttribute("lat");
						var save_lng0 = markers[recup_id].getAttribute("lng");
						var latlng0 = new GLatLng(parseFloat(save_lat0),parseFloat(save_lng0));
						//
						if(y == (z-1)) {
							string_grid += "<td bgcolor='"+couleur_ligne+"'><table class='matable' width='100%'><tr class='montd'><td class='montd'><b>"+recup_address+"<br />BY "+recup_name+"</b></td><td class='montd' align='right'><img src='../map_module/images/"+image_name+".png'></td></tr></table></td>";
						} else {
							// RECUPER LES INFOS
							recup_yd = all_airports_grid[y][0];
							recup_name = markers[recup_yd].getAttribute("name");
							recup_address = all_airports_grid[y][1];
							recup_cary = all_airports_grid[y][2];
							var save_lat1 = markers[recup_yd].getAttribute("lat");
							var save_lng1 = markers[recup_yd].getAttribute("lng");
							var latlng1 = new GLatLng(parseFloat(save_lat1),parseFloat(save_lng1));
							//
							distance = (latlng0.distanceFrom(latlng1))/1000;
							t_entier_vol = (distance/500+0.25)/24;
							t_entier_vol += recup_cari+recup_cary;
							t_entier_vol += embarquement*2;
							t_jours_vol = Math.floor(t_entier_vol);
							t_heures_vol = Math.floor((t_entier_vol-t_jours_vol)*24);
							t_minutes_vol = Math.floor((t_entier_vol-t_jours_vol-t_heures_vol/24)*24*60);
							//
							t_entier_tot = (distance/500+0.25)/24;
	
							t_jours_tot = Math.floor(t_entier_tot);
							t_heures_tot = Math.floor((t_entier_tot-t_jours_tot)*24);
							t_minutes_tot = Math.floor((t_entier_tot-t_jours_tot-t_heures_tot/24)*24*60);
							//
							string_grid += "<td align='center' bgcolor='"+couleur_ligne+"'><b>";
							if(t_jours_vol > 0) {
								string_grid += t_jours_vol+j_name;
							}
							if(t_heures_vol > 0) {
								string_grid += t_heures_vol+h_name;
							}
							string_grid += t_minutes_vol+m_name;
							string_grid += "</b><br />";
							string_grid += "[ ";
							if(t_jours_tot > 0) {
								string_grid += t_jours_tot+j_name;
							}
							if(t_heures_tot > 0) {
								string_grid += t_heures_tot+h_name;
							}
							string_grid += t_minutes_tot+m_name;
							string_grid += " ]";
							string_grid += "</td>";
						}
					}
				}
				// AJOUTE LES /TR SI FIN
				if(y == (all_airports_grid.length-1)) {
					string_grid += "</tr>";
				}
			}
		}
		//
		string_grid += "</table></td></tr>";
		string_grid += "<tr><td height='40px' class='montd'></td></tr>";
		//
	}
	//
	string_grid += "</table>";
	// REMPLACE LES CARACTERES A PROBLEMES
	//string_grid = string_grid.replace(/'/g, "%27");
	//string_grid = string_grid.replace(/#/g, "%23");
	document.hidden.string_grid.value = string_grid;
	//alert(document.hidden.hidden.value);
	document.hidden.submit();
	//
	//window.open("library/php/content.en_time_grid.php?string_grid="+string_grid);
}
//
function popup_legend() {
	window.open ('./library/map_module/legend.html', 'LEGEND', config='height=450, width=600, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no')
}
//------------------------------------------------------------------------------------- affichage d'erreurs
function handleErrors1(){
	// AU CAS OU UNE ERREUR SE PRODUIT AVEC LA RECHERCHE D UNE ROUTE, AFFICHE TEMPS INCONNU DANS LA CASE CAR TIME
	// LE TEMPS EST COMPTE A 0
	document.combos1.car_time.value = "UNKNOWN, SORRY";
	temp_car = 0;
	//
	if (gdir1.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: " + gdir1.getStatus().code);
	else if (gdir1.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: " + gdir1.getStatus().code);
	else if (gdir1.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: " + gdir1.getStatus().code);
	else if (gdir1.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: " + gdir1.getStatus().code);
	else if (gdir1.getStatus().code == G_GEO_BAD_REQUEST)
		alert("A directions request could not be successfully parsed.\n Error code: " + gdir1.getStatus().code);
	else alert("An unknown error occurred.");
}