function maj_champ(id_champ, valeur)
{
	var champ = window.document.getElementById(id_champ);
	var champ_ville = window.document.getElementById('id_ville');
	var champ_ville2 = window.document.getElementById('id_ville2');
	var val_ville = valeur;

	if(champ)
	{
		champ.value = valeur;
//alert(id_champ + '\n\n' + champ.id + '\n\n' + champ.value);
	}

	if (id_champ.indexOf('_arrivee') != -1)
	{
		if (val_ville.indexOf('|') != -1)
		{
			val_ville = val_ville.split('|')[2];
		}
		if (champ_ville)
		{
			champ_ville.value = val_ville;
		}
		if (champ_ville2)
		{
			champ_ville2.value = val_ville;
		}
	}
	return;
}

function goRecherche()
{
	dir = "0";
	
	if(document.forms["form_avion"].type.value == "AS")
	{
		document.forms["form_avion"].retourj.value="";
		document.forms["form_avion"].retourm.value="";
		document.forms["form_avion"].retoura.value="";
	}

	if(document.forms["form_avion"].type.value != "MD"){
		document.forms["form_avion"].mode.value="";
		document.forms["form_avion"].depart_R.value="";
		document.forms["form_avion"].arrivee_R.value="";
		document.forms["form_avion"].iata_depart_R.value="";
		document.forms["form_avion"].iata_arrivee_R.value="";
	}
	else
	{
		document.forms["form_avion"].mode.value="OJ";
	}

	vDepart = document.forms["form_avion"].depart.value;
	vArrivee = document.forms["form_avion"].arrivee.value;
	vDepart_R = document.forms["form_avion"].depart_R.value;
	vArrivee_R = document.forms["form_avion"].arrivee_R.value;
	tVol = document.forms["form_avion"].type.value;
	jDep = document.forms["form_avion"].departj.value;
	mDep = document.forms["form_avion"].departm.value;
	aDep = document.forms["form_avion"].departa.value;
	hDep = document.forms["form_avion"].HeureDepart.value;
	jAr = document.forms["form_avion"].retourj.value;
	mAr = document.forms["form_avion"].retourm.value;
	aAr = document.forms["form_avion"].retoura.value;
	hAr = document.forms["form_avion"].HeureRetour.value;
	cla = document.forms["form_avion"].classe.value;
	nbAdu = document.forms["form_avion"].adu.value;
	nbEnf = document.forms["form_avion"].enf.value;
	nbBeb = document.forms["form_avion"].beb.value;
	if(document.forms["form_avion"].direct)
	{
		if(document.forms["form_avion"].direct.checked==true)
		{
			dir = "1"; 
		}
		else
		{
			dir = "0";
		}
	}

	sendVoyagiste_Recherche();
}

function sendVoyagiste_Recherche()
{
	var ErrMsg = "\n";
	var lenInit = ErrMsg.length;

	if (tVol=="") 
	{
		ErrMsg += "Vous devez indiquez votre type de vol.\n";
	}

	if (vDepart=="") 
	{
		ErrMsg += "Vous devez indiquez votre ville de départ";
		if(tVol=="MD") ErrMsg += " aller";
		ErrMsg += ".\n";
		document.forms["form_avion"].depart.focus();
	}

	if (vArrivee=="") 
	{
		ErrMsg += "Vous devez indiquez votre ville d'arrivée";
		if(tVol=="MD") ErrMsg += " aller";
		ErrMsg += ".\n";
		document.forms["form_avion"].arrivee.focus();
	}
	
	if (vDepart_R=="" && tVol=="MD") 
	{
		ErrMsg += "Vous devez indiquez votre ville de départ retour.\n";
		document.forms["form_avion"].depart_R.focus();
	}

	if (vArrivee_R=="" && tVol=="MD") 
	{
		ErrMsg += "Vous devez indiquez votre ville d'arrivée retour.\n";
		document.forms["form_avion"].arrivee_R.focus();
	}

	if (nbAdu<nbBeb) 
	{
		ErrMsg += "Vous ne pouvez pas embarquer plus de bébés que d'adultes.\n";
		document.forms["form_avion"].beb.focus();
	}

	var td=new Date();
	var tdjr=td.getDate();
	var tdms=td.getMonth()+1;
	var tdan=td.getYear(); 
	var date_td=new Date(tdan,tdms-1,tdjr)
	var date_in=new Date("20"+aDep,mDep-1,jDep);
	nbng  = ( date_in.getTime() - date_td.getTime() ) / 86400000 ;
	//alert(date_td+" - " +date_in+"   " + nbng);
	//alert(aDep+" / " + mDep + " / " +jDep);
	if ((nbng<="0"))
	{
		ErrMsg += "Votre date de départ doit être postérieur à la date du jour.\n";
		document.forms["form_avion"].departj.focus();
	}
	else
	{
		var date_in=new Date("20"+aDep,mDep-1,jDep);
		var date_out=new Date("20"+aAr,mAr-1,jAr);
		nbnghts  = ( date_out.getTime() - date_in.getTime() ) / 86400000 ;
		nbnghts  = nbnghts + 1 ;
		if ((nbnghts<="0") && (tVol=="AR" || tVol=="MD"))
		{
			ErrMsg += "Votre date de retour ne peut pas être antérieure à votre date de départ.\n";
			document.forms["form_avion"].retourj.focus();
		}
	}
		
	if (ErrMsg.length > lenInit)
	{
		alert(ErrMsg);
	}
	else{
		// Si ville depart aller=Ville arivee retour et ville arrivee aller = ville depart retour alors
		// il s'agit d'un aller-retour
		if(vDepart == vArrivee_R && vArrivee == vDepart_R)
		{
			document.forms["form_avion"].type.value='AR';
			document.forms["form_avion"].mode.value='';
		}
		document.forms["form_avion"].submit();
	}
}

function goVoyagiste_2(nomVoyagiste, strVoyagiste, voy_code, IDVol, all_dep_iata, all_arr_iata, ret_dep_iata, ret_arr_iata, all_dep_iata_rech, all_arr_iata_rech, ret_dep_iata_rech, ret_arr_iata_rech, allerCompagnie, retourCompagnie, allerDepartAeroport, allerArriveeAeoport, retourDepartAeroport, retourArriveeAeoport, allerDirect, retourDirect, alleriatacie, retouriatacie, allerdepheure, allerarrheure, retourdepheure, retourarrheure)
{
	dir = "0";
//	vDepart = document.forms["form_avion"].depart.value;
	vDepart = all_dep_iata_rech;
//	vArrivee = document.forms["form_avion"].arrivee.value;
	vArrivee = all_arr_iata_rech;
	partId = document.forms["form_avion"].partId.value;
	tVol = document.forms["form_avion"].type.value;
	jDep = document.forms["form_avion"].departj.value;
	mDep = document.forms["form_avion"].departm.value;
	aDep = document.forms["form_avion"].departa.value;
	hDep = document.forms["form_avion"].HeureDepart.value;
	jAr = document.forms["form_avion"].retourj.value;
	mAr = document.forms["form_avion"].retourm.value;
	aAr = document.forms["form_avion"].retoura.value;
	hAr = document.forms["form_avion"].HeureRetour.value;
	cla = document.forms["form_avion"].classe.value;
	nbAdu = document.forms["form_avion"].adu.value;
	nbEnf = document.forms["form_avion"].enf.value;
	nbBeb = document.forms["form_avion"].beb.value;
	if(document.forms["form_avion"].direct)
	{
		if(document.forms["form_avion"].direct.checked==true)
		{
			dir = "1"; 
		}
		else
		{
			dir = "0";
		}
	}

	document.forms["form_sel"].partId.value = partId;
	document.forms["form_sel"].type.value = tVol;

    document.forms["form_sel"].depart.value = vDepart;
    document.forms["form_sel"].arrivee.value = vArrivee;

    document.forms["form_sel"].id_all_dep_iata.value = all_dep_iata;
    document.forms["form_sel"].id_all_arr_iata.value = all_arr_iata;
    document.forms["form_sel"].id_ret_dep_iata.value = ret_dep_iata;
    document.forms["form_sel"].id_ret_arr_iata.value = ret_arr_iata;
    document.forms["form_sel"].id_all_dep_iata_rech.value = all_dep_iata_rech;
    document.forms["form_sel"].id_all_arr_iata_rech.value = all_arr_iata_rech;
    document.forms["form_sel"].id_ret_dep_iata_rech.value = ret_dep_iata_rech;
    document.forms["form_sel"].id_ret_arr_iata_rech.value = ret_arr_iata_rech;

	document.forms["form_sel"].departj.value = jDep;
	document.forms["form_sel"].departm.value = mDep;
	document.forms["form_sel"].departa.value = aDep;
	document.forms["form_sel"].HeureDepart.value = hDep;
	document.forms["form_sel"].retourj.value = jAr;
	document.forms["form_sel"].retourm.value = mAr;
	document.forms["form_sel"].retoura.value = aAr;
	document.forms["form_sel"].HeureRetour.value = hAr;
	document.forms["form_sel"].classe.value = cla;
	document.forms["form_sel"].adu.value = nbAdu;
	document.forms["form_sel"].enf.value = nbEnf;
	document.forms["form_sel"].beb.value = nbBeb;
	document.forms["form_sel"].direct.value = dir;

    document.forms["form_sel"].nomVoyagiste.value = nomVoyagiste;
	document.forms["form_sel"].nomSite.value = strVoyagiste;
    document.forms["form_sel"].id_voy_code.value = voy_code;
    document.forms["form_sel"].id_IDVol.value = IDVol;

    document.forms["form_sel"].id_allerCompagnie.value = allerCompagnie;
    document.forms["form_sel"].id_retourCompagnie.value = retourCompagnie;
    document.forms["form_sel"].id_allerDepartAeroport.value = allerDepartAeroport;
    document.forms["form_sel"].id_allerArriveeAeoport.value = allerArriveeAeoport;
    document.forms["form_sel"].id_retourDepartAeroport.value = retourDepartAeroport;
    document.forms["form_sel"].id_retourArriveeAeoport.value = retourArriveeAeoport;
    document.forms["form_sel"].id_allerDirect.value = allerDirect;
    document.forms["form_sel"].id_retourDirect.value = retourDirect;

    document.forms["form_sel"].id_alleriatacie.value = alleriatacie;
    document.forms["form_sel"].id_retouriatacie.value = retouriatacie;
    document.forms["form_sel"].id_allerdepheure.value = allerdepheure;
    document.forms["form_sel"].id_allerarrheure.value = allerarrheure;
    document.forms["form_sel"].id_retourdepheure.value = retourdepheure;
    document.forms["form_sel"].id_retourarrheure.value = retourarrheure;

//	URL = "go_voyagiste.asp?partId=" + partId + "&nomVoyagiste=" + nomVoyagiste + "&nomSite=" + strVoyagiste + "&voy_code=" + voy_code + "&IDVol=" + IDVol + "&depart=" + vDepart + "&arrivee=" + vArrivee + "&type=" + tVol + "&departj=" + jDep + "&departm=" + mDep + "&departa=" + aDep + "&HeureDepart=" + hDep + "&retourj=" + jAr + "&retourm=" + mAr + "&retoura=" + aAr + "&HeureRetour=" + hAr + "&classe=" + cla + "&adu=" + nbAdu + "&enf=" + nbEnf + "&beb=" + nbBeb + "&direct=" + dir + "&all_dep_iata=" + all_dep_iata + "&all_arr_iata=" + all_arr_iata + "&ret_dep_iata=" + ret_dep_iata + "&ret_arr_iata=" + ret_arr_iata  + "&all_dep_iata_rech=" + all_dep_iata_rech + "&all_arr_iata_rech=" + all_arr_iata_rech + "&ret_dep_iata_rech=" + ret_dep_iata_rech + "&ret_arr_iata_rech=" + ret_arr_iata_rech;
//	document.forms["form_sel"].action = URL;

	document.forms["form_sel"].action = "go_voy.asp";
	document.forms["form_sel"].method = "POST";
	document.forms["form_sel"].target = "_blank";
	document.forms["form_sel"].submit();

	return;
}

function popup_goVoyagiste_2(strVoyagiste, voy_code, IDVol, all_dep_iata, all_arr_iata, ret_dep_iata, ret_arr_iata, all_dep_iata_rech, all_arr_iata_rech, ret_dep_iata_rech, ret_arr_iata_rech)
{
	dir = "0";
//	vDepart = document.forms["form_avion"].depart.value;
	vDepart = all_dep_iata_rech;
//	vArrivee = document.forms["form_avion"].arrivee.value;
	vArrivee = all_arr_iata_rech;
	partId = document.forms["form_avion"].partId.value;
	tVol = document.forms["form_avion"].type.value;
	jDep = document.forms["form_avion"].departj.value;
	mDep = document.forms["form_avion"].departm.value;
	aDep = document.forms["form_avion"].departa.value;
	hDep = document.forms["form_avion"].HeureDepart.value;
	jAr = document.forms["form_avion"].retourj.value;
	mAr = document.forms["form_avion"].retourm.value;
	aAr = document.forms["form_avion"].retoura.value;
	hAr = document.forms["form_avion"].HeureRetour.value;
	cla = document.forms["form_avion"].classe.value;
	nbAdu = document.forms["form_avion"].adu.value;
	nbEnf = document.forms["form_avion"].enf.value;
	nbBeb = document.forms["form_avion"].beb.value;
	if(document.forms["form_avion"].direct)
	{
		if(document.forms["form_avion"].direct.checked==true)
		{
			dir = "1"; 
		}
		else
		{
			dir = "0";
		}
	}

	URL = "go_voyagiste.asp?partId=" + partId + "&nomSite=" + strVoyagiste + "&voy_code=" + voy_code + "&IDVol=" + IDVol + "&depart=" + vDepart + "&arrivee=" + vArrivee + "&type=" + tVol + "&departj=" + jDep + "&departm=" + mDep + "&departa=" + aDep + "&HeureDepart=" + hDep
		+ "&retourj=" + jAr + "&retourm=" + mAr + "&retoura=" + aAr + "&HeureRetour=" + hAr + "&classe=" + cla
		+ "&adu=" + nbAdu + "&enf=" + nbEnf + "&beb=" + nbBeb + "&dir=" + dir + "&all_dep_iata=" + all_dep_iata + "&all_arr_iata=" + all_arr_iata + "&ret_dep_iata=" + ret_dep_iata + "&ret_arr_iata=" + ret_arr_iata  + "&all_dep_iata_rech=" + all_dep_iata_rech + "&all_arr_iata_rech=" + all_arr_iata_rech + "&ret_dep_iata_rech=" + ret_dep_iata_rech + "&ret_arr_iata_rech=" + ret_arr_iata_rech;

	loc1 = "0";
	loc2 = "0";
	if (strVoyagiste == "opodo") { loc1 = "0" ; loc2 = "0" };
	if (strVoyagiste == "vivacances") { loc1 = "20" ; loc2 = "0" };
	if (strVoyagiste == "expedia") { loc1 = "40" ; loc2 = "0" };
	if (strVoyagiste == "anyway") { loc1 = "60" ; loc2 = "0" };
	if (strVoyagiste == "voyages-sncf.com") { loc1 = "0" ; loc2 = "30" };
	if (strVoyagiste == "ebookers") { loc1 = "20" ; loc2 = "30" };
	if (strVoyagiste == "lastminute.com") { loc1 = "40" ; loc2 = "30" };
	if (strVoyagiste == "govoyages") { loc1 = "60" ; loc2 = "30" };

	LOC = "toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, width=790, height=570, left=" + loc1 + ",top=" + loc2;
//alert(URL);
	window.open(URL, "", LOC);

	return;
}
