//Esta variable dice cuántos días después empieza a contar el calendario.
var diasmas = 3;
var today = new Date();
var minDate = new Date(Date.parse((parseInt(today.getMonth()) + 1) + "/" + (parseInt(today.getDate()) + diasmas) + "/" + today.getFullYear()));
var minDate2 = new Date(Date.parse((parseInt(today.getMonth()) + 1) + "/" + (parseInt(today.getDate()) + 6) + "/" + today.getFullYear()));
var maxDate = new Date(Date.parse((parseInt(today.getMonth()) + 12) + "/" + today.getDate() + "/" + today.getFullYear()));
var sesionExpired = false;
var sessionTimeExpired = "20";

function changeStyle(fldId, color, weight) {
	if (document.all) {
		if (document.all[fldId] != null) {
			document.all[fldId].style.color=color;
			document.all[fldId].style.fontWeight=weight;
		}
	}
}
  
/* controll form tab voli
********************************************************************/

function checkSearchMPForm(form) {
	if (form.departureCity.value == "") {
		alert("Devi indicare un aeroporto di partenza.");
		form.departureCity.focus();
		return false;
	}
	
	if (form.departureCity.value == "Scrivi la tua città") {
		alert("Devi indicare un aeroporto di partenza.");
		form.departureCity.focus();
		return false;
	}	
	
	if (form.arrivalCity.value == "") {
		alert("Devi indicare un aeroporto di destinazione.");
		form.arrivalCity.focus();
		return false;
	}
	
	if (form.arrivalCity.value == "Scrivi la tua città") {
		alert("Devi indicare un aeroporto di destinazione.");
		form.arrivalCity.focus();
		return false;
	}
	
	
if (form.depDate.value!="Sono flessibile" && form.retDate.value!="Sono flessibile") {
	
	if (!parseDate(form.depDate.value, form.departureDate)) {
		alert("Devi scrivere una data di partenza corretta. Ex. " + form.tmpej.value);
		return false;
	}
	
	var idep = parseInt(form.departureDate.value.substring(4) + form.departureDate.value.substring(2,4) + form.departureDate.value.substring(0,2));
	var nd = new Date();
	var td = parseInt(nd.getYear().toString() + ((nd.getMonth() + 1)<10?("0"+(nd.getMonth()+1).toString()):(nd.getMonth()+1).toString()) + (nd.getDate()<10?("0"+nd.getDate().toString()):nd.getDate().toString())); 
	
	
	//TODO: check data sortida >= data d'avui.	
	//if (td >= idep) {
	if (td > idep) {
		alert("La data di partenza non può essere anteriore alla data odierna.");
		return false;
	} 
	
	form.isZapOff.value="0";
	
	if ((idep >= 20050926) && (idep <= 20051130)) {
		if (form.isZapOffdates.value == "1") form.isZapOff.value="1";
	} else {
		form.isZapOff.value="0";
	}
	
	if (form.tripType[0].checked) {
		if (!parseDate(form.retDate.value, form.returnDate)) {
			alert("Devi scrivere una data di ritorno corretta. Ex. " + form.tmpej.value);
			return false;
		}
		
		var iret = parseInt(form.returnDate.value.substring(4) + form.returnDate.value.substring(2,4) + form.returnDate.value.substring(0,2));
		
		if (idep > iret) {
			alert("La data di ritorno dev'essere posteriore a quella di partenza.");
			return false;
		}
	
		if  ((form.isZapOff.value == "1") && ((iret >= 20050923) && (iret <= 20051130))) {
			if (form.isZapOffdates.value == "1") form.isZapOff.value="1";
		} else {
			form.isZapOff.value="0";
		}
		
	}
	
	} else {
	document.flighsearch.action="/edreams/italiano/amadeus3/checkCitys.jhtml";
}	
	
	
	
	var nadults = parseInt(form.adults.value,"10");
	var nchilds = parseInt(form.childs.value,"10");
	var nbabies = parseInt(form.infants.value,"10");
	var nbabieswith = parseInt(form.infantswithseats.value,"10");
	var nyouth = parseInt(form.youths.value,"10");
	var nstudents = parseInt(form.students.value,"10");
	var nsenior = 0;
	
	ntotpax = nadults + nchilds + nbabies + nbabieswith + nyouth + nstudents + nsenior;
	ntotadults = nadults + nsenior + nstudents;
	ntotchilds = nchilds + nbabies + nbabieswith;
	
	if (ntotpax > 9) {
		alert("Il numero massimo di passeggeri è 9.");
		return false;
	}
	
	if (ntotpax < 1) {
		alert("Non hai selezionato nessun passeggero");
		return false;
	}
	
	if ((ntotchilds > 0) && (ntotadults == 0)) {
		alert("I bambini non possono viaggiare da soli.");
		return false;
	}
	
	if (ntotchilds > (ntotadults*2)) {
		alert("Massimo 2 bambini per adulto.");
		return false;
	}

	if (nchilds > (ntotadults*2)) {
		alert("Massimo 2 bambini per adulto.");
		return false;
	}

	if (nbabies > ntotadults) {
		alert("Massimo 1 bambino per adulto.");
		return false;
	}

	form.service_class.value=form.clase[form.clase.selectedIndex].value.charAt(0);
	form.bookingClass.value=form.clase[form.clase.selectedIndex].value.charAt(0);
	

	if(form.departureCityHd)
		if (form.departureCityHd.value != "")
			form.departureCity.value = form.departureCityHd.value;
	
	if(form.arrivalCityHd)
		if (form.arrivalCityHd.value != "")
			form.arrivalCity.value = form.arrivalCityHd.value;
	
	setSwooshStep("paso1", "vuelos", form.id)
	hideLayer('edreamsScreen');
	showLayer('waitScreen');
	window.scrollTo(1,1);

	var searchCR14716 = document.getElementById("searchCR14716");
	if(searchCR14716 != null && searchCR14716.value=='true'){
		var depCode = form.departureCity.value;
		var retCode = form.arrivalCity.value;
		var depDay = form.depDate.value.substring(0, 2);
		var depMonth = form.depDate.value.substring(3, 5);
		var depYear = form.depDate.value.substring(6);
		var retDay = depDay;
		var retMonth = depMonth;
		var retYear = depYear;
		if (form.trip.value == 1) {
			retDay = form.retDate.value.substring(0, 2);
			retMonth = form.retDate.value.substring(3, 5);
			retYear = form.retDate.value.substring(6);
		}
		var url = 'http://results.edreams.it/edreams/siteunder_ta.jsp?FROM=' + depCode + '&TO=' + retCode + '&DEPART_DD=' + depDay + '&DEPART_MM=' + depMonth + '&DEPART_YYYY=' + depYear + '&RETOUR_DD=' + retDay + '&RETOUR_MM=' + retMonth + '&RETOUR_YYYY=' + retYear;
		var myWindow=window.open(url,'','width=650,height=415,scrollbars=yes');
		window.self.focus();
	}
	
    return true;
}
function hideLayer(layername) {
	document.getElementById(layername).style.display = 'none';
	document.getElementById(layername).style.visibility = 'hidden';
}

function showLayer(layername) {
	hideLayer(layername);
	document.getElementById(layername).style.display = 'block';
	document.getElementById(layername).style.visibility = 'visible';
}
function parseDate(dateString, fldform) {
	if (dateString.length != 10) {
		return false;
	}
	
	if ((dateString.charAt(2) !='/') || (dateString.charAt(5) != '/'))  {
		return false;
	}
	
	var diafecha, mesfecha, anyofecha;
	var d = new Date();
	var diasmes = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

	diafecha = dateString.substring(0, 2);
	mesfecha = dateString.substring(3, 5);
	anyofecha = dateString.substring(6);

	if (isNaN(diafecha) || isNaN(mesfecha) || isNaN(anyofecha)) {
		return false;
	}
	
	if (anyofecha < d.getYear()) {
		return false;
	}
	
	if ((mesfecha < 1) || (mesfecha > 12)) {
		return false;
	}

	if ((diafecha < 1) || (diafecha > diasmes[mesfecha])) {
		return false;
	}

	fldform.value = diafecha + mesfecha + anyofecha;
	return true
}

function checkSelItinerary(form) {
	selIn = false;
	selOut = false;
	selOut3 = false;
	
	obj = form.outBoundSegment;
	if (obj == null) {
		alert("Questo volo non puo' essere selezionato.");
		return false;
	}
	
	if (obj.length > 0) {
		for (var i = 0; i < obj.length; i++) {
		    if (obj[i].checked) {
				selOut = true;
			}
		}
	} else {
	    if (obj.checked) {
			selOut = true;
		}
	}

	if ((selOut == false)) {
		alert('Devi scegliere un volo di andata in questo riquadro.');
		return false;
	}
	
	obj = form.inBoundSegment;

	if (obj != null) {
		if (obj.length > 0) {
			for (var i = 0; i < obj.length; i++) {
			    if (obj[i].checked) {
					selIn = true;
				}
			}
		} else {
		    if (obj.checked) {
				selIn = true;
			}
		}
	
		if ((selIn == false)) {
			obj3 = form.otherBoundSegment;
			if (obj3 != null) {
				alert("Devi scegliere 3 voli all'interno dello stesso riquadro.");
			} else {
				alert("Devi scegliere un volo di andata e uno di ritorno all'interno dello stesso riquadro.");
			}
			return false;
		}
	}
	
	obj = form.otherBoundSegment;
	if (obj != null) {
		if (obj.length > 0) {
			for (var i = 0; i < obj.length; i++) {
			    if (obj[i].checked) {
					selOut3 = true;
				}
			}
		} else {
		    if (obj.checked) {
				selOut3 = true;
			}
		}
	
		if ((selOut3 == false)) {
			alert("Devi scegliere 3 voli all'interno dello stesso riquadro.");
			return false;
		}
	}
	

	return true;
}


function checkSearchColumnForm(form) {
// check cities
	changeStyle("depCityCol", "#000000", "normal");
	changeStyle("arrCityCol", "#000000", "normal");
	if (form.trip.value == 1) {
		changeStyle("retDateCol", "#000000", "normal");
	}
	changeStyle("depDateCol", "#000000", "normal");
	
	if (form.departureCity.value == "")	{
		changeStyle("depCityCol", "#ff0000", "bold");
		alert("Devi indicare un aeroporto di partenza.");
		form.departureCity.focus();
		return false;
	}
	
	if (form.departureCity.value == "Scrivi la tua città")	{
		changeStyle("depCityCol", "#ff0000", "bold");
		alert("Devi indicare un aeroporto di partenza.");
		form.departureCity.focus();
		return false;
	}
	
	if (form.arrivalCity.value == "") {
		changeStyle("arrCityCol", "#ff0000", "bold");
		alert("Devi indicare un aeroporto di destinazione.");
		form.arrivalCity.focus();
		return false;
	}
	
	if (form.arrivalCity.value == "Scrivi la tua città") {
		changeStyle("arrCityCol", "#ff0000", "bold");
		alert("Devi indicare un aeroporto di destinazione.");
		form.arrivalCity.focus();
		return false;
	}

	
if (form.depDate.value!="Sono flessibile" && form.retDate.value!="Sono flessibile") {		
	
	
	if (form.depDate.value.length != 10) {
		changeStyle("depDateCol", "#ff0000", "bold");
		alert("Il formato della data di partenza non è corretto.");
		return false;
	}
	
	if ((form.depDate.value.charAt(2) !='/') || (form.depDate.value.charAt(5) != '/'))  {
		changeStyle("depDateCol", "#ff0000", "bold");
		alert("Il formato della data di partenza non è corretto.");
		return false;
	}
	
	var diafecha, mesfecha, anyofecha;
	var d = new Date();
	var diasmes = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

	diafecha = form.depDate.value.substring(0, 2);
	mesfecha = form.depDate.value.substring(3, 5);
	anyofecha = form.depDate.value.substring(6);
	
	idep = parseInt(anyofecha + mesfecha + diafecha);
	var nd = new Date();
	var td = parseInt(nd.getYear().toString() + ((nd.getMonth() + 1)<10?("0"+(nd.getMonth()+1).toString()):(nd.getMonth()+1).toString()) + (nd.getDate()<10?("0"+nd.getDate().toString()):nd.getDate().toString())); 

	//if (td >= idep) {
	if (td > idep) {
		changeStyle("depDateFld", "#ff0000", "bold");
		alert("La data di partenza non può essere anteriore alla data odierna.");
		return false;
	}

	if (isNaN(diafecha) || isNaN(mesfecha) || isNaN(anyofecha)) {
		changeStyle("depDateCol", "#ff0000", "bold");
		alert("Il formato della data di ritorno non è corretto.");
		return false;
	}
	
	if (anyofecha < d.getYear()) {
		changeStyle("depDateCol", "#ff0000", "bold");
		alert("La data di partenza non è corretta.");
		return false;
	}
	
	if ((mesfecha < 1) || (mesfecha > 12)) {
		changeStyle("depDateCol", "#ff0000", "bold");
		alert("La data di partenza non è corretta.");
		return false;
	}

	if ((diafecha < 1) || (diafecha > diasmes[mesfecha])) {
		changeStyle("depDateCol", "#ff0000", "bold");
		alert("La data di partenza non è corretta.");
		return false;
	}

	form.departureDate.value = diafecha + mesfecha + anyofecha;
	
	form.isZapOff.value="0";
	
	if ((idep >= 20050926) && (idep <= 20051130)) {
		if (form.isZapOffdates.value == "1") form.isZapOff.value="1";
	} else {
		form.isZapOff.value="0";
	}
	
	if (form.trip.value == 1) {
		if (form.retDate.value.length != 10) {
			changeStyle("retDateCol", "#ff0000", "bold");
			alert("Il formato della data di ritorno non è corretto.");
			return false;
		}
	
		if ((form.retDate.value.charAt(2) !='/') || (form.retDate.value.charAt(5) != '/'))  {
			changeStyle("retDateCol", "#ff0000", "bold");
			alert("Il formato della data di ritorno non è corretto.");
			return false;
		}

		diafecha = form.retDate.value.substring(0, 2);
		mesfecha = form.retDate.value.substring(3, 5);
		anyofecha = form.retDate.value.substring(6);

		if (isNaN(diafecha) || isNaN(mesfecha) || isNaN(anyofecha)) {
			changeStyle("retDateCol", "#ff0000", "bold");
			alert("Il formato della data di ritorno non è corretto.");
			return false;
		}
	
		if (anyofecha < d.getYear()) {
			changeStyle("retDateCol", "#ff0000", "bold");
			alert("La data di ritorno non è corretta.");
			return false;
		}
	
		if ((mesfecha < 1) || (mesfecha > 12)) {
			changeStyle("depDateCol", "#ff0000", "bold");
			alert("La data di ritorno non è corretta.");
			return false;
		}

		if ((diafecha < 1) || (diafecha > diasmes[mesfecha])) {
			changeStyle("depDateCol", "#ff0000", "bold");
			alert("La data di ritorno non è corretta.");
			return false;
		}

		iret = parseInt(anyofecha + mesfecha + diafecha);
		
		if (idep > iret) {
			changeStyle("depDateCol", "#ff0000", "bold");
			changeStyle("retDateCol", "#ff0000", "bold");
			alert("La data di ritorno deve essere posteriore alla data di partenza.");
			return false;
		}

		form.returnDate.value = diafecha + mesfecha + anyofecha;
		
		if  ((form.isZapOff.value == "1") && ((iret >= 20050923) && (iret <= 20051130))) {
			if (form.isZapOffdates.value == "1") form.isZapOff.value="1";
		} else {
			form.isZapOff.value="0";
		}
	}
	
	
	} else {
	document.flightsearch.action="/edreams/italiano/amadeus3/checkCitys.jhtml";
}	
	
	if(form.departureCityHd)
		if (form.departureCityHd.value != "")
			form.departureCity.value = form.departureCityHd.value;
	
	if(form.arrivalCityHd)
		if (form.arrivalCityHd.value != "")
			form.arrivalCity.value = form.arrivalCityHd.value;
	
	return true;
}

function checkFormETicket1(formPassengers) {
	if (sesionExpired == true) {
		alert("Sono trascorsi " + sessionTimeExpired + " minuti dall'inizio della tua richiesta di prenotazione. La sessione é scaduta. Per poter effettuare la prenotazione devi realizzare una nuova ricerca.");
		return false;
	}
	for (var i=1; i <= parseInt(formPassengers.nPassengers.value); i++) {
		changeStyle("nameFld"+i, "#000000", "normal");
		changeStyle("surnameFld"+i, "#000000", "normal");
		dob = eval("formPassengers.elements['dob" + i + "'].value");
		if (dob == "1") {
			changeStyle("dobFld"+i, "#000000", "normal");
		}
		IDP = eval("formPassengers.elements['Id" + i + "'].value");
		if (IDP == "1") {
			changeStyle("idFld"+i, "#000000", "normal");
		}
		
		fqtv1 = eval("formPassengers.elements['fqtv1" + i + "'].value");
		if (fqtv1 == "1") {
			changeStyle("fqtv1" + i + "fld", "#000000", "normal");
		}
		
		fqtv2 = eval("formPassengers.elements['fqtv2" + i + "'].value");
		if (fqtv2 == "1") {
			changeStyle("fqtv2" + i + "fld", "#000000", "normal");
		}
	}

	for (var i=1; i <= parseInt(formPassengers.nPassengers.value); i++) {
		if (!checkPassengerAndId(formPassengers, i)) return false; // passenger had errors
	}
	
	for (var i=1; i <= parseInt(formPassengers.nPassengers.value); i++) {
		if (!checkPassengerFrequent(formPassengers, i, 1)) return false; // passenger had errors
	}
	
	for (var i=1; i <= parseInt(formPassengers.nPassengers.value); i++) {
		if (!checkPassengerFrequent(formPassengers, i, 2)) return false; // passenger had errors
	}
	return true;
}

function checkPassengerBirthDate(formPassengers, id) {
	var passType = eval("formPassengers.elements['passType" + id + "'].value");
	var bdateDay = eval("formPassengers.elements['birthDateDay" + id + "'].value");
	var bdateMonth = eval("formPassengers.elements['birthDateMonth" + id + "'].value");
	var bdateYear = eval("formPassengers.elements['birthDateYear" + id + "'].value");
	
	var iBDay = parseInt(bdateDay, 10);
	var iBMonth = parseInt(bdateMonth, 10);
	var iBYear = parseInt(bdateYear, 10);
	
	bthdate = "" + bdateYear + bdateMonth + bdateDay;
	var iBDate = parseInt(bthdate, 10);
	
	document.getElementById('birthDate' + id).value = bdateDay + "'/'" + bdateMonth + "'/'" + bdateYear ;
	
	if (bthdate == "") {
		alert("Per favore indica la data di nascita del passeggero " + id);
		eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
		return false;
	}
	
	if (bthdate.length != 8) {
		alert("Per favore indica la data di nascita del passeggero " + id);
		eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
		return false;
	}
	
	if (isNaN(iBDate)) {
		alert("Per favore indica la data di nascita del passeggero " + id);
		eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
		return false;
	}
	
	isLeap = ((iBYear % 4)==0) ? true : false;
	
	if ((iBDay <= 0) || (iBMonth <= 0)) {
		alert("Per favore controlla la data di nascita del passeggero  " + id);
		eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
		return false;
	}
	
	if ((isLeap == true) && (iBMonth == 2)) {
		if ((iBDay > 29)) {
			alert("Per favore controlla la data di nascita del passeggero " + id);
			eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
			return false;
		}
	} else if (iBMonth == 2) {
		if ((iBDay > 28)) {
			alert("Per favore controlla la data di nascita del passeggero " + id);
			eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
			return false;
		}
	} else if ((iBMonth == 4) || (iBMonth == 6) || (iBMonth == 9) || (iBMonth == 11)) {
		if ((iBDay > 30)) {
			alert("Per favore controlla la data di nascita del passeggero " + id);
			eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
			return false;
		}
	} else {
		if ((iBDay > 31)) {
			alert("Per favore controlla la data di nascita del passeggero " + id);
			eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
			return false;
		}
	}
	
	if (bdateYear.length < 4) {
		alert("Per favore controlla la data di nascita del passeggero " + id);
		eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
		return false;
	}
	
	if (formPassengers.todayDate.value < iBDate) {
		alert("Per favore controlla la data di nascita del passeggero " + id + ".\n La data di nascita deve essere anteriore alla data odierna.");
		eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
		return false;
	}
	
	if (passType == 'CHD') {
		if (iBDate < formPassengers.minDateCHD.value) {
			alert("Per favore controlla la data di nascita del passeggero " + id + ".\n Il bambino deve essere nato tra il " + formPassengers.minDateCHD.value.substring(6,8)+'/'+formPassengers.minDateCHD.value.substring(4,6)+'/'+formPassengers.minDateCHD.value.substring(0,4) + " e il " + formPassengers.minDateINF.value.substring(6,8)+'/'+formPassengers.minDateINF.value.substring(4,6)+'/'+formPassengers.minDateINF.value.substring(0,4));
			eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
			return false;
		}
		
		if ( formPassengers.minDateINF.value < iBDate) {
			alert("Per favore controlla la data di nascita del passeggero " + id + ".\n Il bambino deve essere nato tra il " + formPassengers.minDateCHD.value.substring(6,8)+'/'+formPassengers.minDateCHD.value.substring(4,6)+'/'+formPassengers.minDateCHD.value.substring(0,4) + " e il " + formPassengers.minDateINF.value.substring(6,8)+'/'+formPassengers.minDateINF.value.substring(4,6)+'/'+formPassengers.minDateINF.value.substring(0,4));
			eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
			return false;
		}
	} else if ((passType == 'INF') || (passType == 'INS')){
		if (iBDate < formPassengers.minDateINF.value) {
			alert("Per favore controlla la data di nascita del passeggero " + id + ".\n Il bambino deve essere nato dopo il " + formPassengers.minDateINF.value.substring(6,8)+'/'+formPassengers.minDateINF.value.substring(4,6)+'/'+formPassengers.minDateINF.value.substring(0,4));
			eval("formPassengers.elements['birthDateDay" + id + "'].focus()");
			return false;
		}
	} 
	
	return true;
}

function checkPassengerAndId(formPassengers, id) {
	var name = eval("formPassengers.elements['firstName" + id + "'].value");
	var surname = eval("formPassengers.elements['surName" + id + "'].value");
	var dob = eval("formPassengers.elements['dob" + id + "'].value");
	var IDP = eval("formPassengers.elements['Id" + id + "'].value");	
	
	// check passenger data
	if (name == "") {
		changeStyle("nameFld"+id, "#ff0000", "bold");
		alert("Devi indicare il nome del passeggero " + id);
		eval("formPassengers.elements['firstName" + id + "'].focus()");
		return false;
	}
		
	if (name.search(/\d/) != -1) {
		changeStyle("nameFld"+id, "#ff0000", "bold");
		alert("Il nome del passeggero " + id + " non può contenere numeri.");
		eval("formPassengers.elements['firstName" + id + "'].focus()");
		return false;
	}		
		
	if (surname == "") {
		changeStyle("surnameFld"+id, "#ff0000", "bold");
		alert("Devi indicare il cognome del passeggero " + id);
		eval("formPassengers.elements['surName" + id + "'].focus()");
		return false;
	}
		
	if (surname.search(/\d/) != -1) {
		changeStyle("surnameFld"+id, "#ff0000", "bold");
		alert("Il cognome del passeggero " + id + " non può contenere numeri.");
		eval("formPassengers.elements['surName" + id + "'].focus()");
		return false;
	}		
		
	// Check passenger BirthDate		
	if (dob == "1") {
		if (checkPassengerBirthDate(formPassengers, id) == false) {
			return false;
		}
	}
	
	if (IDP == "1") {
		var idNumber = eval("formPassengers.elements['identificationNumber" + id + "'].value");
		var idType = eval("formPassengers.elements['identificationType" + id + "'].value");
	
		if (idNumber == "") {
			changeStyle("idFld"+id, "#ff0000", "bold");
			alert("Devi inserire il documento d'identità del passeggero " + id);
			eval("formPassengers.elements['identificationNumber" + id + "'].focus()");
			return false;
		}
		
		if (checkNIF(idNumber) == false) {
			changeStyle("idFld"+id, "#ff0000", "bold");
			alert("Il numero del documento d'identità non può contenere spazi o trattini");
			eval("formPassengers.elements['identificationNumber" + id + "'].focus()");
			return false;
	    }		
	}		
	return true;
}

function checkNIF(idnum) {			
	var nif;
	var nifLetter;
	if (idnum.indexOf('-') > -1) {
		return false;
	} 
	
	if (idnum.indexOf(' ') > -1) {
		return false;
	} 	
}

function getNIFChar(nif) {
	var resto = nif % 23;
						
	switch (resto) {
		case 0:  letra = "T"; break;
		case 1:  letra = "R"; break;
		case 2:  letra = "W"; break;
		case 3:  letra = "A"; break;
		case 4:  letra = "G"; break;
		case 5:  letra = "M"; break;
		case 6:  letra = "Y"; break;
		case 7:  letra = "F"; break;
		case 8:  letra = "P"; break;
		case 9:  letra = "D"; break;
		case 10: letra = "X"; break;
		case 11: letra = "B"; break;
		case 12: letra = "N"; break;
		case 13: letra = "J"; break;
		case 14: letra = "Z"; break;
		case 15: letra = "S"; break;
		case 16: letra = "Q"; break;
		case 17: letra = "V"; break;
		case 18: letra = "H"; break;
		case 19: letra = "L"; break;
		case 20: letra = "C"; break;
		case 21: letra = "K"; break;
		case 22: letra = "E"; break;
	}
	
	return letra;
}

function checkFormETicket2(formPayment) {
	if (sesionExpired == true) {
		alert("Sono trascorsi " + sessionTimeExpired + " minuti dall'inizio della tua richiesta di prenotazione. La sessione é scaduta. Per poter effettuare la prenotazione devi realizzare una nuova ricerca.");
		return false;
	}
	changeStyle("nameFld", "#000000", "bold");
	changeStyle("surnameFld", "#000000", "bold");
	changeStyle("streetFld", "#000000", "bold");
	changeStyle("cityFld", "#000000", "bold");
	changeStyle("stateFld", "#000000", "bold");
	changeStyle("zipFld", "#000000", "bold");
	changeStyle("phone1Fld", "#000000", "bold");
	changeStyle("emailFld", "#000000", "bold");
	changeStyle("docNumberFld", "#000000", "bold");
	changeStyle("ccTypeFld", "#000000", "bold");
	changeStyle("ccNumberFld", "#000000", "bold");
	changeStyle("ccDateFld", "#000000", "bold");
	changeStyle("ccOwnerFld", "#000000", "bold");
	changeStyle("ccsecurity", "#000000", "bold");	
	/*changeStyle("dcTypeFld", "#000000", "bold");
	changeStyle("dcNumberFld", "#000000", "bold");
	changeStyle("dcDateFld", "#000000", "bold");
	changeStyle("dcOwnerFld", "#000000", "bold");*/
	changeStyle("condFld", "#000000", "bold");
	

	if (formPayment.userRegistration.value=="true") {
		changeStyle("loginFld", "#000000", "bold");
		changeStyle("passFld", "#000000", "bold");
		changeStyle("pass2Fld", "#000000", "bold");
		changeStyle("cond2Fld", "#000000", "bold");
	}
	
	if (formPayment.billingName.value == "") {
		changeStyle("nameFld", "#ff0000", "bold");
		alert("Devi indicare il nome dell'acquirente.");
		formPayment.billingName.focus();
		return false;
	}

	if (formPayment.billingName.value.search(/\d/) != -1) {
		changeStyle("nameFld", "#ff0000", "bold");
		alert("Il nome dell'acquirente non può contenere numeri.");
		formPayment.billingName.focus();
		return false;
	}	
	
	if (formPayment.billingSurname.value == "") {
		changeStyle("surnameFld", "#ff0000", "bold");
		alert("Devi indicare il cognome dell'acquirente.");
		formPayment.billingSurname.focus();
		return false;
	}
	
	if (formPayment.billingSurname.value.search(/\d/) != -1) {
		changeStyle("surnameFld", "#ff0000", "bold");
		alert("Il cognome dell'acquirente non può contenere numeri.");
		formPayment.billingName.focus();
		return false;
	}	

	if (formPayment.billingStreet.value == "") {
		changeStyle("streetFld", "#ff0000", "bold");
		alert("Devi indicare l'indirizzo dell'acquirente.");
		formPayment.billingStreet.focus();
		return false;
	}
	
	if (formPayment.billingCity.value == "") {
		changeStyle("cityFld", "#ff0000", "bold");
		alert("Devi indicare la città dell'acquirente.");
		formPayment.billingCity.focus();
		return false;
	}
	
	if (formPayment.billingState.value == "") {
		changeStyle("stateFld", "#ff0000", "bold");
		alert("Devi indicare la provincia dell'acquirente.");
		formPayment.billingState.focus();
		return false;
	}	
	
	/*if (checkCP(formPayment.billingZip.value) == false) {
		changeStyle("zipFld", "#ff0000", "bold");
		alert("Devi indicare un codice postale corretto per l'acquirente.");
		formPayment.billingZip.focus();
		return false;
	}*/
	
	if (formPayment.billingZip.value == "") {
		changeStyle("zipFld", "#ff0000", "bold");
		alert("Devi indicare il codice postale dell'acquirente.");
		formPayment.billingZip.focus();
		return false;
	}

	if (formPayment.billingPhone1.value == "") {
		changeStyle("phone1Fld", "#ff0000", "bold");
		alert("Devi indicare il numero di telefono dell'acquirente.");
		formPayment.billingPhone1.focus();
		return false;
	}	
	
	if (formPayment.billingPhone1.value.length < 6) {
		changeStyle("phone1Fld", "#ff0000", "bold");
		alert("Il numero di telefono dell'acquirente non è corretto, deve contenere almeno 6 cifre.");
		formPayment.billingPhone1.focus();
		return false;
	}
	
	if (checkEmail(formPayment.billingEmail.value) == false) {
		changeStyle("emailFld", "#ff0000", "bold");
		alert("Devi indicare un indirizzo email corretto per l'acquirente.");
		formPayment.billingEmail.focus();
		return false;
	}

	if (formPayment.billingDocumentNumber.value == "") {
		changeStyle("docNumberFld", "#ff0000", "bold");
		alert("Devi indicare il numero di Carta d'identità o passaporto");
		formPayment.billingDocumentNumber.focus();
		return false;
	}
	
	if ((formPayment.occ.value=="true") && (formPayment.creditcard[0].checked)) {
	
		if ((formPayment.cctypefake.value == "VD") || (formPayment.cctypefake.value == "VE")){
			formPayment.cctype.value = "VI";
		} else {
			formPayment.cctype.value = formPayment.cctypefake.value;
		}
	
		if (formPayment.cctype.value == "") {
			changeStyle("ccTypeFld", "#ff0000", "bold");
			alert("Devi selezionare il tipo di carta di credito");
			return false;
		}
		
		if (formPayment.ccnumber.value == "") {
			changeStyle("ccNumberFld", "#ff0000", "bold");
			alert("Devi indicare il numero della carta di credito.");
			formPayment.ccnumber.focus();
			return false;
		}
		
		if (formPayment.ccowner.value == "") {
			changeStyle("ccOwnerFld", "#ff0000", "bold");
			alert("Devi indicare il nome del titolare della carta di credito.");
			formPayment.ccowner.focus();
			return false;
		}
		
		if (formPayment.ccowner.value.search(/\d/) != -1) {
			changeStyle("ccOwnerFld", "#ff0000", "bold");
			alert("Il nome del titolare della carta di credito non può contenere numeri.");
			formPayment.ccowner.focus();
			return false;
		}			
		
		if 	(checkExpirationDate(formPayment, "ccDateFld") == false) {
			return false;
		}
		
		if 	(checkCardNumberM(formPayment.ccnumber.value, formPayment.cctype.value, formPayment.ccj.value) == false) {
			changeStyle("ccNumberFld", "#ff0000", "bold");
			changeStyle("ccDateFld", "#ff0000", "bold");
			return false;
		}
		
		if (formPayment.cctype.value == "AX") {
			formPayment.shippingandhandling.value = (((parseInt(formPayment.shippingandhandlingtmp.value,"10") + parseInt(formPayment.totalamount.value,"10")) * 0.015) + parseInt(formPayment.shippingandhandlingtmp.value,"10")).toFixed(2);
		}
		else if (formPayment.cctype.value == "DC"){
			formPayment.shippingandhandling.value = (((parseInt(formPayment.shippingandhandlingtmp.value,"10") + parseInt(formPayment.totalamount.value,"10")) * 0.025) + parseInt(formPayment.shippingandhandlingtmp.value,"10")).toFixed(2);
			} else {
			formPayment.shippingandhandling.value =  formPayment.shippingandhandlingtmp.value;
		}
		
	/***************** controllo codice di sicurezza (eticket)*/
	
	if (formPayment.ccsecurity.value != "") {
		if (formPayment.ccsecurity.value.search(/\D/) != -1) {
			changeStyle("ccSecurityFld", "#ff0000", "bold");
			alert("Il codice di sicurezza della carta di credito non può contenere caratteri non numerici.");
			formPayment.ccsecurity.focus();
			return false;		
		}
	
		if (formPayment.cctype.value == 'AX') {
			if (formPayment.ccsecurity.value.length != 4) {
				changeStyle("ccSecurityFld", "#ff0000", "bold");
				alert("Il codice di sicurezza per le carte American Express deve essere di 4 cifre.");
				formPayment.ccsecurity.focus();
				return false;
			}
		} else if (formPayment.ccsecurity.value.length != 3) {
			changeStyle("ccSecurityFld", "#ff0000", "bold");
			alert("Il codice di sicurezza per le carte Visa, Mastercard e JCB deve essere di 3 cifre");
			formPayment.ccsecurity.focus();
			return false;
		}
	} else {
		changeStyle("ccSecurityFld", "#ff0000", "bold");
		alert("Devi scrivere il codice di sicurezza della Carta di credito/debito.");
		formPayment.ccsecurity.focus();
		return false;
	}
	/***************** fine controllo codice di sicurezza*/

	}

	/* if ((formPayment.occ.value=="true") && (formPayment.creditcard[1].checked)) {
		if (formPayment.dctype.value == "") {
			changeStyle("dcTypeFld", "#ff0000", "bold");
			alert("Devi selezionare la data di scadenza della carta di  debito.");
			return false;
		}

		if (formPayment.dcnumber.value == "") {
			changeStyle("dcNumberFld", "#ff0000", "bold");
			alert("Devi indicare il numero della carta di debito.");
			return false;
		}

		if (formPayment.dcowner.value == "") {
			changeStyle("dcOwnerFld", "#ff0000", "bold");
			alert("Devi indicare il nome del titolare della carta di debito.");
			return false;
		}

		if (formPayment.dcowner.value.search(/\d/) != -1) {
			changeStyle("dcOwnerFld", "#ff0000", "bold");
			alert("Il nome del titolare della carta di debito non può contenere numeri.");
			return false;
		}

		if (formPayment.dcmonth.value == "") {
			changeStyle("dcDateFld", "#ff0000", "bold");
			alert("Devi selezionare la data di scadenza della carta di debito.");
			return false;
		}

		if (formPayment.dcyear.value == "") {
			changeStyle("dcDateFld", "#ff0000", "bold");
			alert("Devi selezionare la data di scadenza della carta di debito.");
			return false;
		}

		if 	(checkCardNumber(formPayment.dcyear.value, formPayment.dcmonth.value, formPayment.dcnumber.value, formPayment.dctype.value) == false) {
			changeStyle("dcNumberFld", "#ff0000", "bold");
			changeStyle("dcDateFld", "#ff0000", "bold");
			return false;
		}
	} */


	if (formPayment.acceptedconditions.checked == "") {
		changeStyle("condFld", "#ff0000", "bold");
		alert("Devi leggere e accettare le condizioni relative all'emissione dei biglietti.");
		return false;
	}

	if (formPayment.userRegistration.value=="true") {
		if (checkNewUser(formPayment) == false) {
			return false;
		}
	}
    if ((formPayment.ccj.value == formPayment.ccnumber.value) && (formPayment.ccj.value.indexOf("xxxxxxxx") != -1)) {
		formPayment.ccnumber.value = "";
	}

    if(formPayment.multiIATA == 1){
        if (checkTPE(formPayment) == false) {
		    return false;
    	}
    }

	return true;
}

function checkCP(cp) {
	var recp = new RegExp("[0-9]{5}");

	if (recp.test(cp) == false) {
		return false;
	}

	if (cp.length != 5) {
		return false;
	}
}

function checkEmail(emc2){
    var rexemail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

	if (rexemail.test(emc2) == false) {
		return false;
	}
}

function checkCardNumber(ccyear, ccmonth, ccnumber, cctype, ccj) {
	if (!isExpiryDate(ccyear, ccmonth)) {
		alert("Devi indicare una data di scadenza corretta.");
		return false;
	} else if (!isCardNumber(ccnumber, cctype)) {
		alert("Il numero della carta di credito non è corretto.");
		return false;
	} else {
		return true;
	}
}

function isExpiryDate(year, month) {
	if (!isNum(year+"")) {
		return false;
	}
	if (!isNum(month+"")) {
		return false;
	}
	today = new Date();
	expiry = new Date("20"+year, month);
	if (today.getTime() > expiry.getTime()) {
		return false;
	} else {
		return true;
	}
}

function isNum(argvalue) {
	argvalue = argvalue.toString();
	if (argvalue.length == 0)
	return false;
	for (var n = 0; n < argvalue.length; n++)
	if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
	return false;
	return true;
}

function isCardNumber(cardnumber, type) {
	if (type == "4B") {
		return true;
	}

	if (!luhnCheck(cardnumber))
		return false;

	if (type == "CA") {
		len = new Array('16');
		rules = new Array('51','52','53','54','55');
	}
	if (type == "VI") {
		len = new Array('13','16');
		rules = new Array('4');
	}
	if (type == "VD") {
		len = new Array('13','16');
		rules = new Array('4');
	}
	if (type == "VE") {
		len = new Array('13','16');
		rules = new Array('4');
	}
	if (type == "AX") {
		len = new Array('15');
		rules = new Array('34','37');
	}
	if (type == "DC") {
		len = new Array('14');
		rules = new Array('30','36','38');
	}
	if (type == "JC") {
        len = new Array('16');
        rules = new Array('35');
    }
    if (type == "MA") {
		len = new Array('16');
		rules = new Array('50','51','52','53','54','55');
	}
    for (var n = 0; n < len.length; n++)
		if (cardnumber.toString().length == len[n]) {
			for (var m = 0; m < rules.length; m++) {
				var headdigit = cardnumber.substring(0, rules[m].toString().length);
				if (headdigit == this.rules[m])
					return true;
			}
			return false;
		}
	return false;
}

function luhnCheck(CardNumber) {
	if (! isNum(CardNumber)) {
		return false;
	}

	var no_digit = CardNumber.length;
	var oddoeven = no_digit & 1;
	var sum = 0;
	for (var count = 0; count < no_digit; count++) {
		var digit = parseInt(CardNumber.charAt(count));
		if (!((count & 1) ^ oddoeven)) {
			digit *= 2;
			if (digit > 9)
				digit -= 9;
		}
		sum += digit;
	}
	if (sum % 10 == 0)
		return true;
	else
		return false;
}

function checkNewUser(fp) {
	if (checkEmail(fp.login.value) == false) {
		changeStyle("loginFld", "#ff0000", "bold");
		alert("Devi indicare un indirizzo email corretto come login.");
		return false;
	}

	if (fp.password.value == "") {
		changeStyle("passFld", "#ff0000", "bold");
		alert("Devi indicare la password.");
		return false;
	}

	if (fp.password2.value == "") {
		changeStyle("pass2Fld", "#ff0000", "bold");
		alert("Devi indicare la password 2");
		return false;
	}

	if (fp.password2.value != fp.password.value) {
		changeStyle("passFld", "#ff0000", "bold");
		changeStyle("pass2Fld", "#ff0000", "bold");
		alert("Le due password non sono uguali.");
		return false;
	}

	if (fp.acceptedConditions2.checked == "") {
		changeStyle("cond2Fld", "#ff0000", "bold");
		alert("Devi accettare le condizioni per accedere ai servizi di eDreams.");
		return false;
	}

	return true;
}

function checkTPE(formP) {
	if (formP.insuranceId[0] != undefined) {
		if ((formP.insuranceId[0].checked) || (formP.insuranceId[1].checked)) {
			if (!(formP.creditcard[0].checked)) {
					alert("Attenzione: puoi stipulare un'assicurazione solo se hai selezionato il pagamento con carta di credito, debito o prepagata.");
					return false;
			}
		}
	} else {
		if (formP.insuranceId.checked) {
			if (!(formP.creditcard[0].checked)) {
					alert("Attenzione: puoi stipulare un'assicurazione solo se hai selezionato il pagamento con carta di credito, debito o prepagata.");
					return false;
			}
		}
	}
	return true;
}

function checkFormPayment1(formPassengers) {
		if (sesionExpired == true) {
			alert("Sono trascorsi " + sessionTimeExpired + " minuti dall'inizio della tua richiesta di prenotazione. La sessione é scaduta. Per poter effettuare la prenotazione devi realizzare una nuova ricerca.");
			return false;
		}
	// perform data checks for every pasenger
	for (var i=1; i <= parseInt(formPassengers.nPassengers.value); i++) {
		changeStyle("nameFld"+i, "#000000", "bold");
		changeStyle("surnameFld"+i, "#000000", "bold");
		dob = eval("formPassengers.elements['dob" + i + "'].value");
		if (dob == "1") {
			changeStyle("dobFld"+i, "#000000", "normal");
		}

		changeStyle("nameFld"+i, "#000000", "bold");
		changeStyle("surnameFld"+i, "#000000", "bold");
		dob = eval("formPassengers.elements['dob" + i + "'].value");
		if (dob == "1") {
			changeStyle("dobFld"+i, "#000000", "normal");
		}

		IDP = eval("formPassengers.elements['Id" + i + "'].value");
		if (IDP == "1") {
			changeStyle("idFld"+i, "#000000", "normal");
		}

		fqtv1 = eval("formPassengers.elements['fqtv1" + i + "'].value");
		if (fqtv1 == "1") {
			changeStyle("fqtv1" + i + "fld", "#000000", "normal");
		}

		fqtv2 = eval("formPassengers.elements['fqtv2" + i + "'].value");
		if (fqtv2 == "1") {
			changeStyle("fqtv2" + i + "fld", "#000000", "normal");
		}
	}

	for (var i=1; i <= parseInt(formPassengers.nPassengers.value); i++) {
		if (!checkPassengerAndId(formPassengers, i)) return false; // passenger had errors
	}

	for (var i=1; i <= parseInt(formPassengers.nPassengers.value); i++) {
		if (!checkPassengerFrequent(formPassengers, i, 1)) return false; // passenger had errors
	}

	for (var i=1; i <= parseInt(formPassengers.nPassengers.value); i++) {
		if (!checkPassengerFrequent(formPassengers, i, 2)) return false; // passenger had errors
	}

	return true;
}

function checkPassenger(formPassengers, id) {
	var name = eval("formPassengers.elements['firstName" + id + "'].value");
	var surname = eval("formPassengers.elements['surName" + id + "'].value");
	var dob = eval("formPassengers.elements['dob" + id + "'].value");

	// check passenger  data
	if (name == "") {
		changeStyle("nameFld"+id, "#ff0000", "bold");
		alert("Devi indicare un nome per il passeggero " + id);
		eval("formPassengers.elements['firstName" + id + "'].focus()");
		return false;
	}

	if (name.search(/\d/) != -1) {
		changeStyle("nameFld"+id, "#ff0000", "bold");
		alert("Il nome del passeggero " + id + " non può contenere numeri.");
		eval("formPassengers.elements['firstName" + id + "'].focus()");
		return false;
	}

	if (surname == "") {
		changeStyle("surnameFld"+id, "#ff0000", "bold");
		alert("Devi indicare un cognome per il passeggero " + id);
		eval("formPassengers.elements['surName" + id + "'].focus()");
		return false;
	}

	if (surname.search(/\d/) != -1) {
		changeStyle("surnameFld"+id, "#ff0000", "bold");
		alert("Il cognome del passeggero " + id + " non può contenere numeri.");
		eval("formPassengers.elements['surName" + id + "'].focus()");
		return false;
	}

	if (dob == "1") {
		var bdate = eval("formPassengers.elements['birthDate" + id + "'].value");
		var regxDate = new RegExp("[0-3][0-9]\/[0-2][0-9]\/[1-2][0-9]{3,3}");
		if (regxDate.test(bdate) == false) {
			changeStyle("dobFld"+id, "#ff0000", "bold");
			alert("Devi indicare la data di nascita del passeggero " + id);
			eval("formPassengers.elements['birthDate" + id + "'].focus()");
			return false;
		}

		if (bdate == "") {
			changeStyle("dobFld"+id, "#ff0000", "bold");
			alert("Devi indicare la data di nascita del passeggero " + id);
			eval("formPassengers.elements['birthDate" + id + "'].focus()");
			return false;
		}
	}

	return true;
}

function checkFormPayment2(formPayment, paper) {
	if (sesionExpired == true) {
		alert("Sono trascorsi " + sessionTimeExpired + " minuti dall'inizio della tua richiesta di prenotazione. La sessione é scaduta. Per poter effettuare la prenotazione devi realizzare una nuova ricerca.");
		return false;
	}

	changeStyle("nameFld", "#000000", "bold");
	changeStyle("surnameFld", "#000000", "bold");
	changeStyle("streetFld", "#000000", "bold");
	changeStyle("cityFld", "#000000", "bold");
	changeStyle("stateFld", "#000000", "bold");
	changeStyle("zipFld", "#000000", "bold");
	changeStyle("phone1Fld", "#000000", "bold");
	changeStyle("emailFld", "#000000", "bold");
	changeStyle("docNumberFld", "#000000", "bold");
	changeStyle("ccTypeFld", "#000000", "bold");
	changeStyle("ccNumberFld", "#000000", "bold");
	changeStyle("ccDateFld", "#000000", "bold");
	changeStyle("ccOwnerFld", "#000000", "bold");
	changeStyle("ccsecurity", "#000000", "bold");
	changeStyle("condFld", "#000000", "normal");

	if (formPayment.userRegistration.value=="true") {
		changeStyle("loginFld", "#000000", "bold");
		changeStyle("passFld", "#000000", "bold");
		changeStyle("pass2Fld", "#000000", "bold");
		changeStyle("cond2Fld", "#000000", "bold");
	}

	if (formPayment.billingName.value == "") {
		changeStyle("nameFld", "#ff0000", "bold");
		alert("Devi indicare il nome dell'acquirente.");
		formPayment.billingName.focus();
		return false;
	}

	if (formPayment.billingName.value.search(/\d/) != -1) {
		changeStyle("nameFld", "#ff0000", "bold");
		alert("Il nome dell'acquirente non può contenere numeri.");
		formPayment.billingName.focus();
		return false;
	}

	if (formPayment.billingSurname.value == "") {
		changeStyle("surnameFld", "#ff0000", "bold");
		alert("Devi indicare il cognome dell'acquirente.");
		formPayment.billingSurname.focus();
		return false;
	}

	if (formPayment.billingSurname.value.search(/\d/) != -1) {
		changeStyle("surnameFld", "#ff0000", "bold");
		alert("Il cognome dell'acquirente non può contenere numeri.");
		formPayment.billingName.focus();
		return false;
	}

	if (formPayment.billingStreet.value == "") {
		changeStyle("streetFld", "#ff0000", "bold");
		alert("Devi indicare l'indirizzo dell'acquirente.");
		formPayment.billingStreet.focus();
		return false;
	}

	if (formPayment.billingStreet.value.search(/\d/) == -1) {
		billingStreetNumber = confirm("Devi inserire il numero civico dell'indirizzo.\n\nClicca OK per inserirlo.\nSe invece l'indirizzo non ha un numero civico clicca su Annulla");
		if (billingStreetNumber){
			changeStyle("streetFld", "#ff0000", "bold");
			formPayment.billingStreet.focus();
			return false;
		}
	}


	if (formPayment.billingCity.value == "") {
		changeStyle("cityFld", "#ff0000", "bold");
		alert("Devi indicare la città dell'acquirente.");
		formPayment.billingCity.focus();
		return false;
	}

	if (formPayment.billingState.value == "") {
		changeStyle("stateFld", "#ff0000", "bold");
		alert("Devi indicare la provincia dell'acquirente.");
		formPayment.billingState.focus();
		return false;
	}

	/*if (checkCP(formPayment.billingZip.value) == false) {
		changeStyle("zipFld", "#ff0000", "bold");
		alert("Il codice postale dell'acquirente non è corretto");
		formPayment.billingZip.focus();
		return false;
	}*/

	if (formPayment.billingZip.value == "") {
		changeStyle("zipFld", "#ff0000", "bold");
		alert("Devi indicare il codice postale dell'acquirente");
		formPayment.billingZip.focus();
		return false;
	}

	if (formPayment.billingPhone1.value == "") {
		changeStyle("phone1Fld", "#ff0000", "bold");
		alert("Devi indicare il numero di telefono dell'acquirente.");
		formPayment.billingPhone1.focus();
		return false;
	}

	if (formPayment.billingPhone1.value.length < 6) {
		changeStyle("phone1Fld", "#ff0000", "bold");
		alert("Il numero di telefono dell'acquirente non è corretto, deve contenere almeno 6 cifre.");
		formPayment.billingPhone1.focus();
		return false;
	}

	if (checkEmail(formPayment.billingEmail.value) == false) {
		changeStyle("emailFld", "#ff0000", "bold");
		alert("Devi indicare l'indirizzo email dell'acquirente.");
		formPayment.billingEmail.focus();
		return false;
	}

	if (formPayment.billingDocumentNumber.value == "") {
		changeStyle("docNumberFld", "#ff0000", "bold");
		alert("Devi scrivere il numero del tuo passaporto o della carta d'identità");
		formPayment.billingDocumentNumber.focus();
		return false;
	}

	if ((formPayment.occ.value=="true") && (formPayment.creditcard[0].checked)) {

		if ((formPayment.cctypefake.value == "VD") || (formPayment.cctypefake.value == "VE")){
			formPayment.cctype.value = "VI";
		} else {
			formPayment.cctype.value = formPayment.cctypefake.value;
		}


		if (formPayment.cctype.value == "") {
			changeStyle("ccTypeFld", "#ff0000", "bold");
			alert("Devi selezionare il tipo di carta di credito/debito.");
			return false;
		}

		if (formPayment.ccnumber.value == "") {
			changeStyle("ccNumberFld", "#ff0000", "bold");
			alert("Devi scrivere il numero della carta di credito/debito.");
			formPayment.ccnumber.focus();
			return false;
		}

		if (formPayment.ccowner.value == "") {
			changeStyle("ccOwnerFld", "#ff0000", "bold");
			alert("Devi scrivere il nome del titolare della carta di credito/debito.");
			formPayment.ccowner.focus();
			return false;
		}

		if (formPayment.ccowner.value.search(/\d/) != -1) {
			changeStyle("ccOwnerFld", "#ff0000", "bold");
			alert("Il nome del titolare della carta di credito/debito non può contenere numero.");
			formPayment.ccowner.focus();
			return false;
		}

		if 	(checkExpirationDate(formPayment, "ccDateFld") == false) {
			return false;
		}

		if 	(checkCardNumberM(formPayment.ccnumber.value, formPayment.cctype.value, formPayment.ccj.value) == false) {
			changeStyle("ccNumberFld", "#ff0000", "bold");
			changeStyle("ccDateFld", "#ff0000", "bold");
			return false;
		}

		if (formPayment.cctype.value == "AX") {
			formPayment.shippingandhandling.value = (((parseInt(formPayment.shippingandhandlingtmp.value,"10") + parseInt(formPayment.totalamount.value,"10")) * 0.015) + parseInt(formPayment.shippingandhandlingtmp.value,"10")).toFixed(2);
		}
		else if (formPayment.cctype.value == "DC"){
			formPayment.shippingandhandling.value = (((parseInt(formPayment.shippingandhandlingtmp.value,"10") + parseInt(formPayment.totalamount.value,"10")) * 0.025) + parseInt(formPayment.shippingandhandlingtmp.value,"10")).toFixed(2);
			} else {
			formPayment.shippingandhandling.value =  formPayment.shippingandhandlingtmp.value;
		}

		/***************** controllo codice di sicurezza (paper)*/

		if (formPayment.ccsecurity.value != "") {
			if (formPayment.ccsecurity.value.search(/\D/) != -1) {
				changeStyle("ccSecurityFld", "#ff0000", "bold");
				alert("Il codice di sicurezza della carta di credito non può contenere caratteri non numerici.");
				formPayment.ccsecurity.focus();
				return false;
			}

			if (formPayment.cctype.value == 'AX') {
				if (formPayment.ccsecurity.value.length != 4) {
					changeStyle("ccSecurityFld", "#ff0000", "bold");
					alert("Il codice di sicurezza per le carte American Express deve essere di 4 cifre.");
					formPayment.ccsecurity.focus();
					return false;
				}
			} else if (formPayment.ccsecurity.value.length != 3) {
				changeStyle("ccSecurityFld", "#ff0000", "bold");
				alert("Il codice di sicurezza per le carte Visa, Mastercard e JCB deve essere di 3 cifre");
				formPayment.ccsecurity.focus();
				return false;
			}
		} else {
			changeStyle("ccSecurityFld", "#ff0000", "bold");
			alert("Devi scrivere il codice di sicurezza della Carta di credito/debito.");
			formPayment.ccsecurity.focus();
			return false;
		}
		/***************** fine controllo codice di sicurezza*/

	}



	if (formPayment.acceptedconditions.checked == "") {
		changeStyle("condFld", "#ff0000", "bold");
		alert("Devi leggere e accettare le condizioni relative all'emissione dei biglietti.");
		return false;
	}

	if (formPayment.userRegistration.value=="true") {
		if (checkNewUser(formPayment) == false) {
			return false;
		}
	}

    if ((formPayment.ccj.value == formPayment.ccnumber.value) && (formPayment.ccj.value.indexOf("xxxxxxxx") != -1)) {
		formPayment.ccnumber.value = "";
	}

    if(formPayment.multiIATA == 1){
        if (checkTP1(formPayment) == false) {
    		return false;
    	}
    }
	if(paper==true){
		formPayment.deliveryStreet.value = formPayment.billingStreet.value;
		formPayment.deliveryCity.value = formPayment.billingCity.value;
		formPayment.deliveryState.value = formPayment.billingState.value;
		formPayment.deliveryZip.value = formPayment.billingZip.value;
		formPayment.deliveryZip2.value = formPayment.billingZip.value;
		formPayment.deliveryName.value = formPayment.billingName.value;
		formPayment.deliverySurname.value = formPayment.billingSurname.value;
	}

	return true;
}

 function filterNum(str) {
         re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
          // remove special characters like "$" and "," etc...
          return str.replace(re, "");
     }

function checkTP1(formP) {
	if (formP.insuranceId[0] != undefined) {
		if ((formP.insuranceId[0].checked) || (formP.insuranceId[1].checked)) {
			if (!(formP.creditcard[0].checked)) {
					alert("Attenzione: puoi stipulare un'assicurazione solo se hai selezionato il pagamento con carta di credito, debito o prepagata.");
					return false;
			}
		}
	} else {
		if (formP.insuranceId.checked) {
			if (!(formP.creditcard[0].checked)) {
					alert("Attenzione: puoi stipulare un'assicurazione solo se hai selezionato il pagamento con carta di credito, debito o prepagata.");
					return false;
			}
		}
	}
	return true;
}

function chooseOnlyOne(obj) {
	a = document.getElementsByName(obj.name);
	for (i = 0; i < a.length; i++) {
		a[i].name;
		a[i].checked =  false;
	}
	obj.checked = true;
}

function copyFld(fldsrc, flddst, fldlock) {
	if ((fldsrc != null) && (flddst != null) && (fldlock != null)) {
		if (fldlock[0].checked == true) {
			flddst.value = fldsrc.value;
		}
	}
}

function copyEmail(fldlock, fldsrc, flddst) {
	if (fldlock.value == "true") {
		flddst.value = fldsrc.value;
	}
}

function copyform(fp) {
	fp.deliveryName.value=fp.billingName.value;
	fp.deliverySurname.value=fp.billingSurname.value;
	fp.deliveryStreet.value=fp.billingStreet.value;
	fp.deliveryCity.value=fp.billingCity.value;
	fp.deliveryState.value=fp.billingState.value;
	fp.deliveryZip.value=fp.billingZip.value;
	fp.deliverybillingcompany.value=fp.billingcompany.value;
}

function cleanform(fp) {
	fp.deliveryName.value="";
	fp.deliverySurname.value="";
	fp.deliveryStreet.value="";
	fp.deliveryCity.value="";
	fp.deliveryState.value="";
	fp.deliveryZip.value="";
	fp.deliverybillingcompany.value="";
}

function checkDNI(idnum) {
	var re2 = new RegExp("[0-9]{1,8}");
	var re3 = new RegExp("[A-Za-z]");

	if (re2.test(idnum) == false) {
		return false;
	}
	if (re3.test(idnum) == true) {
		return false;
	}
}

function alert5min() {
	alert("Attenzione, ti informiamo che sono trascorsi 5 minuti dall'inizio del tuo processo di prenotazione. Ti ricordiamo che potremo garantirti la tariffa scelta per ulteriori 5 minuti, al termine dei quali la sessione scadrà. Scaduta la sessione, non ti garantiamo che a seguito di una nuova ricerca di un volo per la medesima destinazione e con la medesima compagnia aerea tu possa trovare nuovamente la tariffa che ti è stata presentata precedentemente. Prenota subito per assicurarti questa tariffa!");
}

function sesion10Ex() {
	sesionExpired = true;
	sessionTimeExpired = "10";
	alert("Sono trascorsi 10 minuti dall'inizio della tua richiesta di prenotazione. La sessione é scaduta. Per poter effettuare la prenotazione devi realizzare una nuova ricerca.");
}

function alert10min() {
	alert("Attenzione, ti informiamo che sono trascorsi 10 minuti dall'inizio del tuo processo di prenotazione. Ti ricordiamo che potremo garantirti la tariffa scelta per ulteriori 10 minuti, al termine dei quali la sessione scadrà. Scaduta la sessione, non ti garantiamo che a seguito di una nuova ricerca di un volo per la medesima destinazione e con la medesima compagnia aerea tu possa trovare nuovamente la tariffa che ti è stata presentata precedentemente. Prenota subito per assicurarti questa tariffa!");
}

function alert15min() {
	alert("Attenzione, ti informiamo che sono trascorsi 15 minuti dall'inizio del tuo processo di prenotazione. Ti ricordiamo che potremo garantirti la tariffa scelta per ulteriori 5 minuti, al termine dei quali la sessione scadrà. Scaduta la sessione, non ti garantiamo che a seguito di una nuova ricerca di un volo per la medesima destinazione e con la medesima compagnia aerea tu possa trovare nuovamente la tariffa che ti è stata presentata precedentemente. Prenota subito per assicurarti questa tariffa!");
}

function sesionEx() {
	sesionExpired = true;
	sessionTimeExpired = "20";
	alert("Sono trascorsi 20 minuti dall'inizio della tua richiesta di prenotazione. La sessione é scaduta. Per poter effettuare la prenotazione devi realizzare una nuova ricerca.");
}

function sesion15Ex() {
	sesionExpired = true;
	sessionTimeExpired = "15";
	alert("Sono trascorsi 15 minuti dall'inizio della tua richiesta di prenotazione. La sessione é scaduta. Per poter effettuare la prenotazione devi realizzare una nuova ricerca.");
}

function checkFormMulti2(formPayment) {
	if (sesionExpired == true) {
		alert("Sono trascorsi " + sessionTimeExpired + " minuti dall'inizio della tua richiesta di prenotazione. La sessione é scaduta. Per poter effettuare la prenotazione devi realizzare una nuova ricerca.");
		return false;
	}

	changeStyle("nameFld", "#000000", "bold");
	changeStyle("surnameFld", "#000000", "bold");
	changeStyle("streetFld", "#000000", "bold");
	changeStyle("cityFld", "#000000", "bold");
	changeStyle("stateFld", "#000000", "bold");
	changeStyle("zipFld", "#000000", "bold");
	changeStyle("phone1Fld", "#000000", "bold");
	changeStyle("emailFld", "#000000", "bold");
	changeStyle("docNumberFld", "#000000", "bold");
	changeStyle("ccTypeFld", "#000000", "bold");
	changeStyle("ccNumberFld", "#000000", "bold");
	changeStyle("ccDateFld", "#000000", "bold");
	changeStyle("ccOwnerFld", "#000000", "bold");
	changeStyle("ccSecurityFld", "#000000", "normal");
	changeStyle("condFld", "#000000", "normal");

	if (formPayment.billingName.value == "") {
		changeStyle("nameFld", "#ff0000", "bold");
		alert("Devi indicare il nome dell'acquirente.");
		formPayment.billingName.focus();
		return false;
	}

	if (formPayment.billingName.value.search(/\d/) != -1) {
		changeStyle("nameFld", "#ff0000", "bold");
		alert("Il nome dell'acquirente non può contenere numeri.");
		formPayment.billingName.focus();
		return false;
	}

	if (formPayment.billingSurname.value == "") {
		changeStyle("surnameFld", "#ff0000", "bold");
		alert("Devi indicare il cognome dell'acquirente.");
		formPayment.billingSurname.focus();
		return false;
	}

	if (formPayment.billingSurname.value.search(/\d/) != -1) {
		changeStyle("surnameFld", "#ff0000", "bold");
		alert("Il cognome dell'acquirente non può contenere numeri.");
		formPayment.billingName.focus();
		return false;
	}

	if (formPayment.billingStreet.value == "") {
		changeStyle("streetFld", "#ff0000", "bold");
		alert("Devi indicare l'indirizzo dell'acquirente.");
		formPayment.billingStreet.focus();
		return false;
	}

	if (formPayment.billingCity.value == "") {
		changeStyle("cityFld", "#ff0000", "bold");
		alert("Devi indicare la città dell'acquirente.");
		formPayment.billingCity.focus();
		return false;
	}

	if (formPayment.billingState.value == "") {
		changeStyle("stateFld", "#ff0000", "bold");
		alert("Devi indicare la provincia dell'acquirente.");
		formPayment.billingState.focus();
		return false;
	}

	if (formPayment.billingZip.value == "") {
		changeStyle("zipFld", "#ff0000", "bold");
		alert("Devi indicare il codice postale dell'acquirente.");
		formPayment.billingZip.focus();
		return false;
	}

	if (formPayment.billingPhone1.value == "") {
		changeStyle("phone1Fld", "#ff0000", "bold");
		alert("Devi indicare il numero di telefono dell'acquirente.");
		formPayment.billingPhone1.focus();
		return false;
	}

	if (formPayment.billingPhone1.value.length < 6) {
		changeStyle("phone1Fld", "#ff0000", "bold");
		alert("Il numero di telefono dell'acquirente non è corretto, deve contenere almeno 6 cifre.");
		formPayment.billingPhone1.focus();
		return false;
	}

	if (checkEmail(formPayment.billingEmail.value) == false) {
		changeStyle("emailFld", "#ff0000", "bold");
		alert("Devi indicare un indirizzo email corretto per l'acquirente.");
		formPayment.billingEmail.focus();
		return false;
	}

	if (formPayment.billingDocumentNumber.value == "") {
		changeStyle("docNumberFld", "#ff0000", "bold");
		alert("Devi indicare il numero di Carta d'identità o passaporto");
		formPayment.billingDocumentNumber.focus();
		return false;
	}

	if ((formPayment.occ.value=="true") && (formPayment.creditcard.value="1")) {
		if (formPayment.cctype.value == "") {
			changeStyle("ccTypeFld", "#ff0000", "bold");
			alert("Devi selezionare il tipo di carta di credito");
			return false;
		}

		if (formPayment.ccnumber.value == "") {
			changeStyle("ccNumberFld", "#ff0000", "bold");
			alert("Devi indicare il numero della carta di credito.");
			formPayment.ccnumber.focus();
			return false;
		}

		if (formPayment.ccowner.value == "") {
			changeStyle("ccOwnerFld", "#ff0000", "bold");
			alert("Devi indicare il nome del titolare della carta di credito.");
			formPayment.ccowner.focus();
			return false;
		}

		if (formPayment.ccowner.value.search(/\d/) != -1) {
			changeStyle("ccOwnerFld", "#ff0000", "bold");
			alert("Il nome del titolare della carta di credito non può contenere numeri.");
			formPayment.ccowner.focus();
			return false;
		}

		if 	(checkExpirationDate(formPayment, "ccDateFld") == false) {
			return false;
		}

		if 	(checkCardNumberM(formPayment.ccnumber.value, formPayment.cctype.value, formPayment.ccj.value) == false) {
			changeStyle("ccNumberFld", "#ff0000", "bold");
			changeStyle("ccDateFld", "#ff0000", "bold");
			return false;
		}

		if (formPayment.ccsecurity.value != "") {
			if (formPayment.ccsecurity.value.search(/\D/) != -1) {
				changeStyle("ccSecurityFld", "#ff0000", "bold");
				alert("Il codice di sicurezza della carta di credito non può contenere caratteri non numerici.");
				formPayment.ccsecurity.focus();
				return false;
			}

			if (formPayment.cctype.value == 'AX') {
				if (formPayment.ccsecurity.value.length != 4) {
					changeStyle("ccSecurityFld", "#ff0000", "bold");
					alert("Il codice di sicurezza per American Express deve essere di 4 cifre. Per favore reintroduci il codice di sicurezza.");
					formPayment.ccsecurity.focus();
					return false;
				}
			} else if (formPayment.ccsecurity.value.length != 3) {
				changeStyle("ccSecurityFld", "#ff0000", "bold");
				alert("Il codice di sicurezza per Visa e Mastercard deve essere di 3 cifre. Per favore reitroduci il codice di sicurezza.");
				formPayment.ccsecurity.focus();
				return false;		
			}
		} else {
			changeStyle("ccSecurityFld", "#ff0000", "bold");
			alert("Devi scrivere il codice di sicurezza della Carta di credito/debito.");
			formPayment.ccsecurity.focus();
			return false;
		}
	}
	
	if (formPayment.acceptedconditions.checked == "") {
		changeStyle("condFld", "#ff0000", "bold");
		alert("Devi leggere e accettare le condizioni relative alla tariffa del volo regolare e alla tariffa del volo low cost.");
		return false;
	}
	
	if ((formPayment.occ.value=="true") && (formPayment.creditcard.value="1")) {
		if ((formPayment.cctype.value == "CM") || (formPayment.cctype.value == "VD")) {
			formPayment.procedureName0.value = "DEBITO";
			formPayment.procedureValue0.value = formPayment.cctype.value;
		}
	}
	
	hideVisibilityInvoice('invoiceData');
	
	return true;
}

function checkCardNumberM(ccnumber, cctype, ccj) {
	if (ccnumber == ccj) {
		return true;
	} else if (!isCardNumber(ccnumber, cctype)) {
		alert("Il numero della carta di credito non è corretto.");
		return false;
	} else {
		return true;
	}
}

// new function for credit card date expiration date ****************** 
function checkExpirationDate(fp, ccDateFld) {
var intMonth;
var intYear;
var intMinYear;
var intMaxYear;

if (fp.ccmonth.value.length == 0) {
	changeStyle(ccDateFld, "#ff0000", "bold");
	alert("Per favore, indica il mese di scadenza della carta di credito così come appare sulla carta. Per esempio: 01.");
	fp.ccmonth.focus();
	return false;
}

if ((fp.ccmonth.value.length != 2) || (isNaN(parseInt(fp.ccmonth.value, 10)))) {
	changeStyle(ccDateFld, "#ff0000", "bold");
	alert("Per favore, indica il mese di scadenza della carta di credito così come appare sulla carta. Per esempio: 01.");
	fp.ccmonth.focus();
	return false;
}

intMonth = parseInt(fp.ccmonth.value, 10);

if (intMonth < 1) {
	changeStyle(ccDateFld, "#ff0000", "bold");
	alert("Per favore, indica il mese di scadenza della carta di credito così come appare sulla carta. Per esempio: 01.");
	fp.ccmonth.focus();
	return false;
}

if (intMonth >12) {
	changeStyle(ccDateFld, "#ff0000", "bold");
	alert("Per favore, indica il mese di scadenza della carta di credito così come appare sulla carta. Per esempio: 01.");
	fp.ccmonth.focus();
	return false;
}

if (fp.ccyear.value.length == 0) {
	changeStyle(ccDateFld, "#ff0000", "bold");
	alert("Per favore, indica l'anno di scadenza della carta di credito così come appare sulla carta. Per esempio: 08.");
	fp.ccyear.focus();
	return false;
}

if ((fp.ccyear.value.length != 2) || (isNaN(parseInt(fp.ccyear.value, 10)))) {
	changeStyle(ccDateFld, "#ff0000", "bold");
	alert("Per favore, indica l'anno di scadenza della carta di credito così come appare sulla carta. Per esempio: 08.");
	fp.ccyear.focus();
	return false;
}

intYear = parseInt(fp.ccyear.value, 10);
intMinYear = parseInt(fp.minYear.value, 10);
intMaxYear = parseInt(fp.maxYear.value, 10);

if (intYear < intMinYear) {
	changeStyle(ccDateFld, "#ff0000", "bold");
	alert("Per favore, verifica che l'anno di scadenza della carta di credito così come appare sulla carta. Per esempio: 08.");
	fp.ccyear.focus();
	return false;
}

if (intYear > intMaxYear) {
	changeStyle(ccDateFld, "#ff0000", "bold");
	alert("Per favore, indica l'anno di scadenza della carta di credito così come appare sulla carta. Per esempio: 08.");
	fp.ccyear.focus();
	return false;
}

if (parseInt('' + fp.ccyear.value + fp.ccmonth.value,10) < parseInt('' + fp.minYear.value + fp.minMonth.value,10)) {
	changeStyle(ccDateFld, "#ff0000", "bold");
	alert("Per favore, verifica la data di scadenza inserita.\nLa data di scadenza deve esssere posteriore o uguale alla data odierna actual (" + fp.ccmonth.value + "/" + fp.ccyear.value + " posteriore o uguale " + fp.minMonth.value + "/" + fp.minYear.value + ")");
	fp.ccyear.focus();
	return false;
}

return true;
}

function hideVisibilityInvoice(id) {
	// Is a DOM browser?
	DOM = (document.getElementById);
	ALL = (document.all);
	
	if (DOM) {
		var elem = document.getElementById(id);
	} else if (ALL) {
		var elem = document.all[id];
	}
	
	if (elem != null) {
		elem.style.visibility = 'hidden';
		elem.style.display = 'none';
	}
}

function openPickUpList() {
	var url = '/edreams/italiano/amadeus3/options/pickUpList.jhtml?regName=';
	
	if (document.getElementById('regions')) {
		el = document.getElementById('regions');
		
		if (el.value == "") {
			alert("Devi scegliere una provincia.");
			el.focus();
			return false;
		}
		
		url =  url + el.value;
	}
	
	window.open(url, 'window', 'width=600,height=470,scrollbars=YES,resizable=YES');
}

function changeVisibilityPickUp(f, id) {
	// Is a DOM browser?
	DOM = (document.getElementById);
	ALL = (document.all);
	
	if (DOM) {
		var elem = document.getElementById(id);
	} else if (ALL) {
		var elem = document.all[id];
	}
	
	if (f.deliveryType[0].checked == false){
		if (elem != null) {
			elem.style.visibility = 'visible';
			elem.style.display = 'block';
		}
	} else {
		if (elem != null) {
			elem.style.visibility = 'hidden';
			elem.style.display = 'none';
		}
	}
}

function closeAlertBox(elem) {
 	if (document.getElementById(elem)) document.getElementById(elem).style.display = 'none';
	if (document.getElementById(elem + 'Shim')) document.getElementById(elem + 'Shim').style.display = 'none';
}

function showAlertBox(elem,obj, ofy) {
	if ((document.getElementById(elem)) && (document.getElementById(elem + 'Shim')) && (document.getElementById(obj))) {
		aBox = document.getElementById(elem);
    	aShim = document.getElementById(elem + 'Shim');	// workaround: msie div over select
	
		var sheight = aShim.style.height.substring(0, (aShim.style.height.length - 2));
		if (isNaN(sheight)) {
			sheight = 150;
		}
		
		if (isNaN(ofy)) ofy = 15; // default value for y-offset
		
	    aBox.style.top = findOffsetTop(document.getElementById(obj)) - ofy - sheight + 'px';
    	aBox.style.left = findOffsetLeft(document.getElementById(obj)) + 'px';

		aShim.style.top = findOffsetTop(document.getElementById(obj)) - ofy - sheight + 2 + 'px';
		aShim.style.left = findOffsetLeft(document.getElementById(obj)) + 2 + 'px';
		aShim.style.zIndex = aBox.style.zIndex - 1;

		aBox.style.display = 'inline';
		if (_sbShowBGIframe()) {
       		aShim.style.display = 'inline';
		}
	}
}

function findOffsetLeft(element) {
    return findOffset(element, "offsetLeft");
}

function findOffsetTop(element) {
    return findOffset(element, "offsetTop");
}
function findOffset(element, type) {
    var os = 0;
    while(element) {
        os += element[type];
        element = element.offsetParent;
    }
    return os;
}
function _sbShowBGIframe() {
    return ( window.opera ) ? false : true;
}

function controlCheckbox(inValue){
	var checkElementCancelacion;
	var checkElementAssistencia;
	var boxElviaGuestsName;
	
	if(document.all){
		checkElementCancelacion = document.all('insuranceIdComplete');
		checkElementAssistencia = document.all('insuranceIdSimple');
	}else{
		checkElementCancelacion = document.getElementById('insuranceIdComplete');
		checkElementAssistencia = document.getElementById('insuranceIdSimple');
	}
	
	if(inValue=='insuranceIdComplete'){
		if(checkElementCancelacion.checked){
			checkElementAssistencia.checked=false;
		}else{
			checkElementCancelacion.checked=false;
		}
	} else if(inValue=='insuranceIdSimple'){
		if(checkElementAssistencia.checked){
			checkElementCancelacion.checked=false;
		}else{
			checkElementAssistencia.checked=false;
		}
	}
}

function checkPassengerFrequent(formPassengers, id, trip) {
	var fqtv = eval("formPassengers.elements['fqtv" + trip + id + "'].value");
		
	if (fqtv == "1") {
		var freqTravelId = eval("formPassengers.elements['frequentFlyerNumber" + trip + id + "'].value");
		var freqTravelProgram = eval("formPassengers.elements['frequentFlyerCompany" + trip + id + "'].value");

		if ((freqTravelId != '') && (freqTravelProgram == '')) {
			changeStyle("fqtv" + trip + id + "fld", "#ff0000", "normal");
			alert("Per favore, indica la compagnia aerea del tuo programma frequent flyer.");
			return false;
		}
		
		if ((freqTravelId == '') && (freqTravelProgram != '')) {
			changeStyle("fqtv" + trip + id + "fld", "#ff0000", "normal");
			alert("Por favore, indica il numero de socio del tuo programma frequent flyer..");
			return false;
		}
	}
		
	return true;
}

function cleanUpDate(fld) {
	tfld = fld.value;
	if ((tfld == "gg") || (tfld == "mm") || (tfld == "aaaa")) {
		fld.value = '';
	} 
}

function checkSearchMultiForm(form) {
// check passengers
	var nadults = 0;
	var nchilds = 0;
	var ninfants = 0;
	
	if(form.adults){
		nadults = parseInt(form.adults.value,"10");
	}
	if(form.childs){
		nchilds = parseInt(form.childs.value,"10");
	}
	if(form.infants){
		ninfants = parseInt(form.infants.value,"10");
	}
	
	var ntotpax=0;

	ntotpax = nadults + nchilds+ninfants;
	
	if (ntotpax > 9) {
		alert("Il numero massimo di passeggeri è 9.");
		return false;
	}
	
	if (ntotpax < 1) {
		alert("Non hai selezionato nessun passeggero");
		return false;
	}

	if ((nchilds+ninfants) > (nadults*2)) {
		alert("Massimo 2 bambini per adulto.");
		return false;
	}
	if ((ninfants) > nadults) {
		alert("Massimo 1 bambino per adulto.");
		return false;
	}	

// check cities
	if (form.departureCity.value == "" || form.departureCity.value == "Scrivi la tua città") {
		alert("Per favore inserisci la città di partenza del primo volo.");
		form.departureCity.focus();
		return false;
	}
	if (form.departureCity.value.search(/\d/) != -1) {
		alert("Il nome della città di partenza del primo volo non può contenere numeri.");
		form.departureCity.focus();
		return false;
	}
	
	if (form.arrivalCity.value == "" || form.arrivalCity.value == "Scrivi la tua città") {
		alert("Per favore inserisci la città di destinazione del primo volo.");
		form.arrivalCity.focus();
		return false;
	}
	
	if (form.arrivalCity.value.search(/\d/) != -1) {
		alert("La ciudad de destino del primer vuelo no puede contener números.");
		form.arrivalCity.focus();
		return false;
	}
	
	if ((form.departureCity1.value != "") && (form.departureCity1.value.search(/\d/) != -1)) {
		alert("Il nome della città di partenza del secondo volo non può contenere numeri.");
		form.departureCity1.focus();
		return false;
	}
	
	if ((form.arrivalCity1.value != "") && (form.arrivalCity1.value.search(/\d/) != -1)) {
		alert("Il nome della città di destinazione del secondo volo non può contenere numeri.");
		form.arrivalCity1.focus();
		return false;
	}
	
	if ((form.departureCity1.value == "") && (form.arrivalCity1.value != "")) {
		alert("Per favore inserisci la città di partenza del secondo volo.");
		form.departureCity1.focus();
		return false;
	}
	
	if ((form.departureCity1.value != "") && (form.arrivalCity1.value == "")) {
		alert("Per favore inserisci la città di destinazione del secondo volo.");
		form.arrivalCity1.focus();
		return false;
	}
	
	if ((form.departureCity2.value != "") && (form.departureCity2.value.search(/\d/) != -1)) {
		alert("Il nome della città di partenza del terzo volo non può contenere numeri.");
		form.departureCity2.focus();
		return false;
	}
	
	if ((form.arrivalCity2.value != "") && (form.arrivalCity2.value.search(/\d/) != -1)) {
		alert("Il nome della città di destinazione del terzo volo non può contenere numeri.");
		form.arrivalCity2.focus();
		return false;
	}
	
	if ((form.departureCity2.value == "") && (form.arrivalCity2.value != "")) {
		alert("Per favore inserisci la città di destinazione del terzo volo.");
		form.departureCity2.focus();
		return false;
	}
	
	if ((form.departureCity2.value != "") && (form.arrivalCity2.value == "")) {
		alert("Per favore inserisci la città di destinazione del terzo volo.");
		form.arrivalCity2.focus();
		return false;
	}
	
	if (((form.departureCity2.value != "") && (form.arrivalCity2.value != "")) && ((form.departureCity1.value == "") || (form.arrivalCity1.value == ""))) {
		if (form.departureCity1.value == "") {
			alert("Per favore inserisci la città di partenza del secondo volo.");
			form.departureCity1.focus();
		} else {
			alert("Per favore inserisci la città di destinazione del secondo volo.");
			form.arrivalCity1.focus();
		}
		return false;
	}

// check dates
	if (form.depDate.value == "") {
		alert("Per favore indica la data di partenza del primo volo.");
		return false;
	}

	if ((form.depDate.value.length != 10) || (form.depDate.value.charAt(2) !='/') || (form.depDate.value.charAt(5) != '/'))  {
		alert("Il formato corretto della data di partenza del primo volo è gg/mm/aaaa (Es. 24/11/2007)");
		return false;
	}

	if (form.chkAirportsType.checked) form.AirportsType.value='PRIMARY';

	var diafecha, mesfecha, anyofecha;
	var d = new Date();
	var diasmes = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

	diafecha = form.depDate.value.substring(0, 2);
	mesfecha = form.depDate.value.substring(3, 5);
	anyofecha = form.depDate.value.substring(6);
	
	idep = parseInt(anyofecha + mesfecha + diafecha);

	if (isNaN(diafecha) || isNaN(mesfecha) || isNaN(anyofecha)) {
		alert("Il formato corretto della data di partenza del primo volo è gg/mm/aaaa (Es. 24/11/2007)");
		return false;
	}
	
	if (anyofecha < d.getYear()) {
		alert("La data di partenza del primo volo deve essere posteriore alla data odierna.");
		return false;
	}
	
	if ((mesfecha < 1) || (mesfecha > 12)) {
		alert("Il formato corretto della data di partenza del primo volo è gg/mm/aaaa (Es. 24/11/2007)");
		return false;
	}

	if ((diafecha < 1) || (diafecha > diasmes[mesfecha])) {
		alert("Il formato corretto della data di partenza del primo volo è gg/mm/aaaa (Es. 24/11/2007)");
		return false;
	}

	form.departureDate.value = diafecha + mesfecha + anyofecha;

	if ((form.departureCity1.value != "") && (form.arrivalCity1.value != "")) {
		if (form.retDate.value == "") {
			alert("Per favore indica la data di partenza del secondo volo.");
			return false;
		}
	
		if (form.retDate.value.length != 10) {
			alert("Il formato corretto della data di partenza del secondo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}
	
		if ((form.retDate.value.charAt(2) !='/') || (form.retDate.value.charAt(5) != '/'))  {
			alert("Il formato corretto della data di partenza del secondo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		diafecha = form.retDate.value.substring(0, 2);
		mesfecha = form.retDate.value.substring(3, 5);
		anyofecha = form.retDate.value.substring(6);

		if (isNaN(diafecha) || isNaN(mesfecha) || isNaN(anyofecha)) {
			alert("Il formato corretto della data di partenza del secondo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}
	
		if (anyofecha < d.getYear()) {
			alert("La data di partenza del secondo volo deve essere posteriore alla data odierna.");
			return false;
		}
	
		if ((mesfecha < 1) || (mesfecha > 12)) {
			alert("Il formato corretto della data di partenza del secondo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		if ((diafecha < 1) || (diafecha > diasmes[mesfecha])) {
			alert("Il formato corretto della data di partenza del secondo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		iret = parseInt(anyofecha + mesfecha + diafecha);
		
		if (idep > iret) {
			alert("La data di partenza del secondo volo deve essere posteriore alla data di partenza del primo volo.");
			return false;
		}

		form.returnDate.value = diafecha + mesfecha + anyofecha;
	}
	
	if ((form.departureCity2.value != "") && (form.arrivalCity2.value != "")) {
		if (form.seg3Date.value == "") {
			alert("Per favore indica la data di partenza del terzo volo.");
			return false;
		}
	
		if (form.seg3Date.value.length != 10) {
			alert("Il formato corretto della data di partenza del terzo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}
	
		if ((form.seg3Date.value.charAt(2) !='/') || (form.seg3Date.value.charAt(5) != '/'))  {
			alert("Il formato corretto della data di partenza del terzo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		diafecha = form.seg3Date.value.substring(0, 2);
		mesfecha = form.seg3Date.value.substring(3, 5);
		anyofecha = form.seg3Date.value.substring(6);

		if (isNaN(diafecha) || isNaN(mesfecha) || isNaN(anyofecha)) {
			alert("Il formato corretto della data di partenza del terzo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}
	
		if (anyofecha < d.getYear()) {
			alert("La data di partenza del terzo volo deve essere posteriore alla data odierna.");
			return false;
		}
	
		if ((mesfecha < 1) || (mesfecha > 12)) {
			alert("Il formato corretto della data di partenza del terzo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		if ((diafecha < 1) || (diafecha > diasmes[mesfecha])) {
			alert("Il formato corretto della data di partenza del terzo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		idep3 = parseInt(anyofecha + mesfecha + diafecha);
		
		if (iret > idep3) {
			alert("La data di partenza del terzo volo deve essere posteriore alla data di partenza del secondo volo.");
			return false;
		}
		
		if ((idep == iret) && (iret == idep3)) {
			alert("Non è possibile fare la ricerca dei voli per le date selezionate. Non si possono fare 3 voli nello stesso giorno. ");
			return false;
		}

		form.segment3Date.value = diafecha + mesfecha + anyofecha;
	}
	return true;
}

function checkSearchColumnFormMulti(form) {
// check passengers
	var nadults = 0;
	var nchilds = 0;
	var ninfants = 0;
	
	if(form.adults){
		nadults = parseInt(form.adults.value,"10");
	}
	if(form.childs){
		nchilds = parseInt(form.childs.value,"10");
	}
	if(form.infants){
		ninfants = parseInt(form.infants.value,"10");
	}
	
	var ntotpax=0;

	ntotpax = nadults + nchilds+ninfants;
	
	if (ntotpax > 9) {
		alert("Il numero masssimo di passeggeri è 9.");
		return false;
	}
	
	if (ntotpax < 1) {
		alert("Non hai selezionato alcun passeggero.");
		return false;
	}

	if ((nchilds+ninfants) > (nadults*2)) {
		alert("Al massimo 2 bambini per ogni adulto.");
		return false;
	}
	if ((ninfants) > nadults) {
		alert("Al massimo un neonato per adulto.");
		return false;
	}	

// check cities
	if (form.departureCity.value == "" || form.departureCity.value == "Scrivi la tua città") {
		alert("Per favore inserisci la città di partenza del primo volo.");
		form.departureCity.focus();
		return false;
	}
	if (form.departureCity.value.search(/\d/) != -1) {
		alert("Il nome della città di partenza del primo volo non può contenere numeri.");
		form.departureCity.focus();
		return false;
	}
	
	if (form.arrivalCity.value == "" || form.arrivalCity.value == "Scrivi la tua città") {
		alert("Per favore inserisci la città di destinazione del primo volo.");
		form.arrivalCity.focus();
		return false;
	}
	
	if (form.arrivalCity.value.search(/\d/) != -1) {
		alert("La ciudad de destino del primer vuelo no puede contener números.");
		form.arrivalCity.focus();
		return false;
	}
	
	if ((form.departureCity1.value != "") && (form.departureCity1.value.search(/\d/) != -1)) {
		alert("Il nome della città di partenza del secondo volo non può contenere numeri.");
		form.departureCity1.focus();
		return false;
	}
	
	if ((form.arrivalCity1.value != "") && (form.arrivalCity1.value.search(/\d/) != -1)) {
		alert("Il nome della città di destinazione del secondo volo non può contenere numeri.");
		form.arrivalCity1.focus();
		return false;
	}
	
	if ((form.departureCity1.value == "") && (form.arrivalCity1.value != "")) {
		alert("Per favore inserisci la città di partenza del secondo volo.");
		form.departureCity1.focus();
		return false;
	}
	
	if ((form.departureCity1.value != "") && (form.arrivalCity1.value == "")) {
		alert("Per favore inserisci la città di destinazione del secondo volo.");
		form.arrivalCity1.focus();
		return false;
	}
	
	if ((form.departureCity2.value != "") && (form.departureCity2.value.search(/\d/) != -1)) {
		alert("Il nome della città di partenza del terzo volo non può contenere numeri.");
		form.departureCity2.focus();
		return false;
	}
	
	if ((form.arrivalCity2.value != "") && (form.arrivalCity2.value.search(/\d/) != -1)) {
		alert("Il nome della città di destinazione del terzo volo non può contenere numeri.");
		form.arrivalCity2.focus();
		return false;
	}
	
	if ((form.departureCity2.value == "") && (form.arrivalCity2.value != "")) {
		alert("Per favore inserisci la città di partenza del terzo volo.");
		form.departureCity2.focus();
		return false;
	}
	
	if ((form.departureCity2.value != "") && (form.arrivalCity2.value == "")) {
		alert("Per favore inserisci la città di destinazione del terzo volo.");
		form.arrivalCity2.focus();
		return false;
	}
	
	if (((form.departureCity2.value != "") && (form.arrivalCity2.value != "")) && ((form.departureCity1.value == "") || (form.arrivalCity1.value == ""))) {
		if (form.departureCity1.value == "") {
			alert("Per favore inserisci la città di partenza del secondo volo.");
			form.departureCity1.focus();
		} else {
			alert("Per favore inserisci la città di destinazione del secondo volo.");
			form.arrivalCity1.focus();
		}
		return false;
	}

// check dates
	if (form.depDate.value == "") {
		alert("Per favore indica la data di partenza del primo volo.");
		return false;
	}

	if ((form.depDate.value.length != 10) || (form.depDate.value.charAt(2) !='/') || (form.depDate.value.charAt(5) != '/'))  {
		alert("Il formato corretto della data di partenza del primo volo è gg/mm/aaaa (Es. 24/11/2007)");
		return false;
	}

	if (form.chkAirportsType.checked) form.AirportsType.value='PRIMARY';

	var diafecha, mesfecha, anyofecha;
	var d = new Date();
	var diasmes = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

	diafecha = form.depDate.value.substring(0, 2);
	mesfecha = form.depDate.value.substring(3, 5);
	anyofecha = form.depDate.value.substring(6);
	
	idep = parseInt(anyofecha + mesfecha + diafecha);

	if (isNaN(diafecha) || isNaN(mesfecha) || isNaN(anyofecha)) {
		alert("Il formato corretto della data di partenza del primo volo è gg/mm/aaaa (Es. 24/11/2007)");
		return false;
	}
	
	if (anyofecha < d.getYear()) {
		alert("La data di partenza del primo volo deve essere posteriore alla data odierna.");
		return false;
	}
	
	if ((mesfecha < 1) || (mesfecha > 12)) {
		alert("Il formato corretto della data di partenza del primo volo è gg/mm/aaaa (Es. 24/11/2007)");
		return false;
	}

	if ((diafecha < 1) || (diafecha > diasmes[mesfecha])) {
		alert("Il formato corretto della data di partenza del primo volo è gg/mm/aaaa (Es. 24/11/2007)");
		return false;
	}

	form.departureDate.value = diafecha + mesfecha + anyofecha;

	if ((form.departureCity1.value != "") && (form.arrivalCity1.value != "")) {
		if (form.retDate.value == "") {
			alert("Per favore indica la data di partenza del secondo volo.");
			return false;
		}
	
		if (form.retDate.value.length != 10) {
			alert("Il formato corretto della data di partenza del secondo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}
	
		if ((form.retDate.value.charAt(2) !='/') || (form.retDate.value.charAt(5) != '/'))  {
			alert("Il formato corretto della data di partenza del secondo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		diafecha = form.retDate.value.substring(0, 2);
		mesfecha = form.retDate.value.substring(3, 5);
		anyofecha = form.retDate.value.substring(6);

		if (isNaN(diafecha) || isNaN(mesfecha) || isNaN(anyofecha)) {
			alert("Il formato corretto della data di partenza del secondo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}
	
		if (anyofecha < d.getYear()) {
			alert("La data di partenza del secondo volo deve essere posteriore alla data odierna.");
			return false;
		}
	
		if ((mesfecha < 1) || (mesfecha > 12)) {
			alert("Il formato corretto della data di partenza del secondo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		if ((diafecha < 1) || (diafecha > diasmes[mesfecha])) {
			alert("Il formato corretto della data di partenza del secondo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		iret = parseInt(anyofecha + mesfecha + diafecha);
		
		if (idep > iret) {
			alert("La data di partenza del secondo volo deve essere posteriore alla data di partenza del primo volo.");
			return false;
		}

		form.returnDate.value = diafecha + mesfecha + anyofecha;
	}
	
	if ((form.departureCity2.value != "") && (form.arrivalCity2.value != "")) {
		if (form.seg3Date.value == "") {
			alert("Per favore indica la data di partenza del terzo volo.");
			return false;
		}
	
		if (form.seg3Date.value.length != 10) {
			alert("Il formato corretto della data di partenza del terzo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}
	
		if ((form.seg3Date.value.charAt(2) !='/') || (form.seg3Date.value.charAt(5) != '/'))  {
			alert("Il formato corretto della data di partenza del terzo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		diafecha = form.seg3Date.value.substring(0, 2);
		mesfecha = form.seg3Date.value.substring(3, 5);
		anyofecha = form.seg3Date.value.substring(6);

		if (isNaN(diafecha) || isNaN(mesfecha) || isNaN(anyofecha)) {
			alert("Il formato corretto della data di partenza del terzo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}
	
		if (anyofecha < d.getYear()) {
			alert("La data di partenza del terzo volo deve essere posteriore alla data odierna.");
			return false;
		}
	
		if ((mesfecha < 1) || (mesfecha > 12)) {
			alert("Il formato corretto della data di partenza del terzo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		if ((diafecha < 1) || (diafecha > diasmes[mesfecha])) {
			alert("Il formato corretto della data di partenza del terzo volo è gg/mm/aaaa (Es. 24/11/2007)");
			return false;
		}

		idep3 = parseInt(anyofecha + mesfecha + diafecha);
		
		if (iret > idep3) {
			alert("La data di partenza del terzo volo deve essere posteriore alla data di partenza del secondo volo.");
			return false;
		}
		
		if ((idep == iret) && (iret == idep3)) {
			alert("Non è possibile fare la ricerca dei voli per le date selezionate. Non si possono fare 3 voli nello stesso giorno. ");
			return false;
		}

		form.segment3Date.value = diafecha + mesfecha + anyofecha;
	}

	return true;
}

/*******************************************************************

price & insurance

********************************************************************/

function addCommas(nStr)
{
	nStr += "";
	x = nStr.split(".");
	x1 = x[0];
	x2 = x.length > 1 ? "," + x[1] : "";
	var rgx = /(\d+)(\d{3})/;
	
	while (rgx.test(x1)) 
	{
		x1 = x1.replace(rgx, "$1" + "." + "$2");
	}
	
	return x1 + x2;
}

function pricingBags(index) {
	// numero de segmentos
	var numSegments = parseInt(document.getElementById('numSegments').value, 10);
	// elemento numero de maletas seleccionadas
	var numBagPaxSel = document.getElementById('numBags' + index);
	// tipo pasajero
	var paxType = document.getElementById('passType' + index).value;

	// Verificamos que tengamos el elemento selector de maletas
	if ((numBagPaxSel != null) && (paxType != "INF")) {
		// Numero de maletas del pasajero (index)
		var numBagPax = parseInt(numBagPaxSel.options[numBagPaxSel.selectedIndex].value, 10);
		// Percio de las maletas. Hay un campo hidden para cada posibilidad de numero de maleta
		var bagPr = parseFloat(document.getElementById('bagPr' + numBagPax).value, 10);
		// elemento donde escribiremos el precio de las maletas
		var elPrBags = document.getElementById('prBags' + index);
		elPrBags.innerHTML = addCommas((numSegments * bagPr).toFixed(2)) + '€';
	}
}

function pricingInsurance(elem) 
{
	var insuranceCost = parseFloat(document.getElementById("insurancePr" + elem).value, 10);
	var insuranceCheck = document.getElementById("insuranceId" + elem);
	var insuranceElem = document.getElementById("insPr" + elem);
	var divInsurance = document.getElementById("divInsurance" + elem);	
	
	if (insuranceCheck.checked == true) 
	{
		insuranceElem.innerHTML = addCommas(insuranceCost.toFixed(2)) + " €";
		divInsurance.style.display = "block";
		insuranceElem.style.display = "block";
	} 
	else 
	{
		insuranceElem.innerHTML = " €";
		divInsurance.style.display = "none";
		insuranceElem.style.display = "none";
	}
	
	recalTotalPrice();
}

function pricingCC()
{
	var cctypeSel = document.getElementById("cctype");
	var cctypeVal = cctypeSel.options[cctypeSel.selectedIndex].value;
	var cctypeFee = parseFloat(document.getElementById("fee" + cctypeVal).value, 10);
	
	var elCCfee = document.getElementById("ccFeeDiv");
	elCCfee.innerHTML = addCommas(cctypeFee.toFixed(2)) + " €";
	
	var hdCCfee = document.getElementById("ccFee");
	hdCCfee.value = cctypeFee;
	
	recalTotalPrice();
}

function pricingCCp() 
{
	var addCCFee = true;
	var bankTransferPaymentMethod = document.getElementById("bankTransferPaymentMethod");
	
	if (bankTransferPaymentMethod != null) 
		if (bankTransferPaymentMethod.checked == true)
			addCCFee = false;

	if (addCCFee == true)
	{
		var cctypeSel = document.getElementById("cctypefake");
		var cctypeVal = cctypeSel.options[cctypeSel.selectedIndex].value;
		var CCfeeValue = parseFloat(document.getElementById("fee" + cctypeVal).value, 10);
	
		var elCCfee = document.getElementById("ccFeeDiv");
		elCCfee.innerHTML = addCommas(CCfeeValue.toFixed(2)) + " €";
	
		var hdCCfee = document.getElementById("ccFee");
		hdCCfee.value = CCfeeValue.toFixed(2);
	}
	else
	{
		var elCCfee = document.getElementById("ccFeeDiv");
		elCCfee.innerHTML = "0,00" + " €";
		
		var hdCCfee = document.getElementById("ccFee");
		hdCCfee.value = 0;
	}
	
	recalTotalPrice();
}

function recalTotalPrice() 
{
	if (document.getElementById("bagsPr") != null)
		bagsPr = parseFloat(document.getElementById("bagsPr").value, 10);
	else
		bagsPr = 0;
	
	var ticketPr = parseFloat(document.getElementById("ticketPr").value, 10);
	
	if (document.getElementById("insuranceId3") != null) 
	{
		insuranceCost3 = parseFloat(document.getElementById("insurancePr3").value, 10);
		insuranceCheck3 = document.getElementById("insuranceId3");
		if (insuranceCheck3.checked == false)
			insuranceCost3 = 0;
	}
	else
		insuranceCost3 = 0;
	
	if (document.getElementById("insuranceId10") != null)
	{
		insuranceCost10 = parseFloat(document.getElementById("insurancePr10").value, 10);
		insuranceCheck10 = document.getElementById("insuranceId10");
		if (insuranceCheck10.checked != true)
			insuranceCost10 = 0;
	}
	else
		insuranceCost10 = 0;
	
	if (document.getElementById("insuranceId11") != null) 
	{
		insuranceCost11 = parseFloat(document.getElementById("insurancePr11").value, 10);
		insuranceCheck11 = document.getElementById("insuranceId11");
		if (insuranceCheck11.checked != true)
			insuranceCost11 = 0;
	} 
	else
		insuranceCost11 = 0;
	
	var addCCFee = true;
	var bankTransferPaymentMethod = document.getElementById("bankTransferPaymentMethod");
	if (bankTransferPaymentMethod != null)
		if (bankTransferPaymentMethod.checked == true)
			addCCFee = false;
	
	if (addCCFee == false)
		hdCCfee = 0;
	else
		hdCCfee = parseFloat(document.getElementById("ccFee").value, 10); 
	
	if (document.getElementById("promotionalCodeValue") != null) {
		promotionDiscount = parseFloat(document.getElementById("promotionalCodeValue").value, 10);
	}else{
		promotionDiscount = 0;
	}
	
	var totalPrice = ticketPr + hdCCfee + bagsPr + insuranceCost3 + insuranceCost10 + insuranceCost11 + promotionDiscount;
	
	var finalPriceBoxBudget = document.getElementById("finalPriceBoxBudget");
	finalPriceBoxBudget.innerHTML = addCommas(totalPrice.toFixed(2)) + " €";
	
	var prWithAssistance = document.getElementById("prWithAssistance");
	if (prWithAssistance != null)
		prWithAssistance.innerHTML = addCommas(totalPrice.toFixed(2)) + " €";
}

function initBagsPrice() {
	var nPassengers = parseInt(document.getElementById('nPassengers').value, 10);
	var nTotalBags = 0;
	
	for (var i = 1; i <= nPassengers; i++) {
		pricingBags(i);
	}
}
//Funciones para Ryanair checkin online
function haveBags(doHave, ind){
	if(doHave){
		document.getElementById("checkInOn").style.display="none";
		for(var i=1; i<=ind; i++){
			var capamaletas= "nuMal"+i;
			document.getElementById(capamaletas).style.display="block";
			document.getElementById("numBags"+i).value = 0;
		}
		initBagsPrice();
	}else{
		document.getElementById("checkInOn").style.display="block";
		for(var i=1; i<=ind; i++){
			var capamaletas= "nuMal"+i;
			document.getElementById(capamaletas).style.display="none";
			document.getElementById("numBags"+i).value = 0;
		}
		for (i=0;i<document.forms[0].airportCheckIn.length;i++) {
			if (document.forms[0].airportCheckIn[i].checked) {
				var withB = document.forms[0].airportCheckIn[i].value;
				
			}
		}
		//initBagsPrice();
		checkInAirport(withB, ind);
	}
}
function checkInAirport(inAiport, ind){
	if(inAiport == "true"){
		inAiport =true;
	} else if(inAiport == "false"){
		inAiport =false;
	}
	if(inAiport){
		for(var i=1; i<=ind; i++){
			document.getElementById("numBags"+i).value = 0;
		}
		initBagsPrice();
	}else{
		for(var i=1; i<=ind; i++){
			var capaprecio= "prBags"+i;
			document.getElementById(capaprecio).innerHTML = "0 &euro;";
			document.getElementById("numBags"+i).value = 0;
		}
	}
}
function promotionsAjax(){
	var xmlHttp;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){
		// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			if (xmlHttp.status == 200) {
				var aux = eval('(' + xmlHttp.responseText + ')');
				
				if(aux.discount < 0){
					document.getElementById("divPromotionCodePr").innerHTML=aux.discount + ' €';
					document.getElementById("divPromotionCodeTx").innerHTML=aux.text;
					document.getElementById("promotionalCodeValue").value=aux.discount;
					document.getElementById("divPromotionCodePr").style.display='block';
					document.getElementById("divPromotionCodeTx").style.display='block';
					recalTotalPrice();
				}else{
					document.getElementById("divPromotionCodePr").innerHTML='';
					document.getElementById("divPromotionCodeTx").innerHTML='';
					document.getElementById("promotionalCodeValue").value=0;
					document.getElementById("divPromotionCodePr").style.display='none';
					document.getElementById("divPromotionCodeTx").style.display='none';
					recalTotalPrice();
				}
			}
		}
	}
	
	var url = '/edreams/italiano/amadeus3/ecommerce/promotionCodes.jhtml?code=' + document.getElementById("promotionalCode").value;
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
