// JavaScript Document



function validateForm(form) {

	var orig = document.bookFlightsForm.origin.value;
	var dest = document.bookFlightsForm.dest.value;
	orig = orig.replace("ä", "ae");
	orig = orig.replace("Ä", "Ae");
	orig = orig.replace("ü", "ue");
	orig = orig.replace("Ü", "Ue");
	orig = orig.replace("ö", "oe");
	orig = orig.replace("Ö", "Oe");
	orig = orig.replace("ß", "ss");
	orig = orig.replace("é", "e");
	orig = orig.replace("è", "e");
	orig = orig.replace("ê", "e");
	orig = orig.replace("à", "a");
	orig = orig.replace("ô", "o");
	orig = orig.replace("î", "i");
	orig = orig.replace("â", "a");
	orig = orig.replace("ï", "i");
	orig = orig.replace("Â", "a");
	orig = orig.replace("Î", "i");
	orig = orig.replace("Ï", "i");
	dest = dest.replace("ä", "ae");
	dest = dest.replace("Ä", "Ae");
	dest = dest.replace("ü", "ue");
	dest = dest.replace("Ü", "Ue");
	dest = dest.replace("ö", "oe");
	dest = dest.replace("Ö", "Oe");
	dest = dest.replace("ß", "ss");
	dest = dest.replace("é", "e");
	dest = dest.replace("è", "e");
	dest = dest.replace("ê", "e");
	dest = dest.replace("à", "a");
	dest = dest.replace("ô", "o");
	dest = dest.replace("î", "i");
	dest = dest.replace("â", "a");
	dest = dest.replace("ï", "i");
	dest = dest.replace("Â", "a");
	dest = dest.replace("Î", "i");
	dest = dest.replace("Ï", "i");	
    document.bookFlightsForm.origin.value = orig;
    document.bookFlightsForm.dest.value = dest;

	if (document.bookFlightsForm.origin.value.length < 3) {
		alert("Veuillez sélectionner un aéroport de départ.");
		document.bookFlightsForm.origin.focus();
		return false;
	} else if (document.bookFlightsForm.dest.value.length < 3) {
		alert("Veuillez entrer une ville de destination ou un code aéroport.");
		document.bookFlightsForm.dest.focus();
		return false;
	} 
	

	
	if(checkValidDay('F')){}else{return false;}
	if(testAge()){}else{return false;}

	//setting the departdate and returndate in the hidden value
	str_departyearandmonth=document.bookFlightsForm.MONTH_DATE.options[document.bookFlightsForm.MONTH_DATE.selectedIndex].value;
	str_departyear=str_departyearandmonth.substring(0,4);
	str_departmonth=str_departyearandmonth.substring(4,6);
	document.bookFlightsForm.departdate.value=str_departdate=str_departyear+"-"+str_departmonth+"-"+document.bookFlightsForm.DAY_DATE.options[document.bookFlightsForm.DAY_DATE.selectedIndex].value;

	str_returnyearandmonth=document.bookFlightsForm.MONTH_RDATE.options[document.bookFlightsForm.MONTH_RDATE.selectedIndex].value;
	str_returnyear=str_returnyearandmonth.substring(0,4);
	str_returnmonth=str_returnyearandmonth.substring(4,6);
	document.bookFlightsForm.returndate.value=str_returndate=str_returnyear+"-"+str_returnmonth+"-"+document.bookFlightsForm.DAY_RDATE.options[document.bookFlightsForm.DAY_RDATE.selectedIndex].value;
	return true;
}



function checkValidDay(com){

	if(com == 'H'){
		var dep_day = document.bookHotelsForm.DAY_DATE.options[document.bookHotelsForm.DAY_DATE.selectedIndex].value;
		var ret_day = document.bookHotelsForm.DAY_RDATE.options[document.bookHotelsForm.DAY_RDATE.selectedIndex].value;
		var dep_monyear = document.bookHotelsForm.MONTH_DATE.options[document.bookHotelsForm.MONTH_DATE.selectedIndex].value;
		var ret_monyear = document.bookHotelsForm.MONTH_RDATE.options[document.bookHotelsForm.MONTH_RDATE.selectedIndex].value;

	}
	if(com == 'F'){
		var dep_day = document.bookFlightsForm.DAY_DATE.options[document.bookFlightsForm.DAY_DATE.selectedIndex].value;
		var ret_day = document.bookFlightsForm.DAY_RDATE.options[document.bookFlightsForm.DAY_RDATE.selectedIndex].value;
		var dep_monyear = document.bookFlightsForm.MONTH_DATE.options[document.bookFlightsForm.MONTH_DATE.selectedIndex].value;
		var ret_monyear = document.bookFlightsForm.MONTH_RDATE.options[document.bookFlightsForm.MONTH_RDATE.selectedIndex].value;
	}

	if(com == 'C'){
		var dep_day = document.bookCarsForm.DAY_DATE.options[document.bookCarsForm.DAY_DATE.selectedIndex].value;
		var ret_day = document.bookCarsForm.DAY_RDATE.options[document.bookCarsForm.DAY_RDATE.selectedIndex].value;
		var dep_monyear = document.bookCarsForm.MONTH_DATE.options[document.bookCarsForm.MONTH_DATE.selectedIndex].value;
		var ret_monyear = document.bookCarsForm.MONTH_RDATE.options[document.bookCarsForm.MONTH_RDATE.selectedIndex].value;
	}

	var dep_year = dep_monyear.substr(0,4);
	var dep_month = dep_monyear.substr(4,2);
	var ret_year = ret_monyear.substr(0,4);
	var ret_month = ret_monyear.substr(4,2);
	var depday_max = GetMonthMaxDays(dep_year,dep_month-1);
	var retday_max = GetMonthMaxDays(ret_year,ret_month-1);
	var newDt = new Date();
	var currDay= (newDt.getDate());
	var currMon= (newDt.getMonth()+1);
	var currYear = (newDt.getFullYear());
	var temp_new = currMon.toString();
                if (temp_new.length == 1){
                 currMon= '0'+currMon;
				 }
 	var a = (currMon.toString());
	var b = (currYear .toString());
	var MonYear =  (b+a);


	if(dep_day > depday_max)
	{
		alert("Date de départ non valide.");
		return false;
	}
		else if(ret_day > retday_max)
		{
			alert("Date de retour non valide.");
			return false;
		}
		else if((ret_monyear < dep_monyear))
			{
			alert("Date de départ non valide.");
			return false;
			}
	
			else if(((dep_monyear == ret_monyear)&&(ret_day < dep_day)))
				{
				alert("Date de départ non valide.");
				return false;
				}
				 if((dep_day <= currDay)&&(dep_monyear <= MonYear))
				{
					alert("Date de retour non valide.");
					return false;
				}
				
	if(com == 'C')
		{
		makeURL();
		}
		else{
			return true;
			}

}

function validateHotel(){
	
   var orig = document.bookHotelsForm.market.value;
	orig = orig.replace("ä", "ae");
	orig = orig.replace("Ä", "Ae");
	orig = orig.replace("ü", "ue");
	orig = orig.replace("Ü", "Ue");
	orig = orig.replace("ö", "oe");
	orig = orig.replace("Ö", "Oe");
	orig = orig.replace("ß", "ss");
	orig = orig.replace("é", "e");
	orig = orig.replace("è", "e");
	orig = orig.replace("ê", "e");
	orig = orig.replace("à", "a");
	orig = orig.replace("ô", "o");
	orig = orig.replace("î", "i");
	orig = orig.replace("â", "a");
	orig = orig.replace("ï", "i");
	orig = orig.replace("Â", "a");
	orig = orig.replace("Î", "i");
	orig = orig.replace("Ï", "i");

	document.bookHotelsForm.market.value = orig;
	
	if (document.bookHotelsForm.market.value.length < 3) {
		alert("Choisissez une ville de destination");
		document.bookHotelsForm.market.focus();
		return false;
	}
	

	if(checkValidDay('H')){}else{return false;}

	//setting the departdate and returndate in the hidden value
	str_departyearandmonth=document.bookHotelsForm.MONTH_DATE.options[document.bookHotelsForm.MONTH_DATE.selectedIndex].value;
	str_departyear=str_departyearandmonth.substring(0,4);
	str_departmonth=str_departyearandmonth.substring(4,6);
	document.bookHotelsForm.checkin.value=str_departdate=str_departyear+"-"+str_departmonth+"-"+document.bookHotelsForm.DAY_DATE.options[document.bookHotelsForm.DAY_DATE.selectedIndex].value;

	str_returnyearandmonth=document.bookHotelsForm.MONTH_RDATE.options[document.bookHotelsForm.MONTH_RDATE.selectedIndex].value;
	str_returnyear=str_returnyearandmonth.substring(0,4);
	str_returnmonth=str_returnyearandmonth.substring(4,6);
	document.bookHotelsForm.checkout.value=str_returndate=str_returnyear+"-"+str_returnmonth+"-"+document.bookHotelsForm.DAY_RDATE.options[document.bookHotelsForm.DAY_RDATE.selectedIndex].value;

	return true;
}

function setHiddenDates(){

    var orig = document.bookHotelsForm.market.value;
	orig = orig.replace("ä", "ae");
	orig = orig.replace("Ä", "Ae");
	orig = orig.replace("ü", "ue");
	orig = orig.replace("Ü", "Ue");
	orig = orig.replace("ö", "oe");
	orig = orig.replace("Ö", "Oe");
	orig = orig.replace("ß", "ss");
	orig = orig.replace("é", "e");
	orig = orig.replace("è", "e");
	orig = orig.replace("ê", "e");
	orig = orig.replace("à", "a");
	orig = orig.replace("ô", "o");
	orig = orig.replace("î", "i");
	orig = orig.replace("â", "a");
	orig = orig.replace("ï", "i");
	orig = orig.replace("Â", "a");
	orig = orig.replace("Î", "i");
	orig = orig.replace("Ï", "i");

	document.bookHotelsForm.market.value = orig;
	
	if (document.bookHotelsForm.market.value.length < 3) {
		alert("Choisissez une ville de destination");
		document.bookHotelsForm.market.focus();
		return false;
	}
	

	if(checkValidDay('H')){}else{return false;}

	//setting the departdate and returndate in the hidden value
	str_departyearandmonth=document.bookHotelsForm.MONTH_DATE.options[document.bookHotelsForm.MONTH_DATE.selectedIndex].value;
	str_departyear=str_departyearandmonth.substring(0,4);
	str_departmonth=str_departyearandmonth.substring(4,6);
	document.bookHotelsForm.checkin.value=str_departdate=str_departyear+"-"+str_departmonth+"-"+document.bookHotelsForm.DAY_DATE.options[document.bookHotelsForm.DAY_DATE.selectedIndex].value;

	str_returnyearandmonth=document.bookHotelsForm.MONTH_RDATE.options[document.bookHotelsForm.MONTH_RDATE.selectedIndex].value;
	str_returnyear=str_returnyearandmonth.substring(0,4);
	str_returnmonth=str_returnyearandmonth.substring(4,6);
	document.bookHotelsForm.checkout.value=str_returndate=str_returnyear+"-"+str_returnmonth+"-"+document.bookHotelsForm.DAY_RDATE.options[document.bookHotelsForm.DAY_RDATE.selectedIndex].value;

	return true;
}


function hideoptions() 
{
   
}
function validateCar(){
//Validation Starts here
	var orig1 = document.bookCarsForm.pickuptype.value;
	var dest3 = document.bookCarsForm.dropofftype.value;	
	
	orig1 = orig1.replace("ä", "ae");
	orig1 = orig1.replace("Ä", "Ae");
	orig1 = orig1.replace("ü", "ue");
	orig1 = orig1.replace("Ü", "Ue");
	orig1 = orig1.replace("ö", "oe");
	orig1 = orig1.replace("Ö", "Oe");
	orig1 = orig1.replace("ß", "ss");
	orig1 = orig1.replace("é", "e");
	orig1 = orig1.replace("è", "e");
	orig1 = orig1.replace("ê", "e");
	orig1 = orig1.replace("â", "a");
	orig1 = orig1.replace("î", "i");
	orig1 = orig1.replace("Â", "a");
	orig1 = orig1.replace("ï", "i");
	orig1 = orig1.replace("Î", "i");
	orig1 = orig1.replace("û", "u");
	dest3 = dest3.replace("ä", "ae");
	dest3 = dest3.replace("Ä", "Ae");
	dest3 = dest3.replace("ü", "ue");
	dest3 = dest3.replace("Ü", "Ue");
	dest3 = dest3.replace("ö", "oe");
	dest3 = dest3.replace("Ö", "Oe");
	dest3 = dest3.replace("ß", "ss");
	dest3 = dest3.replace("é", "e");
	dest3 = dest3.replace("è", "e");
	dest3 = dest3.replace("ê", "e");
	dest3 = dest3.replace("â", "a");
	dest3 = dest3.replace("î", "i");
	dest3 = dest3.replace("Â", "a");
	dest3 = dest3.replace("ï", "i");
	dest3 = dest3.replace("Î", "i");
	dest3 = dest3.replace("û", "u");
	
	document.bookCarsForm.pickuptype.value = orig1;
	document.bookCarsForm.dropofftype.value = dest3;

	var pickcity = document.bookCarsForm.pickuptype.value;
	var dropcity = document.bookCarsForm.dropofftype.value;
	

		/* OLD */
			/*
		if((pickcity.length < 3)||!(pickcity.match(/^[a-zA-Z]+$/)))
		{
			alert("Nom de la ville ou du code aéroport de départ.");
			return false;
		}
	
			if((dropcity.length < 3)||!(dropcity.match(/^[a-zA-Z]+$/)))
			{
				alert("Nom de la ville ou du code aéroport d'arrivée.");
				return false;
			}*/
			
			/* NEW */
		if(pickcity.length < 3)
		{
			alert("Nom de la ville ou du code aéroport de départ.");
			return false;
		}
	
		if(dropcity.length < 3)
		{
			alert("Nom de la ville ou du code aéroport d'arrivée.");
			return false;
		}
		
	if(checkValidDay('C')){}else{return false;}

//Validation  for Car Ends here
}



/*Test âge des enfants*/
function testAge() {
nbChild = document.bookFlightsForm.children.value;
age1 = document.bookFlightsForm.childAges1.value;
age2 = document.bookFlightsForm.childAges2.value;
age3 = document.bookFlightsForm.childAges3.value;
	// Test si tous les enfants ont des âges
	if ((nbChild == 1) && (age1 == '')) {
	alert("Veuillez indiquer l'âge de l'enfant");
	return false;
	}
	if (((nbChild == 2) && (age1 == '')) || ((nbChild == 2) && (age2 == ''))) {
	alert("Veuillez indiquer l'âge de tous les enfants");
	return false;
	}
	if (((nbChild == 3) && (age1 == '')) || ((nbChild == 3) && (age2 == '')) || ((nbChild == 3) && (age3 == ''))) {
	alert("Veuillez indiquer l'âge de tous les enfants");
	return false;
	}
	// Test si il y a des âges en trop
	if ((nbChild == 0) && ((age1 != '') || (age2 != '') || (age3 != ''))) {
	alert("Veuillez vérifier le nombre d'enfants");
	return false;
	}
	if ((nbChild == 1) && ((age2 != '') || (age3 != ''))) {
	alert("Veuillez vérifier le nombre d'enfants");
	return false;
	}
	if ((nbChild == 2) && (age3 != '')) {
	alert("Veuillez vérifier le nombre d'enfants");
	return false;
	}
	
	
return true;
}




