	//============================================================================
	//-                      Copyright © 2006 Maxxcom Sas                        -
	//-                           All rights reserved.                           -
	//-                                                                          -
	//-    Questo codice sorgente è protetto da copyright in base alle leggi e   -
	//-    ai trattati internazionali. L'uso non autorizzato, la riproduzione    -
	//-    parziale o totale, l'alterazione, la distribuzione di questo codice   -
	//-    sorgente saranno perseguite in sede penale e civile in ottemperanza   -
	//-    alle leggi esistenti. Sono soggette alle rispettive licenze freeware, -
	//-    GPL, LGPL o di altro tipo, le parti di codice sorgente acquisite da   -
	//-    terze parte anche senza il consenso scritto. In tal caso i nomi degli -
	//-    autori sono riportati a monte delle procedure utilizzate e/o incluse. -
	//-    Eventuali omissioni o errori potranno essere comunicati all'indirizzo -
	//-    email info@maxxcom.it per una pronta correzione e/o integrazione.     -
	//-                                                                          -
	//-    www.maxxcom.it                                                        -
	//============================================================================

	function ClearRoundTripFields() {
		var Ritorno = getObject("FL_Dataritorno");
		Ritorno.value = '';
	}

	function TravelType() {
		var Travelmode = getObject('FL_Travelmode');
		if (Travelmode.type == "hidden")
			return Travelmode.value;
		if (getObject('FL_Travelmode').checked)
			return "RT";
		else
			return "OW";
	}

	function FixReturnDate(cal) {
		if (typeof cal == "object") { cal.hide(); }
		var travel = TravelType();
		if (TravelType() == "RT") {
			var Andata = getObject('FL_Datapartenza');
			var Ritorno = getObject('FL_Dataritorno');
			if (Ritorno.value == '') { 
				Ritorno.value = Andata.value;
			} else {
		        var ret = isValidDate(Andata.value);
		        if (ret != 0) { 
                    Ritorno.value = Andata.value; 
                } else {
                    dt1 = (Andata.value.replace("-", "/")).split("/");
		            d1 = new Date(dt1[1] + "/" + dt1[0] + "/" + dt1[2]);
			        var ret = isValidDate(Ritorno.value);
		            if (ret != 0) { 
                        Ritorno.value = Andata.value; 
                    } else {
			            dt2 = (Ritorno.value.replace("-", "/")).split("/");
			            d2 = new Date(dt2[1] + "/" + dt2[0] + "/" + dt2[2]);
			            if (d2 < d1) { Ritorno.value = Andata.value; }
                    }
                }
            }
		}
	}

	function checkAirports() {
		var Departure  = getObject('FL_Departure').value;
		var Arrival    = getObject('FL_Arrival').value;
		//var Gift = getObject('FL_Certificato').value;
		if (Departure == '') {
			alert ("\nYou need to indicate the departure airport!\n");
			return false;
		}
		else if (Arrival == '') {
			alert ("\nYou need to idicate the destination airport!\n");
			return false;
		}
		else if (Departure == Arrival) {
			alert ("\nDeparture and destination can not coincide!\n");
			return false;
		}
		
		return true;
	}

	function checkPassengers() {
		var adults  = getObject("FL_Adults").selectedIndex;
		var children  = getObject("FL_Children").selectedIndex;
		var passengers = adults + children;
		var infants = getObject("FL_Infants").selectedIndex;
		if (infants  > 0) {
			if (adults  <= 0) {
				alert("\nInfants (from 0 - 23 months) can not be booked on their own!\n");
				return false;
			}
			if (adults < infants){
				alert("\nThe number of infants (from 0 to 2 years) can not exceed the number of adult passengers!\n");
				return false;
			}
		}
		if (children > 0) {
			if (adults <= 0) {
				alert("\nPassengers less than 12 years of age must be accompanied by an adult!\n");
				return false;
			}
		}
		if (adults + children == 0) {
			alert("\nYou need to make a booking for an adult passenger or a child at least.\n");
			return false;
		}
		return true;
	}

    //ritorna -1 se date1>date2, ritorna 1 se date1<date, ritorna 0 se date1=date2
	function compareDates(date1, date2) {
		var year1 = date1.getYear();
		var year2 = date2.getYear();
		var month1 = date1.getMonth();
		var month2 = date2.getMonth();
		var day1 = date1.getDate();
		var day2 = date2.getDate();
		if (year1 > year2) { return -1; }
		if (year2 > year1) { return 1; }
		if (month1 > month2) { return -1; }
		if (month2 > month1) { return 1; }
		if (day1 > day2) { return -1; }
		if (day2 > day1) { return 1; }
		return 0;
	}

	function HidePastDates(date) {
		var now = new Date();
		if (compareDates(now, date) < 0) {
			return (true);
		}
		return false;
	}

	// é = \u00E9	ì = \u00ED   ù = \u00F9   à = \u00E1  ò = \u00F3
	function checkDates(DaysToAdd){
		var Partenza = getObject("FL_Datapartenza");
   		var Ritorno = getObject("FL_Dataritorno");
        Partenza.value = AdjustDate(Partenza.value);
		if (Partenza.value == "") {
			alert('You need to indicate a valid departure date!\n');
			return false;
		}
		var ret = isValidDate(Partenza.value);
		if (ret != 0) {
			switch (ret) {
				case -1:
					alert("The departure date format is not valid!");
					break;
				case -2:
					alert("The indicated month for the departure date is not valid!");
					break;
				case -3:
					alert("The indicated day for the departure date is not valid!");
					break;
				case -4:
					alert("The indicated day of the month for the departure date is not valid!");
					break;
				case -5:
					alert("The indicated year for the departure date is not valid!");
					break;
				default:
					alert('You need to indicate a valid date!');
			}
			Partenza.select();
			Partenza.focus();
			return false;
		}
		dt1 = (Partenza.value.replace("-", "/")).split("/");
		d1 = new Date(dt1[1] + "/" + dt1[0] + "/" + dt1[2]);
		ds = new Date;
        if (DaysToAdd != 0) { ds = AddDays(ds, DaysToAdd); }
		ds.setHours(0, 0, 0, 0);
		if (d1 < ds) {
            //if (DaysToAdd != 0)
    		//	alert('Le prenotazioni possono essere modificate solo fino al giorno prima della partenza!\n\n Negli altri casi occorre contattare il call-center.');
            //else
            if (DaysToAdd == 0)
			    alert('The departure date can not be prior to today\'s date!');
			//return false;
		}
		if (TravelType() == "RT") {
            Ritorno.value = AdjustDate(Ritorno.value);
			if (Ritorno.value == "") {
				alert('You need to indicate a valid date for the return flight!\n');
				return false;
			}
			var ret = isValidDate(Ritorno.value);
			if (ret != 0) {
				switch (ret) {
					case -1:
						alert("The format of the return date is not valid!");
						break;
					case -2:
						alert("The indicated month for the return date is not valid!");
						break;
					case -3:
						alert("The indicated day for the return date is not valid!");
						break;
					case -4:
						alert("The day of the month you selected for the inbound flight is not valid!");
						break;
					case -5:
						alert("The inidcated year for the return date is not valid!");
						break;
					default:
						alert('You need to indicate a valid date for the return flight!');
				}
				Ritorno.select();
				Ritorno.focus();
				return false;
			}
			dt2 = (Ritorno.value.replace("-", "/")).split("/");
			d2 = new Date(dt2[1] + "/" + dt2[0] + "/" + dt2[2]);
			if (d2 < d1) {
				alert('The return date can not be prior to the departure date!');
				return false;
			}
		}
		else {
    		if (TravelType() != "RT" && Ritorno != null) Ritorno.value = '';
		}
		
		conferma = getObject("Cerca_voli");
		if (conferma != null) conferma.disabled = true;

		return true;
	}

	function CheckString(){
		var espressione = new RegExp("[A-Za-z0-9]{10}");
		var Gift = getObject('FL_Certificato');
		if (Gift==null) return true
		if (Gift.value == "") return true
		else
		{
	//	if (!espressione.test(Gift))
		if (!isAlpha(Gift))
		{
			alert("Il codice contiene caratteri non è validi!");
			return false;
		}
		}
		return true;
	}

  

	function submitForm() {
		return (checkAirports() && checkPassengers() && checkDates(0) && CheckString());
	}
	
	function submitFormUmnr() {
		return (checkAirports()  && checkDates(0));
	}

	function submitFormFixedPax() {
		return (checkAirports() && checkDates(1));
	}

	function submitFormPaxCC() {
		return (checkAirports());
	}

