jQuery(document).ready(function () {
    var $ = jQuery;

    var _PICKUPDATE = $("#PICKUPDATE");
    var _HOUR = $("#HOUR");
    var _MINUTE = $("#MINUTE");
    var _CITY = $("#CITY");
    var _ZIP = $("#ZIP");
    var _STREET = $("#STREET");
    var _HOUSENUMBER = $("#HOUSENUMBER");
    var _ADDADDRESS = $("#ADDADDRESS");
    var _ADD1ZIP = $("#ADD1ZIP");
    var _ADD1STREET = $("#ADD1STREET");
    var _ADD1HOUSENUMBER = $("#ADD1HOUSENUMBER");
    var _ADD2ZIP = $("#ADD2ZIP");
    var _ADD2STREET = $("#ADD2STREET");
    var _ADD2HOUSENUMBER = $("#ADD2HOUSENUMBER");
    var _ADD3ZIP = $("#ADD3ZIP");
    var _ADD3STREET = $("#ADD3STREET");
    var _ADD3HOUSENUMBER = $("#ADD3HOUSENUMBER");
    var _PASSENGER = $("#PASSENGER");
    var _SUITCASE = $("#SUITCASE");
    var _HANDLUGGAGE = $("#HANDLUGGAGE");
    var _CHILDSEAT = $("#CHILDSEAT");
    var _BOOSTERSEAT = $("#BOOSTERSEAT");
    var _CARRYCOT = $("#CARRYCOT");
    var _PAYMENT = $("#PAYMENT");
    var _SALUTATION = $("#SALUTATION");
    var _NAME = $("#NAME");
    var _SURNAME = $("#SURNAME");
    var _EMAIL = $("#EMAIL");
    var _PHONE = $("#PHONE");
    var _NOTE = $("#NOTE");
    var _WITHRETURN = $('input[name=WITHRETURN]');
    var _PICKUPDATERETURN = $("#PICKUPDATERETURN");
    var _HOURRETURN = $("#HOURRETURN");
    var _MINUTERETURN = $("#MINUTERETURN");
    var _DEPARTURE = $("#DEPARTURE");
    var _FLIGHTNUMBER = $("#FLIGHTNUMBER");
    var _ORDER = $('#ORDER');
    var _ORDERX = $('#ORDERX');
    var _PRICE = $('#PRICE');
    var _PRICERETURN = $('#PRICERETURN');
    var _TOTAL = $('#TOTAL');
    var _KM = $('#KM');
    var _MIN = $('#MIN');
    var _ADDADDRESS_OPT = $('.ADDADDRESS_OPT');
    var _ADDADDRESS1 = $('#ADDADDRESS1');
    var _ADDADDRESS2 = $('#ADDADDRESS2');
    var _ADDADDRESS3 = $('#ADDADDRESS3');
    var _CHILD = $('input[name=child]');
    var _CHILDGROUP = $('#CHILDGROUP');
    var _NAMESURNAME = $('#NAME, #SURNAME');
    var _RETURNFIELDS = $('#RETURNFIELDS');
    _PICKUPDATE.datepicker({
        prevText: '<i class="fa fa-chevron-left"></i>',
        nextText: '<i class="fa fa-chevron-right"></i>',
        prevStatus: "",
        prevJumpText: "<<",
        prevJumpStatus: "",
        nextStatus: "",
        nextJumpText: ">>",
        nextJumpStatus: "",
        currentText: "heute",
        currentStatus: "",
        todayText: "heute",
        todayStatus: "",
        clearText: "-",
        clearStatus: "",
        closeText: "schließen",
        closeStatus: "",
        monthNames: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
        monthNamesShort: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
        dayNames: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
        dayNamesShort: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
        dayNamesMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
        showMonthAfterYear: false,
        dateFormat: "dd.mm.yy",
        firstDay: 1,
        minDate: 0,
        maxDate: "+12M",
        showWeek: true,
        beforeShow: function(el, inst) {
            $('.ui-datepicker').addClass('notranslate');
        }
    });
    _PICKUPDATERETURN.datepicker({
        prevText: '<i class="fa fa-chevron-left"></i>',
        nextText: '<i class="fa fa-chevron-right"></i>',
        prevStatus: "",
        prevJumpText: "<<",
        prevJumpStatus: "",
        nextStatus: "",
        nextJumpText: ">>",
        nextJumpStatus: "",
        currentText: "heute",
        currentStatus: "",
        todayText: "heute",
        todayStatus: "",
        clearText: "-",
        clearStatus: "",
        closeText: "schließen",
        closeStatus: "",
        monthNames: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
        monthNamesShort: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
        dayNames: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
        dayNamesShort: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
        dayNamesMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
        showMonthAfterYear: false,
        dateFormat: "dd.mm.yy",
        firstDay: 1,
        minDate: 0,
        maxDate: "+12M",
        showWeek: true,
        beforeShow: function(el, inst) {
            $('.ui-datepicker').addClass('notranslate');
        }
    });
//    function ROOT() {
//        var getUrl = window.location;
//        var baseUrl = getUrl.protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
//        return baseUrl;
//
//    }
    document.getElementById("orderform").reset();
//    function ROOT() {
//        var scripts = document.getElementsByTagName("script");
//        var src = scripts[scripts.length - 1].src;
//        var the_arr = src.split('/');
//        the_arr.pop();
//        the_arr.pop();
//        the_arr.pop();
//        return (the_arr.join('/'));
//    }
//    var data = 'MODEL=GET_CITY_SELECT';
//    $.ajax({
//        type: "POST",
//        url: "/app/php/API.php",
//        data: data,
////	    dataType: "json",
//        cache: false,
//        success: function (result)
//        {
//            _CITY.html(result);
//        }
//    });
    $.fn.info = function (id, msg) {
        const Toast = Swal.mixin({
            toast: true,
            position: 'center',
            showConfirmButton: false,
            timer: 7000,
//            timerProgressBar: true,
            customClass: {
                container: 'fehler1'
            }
        });
        Toast.fire({
            icon: 'warning',
            title: '' + msg + '',
        })
        ERR(id);
        _ORDER.show();
        _ORDERX.hide();
//        Swal.queue([{
//                title: 'ACHTUNG!',
//                confirmButtonText: 'OK',
//                text: '' + msg + '',
//                icon: 'warning',
//                //                showLoaderOnConfirm: true,
//                preConfirm: () => {
//                    ERR(id);
//                    _ORDER.show();
//                    _ORDERX.hide();
//                }
//            }])
//        swal({
//            title: "ACHTUNG!",
//            text: "" + msg + "",
//            type: "warning",
//            confirmButtonColor: "#DD6B55",
//            confirmButtonText: "OK",
//            closeOnConfirm: true,
//        },
//                function (isConfirm) {
//                    if (isConfirm) {
//                        ERR(id);
//                        _ORDER.show();
//                        _ORDERX.hide();
//                    }
//                });
        return false;
    };
    $.fn.info_block = function (msg) {
        const Toast = Swal.mixin({
            toast: true,
            position: 'center',
            showConfirmButton: false,
            timer: 7000,
//            timerProgressBar: true,
            customClass: {
                container: 'fehler1'
            }
        });
        Toast.fire({
            icon: 'warning',
            title: '' + msg + '',
        })
//
//        swal({
//            title: "ACHTUNG!",
//            text: "" + msg + "",
//            type: "warning",
//            confirmButtonColor: "#DD6B55",
//            confirmButtonText: "OK",
//            closeOnConfirm: true,
//        },
//                function (isConfirm) {
//                    if (isConfirm) {
//                    }
//                });
        return false;
    };
    $.fn.info_block_stop_4 = function (msg) {
        const Toast = Swal.mixin({
            toast: true,
            position: 'center',
            showConfirmButton: true,
//            timer: 7000,
//            timerProgressBar: true,
            customClass: {
                container: 'fehler1'
            }
        });
        Toast.fire({
            icon: 'warning',
            title: '' + msg + '',
        })
        _ORDER.show();
        _ORDERX.hide();
        ERR('HOUR');
        ERR('MINUTE');
//
//        swal({
//            title: "ACHTUNG!",
//            text: "" + msg + "",
//            type: "warning",
//            confirmButtonColor: "#DD6B55",
//            confirmButtonText: "OK",
//            closeOnConfirm: true,
//        },
//                function (isConfirm) {
//                    if (isConfirm) {
//                        _ORDER.show();
//                        _ORDERX.hide();
//                        ERR('HOUR');
//                        ERR('MINUTE');
//                    }
//                });
        return false;
    };
    function resetADD1() {
        _ADD1ZIP.val('');
        _ADD1STREET.val('');
        _ADD1HOUSENUMBER.val('');
    }
    function resetADD2() {
        _ADD2ZIP.val('');
        _ADD2STREET.val('');
        _ADD2HOUSENUMBER.val('');
    }
    function resetADD3() {
        _ADD3ZIP.val('');
        _ADD3STREET.val('');
        _ADD3HOUSENUMBER.val('');
    }
    function ERR(id) {
        $('#' + id).animatescroll({
            scrollSpeed: 2000,
            padding: 200,
            easing: 'easeOutQuad',
            onScrollEnd: function () {
                $("label[id=E_" + id + "]").addClass('fehler');
                setTimeout(function () {
                    $("label[id=E_" + id + "]").removeClass('fehler');
                }, 4000);
            }
        });
    }






    $.fn.CALCULATE = function () {
        var WAY;
        if ($("form").data("way") === "zum") {
            WAY = "ZUM";
        } else {
            WAY = "VOM";
        }

        var CITY = _CITY.val();
        var ZIP = _ZIP.val();
        var PASSENGER = _PASSENGER.val();
        var SUITCASE = _SUITCASE.val();
        var HANDLUGGAGE = _HANDLUGGAGE.val();
        var HOUR = _HOUR.val();
        var BOOSTERSEAT = _BOOSTERSEAT.val();
        var CHILDSEAT = _CHILDSEAT.val();
        var CARRYCOT = _CARRYCOT.val();
        var ADDADDRESS = _ADDADDRESS.val();
        var PAYMENT = _PAYMENT.val();
        var ADD1ZIP = _ADD1ZIP.val();
        var ADD2ZIP = _ADD2ZIP.val();
        var ADD3ZIP = _ADD3ZIP.val();
        var WITHRETURN = _WITHRETURN.prop("checked") == true ? "1" : "0";
        var HOURRETURN = _HOURRETURN.val();
        var dataString = 'MODEL=GET_PRICE&WAY=' + WAY + '&CITY_ID=' + CITY + '&ZIP_ID=' + ZIP + '&PASSENGER=' + PASSENGER + '&SUITCASE=' + SUITCASE + '&HANDLUGGAGE=' + HANDLUGGAGE + '&HOUR=' + HOUR + '&BOOSTERSEAT=' + BOOSTERSEAT + '&CHILDSEAT=' + CHILDSEAT + '&CARRYCOT=' + CARRYCOT + '&ADDADDRESS=' + ADDADDRESS + '&PAYMENT=' + PAYMENT + '&ADD1ZIP=' + ADD1ZIP + '&ADD2ZIP=' + ADD2ZIP + '&ADD3ZIP=' + ADD3ZIP + '&WITHRETURN=' + WITHRETURN + '&HOURRETURN=' + HOURRETURN;
//    console.log(dataString);
        //alert(dataString);
        $.ajax({
            type: "POST",
            url: "/app/php/API.php",
            data: dataString,
            dataType: "json",
            cache: false,
            success: function (html) {
                if (html['price'] !== '') {
                    var return_price = html['pricereturn'];
                    var total = (+html['price'] + +return_price);
                    var price = parseFloat(html['price']).toFixed(2).replace(".", ",");
                    return_price = parseFloat(return_price).toFixed(2).replace(".", ",");
                    total = parseFloat(total).toFixed(2).replace(".", ",");
                    _PRICE.html(price);
                    _PRICERETURN.html(return_price);
                    _TOTAL.html(total);
                } else {
                    _PRICE.html('0,00');
                    _PRICERETURN.html('0,00');
                    _TOTAL.html('0,00');
                }
//		    if (html[0] !== '') {
//
//			var rueck_price = html[1];
//			var gesamt = (+html[0] + +html[1]);
//			var price = parseFloat(html[0]).toFixed(2).replace(".", ",");
//			rueck_price = parseFloat(rueck_price).toFixed(2).replace(".", ",");
//			gesamt = parseFloat(gesamt).toFixed(2).replace(".", ",");
//			_PRICE.html(price);
//			_PRICERETURN.html(rueck_price);
//			$("#GESAMT").html(gesamt);
//
//		    } else {
//			_PRICE.html('0,00');
//			_PRICERETURN.html('0,00');
//			$("#PRICERETURNSTRIKE").html('0,00');
//			$("#GESAMT").html('0,00');
//		    }
            }
        });
    };
    $.fn.INSERT = function () {
        var PICKUPDATE = _PICKUPDATE.val();
        var HOUR = _HOUR.val();
        var MINUTE = _MINUTE.val();
        var CITY = _CITY.val();
        var ZIP = _ZIP.val();
        var STREET = _STREET.val();
        var HOUSENUMBER = _HOUSENUMBER.val();
        var PASSENGER = _PASSENGER.val();
        var SUITCASE = _SUITCASE.val();
        var HANDLUGGAGE = _HANDLUGGAGE.val();
        var BOOSTERSEAT = _BOOSTERSEAT.val();
        var CHILDSEAT = _CHILDSEAT.val();
        var CARRYCOT = _CARRYCOT.val();
        var ADDADDRESS = _ADDADDRESS.val();
        var ADD1ZIP = _ADD1ZIP.val();
        var ADD1STREET = _ADD1STREET.val();
        var ADD1HOUSENUMBER = _ADD1HOUSENUMBER.val();
        var ADD2ZIP = _ADD2ZIP.val();
        var ADD2STREET = _ADD2STREET.val();
        var ADD2HOUSENUMBER = _ADD2HOUSENUMBER.val();
        var ADD3ZIP = _ADD3ZIP.val();
        var ADD3STREET = _ADD3STREET.val();
        var ADD3HOUSENUMBER = _ADD3HOUSENUMBER.val();
        var PAYMENT = _PAYMENT.val();
        var NOTE = _NOTE.val();
        var SALUTATION = _SALUTATION.val();
        var NAME = _NAME.val();
        var SURNAME = _SURNAME.val();
        var input = document.querySelector("#PHONE");
        var iti = window.intlTelInputGlobals.getInstance(input);
        var number = iti.getNumber();
        var isValid = iti.isValidNumber();
        if (isValid) {
            var numberType = iti.getNumberType();
            if (numberType === intlTelInputUtils.numberType.MOBILE) {
            } else {
                $().info('PHONE', 'Eine Handynummer ist erforderlich.');
                _ORDER.show();
                _ORDERX.hide();
                return false;
            }
        } else {
            $().info('PHONE', 'Ungültige Telefonnummer.');
            _ORDER.show();
            _ORDERX.hide();
            return false;
        }
        _PHONE.val(number);
        var PHONE = _PHONE.val();
        PHONE = encodeURIComponent(PHONE);
        var EMAIL = _EMAIL.val();
        var WITHRETURN = _WITHRETURN.prop("checked") == true ? "1" : "0";
        var PICKUPDATERETURN = _PICKUPDATERETURN.val();
        var HOURRETURN = _HOURRETURN.val();
        var MINUTERETURN = _MINUTERETURN.val();
        var DEPARTURE = _DEPARTURE.val();
        var FLIGHTNUMBER = _FLIGHTNUMBER.val();
        var KM = _KM.text();
        var MIN = _MIN.text();
        var WAY;
        var MODEL;

        if ($("form").data("way") === "zum") {
            WAY = "ZUM";
            MODEL = "INSERT_ZUM";
        } else {
            WAY = "VOM";
            MODEL = "INSERT_VOM";
        }
        PICKUPDATE = moment(PICKUPDATE, "DD.MM.YYYY").toDate();
        PICKUPDATE = moment(PICKUPDATE).format('YYYY-MM-DD');
        PICKUPDATERETURN = moment(PICKUPDATERETURN, "DD.MM.YYYY").toDate();
        PICKUPDATERETURN = moment(PICKUPDATERETURN).format('YYYY-MM-DD');
        var dataString = 'MODEL=' + MODEL + '&WAY=' + WAY + '&PICKUPDATE=' + PICKUPDATE + '&HOUR=' + HOUR + '&MINUTE=' + MINUTE + '&CITY_ID=' + CITY + '&ZIP_ID=' + ZIP + '&STREET_ID=' + STREET + '&HOUSENUMBER=' + HOUSENUMBER + '&PASSENGER=' + PASSENGER + '&SUITCASE=' + SUITCASE + '&BOOSTERSEAT=' + BOOSTERSEAT + '&CARRYCOT=' + CARRYCOT + '&ADDADDRESS=' + ADDADDRESS + '&ADD1ZIP=' + ADD1ZIP + '&ADD1STREET=' + ADD1STREET + '&ADD1HOUSENUMBER=' + ADD1HOUSENUMBER + '&ADD2ZIP=' + ADD2ZIP + '&ADD2STREET=' + ADD2STREET + '&ADD2HOUSENUMBER=' + ADD2HOUSENUMBER + '&ADD3ZIP=' + ADD3ZIP + '&ADD3STREET=' + ADD3STREET + '&ADD3HOUSENUMBER=' + ADD3HOUSENUMBER + '&PAYMENT=' + PAYMENT + '&NOTE=' + NOTE + '&SALUTATION=' + SALUTATION + '&NAME=' + NAME + '&SURNAME=' + SURNAME + '&PHONE=' + PHONE + '&EMAIL=' + EMAIL + '&WITHRETURN=' + WITHRETURN + '&PICKUPDATERETURN=' + PICKUPDATERETURN + '&HOURRETURN=' + HOURRETURN + '&MINUTERETURN=' + MINUTERETURN + '&DEPARTURE=' + DEPARTURE + '&FLIGHTNUMBER=' + FLIGHTNUMBER + '&CHILDSEAT=' + CHILDSEAT + '&KM=' + KM + '&MIN=' + MIN + '&HANDLUGGAGE=' + HANDLUGGAGE;
        $.ajax
                ({
                    type: "POST",
                    url: "/app/php/API.php",
                    data: dataString,
                    dataType: 'json',
                    cache: false,
                    success: function (html)
                    {

                        if (html.STOP === '1') {
                            if (html.MODEL === 'STOP') {
                                $().info_block_stop_4('Für kurzfristige Bestellungen rufen Sie uns unter ' + html.PHONE + ' an. Nächste mögliche Fahrt ' + html.DATE + ' ab ' + html.TIME + ' Uhr');
                                return false;
                            }
                            if (html.MODEL === 'STOP_TIME') {
                                $().info_block_stop_4('Für diesen Zeit (' + HOUR + ':' + MINUTE + ') sind alle Autos beschäftigt,versuchen 10-15 Minuten früher oder später.');
                                return false;
                            }
                            if (html.MODEL === 'STOP_HOUR') {
                                $().info_block_stop_4('Für diesen Zeit (' + HOUR + ':00 - ' + HOUR + ':55) sind alle Autos beschäftigt.');
                                return false;
                            }
                            if (html.MODEL === 'STOP_DAY') {
                                $().info_block('Für diesen Tag (' + PICKUPDATE + ') sind alle Autos beschäftigt.');
                                _ORDER.show();
                                _ORDERX.hide();
                                ERR('PICKUPDATE');
                                return false;
                            }


                        } else if (html.STOP === 'ERROR') {
                            const Toast = Swal.mixin({
                                toast: true,
                                position: 'center',
                                showConfirmButton: true,
//            timer: 7000,
//            timerProgressBar: true,
                                customClass: {
                                    container: 'fehler1'
                                }
                            });
                            Toast.fire({
                                icon: 'error',
                                title: 'Ein Fehler ist aufgetreten, das Senden der E-Mail-Bestätigung ist fehlgeschlagen. Bitte rufen Sie uns unter ' + html.PHONE + ' an',
                            })
                            _ORDER.show();
                            _ORDERX.hide();

                            return false;
                        } else if (html.STOP === 'OK') {

                            if (WITHRETURN == '1') {
                                window.location = './vielen-dank-2.php';
                            } else {
                                window.location = './vielen-dank.php';
                            }

                            return false;
                        } else {
                            const Toast = Swal.mixin({
                                toast: true,
                                position: 'center',
                                showConfirmButton: true,
//            timer: 7000,
//            timerProgressBar: true,
                                customClass: {
                                    container: 'fehler1'
                                }
                            });
                            Toast.fire({
                                icon: 'error',
                                title: 'Ein Fehler ist aufgetreten. Bitte rufen Sie uns unter ' + html.PHONE + ' an',
                            })
                            _ORDER.show();
                            _ORDERX.hide();
                        }

                    }
                });
    };
    $.fn.validation = function () {
        var WAY;

        if ($("form").data("way") === "zum") {
            WAY = "ZUM";
        } else {
            WAY = "VOM";
        }

        if (WAY == 'VOM') {
            if (_DEPARTURE.val() === '') {
                $().info('DEPARTURE', 'Bitte Abflugort eingeben.');
                return false;
            }
            if (_FLIGHTNUMBER.val() === '') {
                $().info('FLIGHTNUMBER', 'Bitte Flugnummer auswählen.');
                return false;
            }
        }
        if (_PICKUPDATE.val() === '') {
            $().info('PICKUPDATE', 'Bitte Abholdatum auswählen.');
            return false;
        }
        if (_HOUR.val() === '') {
            $().info('HOUR', 'Bitte Stunde auswählen.');
            return false;
        }
        if (_MINUTE.val() === '') {
            $().info('MINUTE', 'Bitte Minute auswählen.');
            return false;
        }
        if (_ZIP.val() === '') {
            $().info('ZIP', 'Bitte Postleitzahl auswählen.');
            return false;
        }
        if (_STREET.val() === '') {
            $().info('STREET', 'Bitte Strasse auswählen.');
            return false;
        }
        if (_HOUSENUMBER.val() === '') {
            $().info('HOUSENUMBER', 'Bitte Hausnummer eingeben.');
            return false;
        }

        if (_NAME.val() === '') {
            $().info('NAME', 'Bitte Vorname eingeben.');
            return false;
        }
        if (_SURNAME.val() === '') {
            $().info('SURNAME', 'Bitte Nachname eingeben.');
            return false;
        }
        if (_EMAIL.val() === '') {
            $().info('EMAIL', 'Bitte E-Mail eingeben.');
            return false;
        }
        var emailvalid = _EMAIL.val();
        var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/igm;
        if (!re.test(emailvalid)) {
            $().info('EMAIL', 'Ungültige E-Mail Adresse.');
            return false;
        }
        if (_PHONE.val() === '') {
            $().info('PHONE', 'Bitte Telefonnummer eingeben.');
            return false;
        }
        if (_ADDADDRESS.val() >= 1) {
            if (_ADD1ZIP.val() === '') {
                $().info('ADD1ZIP', 'Bitte Postleitzahl auswählen. (Zusatz-Ziel 1)');
                return false;
            }
            if (_ADD1STREET.val() === '') {
                $().info('ADD1STREET', 'Bitte Strasse auswählen. (Zusatz-Ziel 1)');
                return false;
            }
            if (_ADD1HOUSENUMBER.val() === '') {
                $().info('ADD1HOUSENUMBER', 'Bitte Hausnummer eingeben. (Zusatz-Ziel 1)');
                return false;
            }
        }
        if (_ADDADDRESS.val() >= 2) {
            if (_ADD2ZIP.val() === '') {
                $().info('ADD2ZIP', 'Bitte Postleitzahl auswählen. (Zusatz-Ziel 2)');
                return false;
            }
            if (_ADD2STREET.val() === '') {
                $().info('ADD2STREET', 'Bitte Strasse auswählen. (Zusatz-Ziel 2)');
                return false;
            }
            if (_ADD2HOUSENUMBER.val() === '') {
                $().info('ADD2HOUSENUMBER', 'Bitte Hausnummer eingeben. (Zusatz-Ziel 2)');
                return false;
            }
        }
        if (_ADDADDRESS.val() === 3) {
            if (_ADD3ZIP.val() === '') {
                $().info('ADD3ZIP', 'Bitte Postleitzahl auswählen. (Zusatz-Ziel 3)');
                return false;
            }
            if (_ADD3STREET.val() === '') {
                $().info('ADD3STREET', 'Bitte Strasse auswählen. (Zusatz-Ziel 3)');
                return false;
            }
            if (_ADD3HOUSENUMBER.val() === '') {
                $().info('ADD3HOUSENUMBER', 'Bitte Hausnummer eingeben. (Zusatz-Ziel 3)');
                return false;
            }
        }
        var WITHRETURN = _WITHRETURN.prop("checked") == true ? "1" : "0";
        if (WITHRETURN === '1') {
            if (_PICKUPDATERETURN.val() === '') {
                $().info('PICKUPDATERETURN', 'Bitte Abholdatum auswählen.(bei Rückfahrt)');
                return false;
            }
            if (_HOURRETURN.val() === '') {
                $().info('HOURRETURN', 'Bitte Stunde auswählen.(bei Rückfahrt)');
                return false;
            }
            if (_MINUTERETURN.val() === '') {
                $().info('MINUTERETURN', 'Bitte Minute auswählen.(bei Rückfahrt)');
                return false;
            }
            if (WAY == 'ZUM') {
                if (_DEPARTURE.val() === '') {
                    $().info('DEPARTURE', 'Bitte Abflugort eingeben.(bei Rückfahrt)');
                    return false;
                }
                if (_FLIGHTNUMBER.val() === '') {
                    $().info('FLIGHTNUMBER', 'Bitte Flugnummer auswählen.(bei Rückfahrt)');
                    return false;
                }
            }
        }
        $().INSERT();
    };




    _PICKUPDATE.change(function () {
        $().CALCULATE();
    });
    _HOUR.change(function () {
        $().CALCULATE();
    });
    _MINUTE.change(function () {
    });
    _CITY.change(function () {
        var c = $(this).val();
        if (c != '1') {
            _ADDADDRESS.val('0');
            resetADD1();
            resetADD2();
            resetADD3();
            _ADDADDRESS_OPT.hide(500);
            _ADDADDRESS1.hide(500);
            _ADDADDRESS2.hide(500);
            _ADDADDRESS3.hide(500);
        } else {
            _ADDADDRESS_OPT.show(500);
        }
        _STREET.html('<option value="" selected>Strasse auswählen...</option>');
        var data = 'MODEL=GET_ZIP&CITY_ID=' + $(this).val();
        $.ajax({
            type: "POST",
            url: "/app/php/API.php",
            data: data,
//	    dataType: "json",
            cache: false,
            success: function (result)
            {
                _ZIP.html(result);
                $().CALCULATE();
            }
        });
    });
    _ZIP.change(function () {
        var data = 'MODEL=GET_STREET&ZIP_ID=' + $(this).val();
        $.ajax({
            type: "POST",
            url: "/app/php/API.php",
            data: data,
//	    dataType: "json",
            cache: false,
            success: function (result)
            {
                _STREET.html(result);
                $().CALCULATE();
            }
        });
    });
    _STREET.change(function () {
    });
    _HOUSENUMBER.change(function () {
    });
    _HOUSENUMBER.blur(function () {
    });
    _HOUSENUMBER
            .bind("dragover", false)
            .bind("dragenter", false)
            .bind("drop", function () {
                return false;
            });
    _HOUSENUMBER.on('paste', function () {
        var $el = $(this);
        setTimeout(function () {
            $el.val(function (i, val) {
                return val.replace(/[<>@\]\[\'\=\^\?\´\`(\n)]/g, '')
            })
        })
    });
    _HOUSENUMBER.keypress(function (e) {
        var key = e.keyCode || e.which;
        if (key === 37 || key === 8 || key === 9 || key === 46 || key === 44) {
            return;
        }
        if (key === 39 || key === 222) {
            e.preventDefault();
            return false;
        }
        var regex = new RegExp("^[a-zA-Z0-9 \b\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00df\u002b\u002d\u002f]");
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
        if (regex.test(str)) {
            return true;
        }
        e.preventDefault();
        return false;
    });
    _ADDADDRESS.change(function () {
        var add = $(this).val();
        if (add == '1') {
            _ADDADDRESS1.show(500);
            _ADDADDRESS2.hide(500);
            _ADDADDRESS3.hide(500);
            resetADD2();
            resetADD3();
        } else if (add == '2') {
            _ADDADDRESS1.show(500);
            _ADDADDRESS2.show(500);
            _ADDADDRESS3.hide(500);
            resetADD3();
        } else if (add == '3') {
            _ADDADDRESS1.show(500);
            _ADDADDRESS2.show(500);
            _ADDADDRESS3.show(500);
        } else if (add == '0') {
            _ADDADDRESS1.hide(500);
            _ADDADDRESS2.hide(500);
            _ADDADDRESS3.hide(500);
            resetADD1();
            resetADD2();
            resetADD3();
        }
        $().CALCULATE();
    });
    _ADD1ZIP.change(function () {
        var data = 'MODEL=GET_STREET&ZIP_ID=' + $(this).val();
        $.ajax({
            type: "POST",
            url: "/app/php/API.php",
            data: data,
//	    dataType: "json",
            cache: false,
            success: function (result)
            {
                _ADD1STREET.html(result);
                $().CALCULATE();
            }
        });
    });
    _ADD1STREET.change(function () {
    });
    _ADD1HOUSENUMBER.change(function () {
    });
    _ADD1HOUSENUMBER
            .bind("dragover", false)
            .bind("dragenter", false)
            .bind("drop", function () {
                return false;
            });
    _ADD1HOUSENUMBER.on('paste', function () {
        var $el = $(this);
        setTimeout(function () {
            $el.val(function (i, val) {
                return val.replace(/[<>@\]\[\'\=\^\?\´\`(\n)]/g, '');
            });
        });
    });
    _ADD1HOUSENUMBER.keypress(function (e) {
        var key = e.keyCode || e.which;
        if (key === 37 || key === 8 || key === 9 || key === 46 || key === 44) {
            return;
        }
        if (key === 39 || key === 222) {
            e.preventDefault();
            return false;
        }
        var regex = new RegExp("^[a-zA-Z0-9 \b\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00df\u002b\u002d\u002f]");
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
        if (regex.test(str)) {
            return true;
        }
        e.preventDefault();
        return false;
    });
    _ADD2ZIP.change(function () {
        var data = 'MODEL=GET_STREET&ZIP_ID=' + $(this).val();
        $.ajax({
            type: "POST",
            url: "/app/php/API.php",
            data: data,
//	    dataType: "json",
            cache: false,
            success: function (result)
            {
                _ADD2STREET.html(result);
                $().CALCULATE();
            }
        });
    });
    _ADD2STREET.change(function () {
    });
    _ADD2HOUSENUMBER.change(function () {
    });
    _ADD2HOUSENUMBER
            .bind("dragover", false)
            .bind("dragenter", false)
            .bind("drop", function () {
                return false;
            });
    _ADD2HOUSENUMBER.on('paste', function () {
        var $el = $(this);
        setTimeout(function () {
            $el.val(function (i, val) {
                return val.replace(/[<>@\]\[\'\=\^\?\´\`(\n)]/g, '')
            })
        })
    });
    _ADD2HOUSENUMBER.keypress(function (e) {
        var key = e.keyCode || e.which;
        if (key === 37 || key === 8 || key === 9 || key === 46 || key === 44) {
            return;
        }
        if (key === 39 || key === 222) {
            e.preventDefault();
            return false;
        }
        var regex = new RegExp("^[a-zA-Z0-9 \b\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00df\u002b\u002d\u002f]");
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
        if (regex.test(str)) {
            return true;
        }
        e.preventDefault();
        return false;
    });
    _ADD3ZIP.change(function () {
        var data = 'MODEL=GET_STREET&ZIP_ID=' + $(this).val();
        $.ajax({
            type: "POST",
            url: "/app/php/API.php",
            data: data,
//	    dataType: "json",
            cache: false,
            success: function (result)
            {
                _ADD3STREET.html(result);
                $().CALCULATE();
            }
        });
    });
    _ADD3STREET.change(function () {
    });
    _ADD3HOUSENUMBER.change(function () {
    });
    _ADD3HOUSENUMBER
            .bind("dragover", false)
            .bind("dragenter", false)
            .bind("drop", function () {
                return false;
            });
    _ADD3HOUSENUMBER.on('paste', function () {
        var $el = $(this);
        setTimeout(function () {
            $el.val(function (i, val) {
                return val.replace(/[<>@\]\[\'\=\^\?\´\`(\n)]/g, '')
            })
        })
    });
    _ADD3HOUSENUMBER.keypress(function (e) {
        var key = e.keyCode || e.which;
        if (key === 37 || key === 8 || key === 9 || key === 46 || key === 44) {
            return;
        }
        if (key === 39 || key === 222) {
            e.preventDefault();
            return false;
        }
        var regex = new RegExp("^[a-zA-Z0-9 \b\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00df\u002b\u002d\u002f]");
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
        if (regex.test(str)) {
            return true;
        }
        e.preventDefault();
        return false;
    });
    _PASSENGER.change(function () {
        $().CALCULATE();
    });
    _SUITCASE.change(function () {
        $().CALCULATE();
    });
    _HANDLUGGAGE.change(function () {
        $().CALCULATE();
    });
    _CHILD.change(function () {
        if (_CHILD.prop("checked") == true) {
            _CHILDGROUP.show(500);
        } else {
            _CHILDGROUP.hide(500);
        }
    });
    _BOOSTERSEAT.change(function () {
        $().CALCULATE();
    });
    _CHILDSEAT.change(function () {
        $().CALCULATE();
    });
    _CARRYCOT.change(function () {
        $().CALCULATE();
    });
    _PAYMENT.change(function () {
        $().CALCULATE();
    });
    _NOTE.keypress(function (e) {
        var key = e.keyCode || e.which;
        if (key === 37 || key === 8 || key === 9 || key === 46 || key === 44) {
            return;
        }
        if (key === 39 || key === 222) {
            e.preventDefault();
            return false;
        }
        var regex = new RegExp("^[a-zA-Z0-9 \b\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00df\u002b\u002d\u002f]");
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
        if (regex.test(str)) {
            return true;
        }
        e.preventDefault();
        return false;
    });
    _NOTE.change(function () {
    });
    _NOTE.on('paste', function () {
        var $el = $(this);
        setTimeout(function () {
            $el.val(function (i, val) {
                return val.replace(/[<>@\]\[\'\=\^\?\´\`(\n)]/g, '')
            })
        })
    });
    _NOTE.bind("dragover", false)
            .bind("dragenter", false)
            .bind("drop", function (e) {
                return false;
            });
    _NAMESURNAME.keypress(function (e) {
        var c = String.fromCharCode(e.which);
        var key = e.keyCode || e.which;
        if (key === 37 || key === 8 || key === 9 || key === 46 || key === 44) {
            return;
        }
        if (key === 39 || key === 222) {
            e.preventDefault();
            return false;
        }
        var regex = new RegExp("^[a-zA-Z \b\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00df]");
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
        if (regex.test(str)) {
            return true;
        }
        e.preventDefault();
        return false;
    });
    _SALUTATION.change(function () {
    });
    _NAME.change(function () {
    });
    _NAME.blur(function () {
    });
    _SURNAME.change(function () {
    });
    _SURNAME.blur(function () {
    });
    _EMAIL.keyup(function () {
        this.value = this.value.toLowerCase();
    });
    _EMAIL.blur(function () {
    });
    _PHONE.blur(function () {
        var input = document.querySelector("#PHONE");
        var iti = window.intlTelInputGlobals.getInstance(input);
        var number = iti.getNumber();
    });
    _PHONE.keypress(function (e) {
        var regex = new RegExp("^[0-9 \u002b]");
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
        if (regex.test(str)) {
            return true;
        }
        e.preventDefault();
        return false;
    });
    _EMAIL.keypress(function (e) {
        var regex = /^\S*$/;
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
        if (regex.test(str)) {
            return true;
        }
        e.preventDefault();
        return false;
    });
    _WITHRETURN.change(function () {
        if (_WITHRETURN.prop("checked") == true) {
            _RETURNFIELDS.show(500);
        } else {
            _RETURNFIELDS.hide(500);
        }
        $().CALCULATE();
    });
    _PICKUPDATERETURN.change(function () {
    });
    _HOURRETURN.change(function () {
        $().CALCULATE();
    });
    _MINUTERETURN.change(function () {
        $().CALCULATE();
    });
    _DEPARTURE.autocomplete({
        minLength: 1,
        source: function (request, response) {
            var data = 'MODEL=GET_DEPARTURE&AUTO_DEPARTURE=' + _DEPARTURE.val();
            $.ajax({
                type: "POST",
                url: "/app/php/API.php",
                data: data,
                dataType: "json",
                success: function (data) {
                    response(data);
                }
            });
        },
        select: function (event, ui) {
            // document.getElementById("zum_flugnummer_right_insert").textContent = ui.item.value;
        }
    });
    _DEPARTURE.change(function () {
    });
    _FLIGHTNUMBER.keyup(function () {
        this.value = this.value.toUpperCase();
        if (this.value.match(/[^a-zA-Z0-9]/g)) {
            this.value = this.value.replace(/[^a-zA-Z0-9]/g, '');
        }
    });
    _FLIGHTNUMBER
            .bind("dragover", false)
            .bind("dragenter", false)
            .bind("drop", function () {
                return false;
            });
    _FLIGHTNUMBER.autocomplete({
        minLength: 1,
        source: function (request, response) {
            var data = 'MODEL=GET_FLIGHT_NUMBER&AUTO_FLIGHTNUMBER=' + _FLIGHTNUMBER.val();
            $.ajax({
                type: "POST",
                url: "/app/php/API.php",
                data: data,
                dataType: "json",
                success: function (data) {
                    response(data);
                }
            });
        },
        select: function (event, ui) {
            // document.getElementById("zum_flugnummer_right_insert").textContent = ui.item.value;
        }
    });
    _FLIGHTNUMBER.change(function () {
    });
    _ORDER.click(function () {
        $().CALCULATE();
        _ORDER.hide();
        _ORDERX.show();
        $().validation();
    });
    var input = document.querySelector("#PHONE");
    window.intlTelInput(input, {
        // allowDropdown: false,
        autoHideDialCode: false,
        // autoPlaceholder: "off",
        // dropdownContainer: document.body,
        // excludeCountries: ["us"],
        //formatOnDisplay: false,
        // hiddenInput: "full_number",
        // initialCountry: "auto",
        //localizedCountries: { 'de': 'Deutschland' },
        // nationalMode: false,
        // onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
        // placeholderNumberType: "MOBILE",
        preferredCountries: ['at', 'de', 'ch', 'it', 'fr', 'ro'],
        separateDialCode: true,
    });
    var iti = window.intlTelInputGlobals.getInstance(input);
    input.addEventListener("countrychange", function () {
        var countryData = iti.getSelectedCountryData();
        var number = iti.getNumber();
        var number1 = iti.getNumber(intlTelInputUtils.numberFormat.E164);
    });
});
