// JavaScript Document

var nomDestination;
var codeContinent; // code du continent : utilisˇ pour afficher le jeu de photo de la col de gauche selon le continent

//Function to create an XMLHttp Object.
function getXMLHttp (){
//Create a boolean variable to check for a valid Microsoft ActiveX instance.
	var xmlhttp = false;
	//Check if we are using Internet Explorer.
	try {
	//If the JavaScript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) {
	//If not, then use the older ActiveX object.
		try {
		//If we are using Internet Explorer.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		//Else we must be using a non-Internet Explorer browser.
			xmlhttp = false;
		}
	}
	// If we are not using IE, create a JavaScript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
function changeTextConfig (fieldId, fieldText){
	if (fieldId == 'resultat_destination') {
		nomDestination = fieldText;
		majPhotosParContinent(codeContinent);
	}
	//alert('fieldId : '+fieldId+' , fieldText : '+fieldText);
	if (document.getElementById(fieldId)) {
		document.getElementById(fieldId).innerHTML = fieldText;
	}
	
}
function getTextSelect(fieldId){ 
	var fieldSelect = document.getElementById(fieldId);
	var fieldSelectTextValue = fieldSelect.options[fieldSelect.selectedIndex].text;
	return fieldSelectTextValue;
} 
function getValueSelect(fieldId){ 
	var fieldSelect = document.getElementById(fieldId);
	var fieldSelectTextValue = fieldSelect.options[fieldSelect.selectedIndex].value;
	return fieldSelectTextValue;
} 
function changeCollectionField(){ 

	var fieldSelectColl = getTextSelect('collection');
	changeTextConfig ('resultat_collection', fieldSelectColl);
} 
function resetCollectionField(){ 

	changeTextConfig ('resultat_collection', 'Toutes les collections');
} 

function setValueOfSelect(selectName,valeur) {
//alert('selectName '+selectName+', valeur '+valeur);
	if(selectName=='continent') {
		codeContinent = valeur; // code du continent : util pour afficher le jeu de photo de la col de gauche selon le continent
	}
	if(selectName=='pays') {
		if((valeur=='SAU') || (valeur=='ARM') || (valeur=='AZE') || (valeur=='AZE') || (valeur=='BHR') || (valeur=='CYP') ||
		   (valeur=='ARE') || (valeur=='GEO') || (valeur=='IRN') || (valeur=='IRQ') || (valeur=='ISR') || (valeur=='JOR') ||
		   (valeur=='KWT') || (valeur=='LBN') || (valeur=='OMN') || (valeur=='QAT') || (valeur=='SYR') || (valeur=='TUR'))
		{
		codeContinent = "ASI.MOR"; // code du continent : util pour afficher le jeu de photo de la col de gauche selon le continent
		majPhotosParContinent(codeContinent);
		}
	}
	
	options = document.getElementById(selectName).getElementsByTagName("option");
	var mes="";
	for (var i=0 ; i<options.length; i++)
	{
		mes = mes + ", " + options[i].value;
		if(options[i].value == valeur)
		{
			options[i].selected = true;
		}
	}
}
function putSelectInSession(selectNamedest, dest){
	
	var xmlhttp4 = getXMLHttp();
	var url = "configurateurSession.php?nameSelect="+selectNamedest+"&dest="+selectNamedest;
	xmlhttp4.open("GET", url ,true);
	
	xmlhttp4.onreadystatechange = function() 
	{
		if (xmlhttp4.readyState == 4 && xmlhttp4.status == 200) 
		{
			
		}
	};
	xmlhttp4.send(null);
}
function getChoixSelectCollection(dest){
	
//Get an XMLHttpRequest object for use.
	var dirFileCol = "xml/collections/";
	var pathFileCol = dirFileCol+dest+'.col';
	
	//alert('dest : '+dest);
	var xmlhttp = getXMLHttp();
	//xmlhttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	xmlhttp.open("GET", pathFileCol,true);
	
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('selCollections').innerHTML = xmlhttp.responseText;
		}
	};
	xmlhttp.send(null);
}
function getCarteDefault(dest){
	
//Get an XMLHttpRequest object for use.
	var dirFileMap = "xml/cartes/";
	var pathFileMap = dirFileMap+dest+'.xml';
	
	//alert('dest : '+dest);
	var xmlhttp = getXMLHttp();
	//xmlhttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	xmlhttp.open("GET", pathFileMap,true);
	
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('textMap').innerHTML = xmlhttp.responseText;
		}
	};
	xmlhttp.send(null);
}

function getChoixSelectDest(type,dest){
//Get an XMLHttpRequest object for use.

	/*alert('type : '+type);
	alert('dest : '+dest);*/
	if(type == 'collection')
	{
		typeSelect = 'ville';
		// selection du choix dans le menu deroulant
		setValueOfSelect(typeSelect,dest);
		//putSelectInSession(typeSelect, dest);
		
		// affichage du choix dans le champ text du configurateur
		var selectFieldText = getTextSelect(typeSelect);
		var destFieldText = ': <strong>'+selectFieldText+'</strong>';
				
		changeTextConfig ('libDestinationEntete', destFieldText);
		changeTextConfig ('resultat_destination',selectFieldText);
	}
	if(type != 'collection')
	{
		var dirFile = "xml/select/";
		var pathFile = dirFile+dest+'.xml';
		
		var xmlhttp2 = getXMLHttp();
		var typeSelect = type;
		//xmlhttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp2.open("GET", pathFile,true);
		
		xmlhttp2.onreadystatechange = function() 
		{
			if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200) 
			{
				if((dest == "") || (dest == "WRL"))
				{
					initPage();	
				}
				if(type == 'pays')
				{
					// vide les select du configurateur
					document.getElementById('pays').length=1;
					document.getElementById('ville').length=1;
					document.getElementById('collection').length=1;
					resetCollectionField();
					
					/// fill le select pays
					document.getElementById('selPays').innerHTML = xmlhttp2.responseText;
					typeSelect = "continent";
				}
				if(type == 'ville')
				{
					// vide les select du configurateur
					document.getElementById('ville').length=1;
					document.getElementById('collection').length=1;
					resetCollectionField();
					
					/// fill le select ville
					document.getElementById('selVille').innerHTML = xmlhttp2.responseText;
					typeSelect = 'pays';
				}
				///mise en session de la variable
				putSelectInSession(typeSelect,dest);
				
				// selection du choix dans le menu deroulant
				setValueOfSelect(typeSelect,dest);
				
				// affichage du choix dans le champ text du configurateur
				var selectFieldText = getTextSelect(typeSelect);
				//alert('selectFieldText '+selectFieldText);
				var destFieldText = ': <strong>'+selectFieldText+'</strong>';
				
				//alert('selectFieldText '+selectFieldText);
				changeTextConfig ('libDestinationEntete', destFieldText);
				changeTextConfig ('resultat_destination',selectFieldText);
				//changeTextConfig ('resultat_collection','Toutes les collections');
				
			}
		};
		xmlhttp2.send(null);
	}
}
function getChoixDest(type,dest){
	if(type == 'ville' && dest == ''){
		type = 'pays';
		dest = document.getElementById('continent').value;
		etatBoutonsGo('none');
	}
	if(type == 'collection' && dest == ''){
		type = 'ville';
		dest = document.getElementById('pays').value;
	}
	//alert(type + ' - ' + dest);
	if((dest == "continent") || (dest == "pays") || (dest == "ville") || (dest == "") || (dest == 0) || (dest == "WRL")|| (dest == "undefined"))
	{
		//alert('re-init');
		initPage();
	}
	else
	{
		if(type == 'ville' && dest != ''){
			etatBoutonsGo('block');
		}
		//alert('chargement des donnees');
		getChoixSelectDest(type,dest);
		getCarteDest(dest);
		getChoixSelectCollection(dest);
	}
}

function goCarte(){
	var continent = document.getElementById('continent').value;
	var pays = document.getElementById('pays').value;
	var ville = document.getElementById('ville').value;
	//alert(continent+ " - " + pays+ " - " + ville+ " - " + nomDestination);
		
	document.location.href = "index.php?continent="+continent+"&pays="+pays+"&ville="+ville+"&nomDestination="+nomDestination;
}
// recuperation de variable en javascript
var paramOk = true;

function FaitTableau(n) {
  // Creation d'un tableau (array)
  // aux dimensions du nombre de parametres.
  this.length = n;
  for (var i = 0; i <= n; i++) {
    this[i] = 0;
  }
  return this;
}

function ParamValeur(nValeur) {
  // Recuperation de la valeur d'une variable
  // Pour creer la variable en Javascript.
  var nTemp = "";
  for (var i=0;i<(param.length+1);i++) {
    if (param[i].substring(0,param[i].indexOf("=")) == nValeur)
      nTemp = param[i].substring(param[i].indexOf("=")+1,param[i].length);
  }
  return Decode(nTemp);
}

// Extraction des parametres de la requete HTTP
// et initialise la variable "paramOk" a false
// s'il n'y a aucun parametre.
if (!location.search) {
  paramOk = false;
}
else {
  // Eliminer le "?"
  var nReq = location.search.substring(1,location.search.length);
  // Extrait les differents parametres avec leur valeur.
  nReq = nReq.split("&");
  param = new FaitTableau(nReq.length-1);
  for (var i=0;i<(nReq.length);i++) {
    param[i] = nReq[i];
  }
}

// Decoder la requete HTTP
// manuellement pour le signe (+)
function Decode(tChaine) {
  while (true) {
    var i = tChaine.indexOf('+');
    if (i < 0) break;
    tChaine = tChaine.substring(0,i) + '%20' + tChaine.substring(i + 1, tChaine.length);
  }
  return unescape(tChaine);
}

function initPage(nomCollection)
{
	//alert("initPage : "+nomCollection);
	// si on vien de la page collection on recharge les infos 
	var rcd = "";
	//if(paramOk) rcd = ParamValeur('rcd'); // on desactive le test pour le moment
	if(rcd != ""){
		dest = ParamValeur('dest');
		type = ParamValeur('type');
		col = ParamValeur('col');
		getChoixSelectDest(type,dest);
		getChoixSelectCollection(col);
	}else{
		// reinititalise les textes des champs du config par defaut
		changeTextConfig ('resultat_destination', 'Choisissez votre destination<!-- sur la carte -->');
		if(nomCollection) changeTextConfig ('resultat_collection', nomCollection);
		else changeTextConfig ('resultat_collection', 'Toutes les collections');
		changeTextConfig ('libDestinationEntete', '');
		
		// met la carte du monde par defaut
		getCarteDest('WRL');
		
		// vide les select du configurateur
		document.getElementById('pays').length=1;
		document.getElementById('ville').length=1;
		document.getElementById('collection').length=1;
		
		// selectionne continent par defaut;
		document.getElementById('continent').options[0].selected = true;
		etatBoutonsGo('none');
	}
}

function loadSelectPays(cont,pays,ville,collection)
{
	//alert('cont : '+cont+'/ pays : '+pays+'/ ville : '+ville+'/ collection : '+collection);

	var dirFile = "xml/select/";
	var pathFile = dirFile+cont+'.xml';
		
	var xmlhttpCont = getXMLHttp();

	xmlhttpCont.open("GET", pathFile,true);
		
	xmlhttpCont.onreadystatechange = function() 
	{
		if (xmlhttpCont.readyState == 4 && xmlhttpCont.status == 200) 
		{
			// vide les select du configurateur
			document.getElementById('pays').length=1;
			document.getElementById('ville').length=1;
			document.getElementById('collection').length=1;
				
			/// fill le select pays
			document.getElementById('selPays').innerHTML = xmlhttpCont.responseText;
			
			///mise en session de la variable
			//putSelectInSession(typeSelect,dest);
			
			// selection du choix dans le menu deroulant
			setValueOfSelect('continent',cont);
			getCarteDest(cont);
			//alert("pays : "+pays);
			if(pays != "")
			{
				loadSelectVille(''+pays+'',''+ville+'',''+collection+'');
				etatBoutonsGo('block');
				
			}
		}
	};
	xmlhttpCont.send(null);	
}
function loadSelectVille(pays,ville,collection)
{
	var dirFile = "xml/select/";
	var pathFile = dirFile+pays+'.xml';
		
	var xmlhttpPays = getXMLHttp();

	xmlhttpPays.open("GET", pathFile,true);
		
	xmlhttpPays.onreadystatechange = function() 
	{
		if (xmlhttpPays.readyState == 4 && xmlhttpPays.status == 200) 
		{
			// vide les select du configurateur
			document.getElementById('ville').length=1;
			document.getElementById('collection').length=1;
				
			/// fill le select ville
			document.getElementById('selVille').innerHTML = xmlhttpPays.responseText;
			
			///mise en session de la variable
			//putSelectInSession(typeSelect,dest);
			
			// selection du choix dans le menu deroulant
			setValueOfSelect('pays',pays);
			//alert('pays : '+pays);
			
			//alert('ville : '+ville);
			if(ville == "" || ville == "ESP.NCE" || ville == "ESP.SOU" || ville == "ITA.NCE" || ville == "ITA.SOU")
			{
				setValueOfSelect('pays',pays);
				getCarteDest(pays);
				//alert("getCarteDest : pays");
		
				var selectFieldText = "";
				if(ville == "ESP.NCE") selectFieldText = "Espagne du Nord et du Centre";
				else if(ville == "ESP.SOU") selectFieldText = "Espagne du Sud";
				else if(ville == "ITA.NCE") selectFieldText = "Italie du Nord et du Centre";
				else if(ville == "ITA.SOU") selectFieldText = "Italie du Sud";
				else selectFieldText = getTextSelect('pays');
				var destFieldText = ': <strong>'+selectFieldText+'</strong>';
				
				//alert('loadSelectVille selectFieldText : '+selectFieldText);
				changeTextConfig ('libDestinationEntete', destFieldText);
				changeTextConfig ('resultat_destination',selectFieldText);	
			}
			loadSelectCollection(''+pays+'',''+ville+'',''+collection+'');

		}
	};
	xmlhttpPays.send(null);	
}

function loadSelectCollection(pays,ville,collection)
{
	//Get an XMLHttpRequest object for use.
	var dirFileCol = "xml/collections/";
	if(ville=="")
	{
		var pathFileCol = dirFileCol+pays+'.col';
	}
	if(ville!="")
	{
		var pathFileCol = dirFileCol+ville+'.col';
	}
	
	//alert('dest : '+dest);
	var xmlhttpVille = getXMLHttp();
	//xmlhttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	xmlhttpVille.open("GET", pathFileCol,true);
	
	xmlhttpVille.onreadystatechange = function() 
	{
		if (xmlhttpVille.readyState == 4 && xmlhttpVille.status == 200) 
		{
			// vide les select du configurateur
			document.getElementById('collection').length=1;
				
			/// fill le select collection
			document.getElementById('selCollections').innerHTML = xmlhttpVille.responseText;
			
			// selection du choix dans le menu deroulant
			
			if(ville != "" && ville != "ESP.NCE" && ville != "ESP.SOU" && ville != "ITA.NCE" && ville != "ITA.SOU")
			{
				setValueOfSelect('ville',ville);
				getCarteDest(ville);
				//alert("getCarteDest : ville");
		
				var selectFieldText = getTextSelect('ville');
				var destFieldText = ': <strong>'+selectFieldText+'</strong>';
				
				//alert('loadSelectCollection selectFieldText : '+selectFieldText);
				changeTextConfig ('libDestinationEntete', destFieldText);
				changeTextConfig ('resultat_destination',selectFieldText);	
			}
			if(collection != "")
			{
				setValueOfSelect('collection',collection);
				changeCollectionField();
			}
		}
	};
	xmlhttpVille.send(null);		
}

// nouvelle version
function goGetGDV(typeDest,dest) {
	
	var continent, pays, grouperegion, region, ville, collection, url;
	if((dest != "") && (typeDest != ""))
	{
		if(typeDest == "continent") type = "pays";
		if(typeDest == "souscontinent") type = "pays";
		if(typeDest == "pays") type = "ville";
		if(typeDest == "grouperegion") type = "collection";
		if(typeDest == "region") type = "collection";
		if(typeDest == "departement") type = "collection";
		if(typeDest == "ville") type = "collection";
	
		if(dest == "RUS")
		{
			if(getValueSelect('continent') == "EUR")
			{
				setValueOfSelect(''+typeDest+'', ''+dest+'');
			}
			else
			{
				getSelectDest(''+type+'','EUR');
				setValueOfSelect('continent', 'EUR');
				setValueOfSelect(''+typeDest+'', ''+dest+'');
			}
		}
		continent = getValueSelect('continent');
		if(typeDest == "pays")
		{
			setValueOfSelect(''+typeDest+'', ''+dest+'');

			document.getElementById('ville').length=1;
			document.getElementById('collection').length=1;
			
			pays =  getValueSelect('pays');
			
			if(pays != dest)
			{
				document.getElementById(typeDest).options[0].selected = true;
			}				
		}
		if((typeDest == "ville") || (typeDest == "region"))
		{
			setValueOfSelect('ville', ''+dest+'');
			
			//document.getElementById('collection').length=1;
			//alert('set value : '+dest);
		}
	}
		
	//config = dojo.io.cookie.getCookie("config");
	continent = getValueSelect('continent');
	pays =  getValueSelect('pays');
	ville = getValueSelect('ville');
	collection = getValueSelect('collection');	
	//alert("continent : "+continent+"/ pays : "+pays+"/ ville : "+ville);
		
	url = "gdv.php?dest=";
	
	if((pays == "") && ((continent == "WRL") || (continent == "")))
	{
		self.location="index.php";
	}
	
	if((pays == "") && ((continent != "WRL") && (continent != "")))
	{
		//alert("vous devez renseigner le pays de votre choix");
		alert("il n'existe aucun resultat pour cette destination");
	}
	else
	{
		if((ville == "")||(region == ""))
		{
			if(typeDest == "grouperegion") {url += dest;}
			else url += pays;
		}
		else
		{
			url += ville;
		}
		if (collection != "")
		{ 
			url += "&col=" + collection;
		}
		url += "&nomDestination=" + nomDestination;
		self.location=url;
	}
	
}

function goGetPays(continent,pays,collection) {
	
	var continent, pays, collection, url;
	
	getSelectDest(continent);
	setValueOfSelect('continent', ''+continent+'');
		
	getSelectDest(pays);
	setValueOfSelect('pays', ''+pays+'');
	
	setValueOfSelect('collection', ''+collection+'');
	
	//alert("continent : "+continent+"/ pays : "+pays);
	
	url = "gdv.php?dest="+pays+"&col="+ collection;
	url += "&nomDestination=" + nomDestination;
	self.location=url;
}

function goGetCollection(destCol, collection) {
	
	var destCol, collection, url, fileName;
	
	switch (collection){
		case "GDR": 
			fileName = "col_guide_du_routard.php";
		break;
		case "GBE": 
			fileName = "col_evasion.php";
		break;
		case "GB": 
			fileName = "col_guide_bleu.php";
		break;
		case "WE": 
			fileName = "col_grand_week-end.php";
		break;
		case "VOIR": 
			fileName = "col_guide_voir.php";
		break;
	//alert('fileName : '+fileName+' collection : '+collection);
	}
	
	url = fileName+"?destCol="+destCol+"#etape_2";
	self.location=url;
} 

function getSelectDest (dest){
//Get an XMLHttpRequest object for use.
	var xmlhttp2 = getXMLHttp();
	var url = 'configurateur.php?dest='+dest;
	xmlhttp2.open("GET", url);
	xmlhttp2.onreadystatechange = function() 
	{
		if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200) 
		{
			var selectName = '';
			var docXML2= xmlhttp2.responseXML;
			var type = docXML2.getElementsByTagName("destination")[0].getAttribute('type');
		
			//alert('type = '+type);
			if (type == "souscontinent"){ type="continent";}
			if (type == "continent"){ selectName = "pays";}
			if (type == "pays"){ selectName = "ville";}
			if (type == "ville"){ selectName = "collection";}
			if (type == "region"){ type = "ville"; selectName = "collection";}
			//alert('selectName = '+selectName);
			
			var items = docXML2.getElementsByTagName("lieu");
			
			//on fait juste une boucle sur chaque element "donnee" trouve
			//document.getElementById("message").className="tumevoispas";
			document.getElementById(selectName).length=1;
			
			var index =0;
			var indexTab =0;
			var indexCol = 0;
			var indexColTab = 0;
			var valeur = "";
			var valeurId = "";
			var valeurCol = "";
			var valeurColId = "";
			var tabLieux = new Array();
			var tabCollections = new Array();
			
			
			if((selectName == "pays") || (selectName == "ville"))
			{
				if(selectName == "pays")
				{
				// mise a zero du select pays
				document.getElementById('ville').length=1;
				valeurId = "";
				valeur = "Toutes r&eacute;gions ou villes";
				//on ajoute la valeur du libelle + son id comme nouvel option du select
				document.getElementById('ville').options[0]=new Option(valeur,valeurId);
				}	
				// mise a zero du select collection
				document.getElementById('collection').length=1;
				valeurIdCol = "";
				valeurCol = "Toutes les collections";
				//on ajoute la valeur du libelle + son id comme nouvel option du select
				document.getElementById('collection').options[0]=new Option(valeurCol,valeurIdCol);
				//changeTextConfig ('resultat_collection', 'Toutes les collections');
				//setValueOfSelect('collection','Toutes les collections');
			}
			
			
			// selection du choix dans le menu deroulant
			setValueOfSelect(type,dest);
			
			// affichage du choix dans le champ text du configurateur
			var selectFieldText = getTextSelect(type);
			var destFieldText = ': <strong>'+selectFieldText+'</strong>';
			
			//alert('getSelectDest selectFieldText '+selectFieldText);
			changeTextConfig ('libDestinationEntete', destFieldText);
			changeTextConfig ('resultat_destination',selectFieldText);
			//changeTextConfig ('resultat_collection','Toutes les collections');
			
			//on fait juste une boucle sur chaque element "lieu" trouve
			for (i=0;i<items.length;i++)
			{
				if((selectName == "pays") || (selectName == "ville"))
				{
					// gestion des menus deroulant concernant la location pays, villes ...
					if(i == 0)
					{
						//On incremente l'index pour garder la valeur par defaut et un vide de separation avant les resultats
						index = index + 2;
					}
					var addLieu = true;
					if(tabLieux.length > 0)
					{
						for(k=0; k<tabLieux.length; k++)
						{
							if(selectName == "pays")
							{
								if((tabLieux[k] == items[i].getElementsByTagName("idlieu")[0].firstChild.nodeValue) || (items[i].getAttribute('type') != selectName))
								{	
									addLieu = false;
								}
							}
							if(selectName == "ville")
							{
								if((tabLieux[k] == items[i].getElementsByTagName("idlieu")[0].firstChild.nodeValue) || ((items[i].getAttribute('type') != "ville") && (items[i].getAttribute('type')!= "region")))
								{	
									addLieu = false;
								}
							}
						}
					}
					if(tabLieux.length == 0)
					{
						if(selectName == "pays")
						{
							if(items[i].getAttribute('type') != selectName)
							{	
								addLieu = false;
							}
						}
						if(selectName == "ville")
						{
							if((items[i].getAttribute('type') != "ville") && (items[i].getAttribute('type')!= "region"))
							{	
								addLieu = false;
							}
						}
					}
					if(addLieu == true)
					{
						tabLieux[indexTab] = items[i].getElementsByTagName("idlieu")[0].firstChild.nodeValue;
						//On incremente l'index col 1
						indexTab = indexTab + 1;
							
						//On determine la valeur du libelle, puis on l'affiche
						valeurId = items[i].getElementsByTagName("idlieu")[0].firstChild.nodeValue;
						//alert (valeurId);
						
						//On determine la valeur du libelle, puis on l'affiche
						valeur = items[i].getElementsByTagName("libelle")[0].firstChild.nodeValue;
						//alert (valeur);
						//on ajoute la valeur du libelle + son id comme nouvel option du select
						document.getElementById(selectName).options[index]=new Option(valeur,valeurId);
						
						//On incremente l'index
						index = index + 1;
					}
				}
				//setValueOfSelect(type,dest);
				// gestion des menus deroulant concernant la collection des articles : guide routard...
				if((selectName == "ville") || (selectName == "collection"))
				{
					if(i == 0)
					{
						//On incremente l'index pour garder la valeur par defaut et un vide de separation avant les resultats
						indexCol = indexCol + 2;
					}
					var addCollection = true;
					if(tabCollections.length > 0)
					{
						for(j=0; j<tabCollections.length; j++)
						{
							if(tabCollections[j] == items[i].getElementsByTagName("idcollection")[0].firstChild.nodeValue)
							{	
								addCollection = false;
							}
						}
					}
					if(addCollection == true)
					{
						tabCollections[indexColTab] = items[i].getElementsByTagName("idcollection")[0].firstChild.nodeValue;
						//On incremente l'index col 1
						indexColTab = indexColTab + 1;
						
						//On determine la valeur du libelle, puis on l'affiche
						valeurColId = items[i].getElementsByTagName("idcollection")[0].firstChild.nodeValue;
						//alert ('valeurColId '+valeurColId);
						
						//On determine la valeur du libelle, puis on l'affiche
						valeurCol = items[i].getElementsByTagName("nomcollection")[0].firstChild.nodeValue;
						//alert ('valeurColId '+valeurColId+', valeurCol '+valeurCol);
						//on ajoute la valeur du libelle + son id comme nouvel option du select
						document.getElementById('collection').options[indexCol]=new Option(valeurCol,valeurColId);
						
						//On incremente l'index
						indexCol = indexCol + 1;
					}
				}
			}
		}
	};
	xmlhttp2.send(null);
}

function getCarteDest (carte){
//Get an XMLHttpRequest object for use.
	//alert(carte);
	var xmlhttp3 = getXMLHttp();
	var url = 'configurateurCarte.php?carte='+carte;
	xmlhttp3.open("GET", url);
	xmlhttp3.onreadystatechange = function() 
	{
		if (xmlhttp3.readyState == 4 && xmlhttp3.status == 200) 
		{
			var docXML = xmlhttp3.responseXML;
			var carteName = docXML.getElementsByTagName("map")[0].getAttribute('name');
			//alert('carteName = '+carteName);
			if(carteName != "WRL")
			{
				var carteParent = docXML.getElementsByTagName("map")[0].getElementsByTagName("mapParent")[0].firstChild.nodeValue;
				var carteParentType = docXML.getElementsByTagName("map")[0].getElementsByTagName("mapParent")[0].getAttribute('type');
				//alert('carteParentType = '+carteParentType);
			}
			
			var textMapDyn = '';
			
			// si il existe une carte
			if (carteName != "")
			{
				var items = docXML.getElementsByTagName("area");
				var mapCoordsId = 'textMap';
				var textUsemapDyn = '';
				var divCarteParent = document.getElementById("btn_retour_carte_img");
				var imgCarteParent = '<img src="images/Cartes/btn_retour_carteMonde.gif" />';
				textMapDyn+= '<map id="map_coords" name="'+carteName+'">';
				
				//on fait juste une boucle sur chaque element "lieu" trouve
				for (i=0;i<items.length;i++)
				{
					var coords = items[i].getElementsByTagName("coords")[0].firstChild.nodeValue;
					var href = items[i].getElementsByTagName("href")[0].firstChild.nodeValue;
					var libelle = items[i].getElementsByTagName("libelle")[0].firstChild.nodeValue;
					var shape = items[i].getElementsByTagName("shape")[0].firstChild.nodeValue;
					
					//textMapDyn+= '<area coords="'+coords+'" href="#" onclick="javascript:'+href+'" title="'+libelle+'" shape="'+shape+'"/>';
					textMapDyn+= '<area coords="'+coords+'" href="javascript:'+href+'" title="'+libelle+'" shape="'+shape+'"/>';
				}
				
				textMapDyn+= '</map>';
				
				// ecriture du textMapDyn dans le div
				if (document.getElementById(''+mapCoordsId+'')) {
					document.getElementById(''+mapCoordsId+'').innerHTML = textMapDyn;
				}
				//alert ( 'mapCoordsId = '+mapCoordsId);
				
				textUsemapDyn = '<img usemap="#'+carteName+'" src="images/Cartes/'+carteName+'.gif" />';
				
				document.getElementById("carte_gd_format_img").innerHTML = textUsemapDyn;
				//alert ( 'textMapDyn = '+textUsemapDyn);

				// changement du bouton retour carteparent
				if (carteName!="WRL")
				{
					divCarteParent.style.display = "block";
					if(carteParent == "EUR")
					{
						imgCarteParent="<a href=\"#\"><img onclick=\"getChoixDest('"+carteParentType+"','"+carteParent+"');\" src=\"images/Cartes/btn_retour_carteEurope.gif\" /></a>";	
					}
					if(carteParent != "EUR")
					{
						imgCarteParent="<a href=\"#\"><img onclick=\"getChoixDest('"+carteParentType+"','"+carteParent+"');\" src=\"images/Cartes/btn_retour_carteMonde.gif\" /></a>";
						//alert('imgCarteParent '+imgCarteParent);
					}
					divCarteParent.innerHTML = imgCarteParent;
				}else{
					divCarteParent.style.display = "none";
				}
				//alert('carteParent : '+carteParent); 
			}
			else
			{
				initPage();	
			}
		}
	};
	xmlhttp3.send(null);
}

function etatBoutonsGo (etat){
	if(document.getElementById('btn_go')) document.getElementById('btn_go').style.display = etat;
	if(document.getElementById('btn_go_c')) document.getElementById('btn_go_c').style.display = etat;
}

function majPhotosParContinent(continent) {
	//alert(continent);
	var nouvellesPhotos = [ ];
	switch (continent) {
	case "WRL":
		nouvellesPhotos = [ 
			{"image" : "ill_Af_01.jpg"},
			{"image" : "ill_AmNo_01.jpg"},
			{"image" : "ill_AmCe_01.jpg"},
			{"image" : "ill_AmSu_01.jpg"},
			{"image" : "ill_As_01.jpg"},
			{"image" : "ill_Eu_01.jpg"},
			{"image" : "ill_MoOr_01.jpg"},
			{"image" : "ill_Oc_01.jpg"},
			{"image" : "ill_Pa_01.jpg"}
		];
		break;
	case "AFR":
		nouvellesPhotos = [ 
			{"image" : "ill_Af_01.jpg"},
			{"image" : "ill_Af_02.jpg"},
			{"image" : "ill_Af_03.jpg"},
			{"image" : "ill_Af_04.jpg"}
		];
		break;
	case "ASI":
		nouvellesPhotos = [ 
			{"image" : "ill_As_01.jpg"},
			{"image" : "ill_As_02.jpg"},
			{"image" : "ill_As_03.jpg"},
			{"image" : "ill_As_04.jpg"}
		];
		break;
	case "AME.NOR":
		nouvellesPhotos = [ 
			{"image" : "ill_AmNo_01.jpg"},
			{"image" : "ill_AmNo_02.jpg"},
			{"image" : "ill_AmNo_03.jpg"},
			{"image" : "ill_AmNo_04.jpg"}
		];
		break;
	case "AME.CEN":
		nouvellesPhotos = [ 
			{"image" : "ill_AmCe_01.jpg"},
			{"image" : "ill_AmCe_02.jpg"},
			{"image" : "ill_AmCe_03.jpg"},
			{"image" : "ill_AmCe_04.jpg"}
		];
		break;
	case "AME.SOU":
		nouvellesPhotos = [ 
			{"image" : "ill_AmSu_01.jpg"},
			{"image" : "ill_AmSu_02.jpg"},
			{"image" : "ill_AmSu_03.jpg"},
			{"image" : "ill_AmSu_04.jpg"}
		];
		break;
	case "EUR":
		nouvellesPhotos = [ 
			{"image" : "ill_Eu_01.jpg"},
			{"image" : "ill_Eu_02.jpg"},
			{"image" : "ill_Eu_03.jpg"},
			{"image" : "ill_Eu_04.jpg"}
		];
		break;
	case "OCE":
		nouvellesPhotos = [ 
			{"image" : "ill_Oc_01.jpg"},
			{"image" : "ill_Oc_02.jpg"},
			{"image" : "ill_Oc_03.jpg"},
			{"image" : "ill_Oc_04.jpg"}
		];
		break;
	case "PAC":
		nouvellesPhotos = [ 
			{"image" : "ill_Pa_01.jpg"},
			{"image" : "ill_Pa_02.jpg"},
			{"image" : "ill_Pa_03.jpg"},
			{"image" : "ill_Pa_04.jpg"}
		];
		break;
	case "ASI.MOR":
		nouvellesPhotos = [ 
			{"image" : "ill_MoOr_01.jpg"},
			{"image" : "ill_MoOr_02.jpg"},
			{"image" : "ill_MoOr_03.jpg"},
			{"image" : "ill_MoOr_04.jpg"}
		];
		break;
	default:
		nouvellesPhotos = [ 
			{"image" : "ill_Af_01.jpg"},
			{"image" : "ill_AmNo_01.jpg"},
			{"image" : "ill_AmCe_01.jpg"},
			{"image" : "ill_AmSu_01.jpg"},
			{"image" : "ill_As_01.jpg"},
			{"image" : "ill_Eu_01.jpg"},
			{"image" : "ill_MoOr_01.jpg"},
			{"image" : "ill_Oc_01.jpg"},
			{"image" : "ill_Pa_01.jpg"}
		];
	}
	photos = nouvellesPhotos;
}

