// JavaScript Document
var posLS=0;
var nbs=0;
var valid=false;
var valid2=false;
var ok1=0;
var selec=false;
var selec2=false;
var bool=false;
var httpListe = getHTTPObject();
var httpPhotoPays = getHTTPObject();
var httpGetIdRechVol = getHTTPObject();
var nbAR = 1;
var id_rech=0;
var tabVillesHaut = new Array();
var bool_first_rech=0;
var annulation = 0;
var nbRecherche = 0;

String.prototype.toUcFirst = function () {
var firstLetter = this.substr(0,1).toUpperCase()
return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
}

String.prototype.toUcWords = function(){
return this.toLowerCase().replace(/\w+/g,function(s){
return s.charAt(0).toUpperCase() + s.substr(1);
})
}

function gogogo(id_rech_flash){
	document.form_synthese.id_rech.value=id_rech_flash;
	document.form_synthese.submit();
}

function str_replace($search,$replace,$chaine) {
	var $recommence = 1;
	while ($recommence==1) {
		if($chaine.search($search)==-1) {
			$recommence=0;
		} else {
			$chaine = $chaine.replace($search,$replace);
		}
	}
	return $chaine;
}

function updtRecherche(idRech){
	var prov=document.getElementById('prov');
	var dest=document.getElementById('dest');
	var date1=document.getElementById('date1');
	var date2=document.getElementById('date2');
	infoTmp = tabInfoLastRech[idRech];
	tabInfoTmp = infoTmp.split("#");
	prov.value = tabInfoTmp[0].toUpperCase();
	date1.value = tabInfoTmp[1];
	date2.value = tabInfoTmp[2];
		
	dest.value = tabInfoTmp[3].toUpperCase();
	majDateRetour();
	majDateDepart();
	
	valideForm();
}

function majDateDepart(){
	var val1=document.getElementById('date1').value; 
	var tabDate = val1.split("/");
	
	if(tabDate[0]<10){
		tabDate[0] = "0"+tabDate[0];
	}
	
	tabDate[0] = str_replace("00","0",tabDate[0]);
	if(tabDate[1]<10){
		tabDate[1] = "0"+tabDate[1];
	}
	
	tabDate[1] = str_replace("00","0",tabDate[1]);
	if(tabDate[0]<10){
		document.moteur.DD.value = str_replace("0","",tabDate[0]);
	}else{
		document.moteur.DD.value = tabDate[0];
	}
	
	document.moteur.MM.value = tabDate[1]+"-"+tabDate[2];
	updtJour();
	if(bool_recherche!=1){
		changeJourVol();
		changeMois();
	}
}

function majDateRetour(){
	
	var val1=document.getElementById('date2').value; 
	var tabDate = val1.split("/");
	
	if(tabDate[0]<10){
		tabDate[0] = "0"+tabDate[0];
	}
	
	tabDate[0] = str_replace("00","0",tabDate[0]);
	if(tabDate[1]<10){
		tabDate[1] = "0"+tabDate[1];
	}
	
	tabDate[1] = str_replace("00","0",tabDate[1]);
	if(tabDate[0]<10){
		document.moteur.DD1.value = str_replace("0","",tabDate[0]);
	}else{
		document.moteur.DD1.value = tabDate[0];
	}
	
	document.moteur.MM1.value = tabDate[1]+"-"+tabDate[2];
	updtJour2();
}

function updt_liste_Aller(){
	updtJour();
	changeJourVol();
}

function replaceEspace($chaine) {
	var $recommence = 1;
	while ($recommence==1) {
		if($chaine.search(" ")==-1) {
			$recommence=0;
		} else {
			$chaine = $chaine.replace(" ","+");
		}
	}
	return $chaine;
}

function villePaysHotel() {
	var val1=document.getElementById('selVille').options[document.getElementById('selVille').selectedIndex].value; 
	var nom1=document.getElementById('selVille').options[document.getElementById('selVille').selectedIndex].text;
	if(val1=="") {
		lst=0;
		var selVille =document.getElementById('selVille');
		selVille.style.display = 'none';
		var dest =document.getElementById('dest');
		dest.value='';
		dest.style.display = '';
	} else {
		document.moteur.dest.value=nom1;
	}	
}

function chargeVilles() {
	var selectVilles =document.getElementById('menuVilles');
	while (selectVilles.firstChild != null ) { 
		selectVilles.removeChild(selectVilles.firstChild) ; 
	}
	
	new_liste = document.createElement("select");
	new_liste.setAttribute("name", "selectVilles");
	new_liste.setAttribute("id", "selectVilles");		
	new_liste.setAttribute("onchange", "changeVille()");
	new_liste.onchange=changeVille;
	new_liste.style.fontSize="8pt";		
	new_liste.style.color="#000000";		
	new_liste.style.fontFamily="Arial";	
	
	var sel=0;
	form = document.moteur;
	tabDest = form.dest.value.split("(");
	txtDest = tabDest[0].toUpperCase();
	
	var new_option = document.createElement("option");
	new_liste.appendChild(new_option);
	new_option.value = "";
	new_option.text = "Todas ciudades";
	
	var new_option = document.createElement("option");
	new_liste.appendChild(new_option);
	new_option.value = "";
	new_option.text = "";
	
	for(i=0;i<tabVillesHaut.length;i++) {
		opt1=tabVillesHaut[i].split("|");
		value1=opt1[1];
		nom1=opt1[0];
		if (value1 != '' && nom1 != '') {
			var new_option = document.createElement("option");
			new_liste.appendChild(new_option);
			new_option.value = value1;
			new_option.text = nom1;
			if(nom1.toUpperCase()==destjs.toUpperCase()) {
				sel=i;
			}  
		}
	}
	//alert(sel);
	if (sel > 0) {
		sel = sel + 1;
		new_liste.options[sel].selected = "selected"; 
	}
	selectVilles.appendChild(new_liste);
}

function changePays() {
	var i=document.getElementById("selectPays").selectedIndex;
	var sel = document.getElementById('selectPays'); 
	var pays = sel[i].text; 
	pays=replaceEspace(pays);
	window.location.href="billet-avion-" + pays.toLowerCase() + "-.html";
}

function changeVille() {
	var i=document.getElementById("selectVilles").selectedIndex;
	var sel = document.getElementById('selectVilles'); 
	var ville = sel[i].text; 
	ville=replaceEspace(ville);
	if (ville!="") {
		window.location.href="billet-avion-" + ville.toLowerCase() + ".html";
	} else {
		window.location.href="billet-avion.html";
	}
}

function rst() {
	var td=document.getElementById("tddest");
	td.style.display="none";	
	var im=document.getElementById("imgdest");
	im.style.display="none";		
	var de=document.getElementById("dest");
	de.style.display="";	
	changeSelec();
}

function rst2() {
	var td=document.getElementById("tdprov");
	td.style.display="none";	
	var im=document.getElementById("imgprov");
	im.style.display="none";		
	var pr=document.getElementById("prov");
	pr.style.display="";	
	changeSelec2();
}

function changeSelec() {
	selec=false;
}

function changeSelec2() {
	selec2=false;
}

function NoError() {
	return true;
}

function changeMois() {
	var form = document.moteur;
	//form.MM1.value=form.MM.value;
	changeJourVol();
}

function changeJourVol() {
	var form = document.moteur;
	var DD1tmp=form.DD.value;
	DD1tmp=parseInt(DD1tmp)+7;
	//alert(form.MM1.selectedIndex+" - "+form.MM.selectedIndex);
	if((form.DD1.value<form.DD.value && form.MM1.selectedIndex==form.MM.selectedIndex) || (form.MM1.selectedIndex<form.MM.selectedIndex)){
		if(DD1tmp>31){
			form.DD1.value=DD1tmp-31;
			form.MM1.selectedIndex=form.MM.selectedIndex+1;
		}else{
			form.DD1.value=DD1tmp;
			form.MM1.selectedIndex=form.MM.selectedIndex;
		}
	}
	updtJour();
	updtJour2();
}

function updtJour() {
	d=new Date() ;
	var form = document.moteur;
	var dayNames = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
	var test_array=form.MM.value.split("-");
	a = test_array[1];
	m = test_array[0];
	var nbj = new Number(m);
	m--;
	d.setFullYear(a,m,form.DD.value);
	form.jour.value = dayNames[d.getDay()];
	maj_dateCalendrier();
} 

function updtJour2() {
	d=new Date() ;
	var form = document.moteur;
	var dayNames = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
	var test_array=form.MM1.value.split("-");
	a = test_array[1];
	m = test_array[0];
	var nbj = new Number(m);
	m--;
	d.setFullYear(a,m,form.DD1.value);
	form.jour1.value = dayNames[d.getDay()];
	maj_dateCalendrier2();
} 

function maj_dateCalendrier(){
	var jour=document.moteur.DD.value;
	var jour1=document.moteur.DD1.value;;
	var mois1=document.moteur.MM1.value;
	var moisAnnee=document.moteur.MM.value;
	var tabTmp=moisAnnee.split("-");
	var mois=tabTmp[0];
	var annee=tabTmp[1];
	
	if(jour<10){
		jour="0"+jour;
		jour1=str_replace("0","",jour);
	}
	
	jour=str_replace("00","0",jour);
	if(mois<10){
		mois="0"+mois;
		mois1=str_replace("0","",mois);
	}
	
	mois=str_replace("00","0",mois);
	var dateCal=document.moteur.date1.value;
	var tabDate=dateCal.split("/");
	if((tabDate[0]!=jour && tabDate[0]!=jour1) || (tabDate[1]!=mois && tabDate[1]!=mois1) || (tabDate[2]!=annee)){
		document.moteur.date1.value=jour+'/'+mois+'/'+annee;
	}
}

function maj_dateCalendrier2(){
	var jour=document.moteur.DD1.value;
	var jour1=document.moteur.DD1.value;;
	var mois1=document.moteur.MM1.value;
	var moisAnnee=document.moteur.MM1.value;
	var tabTmp=moisAnnee.split("-");
	var mois=tabTmp[0];
	var annee=tabTmp[1];
	
	if(jour<10){
		jour="0"+jour;
		jour1=str_replace("0","",jour);
	}
	
	jour=str_replace("00","0",jour);
	if(mois<10){
		mois="0"+mois;
		mois1=str_replace("0","",mois);
	}
	
	mois=str_replace("00","0",mois);
	var dateCal=document.moteur.date2.value;
	var tabDate=dateCal.split("/");
	if((tabDate[0]!=jour && tabDate[0]!=jour1) || (tabDate[1]!=mois && tabDate[1]!=mois1) || (tabDate[2]!=annee)){
		document.moteur.date2.value=jour+'/'+mois+'/'+annee;
	}
}

function fctok() {
	updtJour();
	updtJour2();	
}

function changeSelect() {
	var form=document.moteur;
	i=form.Idest.selectedIndex;
	var sel = document.getElementById('Idest'); 
	var texte = sel[i].text; 
	
	if (texte=="Autres...") {
		rst();
	} else {
		form.dest.value=texte;
	}
}

function changeSelect2() {
	var form=document.moteur;
	i=form.Iprov.selectedIndex;
	var sel = document.getElementById('Iprov'); 
	var texte = sel[i].text; 
	if (texte=="Autres...") {
		rst2();
	} else {
		form.prov.value=texte;
	}
}

function getHTTPObject() {
	var xmlhttp;
	
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}

function valideForm() {

	if(bool_first_rech==0){
		bool_first_rech=1;
	}else{
		re_init_flash();
	}
	
	var divzoneScripts =document.getElementById('zoneScripts');
	while (divzoneScripts.firstChild != null ) { 
		divzoneScripts.removeChild(divzoneScripts.firstChild) ; 
	} 
	
	valid=true;
	valid2=true;
	//selec=false;
	//selec2=false;
	bool_iataProv = 0;
	bool_iataDest = 0;
	ok1=0;
	var form=document.moteur;
	if (form.prov.value=="") {
		alert("Indique la ciudad de salida");
		champCur=0;
		//window.setTimeout("initClignote();",1000);
		return false;
	}	else {
		if (form.dest.value=="") {
			alert("Indique la ciudad de destino");
			champCur=2;
			//window.setTimeout("initClignote();",1000);
			return false;
		}
	}
	
	if(form.prov.value.indexOf("-")>=0){
		var tmp1 = form.prov.value.split(" - ");
		var iataProv = tmp1[0];
		var nomProvtmp = tmp1[1];
		bool_iataProv = 1;
	}
	
	if(form.dest.value.indexOf("-")>=0){
		var tmp1 = form.dest.value.split(" - ");
		var iataDest = tmp1[0];
		var nomDesttmp = tmp1[1];
		bool_iataDest = 1;
	}
	
	var jour=document.moteur.DD.value;
	if(jour.length<2) {
		jour = "0" + jour;
	}
	
	var jour1=document.moteur.DD1.value; 
	if(jour1.length<2) {
		jour1 = "0" + jour1;
	} 
	
	var mois=document.moteur.MM.value;
	var mois1=document.moteur.MM1.value;
	var MM=mois.split("-");
	AA = MM[1];
	MM=MM[0];
	var MM1=mois1.split("-");
	AA1=MM1[1];
	MM1=MM1[0];
	var form=document.moteur;
	val = form.AR1.checked;

	if (val==true)  {
		if (AA1<AA) {
			alert("Las fechas mencionadas son incorrectas");
			champCur=6;
			//window.setTimeout("initClignote();",1000);
			valid=false;
		} else if (AA1==AA) {
			if(MM1<MM) {
				alert("Las fechas mencionadas son incorrectas");
				champCur=6;
				//window.setTimeout("initClignote();",1000);
				valid=false;
			} else if ((jour1<jour) && (MM1 == MM )) {
				alert("Las fechas mencionadas son incorrectas");
				champCur=6;
				//window.setTimeout("initClignote();",1000);
				valid=false;
			} 
		}
	}
	
	if (valid==true) {
		if (ok1==0) {
			if ((selec==false) || (selec2==false)) {
				valid2=false;
				if (selec2==true) {
					httpListe.open("GET", "checkVillesVol.php?selec2=" + selec2 + "&Iprov=" + form.Iprov.value + "&prov=" + form.prov.value + "&dest=" + form.dest.value, true);
					//window.open("checkVillesVol.php?selec2=" + selec2 + "&Iprov=" + form.Iprov.value + "&prov=" + form.prov.value + "&dest=" + form.dest.value);
				} else if (selec==true) {
					httpListe.open("GET", "checkVillesVol.php?selec=" + selec + "&Idest=" + form.Idest.value + "&prov=" + form.prov.value + "&dest=" + form.dest.value, true);	
				//	window.open( "checkVillesVol.php?selec=" + selec + "&Idest=" + form.Idest.value + "&prov=" + form.prov.value + "&dest=" + form.dest.value);
				} else {
					httpListe.open("GET", "checkVillesVol.php?prov=" + form.prov.value + "&dest=" + form.dest.value, true);	
					//window.open( "checkVillesVol.php?prov=" + form.prov.value + "&dest=" + form.dest.value);
				}
				
				httpListe.onreadystatechange = handleHttpResponsehttpListe;
				httpListe.send(null);			
			}  		
			window.setTimeout("poste();", 100);
			return false;
		} else {
			recherche();
			return false;

		}
	}
	return false;
}


//pour la page avec les résultats
function poste() {
	if (valid2==true) {
		ok1=1;
		recherche();
	} else {
		window.setTimeout("poste();", 100);
	}
}

function handleHttpResponsehttpListe() {
	var okSelect= 0;
	var okSelect2= 0;
	var tmpprov= "";
	var tmpdest= "";
	if (httpListe.readyState == 4) {
		results = httpListe.responseText;
		var ret1=results.split("provenance;;;");
		//alert(results);
		var sv=document.getElementById("tdprov");
		while ( sv.firstChild != null ) { 
			sv.removeChild(sv.firstChild) ; 
		}			
		var Tvilles=ret1[1].split(";;;");
		if (Tvilles.length==1) {
			if(Tvilles[0] != "") {
				selec2=true;
				var tvil=Tvilles[0].split("|");
				var selectvilles=document.createElement("input");
				selectvilles.setAttribute("id","Iprov");
				selectvilles.setAttribute("name","Iprov");
				selectvilles.setAttribute("type","hidden");
				selectvilles.setAttribute("value",tvil[4]);
				sv.appendChild(selectvilles);
				okSelect2=1;
			} else {
				alert("Indique la ciudad de salida");
			}
		}
	
		if (Tvilles.length>1) {
			var selectvilles2=document.createElement("select");
			selectvilles2.setAttribute("className","frm1");
			selectvilles2.setAttribute("class","frm1");
			selectvilles2.setAttribute("id","Iprov");
			selectvilles2.setAttribute("name","Iprov");
			selectvilles2.setAttribute("onChange","changeSelect2()");
			selectvilles2.onchange = changeSelect2;
			selectvilles2.options.length = 0;
			indice=0;
			for (i=0 ; i < Tvilles.length ; i++) {
				var elem = Tvilles[i];
				if(elem!= "") {
					var tvil=elem.split("|");
					var texte = tvil[1] + " (" + tvil[4] + "), " + tvil[3] + "";					
					var optionObject = new Option(texte,tvil[4]);
					selectvilles2.options[indice] = optionObject;
					indice++;
					if (indice==1) {
						tmpprov = texte;
					}
				}
			} 
			if (indice > 1) {
				indice2 = indice;
				var optionObject = new Option("-------------","");
				selectvilles2.options[indice2] = optionObject;
				indice2++;
				var optionObject = new Option("Autres...","");
				selectvilles2.options[indice2] = optionObject;
				sv.appendChild(selectvilles2);
				sv.style.display="";
				var im=document.getElementById("imgprov");
				im.style.display="";		
				var pr=document.getElementById("prov");
				pr.style.display="none";		
				alert("Indique la ciudad de salida");
				changeSelect2();
			} else {
				sv.appendChild(selectvilles2);
				sv.style.display="none";
				var im=document.getElementById("imgprov");
				im.style.display="none";						
				var pr=document.getElementById("prov");
				pr.style.display="";		
				pr.value = tmpprov;
				okSelect2=1;
			}
			selec2=true;
		}
		var sv=document.getElementById("tddest");
		while ( sv.firstChild != null ) { 
			sv.removeChild(sv.firstChild) ; 
		}	
		var Tvilles=ret1[0].split(";;;");
		if (Tvilles.length==1) {
			if(Tvilles[0] != "") {
				selec=true;				
				var tvil=Tvilles[0].split("|");
				var selectvilles=document.createElement("input");
				selectvilles.setAttribute("id","Idest");
				selectvilles.setAttribute("name","Idest");
				selectvilles.setAttribute("type","hidden");
				selectvilles.setAttribute("value",tvil[4]);
				sv.appendChild(selectvilles);
				okSelect=1;
			} else {
				alert("Indique la ciudad de destino");
			}
		}
		if (Tvilles.length>1) {
			var selectvilles=document.createElement("select");
			selectvilles.setAttribute("className","frm1");
			selectvilles.setAttribute("class","frm1");
			selectvilles.setAttribute("id","Idest");
			selectvilles.setAttribute("name","Idest");
			selectvilles.setAttribute("onChange","changeSelect()");
			selectvilles.onchange = changeSelect;
			selectvilles.options.length = 0;
			indice=0;
			for (i=0 ; i < Tvilles.length ; i++) {
				var elem = Tvilles[i];
				//alert(elem);
				if(elem!= "") {
					var tvil=elem.split("|");
					var texte = tvil[1] + " (" + tvil[4] + "), " + tvil[3] + "";
					var optionObject = new Option(texte,tvil[4]);
					selectvilles.options[indice] = optionObject;
					indice++;
					if (indice==1) {
						tmpdest = texte;
					}
				}
			} 
			
			if (indice > 1) {
				indice2 = indice;
				var optionObject = new Option("-------------","");
				selectvilles.options[indice2] = optionObject;
				indice2++;
				var optionObject = new Option("Autres...","");
				selectvilles.options[indice2] = optionObject;
				sv.appendChild(selectvilles);
				sv.style.display="";			
				var im=document.getElementById("imgdest");
				im.style.display="";		
				var de=document.getElementById("dest");
				de.style.display="none";		
				var selVille=document.getElementById("selVille");
				selVille.style.display="none";		
				alert("Indique la ciudad de salida");
				changeSelect();
			} else {
				sv.appendChild(selectvilles);
				sv.style.display="none";			
				var im=document.getElementById("imgdest");
				im.style.display="none";		
				var de=document.getElementById("dest");
				de.style.display="";	
				var selVille=document.getElementById("selVille");
				selVille.style.display="none";		
				de.value = tmpdest;
				okSelect=1;
			}
			selec=true;
		}
		if ((okSelect==1) && (okSelect2==1)) {
			valid2=true;
		}
	}
}


function afficheTitreVol(){
	var form = document.moteur;
	
	var leDiv =document.getElementById('divTitreRecherche');
	leDiv.style.display="";
	
	var leDiv =document.getElementById('btn_rech_flash1');
	leDiv.style.display="none";
	
	var leDiv =document.getElementById('btn_rech_flash2');
	leDiv.style.display="none";
	
	villeDep = form.prov.value.split("(");
	villeArr = form.dest.value.split("(");
									   
	var leDiv =document.getElementById('divVillesVol');
	leDiv.innerHTML='<font color="#ABFE00">RECHERCHE DU MEILLEUR TARIF POUR LE VOL '+villeDep[0]+' - '+villeArr[0]+'</font>';
	
	var leDiv =document.getElementById('divDatesVol');
	leDiv.innerHTML='Aller : le  '+form.DD.value+'/'+form.MM.value+' - Retour : le '+form.DD1.value+'/'+form.MM1.value+'';
	
	$AD_valeur = form.AD.value;
	$EN_valeur = form.EN.value;
	$BB_valeur = form.BB.value;
	$CL_valeur = form.CL.value;
	
	if(form.AR[0].checked == true) {
		$AR_valeur = "1";
	}else{
		$AR_valeur = "0";
	}
	
	var leDiv =document.getElementById('sousTitreRecherche');
	chaineSousTitre="<strong>Prix pour ";
	
	if ($AD_valeur > 1) {
		chaineSousTitre= chaineSousTitre + $AD_valeur + " adultes ";
		if ($EN_valeur > 1) {
			chaineSousTitre= chaineSousTitre +  " + " + $EN_valeur + " enfants ";
		} else if ($EN_valeur > 0) {
			chaineSousTitre= chaineSousTitre +  " + " + $EN_valeur + " enfant ";
		}
		
		if ($BB_valeur > 1) {
			chaineSousTitre= chaineSousTitre +  " + " + $BB_valeur + " bébés ";
		} else if ($BB_valeur > 0) {
			chaineSousTitre= chaineSousTitre +  " + " + $BB_valeur + " bébé ";
		}
		
	} else if ($AD_valeur>0) {
		chaineSousTitre= chaineSousTitre +  $AD_valeur + " adulte ";
		if ($EN_valeur > 1) {
			chaineSousTitre= chaineSousTitre +  " + " + $EN_valeur + " enfants ";
		} else if ($EN_valeur > 0) {
			chaineSousTitre= chaineSousTitre +  " + " + $EN_valeur + " enfant ";
		}
		
		if ($BB_valeur > 1) {
			chaineSousTitre= chaineSousTitre +  " + " + $BB_valeur + " bébés ";
		} else if ($BB_valeur > 0) {
			chaineSousTitre= chaineSousTitre +  " + " + $BB_valeur + " bébé ";
		}
		
	} else {
		if ($EN_valeur > 1) {
			chaineSousTitre= chaineSousTitre +  $EN_valeur + " enfants ";
		} else if ($EN_valeur > 0) {
			chaineSousTitre= chaineSousTitre +  $EN_valeur + " enfant ";
		} 
	}
	
	if ($AR_valeur==1) chaineSousTitre= chaineSousTitre +  " - ALLER/RETOUR";
	else chaineSousTitre= chaineSousTitre +  " - ALLER SIMPLE";
	
	if($CL_valeur=="1") chaineSousTitre= chaineSousTitre +  " en classe économique";
	else if($CL_valeur=="0") chaineSousTitre= chaineSousTitre +  " en classe affaire";
	else chaineSousTitre= chaineSousTitre +  " en 1ère classe";
	
	chaineSousTitre= chaineSousTitre +  " </strong> (Taxes aéroport et frais de dossier compris)";
	leDiv.innerHTML =chaineSousTitre;
	
	var leDiv =document.getElementById('div2');
	leDiv.style.display="none";
	
	var leDiv =document.getElementById('div3');
	leDiv.style.display="none";
	
	var leDiv =document.getElementById('divFiltre');
	leDiv.style.display="none";
	
	var leDiv =document.getElementById('divGraph');
	leDiv.style.display="none";
}


function recherche() {
	var form = document.moteur;
	Today = new Date();
	
	if(form.AR[0].checked == true) {
		varAR=1;
	} else {
		varAR=0;
	}
	
	id_rech=0;
	parametres= "id_affilie=4&Idest=" + form.Idest.value + "&Iprov=" + form.Iprov.value + "&DD=" + form.DD.value + "&MM=" + form.MM.value + "&DD1=" + form.DD1.value + "&MM1=" + form.MM1.value + "&AD=" + form.AD.value + "&EN=" + form.EN.value + "&BB=" + form.BB.value + "&CL=" + form.CL.value + "&AR=" + varAR + "&Time=" + Today.getTime() + "&max_id_visite=" + max_id_visite;
	urlScript2 = "listevolV4/getIdRech.php?" + parametres;		
	//window.open(urlScript2);
	httpGetIdRechVol.open("GET", urlScript2, true);
	httpGetIdRechVol.onreadystatechange = handleHttpGetIdRechVol;
	httpGetIdRechVol.send(null);
	
	if(autorisation_maj_titre_photoPays==1){
		maj_titre_photoPays(form.Idest.value);
	}
	initialisation();
	window.setTimeout("appel_init_flash();", 500);
}



function handleHttpGetIdRechVol(retour) {
	if (httpGetIdRechVol.readyState == 4) {
		results = httpGetIdRechVol.responseText;
		tabTmp=results.split(";;;");
			if (tabTmp[1] != "maximum") {
				id_rech = tabTmp[1];
			} else {
				AffichDivMaxRecherche();
			}	
	}
}




function maj_titre_photoPays(Idest){
	//window.open("/vol_photoPays.php?idest=" + Idest);
	httpPhotoPays.open("GET", "/vol_photoPays.php?idest=" + Idest, true);
	httpPhotoPays.onreadystatechange = handleHttpResponsePhotoPays;
	httpPhotoPays.send(null);
}

function handleHttpResponsePhotoPays(){
	if (httpPhotoPays.readyState == 4) {
		results = httpPhotoPays.responseText;
		tabTmp=results.split(";;;");
		document.getElementById('picRub').innerHTML=tabTmp[0];
		if(tabTmp[1]!=""){
			document.getElementById('titrePaysMilieu').innerHTML=tabTmp[1];
		}
		if(tabTmp[2]!=""){
			document.getElementById('div_navigation_vol').innerHTML=tabTmp[2];
		}
		if(tabTmp[3]!=""){
			document.getElementById('divOngletsSej').innerHTML=tabTmp[3];
		}
	}
}

function getFlashMovieObject(movieName){
	if (window.document[movieName]){
		return window.document[movieName];
	}
	
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName]){
			return document.embeds[movieName]; 
		}
		
	}else{ // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		return document.getElementById(movieName);
	}
}

function appel_init_flash(){
	if(id_rech>0) {
		init_flash();
	} else {
		window.setTimeout("appel_init_flash();", 100);
	}
}

function re_init_flash(){
	movie = getFlashMovieObject('vol5');	
	movie.SetVariable("REINIT_RECHERCHE", 1);
}

function init_flash(){
	movie = getFlashMovieObject('vol5');
	var form = document.moteur;
	sendText = form.Iprov.value;
	movie.SetVariable("Iprov", sendText);
	sendText = form.Idest.value;
	movie.SetVariable("Idest", sendText);
	sendText = form.prov.value;
	movie.SetVariable("prov", sendText);
	sendText = form.dest.value;
	movie.SetVariable("dest", sendText);
	sendText = form.MM.value;
	movie.SetVariable("MM", sendText);	
	sendText = form.DD.value;
	movie.SetVariable("DD", sendText);	
	sendText = form.MM1.value;
	movie.SetVariable("MM1", sendText);	
	sendText = form.DD1.value;
	movie.SetVariable("DD1", sendText);	
	sendText = form.AD.value;
	movie.SetVariable("AD", sendText);	
	sendText = form.EN.value;
	movie.SetVariable("EN", sendText);	
	sendText = form.BB.value;
	movie.SetVariable("BB", sendText);
	sendText = form.CL.value;
	movie.SetVariable("CL", sendText);	
	
	if(form.AR[0].checked == true) {
		sendText = "1";
	}else{
		sendText = "0";
	}
	movie.SetVariable("AR", sendText);
	if(form.direct.checked == true) {
		sendText = "1";
	}else{
		sendText = "0";
	}
	movie.SetVariable("id_rech", id_rech);
	movie.SetVariable("AFFILIE", idAffilie);
	movie.SetVariable("VD", sendText);
	movie.SetVariable("STOP_RECHERCHE", "0");
	movie.SetVariable("RESULTAT_DEJA_OBTENU", "0");
	movie.SetVariable("VALIDE", "1");
}

function stop_recherche(){
	movie = getFlashMovieObject('vol5');	
	movie.SetVariable("STOP_RECHERCHE", "1");
	var leDiv =document.getElementById('btn_rech_flash1');
	leDiv.style.display="none";
	var leDiv =document.getElementById('btn_rech_flash2');
	leDiv.style.display="none";
}

function resultats_deja_obtenus(){
	movie = getFlashMovieObject('vol5');	
	movie.SetVariable("RESULTAT_DEJA_OBTENU", "1");
	var leDiv =document.getElementById('btn_rech_flash1');
	leDiv.style.display="none";
	var leDiv =document.getElementById('btn_rech_flash2');
	leDiv.style.display="none";
}

function separateur(num) {
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)		num = num.substring(0,num.length-(4*i+3)) + ' ' + num.substring(num.length-(4*i+3));
	return num;
}

function initialisation() {
	window.scroll(0,253);
	nbAR = 1;
	annulation = 0;
	var leDiv =document.getElementById('divFlash');
	leDiv.style.display="";
	var leDiv =document.getElementById('divContenu');
	leDiv.style.display="none";
}

function testDate(LaDateDebut){
	LaDateDebut = LaDateDebut.split("/");
	var LaDate=new Date;
	LaDate.setDate(LaDateDebut[0]);
	LaDate.setMonth(LaDateDebut[1]-1);// On enlève 1 car les mois sont indicés à partir de 0 en JavaScript
	LaDate.setYear(LaDateDebut[2]);
	
	if(LeParam1!=(LaDate.getDate()+"/"+(LaDate.getMonth()+1)+"/"+LaDate.getFullYear())){
		return false;
	}
	return true;
}

function initPage () {
	var leDiv =document.getElementById('accueil');
	leDiv.style.display="";
	var leDiv =document.getElementById('listePage');
	leDiv.style.display="";
}

function creeHidden($chaine1,$chaine2) {
	var sv=document.getElementById("tddest");
	while ( sv.firstChild != null ) { 
		sv.removeChild(sv.firstChild) ; 
	}
	
	var selectvilles=document.createElement("input");
	selectvilles.setAttribute("id","Idest");
	selectvilles.setAttribute("name","Idest");
	selectvilles.setAttribute("type","hidden");
	selectvilles.setAttribute("value",$chaine1);
	sv.appendChild(selectvilles);
	var sv=document.getElementById("tdprov");
	
	while ( sv.firstChild != null ) { 
		sv.removeChild(sv.firstChild) ; 
	}
	var selectvilles=document.createElement("input");
	selectvilles.setAttribute("id","Iprov");
	selectvilles.setAttribute("name","Iprov");
	selectvilles.setAttribute("type","hidden");
	selectvilles.setAttribute("value",$chaine2);
	sv.appendChild(selectvilles);
}	

function defile() {
	posLS = document.getElementById("last_search").scrollTop + 1;
	if (posLS > 20*hauteur) posLS = 0;
	document.getElementById("last_search").scrollTop = posLS;
	window.setTimeout("defile();", 100);
}

function defile2() {
	posLS = document.getElementById("last_search").scrollTop + 1;
	if (posLS > 15*hauteur) posLS = 0;
	document.getElementById("last_search").scrollTop = posLS;
	window.setTimeout("defile();", 100);
}

function changeAR() {
	var form=document.moteur;
	val = form.AR1.checked;
	if (val==true)  {
		document.getElementById("tdDateRet1").style.display = "";
		document.getElementById("tdDateRet2").style.display = "";
	} else {
		document.getElementById("tdDateRet1").style.display = "none";
		document.getElementById("tdDateRet2").style.display = "none";	
	}
}

function GetDowStart() {
	return 1;
}

function GetDateFmt() {
	return "ddmmyy";
}

function GetDateSep() {
	return "/";
}

function CalFldFocus(eP,eD,eDP,dmin,dmax,f,next){
	document.onclick;
	SCal(eP,eD,eDP,dmin,dmax);
	//stopBubble(event);
	if (next == null){
		nextFocus = objNext(f,eD); 
	}else{
		nextFocus = next;
	}
}

function objNext(f,d){
	var fFnd=false,el=f.elements,i=0;
	for(;i < el.length;i++){
		if('hidden'!=el[i].type && false==el[i].disabled && IsVis(el[i]) && fFnd){
			return el[i];
		}
		if(d.id==el[i].id){
			fFnd=true;
		}
	}
	return null;
}

function IsVis(o){
	if(!o || o.type=='hidden'){
		return false;		
	}
	while(o && o.style && o.style.display!='none'){
		o = o.parentNode;	
	}
	return !o || !o.style;
}

function getObj(objID){
	if (document.getElementById){
		return document.getElementById(objID);
	}else if (document.all) {
		return document.all[objID];
	}else if (document.layers) {
		return document.layers[objID];
	}
}

function initValeurProv(){
	if(boolJSprov==1){
		document.getElementById('prov').value="";
		boolJSprov=0;	
	}
}

function initValeurDest(){
	if(boolJSdest==1){
		document.getElementById('dest').value="";
		boolJSdest=0;	
	}
}

function chargementForm() {
	leDiv = document.getElementById("td_01");
	leDiv.innerHTML = 'Ciudad origen';
	leDiv = document.getElementById("td_02");
	leDiv.innerHTML = '<input class="frm1 150px" id="prov" size="30" name="prov" value="' +  jsprov + '" onChange="changeSelec2()" autocomplete="off" tabindex="1"> <span style="display:none;" id="tdprov">&nbsp;</span><span style="display:none;" id="imgprov"><img src="/img/reset.gif" style="cursor:pointer" onClick="rst2()"  alt="rechargez"></span> ';
	leDiv = document.getElementById("td_03");
	leDiv.innerHTML = 'Fecha salida';
	leDiv = document.getElementById("td_06");
	leDiv.innerHTML = 'Ciudad destino';
	leDiv = document.getElementById("td_07");
	leDiv.innerHTML ='<select class="textepetit 150px" name="selVille" id="selVille" style="color:#003399" onChange="villePaysHotel()"> ' + chaineVillePays + '</select><input  class="frm1" name="dest" id="dest" size="30" value="' + jsdest + '"  onChange="changeSelec()" autocomplete="off" tabindex="3"><span style="display:none;" id="tddest">&nbsp;</span><span style="display:none;" id="imgdest"><img src="img/reset.gif" style="cursor:pointer" onClick="rst()" alt="rechargez"></span> ';
	
	
	plus0="";
	plus1="checked";	
	if(jsAR=="0") {
		plus0="checked";
		plus1="";
	}
	leDiv = document.getElementById("td_05");
	leDiv.innerHTML = '<input type="radio" value="1" name="AR" id="AR1"  ' + plus1 + '  onClick="changeAR()"> Ida y vuelta';
	leDiv = document.getElementById("td_08");
	leDiv.innerHTML = '<input type="radio" value="0" name="AR" ' + plus0 + ' onClick="changeAR()"> Sólo Ida';
	
	leDiv = document.getElementById("tdDateRet1");
	leDiv.innerHTML = 'Fecha regreso';	
	leDiv = document.getElementById("td_09");
	leDiv.innerHTML = 'Pasajeros';
	plus1="";
	plus2="";
	plus3="";
	plus4="";
	plus5="";
	plus6="";
	if (jsAD==1) {
		plus1="selected";
	} else if (jsAD==2) {
		plus2="selected";		
	} else if (jsAD==3) {
		plus3="selected";		
	} else if (jsAD==4) {
		plus4="selected";		
	} else if (jsAD==5) {
		plus5="selected";		
	} else if (jsAD==6) {
		plus6="selected";		
	}		
	tempTxt ='<select class="frm1" size="1" name="AD" style="color:#000066">';
	tempTxt = tempTxt + '        <option value="1"  ' + plus1 + '>1 adulto</option>';
	tempTxt = tempTxt + '        <option value="2" ' + plus2 + '>2 adultos</option>';
	tempTxt = tempTxt + '        <option value="3" ' + plus3 + '>3 adultos</option>';
	tempTxt = tempTxt + '        <option value="4" ' + plus4 + '>4 adultos</option>';
	tempTxt = tempTxt + '        <option value="5" ' + plus5 + '>5 adultos</option>';
	tempTxt = tempTxt + '        <option value="6" ' + plus6 + '>6 adultos</option>';
	tempTxt = tempTxt + '</select>&nbsp;';
	plus0="";
	plus1="";
	plus2="";
	plus3="";
	plus4="";
	plus5="";
	if (jsEN==0) {
		plus0="selected";
	} else if (jsEN==1) {
		plus1="selected";
	} else if (jsEN==2) {
		plus2="selected";		
	} else if (jsEN==3) {
		plus3="selected";		
	} else if (jsEN==4) {
		plus4="selected";		
	} else if (jsEN==5) {
		plus5="selected";		
	}	
	tempTxt = tempTxt + '<select class="frm1" size="1" name="EN" style="color:#000066">';
	tempTxt = tempTxt + '        <option value="0" ' + plus0 + '>0 niños</option>';
	tempTxt = tempTxt + '        <option value="1" ' + plus1 + '>1 niño</option>';
	tempTxt = tempTxt + '        <option value="2" ' + plus2 + '>2 niños</option>';
	tempTxt = tempTxt + '        <option value="3" ' + plus3 + '>3 niños</option>';
	tempTxt = tempTxt + '        <option value="4" ' + plus4 + '>4 niños</option>';
	tempTxt = tempTxt + '        <option value="5" ' + plus5 + '>5 niños</option>';
	tempTxt = tempTxt + '</select>&nbsp;';
	plus0="";
	plus1="";
	plus2="";
	plus3="";
	if (jsBB==0) {
		plus0="selected";
	} else if (jsBB==1) {
		plus1="selected";
	} else if (jsBB==2) {
		plus2="selected";		
	} else if (jsBB==3) {
		plus3="selected";		
	}	
	tempTxt = tempTxt + '<select class="frm1" size="1" name="BB" style="color:#000066">';
	tempTxt = tempTxt + '        <option value="0" ' + plus0 + '>0 bebés</option>';
	tempTxt = tempTxt + '        <option value="1" ' + plus1 + '>1 bebé</option>';
	tempTxt = tempTxt + '        <option value="2" ' + plus2 + '>2 bebés</option>';
	tempTxt = tempTxt + '        <option value="3" ' + plus3 + '>3 bebés</option>';
	tempTxt = tempTxt + '</select>';
	leDiv = document.getElementById("td_10");
	leDiv.innerHTML = tempTxt;
	plus1="";
	plus2="";
	plus3="";
	if (jsCL=="1") {
		plus1="selected";
	} else if (jsCL=="0") {
		plus2="selected";
	} else if (jsCL=="2") {
		plus3="selected";		
	}
	leDiv = document.getElementById("td_11");
	leDiv.innerHTML = 'Clase ';
	leDiv = document.getElementById("td_12");
	leDiv.innerHTML = '<select class="frm1"  style="color:#003399" size="1" name="CL"><option value="1" ' + plus1 + '>Turista</option><option value="0" ' + plus2 + '>Business</option><option value="2" ' + plus3 + '>Primera</option></select>';
	leDiv = document.getElementById("td_13");
	if (jsdirect==1) {
		plus="selected";
	} else {
		plus="";
	}
	leDiv.innerHTML = 'Sólo Vuelos directos <input type="checkbox" value="checkbox" name="direct" ' + plus + ' >';
	plus0="";
	plus1="checked";	
	if(jsAR=="0") {
		plus0="checked";
		plus1="";
	}
	leDiv = document.getElementById("tdMM");
	new_liste = document.createElement("select");
	new_liste.setAttribute("name", "MM");
	new_liste.setAttribute("class", "frm1");
	new_liste.setAttribute("className", "frm1");
	new_liste.setAttribute("id", "MM");		
	new_liste.setAttribute("onchange", "updt_liste_Aller()");
	new_liste.onchange=updt_liste_Aller;
	new_liste.style.color="#000066";
	tabDest = tmois1.split("##");
	sel=0;
	for(i=0;i<tabDest.length;i++) {
		opt1=tabDest[i].split("#");
		value1=opt1[0];
		nom1=opt1[1];
		if (value1 != '' && nom1 != '') {
			var new_option = document.createElement("option");
			new_liste.appendChild(new_option);
			new_option.value = value1;
			new_option.text = nom1;
			if(value1==id_MM) {
				sel=i;
			}  
		}
	}
	if (sel > 0) {
		sel = sel;
		new_liste.options[sel].selected = "selected"; 
	}
	
	
	//new_liste.setAttribute("disabled","true");
	leDiv.appendChild(new_liste);
	leDiv = document.getElementById("tdMM1");
	new_liste = document.createElement("select");
	new_liste.setAttribute("name", "MM1");
	new_liste.setAttribute("class", "frm1");
	new_liste.setAttribute("className", "frm1");
	new_liste.setAttribute("id", "MM1");		
	new_liste.setAttribute("onchange", "updtJour2()");
	new_liste.onchange=updtJour2;
	new_liste.style.color="#000066";
	tabDest = tmois2.split("##");
	sel=0;
	for(i=0;i<tabDest.length;i++) {
		opt1=tabDest[i].split("#");
		value1=opt1[0];
		nom1=opt1[1];
		if (value1 != '' && nom1 != '') {
			var new_option = document.createElement("option");
			new_liste.appendChild(new_option);
			new_option.value = value1;
			new_option.text = nom1; 
			if(value1==id_MM1) {
				sel=i;
			}  
		}
	}
	if (sel > 0) {
		sel = sel;
		new_liste.options[sel].selected = "selected"; 
	}
	//new_liste.setAttribute("disabled","true");
	leDiv.appendChild(new_liste);
	leDiv = document.getElementById("tdDD");
	new_liste = document.createElement("select");
	new_liste.setAttribute("name", "DD");
	new_liste.setAttribute("class", "frm1");
	new_liste.setAttribute("className", "frm1");
	new_liste.setAttribute("id", "DD");		
	new_liste.setAttribute("onchange", "updt_liste_Aller()");
	new_liste.onchange=updt_liste_Aller;
	new_liste.style.color="#000066";
	sel=0;
	for(i=1;i<32;i++) {
		value1=i;
		if (i > 9) {
			nom1=i;
		} else {
			nom1="0"+i;
		}
		var new_option = document.createElement("option");
		new_liste.appendChild(new_option);
		new_option.value = value1;
		new_option.text = nom1; 
		if(nom1==id_DD) {
			sel=i;
		}  
	}
	if (sel > 0) {
		sel = sel - 1;
		new_liste.options[sel].selected = "selected"; 
	}
	//new_liste.setAttribute("disabled","true");
	leDiv.appendChild(new_liste);
	leDiv = document.getElementById("tdDD1");
	new_liste = document.createElement("select");
	new_liste.setAttribute("name", "DD1");
	new_liste.setAttribute("class", "frm1");
	new_liste.setAttribute("className", "frm1");
	new_liste.setAttribute("id", "DD1");		
	new_liste.setAttribute("onchange", "updtJour2()");
	new_liste.onchange=updtJour2;
	new_liste.style.color="#000066";
	sel=0;
	for(i=1;i<32;i++) {
		value1=i;
		if (i > 9) {
			nom1=i;
		} else {
			nom1="0"+i;
		}
		var new_option = document.createElement("option");
		new_liste.appendChild(new_option);
		new_option.value = value1;
		new_option.text = nom1; 
		if(nom1==id_DD1) {
			sel=i;
		}  
	}
	if (sel > 0) {
		sel = sel - 1;
		new_liste.options[sel].selected = "selected"; 
	}
	//new_liste.setAttribute("disabled","true");
	leDiv.appendChild(new_liste);
	changeAR();
	
}
function makeRequest(url) {
	var posX = document.body.scrollTop;
	if(posX < 150) posX = 150;
	leDiv = document.getElementById('div_synthese_contenu');
	leDiv.style.display = "none";		
	leDiv = document.getElementById('div_synthese_attente');
	leDiv.style.display = "";			
	leDiv = document.getElementById('monIFrame3');
	leDiv.style.display = "";
	leDiv.style.top = 50 + posX;
	leDiv = document.getElementById('div_synthese');
	leDiv.style.display = "";
	leDiv.style.top = 50 + posX;
	temp_height  = leDiv.style.height;
	leDiv = document.getElementById("monIFrame3");
	leDiv.style.height = temp_height;		
	var http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// Voir la note ci-dessous à propos de cette ligne
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Abandon :( Impossible de créer une instance XMLHTTP');
		return false;
	}
	http_request.onreadystatechange = function() { alertContents(http_request); };
	http_request.open('GET', url, true);
	http_request.send(null);
}


function alertContents(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			retourSV = http_request.responseText;
			//modification des url
			retourSV = str_replace("#url1",taburl[1],retourSV);
			retourSV = str_replace("#url31",taburl[2],retourSV);
			retourSV = str_replace("#url21",taburl[3],retourSV);
			retourSV = str_replace("#url24",taburl[4],retourSV);
			retourSV = str_replace("#url20",taburl[5],retourSV);
			retourSV = str_replace("#url23",taburl[6],retourSV);
			retourSV = str_replace("#url9",taburl[7],retourSV);
			retourSV = str_replace("#url32",taburl[8],retourSV);
			retourSV = str_replace("#url4",taburl[9] + paramTmp,retourSV);
			
			var tab_retour = retourSV.split("####");
			leDiv = document.getElementById('div_synthese_attente');
			leDiv.style.display = "none";			
			leDiv = document.getElementById('div_synthese_contenu');
			leDiv.style.display = "";
			leDiv.innerHTML = tab_retour[0];
			select_init(tab_retour[1]);
			updtRetour(tab_retour[2]);	
			
			var contentHeight= document.getElementById('div_synthese').offsetHeight;
			var footerHeight= document.getElementById('footer').offsetHeight;
			temp_height = contentHeight - footerHeight;				
			temp_height = temp_height + 50;
			leDiv = document.getElementById("div_synthese");
			leDiv.style.height = temp_height;		
			leDiv = document.getElementById("monIFrame3");
			leDiv.style.height = temp_height;		
		}
	}
}

function select_init(id){
	document.getElementById('listeVolRetour').options[id].selected = "selected";
}

function updtRetour(nbretour){
	var val = document.getElementById('listeVolRetour').options[document.getElementById('listeVolRetour').selectedIndex].value; 
	for(i=0; i<nbretour;i++){
		var div =document.getElementById('divRetour'+i);
		var div2 =document.getElementById('divRetour2'+i);
		if(i==val){
			div.style.display = '';
			div2.style.display = '';
		}else{
			div.style.display = 'none';
			div2.style.display = 'none';
		}
	}
}

function close_div_synthese () {				
	leDiv = document.getElementById('monIFrame3');
	leDiv.style.display = "none";
	
	leDiv = document.getElementById('div_synthese');
	leDiv.style.display = "none";
}

