    function Init()
    {
        Update1();
        SetValue("OutArrAir", GetValue("OutArrAir_Temp"));
        SetValue("RetDepAir", GetValue("RetDepAir_Temp"));

        if (GetValue("OutMonth_Temp") == "") { 
			PreSelectMonth("",7,"OutMonth");
		} else {
			SetValue("OutMonth", GetValue("OutMonth_Temp"));
		}
		if (GetValue("RetMonth_Temp") == "") {
			PreSelectMonth("",14,"RetMonth");
		} else {
			SetValue("RetMonth", GetValue("RetMonth_Temp"));
		}
   }
    
    function Update1()
    {
        Routine1(GetValue("OutDepAir"))
    }
    function Update2()
    {
        Routine2(GetValue("OutArrAir"))
    }
    function Update3()
    {
        Routine3(GetValue("RetDepAir"))
    }
    
    function Routine1(asAirportCode)
    {   
	    var outArrAirports = document.FormSearch.OutArrAir;
	    var retDepAirports = document.FormSearch.RetDepAir;
	    var retArrAirports = document.FormSearch.RetArrAir;
	    
	    outArrAirports.length = 0;
	    retDepAirports.length = 0;
	    retArrAirports.length = 0;

	    outArrAirports.options[0] = new Option("---Selezionare---","");
	    retDepAirports.options[0] = new Option("---Selezionare---","");
	    retArrAirports.options[0] = new Option("---Selezionare---","");
	    
	    outArrAirports.options[0].selected = true;
	    retDepAirports.options[0].selected = true;
	    retArrAirports.options[0].selected = true;

        if(asAirportCode!="")
        {
            BuildAirportList(GetAirportLinkedItem(asAirportCode, OBAirportLinkList), outArrAirports);
            BuildAirportList(GetAirportLinkedItem("ALL", OBAirportLinkList), retDepAirports);
            BuildAirportList(GetAirportLinkedItem("ALL", IBAirportLinkList), retArrAirports);
	    }
	    
	    ReturnAirports();
    }
    
    function Routine2(asAirportCode)
    {
        Routine3(asAirportCode);
	    ReturnAirports();
    }
    
    function Routine3(asAirportCode)
    {        
	    var retArrAirports = document.FormSearch.RetArrAir;
	    
	    retArrAirports.length = 0;

	    retArrAirports.options[0] = new Option("---Selezionare---","");
	    
	    retArrAirports.options[0].selected = true;

        if(asAirportCode!="")
        {
            BuildAirportList(GetAirportLinkedItem(asAirportCode, IBAirportLinkList), retArrAirports);
	    }
    }
    
    function ReturnAirports() //changes the return airports to be the same as the outbound ones
	{
	    SetValue("RetDepAir", GetValue("OutArrAir"));
	    SetValue("RetArrAir", GetValue("OutDepAir"));
	}
    
    function BuildAirportList(aoAirport, aoDropDown)
    {
        var i=0;
        var j=1;
        
        //alert(aoAirport.LinkedCodes);
        
        var tempArr = aoAirport.LinkedCodes.split("-");

		for(i=0; i<tempArr.length; i++)
		{
			aoDropDown.options[j] = new Option(GetAirportDescription(tempArr[i]), tempArr[i]);
    		if(j==0)
    		{
    			aoDropDown.options[j].selected = true;
    		}
    		j++;
		}
    }
    
    function GetAirportLinkedItem(asAirportCode, aoAirportLinkList)
    {
        for(var i=0; i<aoAirportLinkList.length; i++)
        {
	        if(aoAirportLinkList[i].Code==asAirportCode)
	        {
	            return aoAirportLinkList[i];
	        }
        }
    }
    
    function GetAirportDescription(asAirportCode)
    {
        for(var i=0; i<AirportList.length; i++)
	    {
	        if (AirportList[i].Code == asAirportCode)
	        {
	            return AirportList[i].Description;
	        }
	    }
	    return asAirportCode;
    }
    
    function AirportLink(asCode, asLinkedCodes)
    {
	    this.Code = asCode;
	    this.LinkedCodes = asLinkedCodes;
    }
    
    function Airport(asCode, asDescription)
    {
	    this.Code = asCode;
	    this.Description = asDescription;
    }
    
    function AddDays(myDate,days) 
    {
        //alert(myDate);
        return new Date(myDate.getTime() + days*24*60*60*1000);
    }

    function CheckDates()
    {   
        var lsOutDate = GetValue("OutDay") + "-" + GetValue("OutMonth") + "-" + GetValue("OutYear");
        var lsRetDate = GetValue("RetDay") + "-" + GetValue("RetMonth") + "-" + GetValue("RetYear");

        var OutDate = new Date(getDateFromFormat(lsOutDate, "dd-MM-yyyy"));
        var RetDate = new Date(getDateFromFormat(lsRetDate, "dd-MM-yyyy"));
		
		if(RetDate < OutDate)
		{
		    RetDate = AddDays(OutDate, 7);
		    
		    SetValue("RetDay", RetDate.getDate().toString().pad(2,"0",0));
		    SetValue("RetMonth", eval(RetDate.getMonth()+1).toString().pad(2,"0",0));
		    SetValue("RetYear", RetDate.getFullYear());
		}
    }
    
	function CheckData()
	{
		//Get Dates
		var lsOutDate = GetValue("OutDay") + "-" + GetValue("OutMonth") + "-" + GetValue("OutYear");
		var lsRetDate = GetValue("RetDay") + "-" + GetValue("RetMonth") + "-" + GetValue("RetYear");
		
        if(!isDate(lsOutDate, "dd-MM-yyyy"))
        {
            alert("Please enter a valid departure date");
            return false;
        }
        if(!isDate(lsRetDate, "dd-MM-yyyy"))
        {
            alert("Please enter a valid return date");
            return false;
        }
        
        var OutDate = new Date(getDateFromFormat(lsOutDate, "dd-MM-yyyy"));
        var RetDate = new Date(getDateFromFormat(lsRetDate, "dd-MM-yyyy"));
        
		var CurrDate = new Date();

        //And validate
		if(OutDate < CurrDate)
		{
			alert('Departure date must be in the future');
			return false;
		}

		if(typeof(firstDepDate) != "undefined" && isDate(firstDepDate, "dd-MMM-yyyy"))
		{
		    var allowedDate = new Date(getDateFromFormat(firstDepDate, "dd-MMM-yyyy"));
		    if(OutDate < allowedDate)
		    {
		        alert("Earliest allowed departure date is " + firstDepDate);
		        return false;
		    }
		}

		if(IsChecked("ReturnFlight"))
		{
		    if(RetDate < CurrDate)
		    {
			    alert('Return date must be in the future');
			    return false;
		    }

		    if(RetDate < OutDate)
		    {
			    alert('Departure date must be earlier than your return date');
			    return false;
		    }
        }

		//Check that airports have been selected for the outward journey 
		if(GetValue("OutDepAir") == "" || GetValue("OutArrAir") == "")
		{
			alert('Selezionare gli aeroporti del viaggio di andata.');
			return false;
		}
		if(IsChecked("ReturnFlight"))
		{
			if(GetValue("RetDepAir") == "" || GetValue("RetArrAir") == "")
			{
				alert('Selezionare gli aeroporti del viaggio di ritorno.');
				return false;
			}
		}

		var NumAdults = eval(GetValue("AdultPax"));
		var NumChi = eval(GetValue("ChildPax"));
		var NumInfants = eval(GetValue("InfantPax"));

		var TotPassengers = NumAdults + NumChi + NumInfants;

		if(NumInfants > NumAdults)
		{
			alert('Il numero di bambini sotto i due (2) anni non puo superare il numero di passeggeri adulti.');
			return false;
		}

		if(TotPassengers > 9)
		{
		    //UK Message
			alert('Per una (1) prenotazione e possibile prenotare massimo 9 passeggeri. Per una vantaggiosa tariffa di gruppo chiamare il nostro reparto gruppi al 199 500 101.');
			return false;
		}

	//----------------------------------------------------
	//- If all form validation is OK, submit the form    -
	//----------------------------------------------------

        SetValue("OutDepDate", GetValue("OutDay") + "-" + GetValue("OutMonth") + "-" + GetValue("OutYear"));
        SetValue("RetDepDate", GetValue("RetDay") + "-" + GetValue("RetMonth") + "-" + GetValue("RetYear"));
        
        SetValue("OutArrAir_Temp", GetValue("OutArrAir"));
        SetValue("RetDepAir_Temp", GetValue("RetDepAir"));
        SetValue("OutMonth_Temp", GetValue("OutMonth"));
        SetValue("RetMonth_Temp", GetValue("RetMonth"));

	//---------------------------------------------------------
	// Build a parameterised URL from the form data.
	// Purpose is to ensure we run the process full-screen,
	// and not locked inside an IFRAME or new browser instance.
	//---------------------------------------------------------
	
	// ------------------
	// Set up the basics:
	// ------------------
	
	var frm				= document.forms['FormSearch'];
	//var builtURL			= "http://test.canadianaffair.ie/Book/Test/Direct/Ie/atopgweb.aspx?";
	//var builtURL			= "http://testairtransat.canadianaffair.com/Book/Test/Direct/It/atopgweb.aspx?";
	//var builtURL			= "http://temporary.canadianaffair.com/Book/Live/Direct/Ie/atopgweb.aspx?";
	var builtURL			= "http://airtransat-it.canadianaffair.com/Book/Live/Direct/It/atopgweb.aspx?";
	
	// ----------------
	// Grab the fields:
	// ----------------
	
	p_hdnRoute			= frm.hdnRoute.value;
	p_SelClass			= frm.SelClass.value;
	p_AtopWebMethod			= frm.AtopWebMethod.value;
	p_AtopWebMode			= frm.AtopWebMode.value;
	p_AtopWebAction			= frm.AtopWebAction.value;
	p_AtopWebState			= frm.AtopWebState.value;
	
	p_OutDepDate			= frm.OutDepDate.value;
	p_RetDepDate			= frm.RetDepDate.value;
	
	if (frm.ReturnFlight.checked) {	p_ReturnFlight = "on"; }
	else { p_ReturnFlight = ""; }	
	
	p_Website			= frm.Website.value;
	p_CarHireDefaultLocation	= frm.CarHireDefaultLocation.value;
	p_Branch			= frm.Branch.value;
	p_Currency			= frm.Currency.value;
	
	p_OutDepAir			= frm.OutDepAir.options[frm.OutDepAir.selectedIndex].value;
	p_OutArrAir			= frm.OutArrAir.options[frm.OutArrAir.selectedIndex].value;
	p_RetDepAir			= frm.RetDepAir.options[frm.RetDepAir.selectedIndex].value;
	p_RetArrAir			= frm.RetArrAir.options[frm.RetArrAir.selectedIndex].value;

	p_AdultPax			= frm.AdultPax.options[frm.AdultPax.selectedIndex].value;
	p_ChildPax			= frm.ChildPax.options[frm.ChildPax.selectedIndex].value;
	p_InfantPax			= frm.InfantPax.options[frm.InfantPax.selectedIndex].value;

	// --------------------------
	// Construct the parm string:
	// --------------------------

	builtURL += 'hdnRoute=' + escape(p_hdnRoute) + '&';
	builtURL += 'SelClass=' + escape(p_SelClass) + '&';
	builtURL += 'AtopWebMethod=' + escape(p_AtopWebMethod) + '&';
	builtURL += 'AtopWebMode=' + escape(p_AtopWebMode) + '&';
	builtURL += 'AtopWebAction=' + escape(p_AtopWebAction) + '&';
	builtURL += 'AtopWebState=' + escape(p_AtopWebState) + '&';
	
	builtURL += 'OutDepDate=' + escape(p_OutDepDate) + '&';
	builtURL += 'RetDepDate=' + escape(p_RetDepDate) + '&';
	
	builtURL += 'ReturnFlight=' + escape(p_ReturnFlight) + '&';
	
	builtURL += 'Website=' + escape(p_Website) + '&';
	builtURL += 'CarHireDefaultLocation=' + escape(p_CarHireDefaultLocation) + '&';
	builtURL += 'Branch=' + escape(p_Branch) + '&';
	builtURL += 'Currency=' + escape(p_Currency) + '&';
	
	builtURL += 'OutDepAir=' + escape(p_OutDepAir) + '&';
	builtURL += 'OutArrAir=' + escape(p_OutArrAir) + '&';
	builtURL += 'RetDepAir=' + escape(p_RetDepAir) + '&';
	builtURL += 'RetArrAir=' + escape(p_RetArrAir) + '&';

	builtURL += 'AdultPax=' + escape(p_AdultPax) + '&';
	builtURL += 'ChildPax=' + escape(p_ChildPax) + '&';
	builtURL += 'InfantPax=' + escape(p_InfantPax);
	
	// ---------------------------------------
	// Let's go there now... Break full screen
	// ---------------------------------------
	
	top.location.href = builtURL;

//alert('TESTING: built url is \n\n'+builtURL);

//	document.forms.FormSearch.method = "POST";
//	document.forms.FormSearch.action = "http://test.canadianaffair.ie/Book/Test/Direct/Ie/atopgweb.aspx";
//	document.forms.FormSearch.submit();
//	return true;

//qqq
}
