/**
 * @category  Application
 * @package   reisen.de
 * @author    Unister GmbH <teamleitung-dev@unister-gmbh.de>
 * @version   $Id: flight.js 8767 2010-07-01 11:23:44Z volker_andres $
 * @copyright Copyright (c) 2006-2008, Unister GmbH
 * @license   this code is property of company Unister GmbH and unterlays internal rules of company.
 * @link      http://www.reisen.de
 */

(function($){

    $.flight = {
        itinerariesCounter : 0,

        maxPax : 9,

        airlineCode : 0,

        airlines : {
            codes : ["AA", "AB", "AC", "AF", "AH", "AI", "AQ", "AR", "AS", "AT", "AV", "AY", "AZ", "A3", "BA", "BD", "BE", "BI", "BR", "BT",
                     "BW", "B2", "CA", "CI", "CM", "CO", "CU", "CX", "CY", "C9", "DE", "DI", "DL", "DM", "EA", "EI", "EK", "ET", "EW", "EY",
                     "FB", "FI", "GA", "GF", "G7", "HF", "HM", "HP", "HR", "HY", "IB", "IC", "IY", "JC", "JK", "JP", "JU", "KE", "KL", "KM",
                     "KU", "K6", "LA", "LB", "LG", "LH", "LO", "LP", "LT", "LX", "LY", "MA", "ME", "MH", "MK", "MP", "MU", "MX", "NH", "NI",
                     "NW", "N6", "OA", "OK", "OL", "OM", "OS", "OU", "OV", "OZ", "PS", "PZ", "QF", "QR", "RG", "RK", "RO", "SA", "SK", "SN",
                     "SQ", "SU", "SV", "SW", "S4", "S7", "TA", "TE", "TG", "TK", "TP", "TU", "UA", "UL", "UN", "US", "UY", "VG", "VH", "VN",
                     "VP", "VX", "XQ", "Z6", "6A", "6N", "9U", "9W", "9Y"],
            "AA" : "American Airlines Inc",
            "AB" : "Air Berlin",
            "AC" : "Air Canada",
            "AF" : "Air France",
            "AH" : "Air Algerie",
            "AI" : "Air India",
            "AQ" : "Aloha Airline",
            "AR" : "Aerolineas Argentinas",
            "AS" : "Alaska Airlines Inc",
            "AT" : "Royal Air Maroc",
            "AV" : "Aerovias Nacionales De Colombia Sa",
            "AY" : "Finn Arlines",
            "AZ" : "Alitalia",
            "A3" : "Aegean Airlines",
            "BA" : "British Airways",
            "BD" : "BMI British Midland",
            "BE" : "British European",
            "BI" : "Royal Brunei Airlines",
            "BR" : "Eva Airways",
            "BT" : "Air Baltic",
            "BW" : "BWIA West Indies Airways",
            "B2" : "Belavia",
            "CA" : "Air China",
            "CI" : "China Airline",
            "CM" : "Copa Airlines",
            "CO" : "Continental Airlines Inc",
            "CU" : "Consolidada Cubana De Avia",
            "CX" : "Cathay Pacific Airways Ltd",
            "CY" : "Cyprus Airways Ltd",
            "C9" : "Cirrus Airlines",
            "DE" : "Condor Flugdienst Gmbh",
            "DI" : "Deutsche BA",
            "DL" : "Delta Air Lines Inc",
            "DM" : "Maersk Air",
            "EA" : "European Regions Airlines",
            "EI" : "Aer Lingus Teoranta Aerlinte Eirean",
            "EK" : "Emirates Airlines",
            "ET" : "Ethiopian Airlines S C",
            "EW" : "Eurowings",
            "EY" : "Etihad Airways",
            "FB" : "Guardair",
            "FI" : "Icelandair",
            "GA" : "Garuda",
            "GF" : "Gulf Air",
            "G7" : "Gandalf Airlines",
            "HF" : "Hapag Lloyd",
            "HM" : "Air Mahe/Inter Island Airways",
            "HP" : "America West",
            "HR" : "Hahn Air",
            "HY" : "Uzbekistan Airways",
            "IB" : "Iberia Airlines",
            "IC" : "Indian Airlines",
            "IN" : "Mat Macedonia",
            "IY" : "Yemen Airways Corporation",
            "JC" : "JAL Express",
            "JK" : "Spanair",
            "JP" : "Adria Airways",
            "JU" : "Yugoslav",
            "KE" : "Korean Air Lines Inc",
            "KL" : "Klm Royal Dutch Airlines",
            "KM" : "Air Malta",
            "KU" : "Kuwait Airways Corporation",
            "K6" : "Khalifa Airways",
            "LA" : "Lan-Linea Aerea Nacional-Chile Sa",
            "LB" : "Boliviano",
            "LG" : "Luxair",
            "LH" : "Lufthansa",
            "LO" : "Lot-Polish",
            "LP" : "LanPeru",
            "LT" : "Lufttransport Uternehmen",
            "LX" : "Swiss",
            "LY" : "El Al Israel Airlines Limited",
            "MA" : "Malev Hungarian Airlines",
            "ME" : "Middle East Airlines Airliban",
            "MH" : "Malaysia Airlines",
            "MK" : "Air Mauritius",
            "MP" : "Martinair",
            "MU" : "China Eastern",
            "MX" : "Mexicana",
            "NH" : "All Nippon Airways Co Ltd",
            "NI" : "Portugalia",
            "NW" : "Northwest Airlines",
            "NZ" : "New Zealand",
            "N6" : "Aero Continente",
            "OA" : "Olympic Airways",
            "OK" : "Czech Airline",
            "OL" : "Ostfriesische Lufttransport Gmbh",
            "OM" : "Miat Mongolia",
            "OS" : "Austrian Airlines",
            "OU" : "Croatia Airlines",
            "OV" : "Estonian Air",
            "OZ" : "Asiana Air",
            "PS" : "Ukraine International Airlines",
            "PZ" : "Transportes Aereos Del Mercosur",
            "QF" : "Qantas Airways Ltd",
            "QR" : "Qatar Airways",
            "RG" : "Varig",
            "RK" : "Air Afrique",
            "RO" : "Tarom",
            "SA" : "South African Airways",
            "SK" : "Scandinavian Airlines System",
            "SN" : "SN Brussels Airlines",
            "SQ" : "Singapore Airlines",
            "SU" : "Aeroflot Russian Airlines",
            "SV" : "Saudi Arabian Airlines",
            "SW" : "Air Namibia",
            "S4" : "Sata International",
            "S7" : "Siberia Airlines",
            "TA" : "Taca International Airlines",
            "TE" : "Lithuanian Airlines",
            "TG" : "Thai Airways International Ltd",
            "TK" : "Turk Hava Yollari",
            "TP" : "Air Portugal",
            "TU" : "Tunis Air",
            "UA" : "United Airlines",
            "UL" : "Sri Lankan Airlines",
            "UN" : "Transaero",
            "US" : "US Airways",
            "UY" : "Cameroon Airlines",
            "VG" : "VLM Airlines",
            "VH" : "Aeropostal Alas De Venezue",
            "VN" : "Vietnam Airlines",
            "VP" : "Vasp Brazilian Airlines",
            "VX" : "Aces",
            "XQ" : "SunExpress",
            "Z6" : "Dnieproavia Joint Stock Aviation Company",
            "6A" : "Aviacsa-Consorcio Aviaxsa",
            "6N" : "Trans Travel Airlines",
            "9U" : "Air Moldova",
            "9W" : "Jet Airways (",
            "9Y" : "Air Kazakstan"

        },

        /**
         * change text in preloader
         */
        changeWaitText : function () {
            if (this.airlineCode >= this.airlines.codes.length) {
                this.airlineCode = 0;
            }

            $('#waitLine1').html("In " + this.itinerariesCounter +" Flügen von über 750 Airlines wird gesucht nach");
            $("#waitLine2").html(this.airlines[this.airlines.codes[this.airlineCode]] + ".");
            this.itinerariesCounter++;
            this.airlineCode++;
        },

        /**
         * view text preloader by send form
         */
        startChangeWaitText : function() {
            setInterval("jQuery.flight.changeWaitText()", 50);
        },

        /**
         * set number of travellers for flight
         */
        setNumPax : function() {
            var adtNum = $('#adultSelector').val();
            var infNum = $('#infantSelector').val();
            var chdNum = $('#childSelector').val();
            if (infNum > adtNum) {
                infNum = adtNum;
            }
            if ((this.maxPax - adtNum) < chdNum) {
                chdNum = this.maxPax - adtNum;
            }
            var infantSelected  = $('#infantSelector').val();
            var infantSelector = $('#infantSelector').empty();

            var childSelected = $('#childSelector').val();
            var childSelector = $('#childSelector').empty();

            ibeForm.addOption(infantSelector, new Option('keine', '', true, true));
            for(var x=1;x<=adtNum;x++) {
                if(x==1) { val=' Kleinkind'; } else { val=' Kleinkinder'; }
                ibeForm.addOption(infantSelector, new Option(x+val, x, false, false));
            }
            if (infantSelected < adtNum) {
                $('#infantSelector option[value="'+ infantSelected +'"]').attr('selected', 'selected');
            } else {
                $('#infantSelector option[value="'+ adtNum +'"]').attr('selected', 'selected');
            }

            chdMax = this.maxPax - adtNum;

            ibeForm.addOption(childSelector, new Option('keine', '', true, true));
            for(x=1;x<=chdMax;x++) {
                if(x==1) { val=' Kind'; }else { val=' Kinder'; }
                ibeForm.addOption(childSelector ,new Option(x+val, x, false, false));
            }

            if (childSelected < chdMax) {
                $('#childSelector option[value="'+ childSelected +'"]').attr('selected', 'selected');
            } else {
                $('#childSelector option:last').attr('selected', 'selected');
            }
        },

        /**
         * disable ReturnDate fields if route oneway
         * @param {Object} parentForm
         */
        disableReturnDate : function(parentForm) {
            $(parentForm).find(".cal").not('.first').attr('disabled', 'disabled');
            $(parentForm).find(".cal").not('.first').datepicker("disable");
            if ($('#sFlightInput_returnDatetime').length > 0) {
                $('#sFlightInput_returnDatetime').attr('disabled', 'disabled');
            }
            if ($('#sFlightInput_returnTimeRange').length > 0) {
                $('#sFlightInput_returnTimeRange').attr('disabled', 'disabled');
            }
        },

        /**
         * enable ReturnDate fields if route returnway
         * @param {Object} parentForm
         */

        enableReturnDate : function(parentForm) {

            $(parentForm).find(".cal").not('.first').removeAttr('disabled');
            $(parentForm).find(".cal").not('.first').datepicker("enable");
            if ($('#sFlightInput_returnDatetime').length > 0) {
                $('#sFlightInput_returnDatetime').removeAttr('disabled');
            }
            if ($('#sFlightInput_returnTimeRange').length > 0) {
                $('#sFlightInput_returnTimeRange').removeAttr('disabled');
            }
        }
    }

})(jQuery);

