PageSourceSearch

https://booking.alpenair.de/js/onlinereservierung.js?d=1791380857

js alpenair.de collected 2026-10-08 22:59:06 UTC 266,551 bytes, 6,576 lines download raw bytes

1var nurHinfahrt;
2var vDisableRowAction = false;
3var vActiveCalc = false;
4var scrolling = false;
5var vTimeoutVariable;
6var vTimeoutVariableInaktivitaet;
7var vTimeoutVariableInaktivitaetTriggered = false;
8
9/**
10 * Ergänzt ausschließlich die klassische Frontend-Buchungsmaske. Der Marker
11 * kommt aus dem Template; Backend und andere Einbindungen bleiben unberührt.
12 * Nach AJAX-Antworten erneut aufrufbar, ohne Handler mehrfach zu registrieren.
13 */
14function updateOnlinebuchungAccessibility() {
15    var root = $("#reservierung_div_comp[data-booking-a11y='true']");
16    if (!root.length) {
17        return;
18    }
19
20    var stationLabel = $.trim(root.find("#booking_station_label").text()) ? "booking_station_label" : "booking_a11y_station";
21    root.find("#hafen_id").attr("aria-labelledby", stationLabel);
22    root.find("#destination_hafen_id, #destination_hafen").attr("aria-labelledby", "booking_a11y_destination");
23    root.find("#cal_hinfahrt_datum").attr("aria-labelledby", root.find("#caption_hinfahrt").length ? "caption_hinfahrt" : "booking_a11y_date");
24    root.find("#cal_rueckfahrt_datum").attr("aria-labelledby", "booking_a11y_return_date");
25
26    var quantity = $.trim(root.find("#booking_a11y_quantity").text());
27    var total = $.trim(root.find("#booking_a11y_total").text());
28    var unit = $.trim(root.find("#booking_a11y_unit_price").text());
29    var currency = $.trim(root.find("#waehrung_id option:selected").text());
30
31    root.find("#tableTicketContainer > tbody > tr, #tableTicketOptionen > tbody > tr").each(function () {
32        var row = $(this);
33        var cell = row.children(".ttCell2");
34        var label = cell.find(".bezeichnung").first();
35        var name = $.trim(label.length ? label.text() : cell.clone().find(".preistyp_buchung_bemerkung, img").remove().end().text());
36        if (!name || !this.id) {
37            return;
38        }
39        var labelId = this.id + "_a11y_label";
40        var descriptionIds = [];
41        if (label.length) {
42            label.attr("id", labelId);
43        }
44        cell.find(".buchung_bemerkung_buchung, .preistyp_buchung_bemerkung").each(function (index) {
45            var id = row.attr("id") + "_a11y_hint_" + index;
46            $(this).attr("id", id);
47            descriptionIds.push(id);
48        });
49        // Tooltip-Inhalte als Beschreibung zuordnen, ohne die sichtbaren
50        // Tariftexte oder die vorhandene Tooltip-Komponente zu verändern.
51        cell.find("img[title]").each(function (index) {
52            var text = $(this).attr("title");
53            if (!text) {
54                return;
55            }
56            var id = row.attr("id") + "_a11y_tooltip_" + index;
57            var description = root.find("#" + id);
58            if (!description.length) {
59                description = $("<span>").attr({id: id, hidden: true}).appendTo(root);
60            }
61            if (description.text() != text) {
62                description.text(text);
63            }
64            descriptionIds.push(id);
65        });
66        row.children(".ttCell1").find("select, input:not([type='hidden'])").each(function () {
67            if (label.length) {
68                $(this).attr("aria-labelledby", "booking_a11y_quantity " + labelId);
69            } else {
70                $(this).attr("aria-label", quantity + " " + name);
71            }
72            if (descriptionIds.length) {
73                var ids = ($(this).attr("aria-describedby") || "").split(/\s+/).filter(Boolean);
74                $.each(descriptionIds, function (index, id) {
75                    if ($.inArray(id, ids) == -1) {
76                        ids.push(id);
77                    }
78                });
79                $(this).attr("aria-describedby", ids.join(" "));
80            }
81        });
82        row.children(".ttCell3, .ttCell4").find("input[readonly]:not([type='hidden'])").each(function () {
83            var caption = $(this).closest("td").hasClass("ttCell3") ? unit : total;
84            $(this).attr({tabindex: -1, "aria-label": caption + " " + name + " " + currency});
85        });
86    });
87    root.find("#anzeige_gesamt input[readonly]:not([type='hidden'])").each(function () {
88        var caption = $.trim($(this).closest("tr, .row").find(".ttCell2").first().text()) || total;
89        $(this).attr({tabindex: -1, "aria-label": caption + " " + currency});
90    });
91    var remarkLabel = root.find("#onlinebuchung_bemerkung").closest(".zusammenfassung_tour").children(".headline_small_underline");
92    if (remarkLabel.length) {
93        remarkLabel.attr("id", "booking_a11y_remark_label");
94        root.find("#onlinebuchung_bemerkung").attr("aria-labelledby", "booking_a11y_remark_label");
95    }
96
97    root.find("ul.suchergebnis > li[onclick]").each(function () {
98        var row = $(this);
99        // Dieselbe Aktion wie beim Anklicken, keine eigene Buchungslogik.
100        row.attr({role: "button", tabindex: 0, "aria-pressed": row.hasClass("active") ? "true" : "false"});
101        row.find(".suchergebnis_auswahl input:radio").attr("tabindex", -1);
102    });
103    root.find("#zeitstrahl_buchungsschritte .caption[onclick]").attr({role: "button", tabindex: 0});
104    root.find("#zeitstrahl_buchungsschritte li").removeAttr("aria-current");
105    root.find("#zeitstrahl_buchungsschritte li.allowed").attr("aria-current", "step");
106    root.find("#zeitstrahl_buchungsschritte .marker").attr("aria-hidden", "true");
107}
108
109function announceOnlinebuchungStatus(text) {
110    var status = $("#reservierung_div_comp[data-booking-a11y='true'] #booking_a11y_status");
111    if (status.length && status.text() != text) {
112        status.text(text);
113    }
114}
115
116function clearOnlinebuchungSearchError() {
117    var root = $("#reservierung_div_comp[data-booking-a11y='true']");
118    root.find("[data-booking-error]").each(function () {
119        var ids = ($(this).attr("aria-describedby") || "").split(/\s+/).filter(function (id) {
120            return id && id != "fehleranzeige_oben";
121        });
122        $(this).removeAttr("aria-invalid data-booking-error");
123        if (ids.length) {
124            $(this).attr("aria-describedby", ids.join(" "));
125        } else {
126            $(this).removeAttr("aria-describedby");
127        }
128    });
129}
130
131/** Bindet den vorhandenen Fehlertext an das betroffene Feld; der Fokus liest
132 * die Beschreibung mit vor. Keine zusätzliche, doppelte Alert-Ansage. */
133function showOnlinebuchungSearchError(selector) {
134    var root = $("#reservierung_div_comp[data-booking-a11y='true']");
135    if (!root.length) {
136        return;
137    }
138    root.find("#fahrt_anzeige").attr("aria-busy", "false");
139    announceOnlinebuchungStatus("");
140    var fields = root.find(selector).filter(":visible");
141    var field = fields.filter(function () {
142        return !$(this).val() || $(this).val() == "0";
143    }).first();
144    if (!field.length) {
145        field = fields.first();
146    }
147    if (field.length) {
148        var ids = (field.attr("aria-describedby") || "").split(/\s+/).filter(Boolean);
149        if ($.inArray("fehleranzeige_oben", ids) == -1) {
150            ids.push("fehleranzeige_oben");
151        }
152        field.attr({"aria-invalid": "true", "data-booking-error": "true", "aria-describedby": ids.join(" ")});
153        field[0].focus();
154    } else {
155        root.find("#fehleranzeige_oben").attr("tabindex", -1).trigger("focus");
156    }
157}
158
159/** Fokus nur bei einem tatsächlichen Schrittwechsel und erst nach Laden der
160 * Ticketfelder. Nachträgliche Preisberechnungen dürfen den Fokus nicht stehlen. */
161function focusOnlinebuchungStep() {
162    var root = $("#reservierung_div_comp[data-booking-a11y='true']");
163    var step = root.data("a11yFocusStep");
164    if (!step || root.data("a11yTicketLoading")) {
165        return;
166    }
167    if ($(".ui-dialog:visible").length) {
168        root.removeData("a11yFocusStep");
169        return;
170    }
171    // blockUI blendet sich animiert aus. Der erste Aufruf darf deshalb den
172    // Fokus noch nicht setzen; begrenzt nachholen, ohne einen Dialog zu stören.
173    if ($(".blockUI:visible").length) {
174        if (Date.now() - root.data("a11yFocusStarted") < 5000) {
175            window.clearTimeout(root.data("a11yFocusTimer"));
176            root.data("a11yFocusTimer", window.setTimeout(focusOnlinebuchungStep, 100));
177        }
178        return;
179    }
180    var panel = root.find(step == "schritt1" ? "#seite1" : (step == "schritt3" ? "#seite4" : "#seite2"));
181    if (!panel.is(":visible")) {
182        return;
183    }
184    // Eine zwischenzeitlich bereits begonnene Eingabe nicht unterbrechen.
185    if ($(document.activeElement).is("input, select, textarea, button, a, [role='button']") && $.contains(panel[0], document.activeElement)) {
186        root.removeData("a11yFocusStep");
187        return;
188    }
189    var target = panel.find("h1:visible, h2:visible, h3:visible, h4:visible").first();
190    if (!target.length) {
191        target = root.find("#" + step + " .caption:visible").first();
192    }
193    if (!target.length) {
194        target = panel;
195        target.attr("aria-label", $.trim(root.find("#" + step + " .caption").text()) || dialog['zf_ticket']);
196    }
197    if (target.attr("role") != "button") {
198        target.attr("tabindex", -1);
199    }
200    root.removeData("a11yFocusStep");
201    target[0].focus({preventScroll: true});
202}
203
204function initOnlinebuchungAccessibility() {
205    var root = $("#reservierung_div_comp[data-booking-a11y='true']");
206    if (!root.length || root.data("a11yInitialized")) {
207        return;
208    }
209    root.data("a11yInitialized", true);
210    updateOnlinebuchungAccessibility();
211    var selector = "ul.suchergebnis > li[onclick], #zeitstrahl_buchungsschritte .caption[onclick]";
212    root.on("keydown.bookingA11y keyup.bookingA11y", selector, function (event) {
213        if (event.target != this || (event.which != 13 && event.which != 32)) {
214            return;
215        }
216        event.preventDefault();
217        if (event.originalEvent && event.originalEvent.repeat) {
218            return;
219        }
220        if (event.type == "keydown" && event.which == 32) {
221            $(this).data("a11ySpacePressed", true);
222            return;
223        }
224        if ((event.which == 13 && event.type == "keydown") ||
225            (event.which == 32 && event.type == "keyup" && $(this).data("a11ySpacePressed"))) {
226            $(this).removeData("a11ySpacePressed");
227            if ($(this).is("li")) {
228                root.find(".justClicked").removeClass("justClicked");
229                $(this).addClass("justClicked");
230            }
231            $(this).trigger("click");
232        }
233    });
234    root.on("focusout.bookingA11y", selector, function () {
235        $(this).removeData("a11ySpacePressed");
236    });
237    root.on("click.bookingA11y", selector, function () {
238        updateOnlinebuchungAccessibility();
239    });
240    root.on("tabsactivate.bookingA11y", "#div-wrap-suchergebnis", function () {
241        updateOnlinebuchungAccessibility();
242        announceOnlinebuchungStatus($.trim(root.find("#booking_a11y_results").text()) + ": " + root.find("ul.suchergebnis > li[onclick]:visible").length);
243    });
244    root.on("change.bookingA11y", "[data-booking-error]", function () {
245        clearOnlinebuchungSearchError();
246        root.find("#fehleranzeige_oben").empty();
247    });
248}
249
250
251var heightWindow=0;
252function showCheckoutInWarenkorb(){
253    if($("#login").val() != "true"){
254
255        //Noch nicht alles Bestätigt
256        if($(".disclaimerbox:not(.newsletter) :checkbox:not(:checked)").length>0){
257            $("#div_payment_field button, #div_payment_field input[type='button']").attr("disabled",true);
258            $(".agbhinweis").removeClass("hide");
259            $("#paypal-button-container, #div_sumup_apple_pay, #div_ayden_apple_pay").addClass("hide");
260        }
261        else{
262            $("#div_payment_field button, #div_payment_field input[type='button']").attr("disabled",false);
263            $(".agbhinweis").addClass("hide");
264            $("#paypal-button-container, #div_sumup_apple_pay, #div_ayden_apple_pay").removeClass("hide");
265        }
266    }
267}
268
269//Temporäre Sitzplatzreservierung
270$(document).ready(function () {
271
272    showCheckoutInWarenkorb();
273
274    //Scrolling ermittlen
275    if ($("#login").val() == "false") {
276        scrolling = true;
277
278        $(".hideonline").closest(".column").addClass("hideonline");
279    }
280
281    if ($("#isOnlineBuchungsMaske").val() == "true") {
282        window.setInterval("setTempSitzplatz()", 15000);
283    }
284
285    if ($("#login").val() == "false" && checkInIframe()) {
286        $(".top_bar_leiste").remove();
287    }
288
289    //Min - Max Datum
290    if ($("#fahrt_suchen .fahrten .cal_around input.hasDatepicker").length > 0) {
291        if ($("#login").val() == "false") {
292            $("#fahrt_suchen .fahrten .cal_around input.hasDatepicker").datepicker("option", "minDate", "-0D");
293        } else if ($("#reservierung_id").length == 0) {
294            $("#fahrt_suchen .fahrten .cal_around input.hasDatepicker").datepicker("option", "minDate", "-3M");
295        }
296        $("#fahrt_suchen .fahrten .cal_around input.hasDatepicker").datepicker("option", "maxDate", "+3Y");
297    }
298
299    if ($("#nur_vormerkung").length > 0 && $("#nur_vormerkung").val() == "1") {
300        if ($("table.table_artikel_ev").length > 0 && $("table.table_artikel_ev select").find("option:selected").not("[value=0]").length > 0) {
301            $("#fahrgaeste").on("change", "select[name^='personen']", function () {
302                $(".buchung_hinweis").html("<div class='callout warning'><p><i class='fa-solid fa-circle-exclamation'> " + dialog['vormerkung_artikel_hinweis'] + "</p></div>");
303            });
304        }
305    }
306
307    $("table#table_artikel_ev tbody, table#table_artikel_ev_vormerkung tbody").sortable();
308
309    $("div.row.textblock").sortable({items: "div.column"});
310
311    $("#table_bezahlung input:radio").click(function () {
312        setFahrtInfo();
313    });
314
315    if ($("#tabscrossselling").length > 0) {
316        $("#tabscrossselling").on("tabsactivate", function (event, ui) {
317            window.dispatchEvent(new Event('resize'));
318        });
319    }
320
321    //Gutschein finden
322    var recht_id = $("#warpper").attr("recht_id");
323    if (recht_id == "1" || recht_id == "3") {
324        $("#gutscheincode").autocomplete({
325            source: "ajax/onlinereservierung.php?aktion=gutscheinlist",
326            minLength: 3,
327            autoFocus: true,
328            delay: 600,
329            select: function (event, ui) {
330
331                setTimeout(function () {
332                    checkGutscheincode();
333                }, 300);
334            }
335        });
336    }
337
338    if (
339        $("#hide_tourfinder").val() != "true"
340        && $("#login").val() == "false"
341        && ($("#linie_id").attr("datum") == "" || $("#linie_id").attr("datum") == "0")
342        && $("#linie_id").val() != "" && $("#linie_id").length > 0
343        && checkInIframe() == false
344        && ($("#hafen_id").val() == $("#destination_hafen_id").val() || $("#destination_hafen_id").val() == "0" || $("#destination_hafen_id").length == 0)
345    ) {
346        OnlinebuchungLoadLinieSuche($("#linie_id").val());
347    }
348    //Bei Ticket den Tourfinder laden in der Standardansicht
349    else if (vProgrammModus == "ticket" && $("#linie_id").length == 0 && $("#hafen_id option").length == 1 && $("#anschluss_fahrt").val()!="1" && $("#datum_set").val()!="1") {
350        OnlinebuchungLoadLinieSuche(-1);
351    }
352
353    //Im Einzelverkauf - und iFrame
354    if ($("#einzelverkauf").length > 0 && $("#login").val() == "false" && checkInIframe()) {
355        $("body").html("<input type='button' onclick='setBlockUI(); goToURLOB(\"" + window.location.href + "\");' value='" + dialog['go_to_onlineshop'] + "' class='button success'>");
356    }
357    //Onlinebuchung innerhalb eines iFrames
358    else if ($("#login").val() == "false" && checkInIframe()) {
359        $("#Kopfzeile_Onlinebuchung_mobile, #Kopfzeile_Onlinebuchung_screen, .top_bar, .bottom_bar, div.row.kopfbereich, div.copyright, .fusszeile_abstand_oben, .fusszeile, .abstand_unten, div.fusszeile_small").remove();
360        $("#tr_hafen_r").addClass("hide");
361        $("#caption_hinfahrt").text(dialog['tour']);
362    }
363
364    //In Iframe - HÖhe justieren
365    if (checkInIframe()) {
366        sendHeight();
367    }
368
369    //Anpassung der Hafen - Stationsliste
370    setHafenList();
371
372    //Ansicht der Statusleiste
373    setZeitstrahlBuchungsschritteLabels();
374    initOnlinebuchungAccessibility();
375
376    $(document).on("input", "input.online-geburtsdatum", function () {
377        formatOnlineGeburtsdatum(this);
378    });
379
380    $(document).on("blur", "input.online-geburtsdatum", function () {
381        checkOnlineGeburtsdatum(this, true);
382    });
383
384    $("#online_einzelverkauf_artikelauswahl").on( "tabsactivate", function( event, ui ) {
385        $(window).trigger("resize");
386    } );
387
388    //Timeout nach x min  Inaktivität - für KS
389    if($("#fahrt_suchen").length > 0 && $("#bodi").attr("login")=="true" && $("#koenigssee").length>0){
390
391        //Timeout in min
392        var timeoutMin = 5;
393        if($("#koenigssee").length>0){
394            timeoutMin = 2;
395        }
396
397        $(document).on("click keyup", function () {
398            if(vTimeoutVariableInaktivitaetTriggered){
399                return;
400            }
401            clearTimeout(vTimeoutVariableInaktivitaet);
402            vTimeoutVariableInaktivitaet = setTimeout(function () {
403
404                if($("#adyenpos-dialog").length>0){
405                    return;
406                }
407
408                vTimeoutVariableInaktivitaetTriggered = true;
409                    if (confirm(dialog['dialog_inaktiv'])) {
410                        window.location.href="/";
411                    }
412                }, timeoutMin*60*1000
413            );
414
415        });
416    }
417
418});
419
420function rueckgeldrechner(obj) {
421
422    var val = parseFloat($(obj).val());
423    var betrag = parseFloat($(obj).attr("betrag"));
424
425    if (val > 0) {
426        var rueckbetrag = val - betrag;
427        $(obj).closest(".row").find(".column.zurueckbetrag").removeClass("hide").find("input").val(dbl2C(rueckbetrag));
428    } else {
429        $(obj).closest(".row").find(".column.zurueckbetrag").addClass("hide");
430    }
431}
432
433function passwortVergessen(vEmail) {
434    if (vEmail == undefined) {
435        vEmail = "";
436    }
437    if (vEmail != "" && isEmail(vEmail)) {
438
439    } else if ($("#email").length > 0) {
440        vEmail = $("#email").val();
441    } else if ($("#anmeldung_kdnr").length > 0) {
442        vEmail = $("#anmeldung_kdnr").val();
443    }
444
445    //Ausgabe in Dialog anzeigen
446    var div = $("<div id='dialog_pw_vergessen'/>");
447    $(div).append("<input type='email' id='customer_email_adress' value='" + vEmail + "' placeholder='" + dialog['email'] + "'/>" +
448        "<br>" +
449        "<br>" +
450        "<br>" +
451        "<input type='button' onclick='passwortVergessenSenden();
451' class='button expanded' value='" + dialog['senden'] + "'/>" +
452        "<br>" +
453        "<br>");
454
455    $(div).dialog({
456        title: dialog['neue_zugangsdaten'],
457        autoOpen: true,
458        position: {
459            my: "center",
460            at: "center",
461            of: window
462        },
463        modal: true,
464        open: function (event, ui) {
465
466        },
467        close: function (event, ui) {
468            $(div).remove();
469        }
470    });
471}
472
473function passwortVergessenSenden() {
474    if (isEmail($("#customer_email_adress").val()) == false) {
475        alert(dialog['email_ungueltig']);
476        return false;
477    }
478
479    setBlockUI();
480    $.post("ajax/onlinereservierung-mydata.php", {
481        aktion: "passwort_vergessen",
482        email: $("#customer_email_adress").val()
483    })
484        .done(function (data) {
485
486            $("#anmeldung_kdnr,#email").val($("#customer_email_adress").val());
487
488            $.unblockUI();
489            $("#dialog_pw_vergessen").dialog("close");
490            setTimeout(function () {
491
492                if (data == "OK") {
493
494                    alert(dialog['pw_vergessen_quittung']);
495                } else {
496                    alert(dialog['pw_vergessen_quittung_false']);
497                }
498            }, 200);
499        });
500}
501
502function goToURLOB(url) {
503    if (checkInIframe()) {
504        window.top.location.href = url;
505    } else {
506        window.location.href = url;
507    }
508}
509
510function BuchungCopy(index, datum, url) {
511    //Dialog
512    var vDialog = $('<div></div>');
513    var markup = $('<input type="date" value="' + datum + '" id="date_time_fahrt"/>');
514
515    $(vDialog).append(markup);
516
517    $(vDialog).dialog({
518        modal: true,
519        title: dialog['datum_waehlen'],
520        open: function () {
521        },
522        close: function () {
523            $(this).dialog("destroy");
524            $(vDialog).remove();
525        },
526        buttons: {
527            [window.dialog["abbrechen"]]: function () {
528                $(this).dialog("close");
529            },
530            Ok: function () {
531                setBlockUI();
532                window.location.href = url + "&hinfahrt_datum=" + convertDatumYYYYMMDDInGerman($("#date_time_fahrt").val()) + "&counter=" + index + "&copybasket=true";
533            }
534        }
535    });
536}
537
538function WarenkorbBerechnenSpezialpreis() {
539    if ($("#acc_zusammenfassen").length == 0) {
540        return;
541    }
542
543    var preistypen = JSON.parse(decodeURIComponent($("#acc_zusammenfassen").attr("preistypen")));
544    setBlockUI();
545    $.post("ajax/onlinereservierung.php", {
546        aktion: "warenkorb_calculate_gesamtpreis",
547        station_start: $("#acc_zusammenfassen").attr("hafen_id"),
548        station_stop: $("#preis_zielstation").val(),
549        rueckfahrt_betrag: $("#use_preis_rueckfahrt").prop("checked") == true ? 1 : 0,
550        datum: $("#acc_zusammenfassen").attr("datum"),
551        linie_id: $("#acc_zusammenfassen").attr("linie_id"),
552        tarif_id: $("#acc_zusammenfassen").attr("tarif_id"),
553        preistypen: preistypen
554    })
555        .done(function (data) {
556            $("#acc_zusammenfassen").attr("ergebnis", JSON.stringify(data.data));
557            $("#button_preis_excec").prop("disabled", false);
558            $("#abweichender_betrag").val(data.gesamtbetrag);
559            $("#button_preis_excec").val(dbl2C(data.gesamtbetrag) + " - " + $("#button_preis_excec").attr("labeld"));
560            $.unblockUI();
561            console.log(data);
562        });
563}
564
565function WarenkorbBerechnenSpezialpreisExec() {
566    if (confirm(window.dialog["ui_33608d48dbcc"])) {
567        setBlockUI();
568        $.post("ajax/onlinereservierung.php", {
569            aktion: "warenkorb_gesamtpreis_exec",
570            betrag: $("#abweichender_betrag").val(),
571            data: JSON.parse($("#acc_zusammenfassen").attr("ergebnis"))
572        })
573            .done(function (data) {
574                window.location.reload();
575            });
576    }
577}
578
579function WarenkorbRefreshPrice(obj){
580    var betrag = $(obj).val();
581    var button = $(obj).closest(".row").find(".button");
582    var dialog = dbl2C(betrag) + " " +  $(button).attr("waehrung") + " " +  $(button).attr("dialog");
583    $(button).val(dialog);
584    $(button).attr("freibetrag",betrag);
585}
586function WarenkorbAddArtikel(artikel_id, anzahl_pax, betrag) {
587    setBlockUI();
588
589    $.post("ajax/onlinereservierung.php",
590        {
591            aktion: "add2Warenkorb",
592            anzahl_pax: anzahl_pax,
593            betrag: betrag,
594            artikel_id: artikel_id
595        })
596        .done(function (data) {
597            window.location.reload();
598        });
599}
600
601
602function TextblockEdit(obj) {
603    var bez = decodeURIComponent($(obj).attr("bezeichnung"));
604
605    if ($(obj).find("textarea.inhalt").val() != "") {
606        var inhaltS = $(obj).find("textarea.inhalt").val();
607    } else {
608        var inhaltS = decodeURIComponent($(obj).attr("data"));
609    }
610
611    var inhalt = $("<div class='row column'/>");
612    $(inhalt).append("<textarea id='tb_inhalt' name='tb_inhalt'>" + inhaltS + "</textarea>");
613    $(inhalt).append("<br><br>");
614    $(inhalt).append("<div class='row column alignright'><input type='button' class='button success' value='" + dialog['uebernehmen'] + "' id='tb_button_speichern'/></div>");
615
616
617    var div = $("<div/>");
618    $(div).append(inhalt);
619
620    $(div).dialog({
621        height: $(window).height() * 0.9,
622        width: $(window).width() * 0.9,
623        title: bez + " - " + dialog['textblock_bearbeiten'],
624        position: {
625            my: "center",
626            at: "center",
627            of: window
628        },
629        modal: true,
630        open: function (event, ui) {
631
632            $("body").css({overflow: 'hidden'});
633            $.unblockUI();
634
635            var vEditor = CKEDITOR.replace("tb_inhalt",
636                {
637                    language: $("#bodi").attr("lang") || "de",
638                    toolbar: 'basic',
639                    removeButtons: 'Source'
640                });
641
642            $("#tb_button_speichern").click(function () {
643                var inhalt = vEditor.getData();
644                $(obj).find("textarea.inhalt").val(inhalt);
645                $(div).dialog('close');
646            });
647        },
648        close: function (event, ui) {
649            $("body").css({overflow: 'inherit'});
650            $(this).remove();
651        }
652    });
653
654
655}
656
657function showZusatzFreieingabeInAcc() {
658    var artikel = {};
659    if ($("table.tableTickethinfahrt[anzahl_freieingabe='1']").length > 0) {
660        $("table.tableTickethinfahrt[anzahl_freieingabe='1']").each(function (index) {
661            if (artikel[$(this).attr("zusatz_id")] == undefined) {
662                artikel[$(this).attr("zusatz_id")] = 0;
663            }
664            artikel[$(this).attr("zusatz_id")]++;
665        });
666
667        $.each(artikel, function (zusatz_id, anzahl) {
668
669            //console.log(zusatz_id+" --- "+anzahl);
670            if (anzahl > 1 && parseInt(zusatz_id) > 0) {
671                var selector = "table.tableTicketZusatz[anzahl_freieingabe='1'][zusatz_id='" + zusatz_id + "']";
672                var seldiv = "acc_freitext_zusatz_id_" + zusatz_id;
673                var bezeichnung = decodeURIComponent($(selector).attr('bezeichnung'));
674
675                var div2 = $("<div/>");
676                $(div2).addClass("container2");
677                $(div2).attr("id", seldiv + "cont");
678                $(selector).wrapAll(div2);
679
680
681                var div = $("<div/>");
682                $(div).attr("id", seldiv);
683                $(div).addClass("container");
684
685                $("#" + seldiv + "cont").wrap(div);
686                $("<h3>" + bezeichnung + "</h3>").insertBefore("#" + seldiv + "cont");
687
688                //Prüfung geöffnet - geschlossen
689                var vActive = false;
690                $("#" + seldiv + "cont input[type='number']").each(function (index) {
691                    if (parseInt($(this).val()) > 0) {
692                        vActive = true;
693                    }
694                });
695
696                if (vActive == true) {
697                    $("#" + seldiv).accordion({
698                        collapsible: true,
699                        heightStyle: "content",
700                        autoHeight: true
701                    });
702                } else {
703                    $("#" + seldiv).accordion({
704                        collapsible: true,
705                        active: false,
706                        heightStyle: "content",
707                        autoHeight: true
708                    });
709                }
710            }
711            if (artikel[$(this).attr("zusatz_id")] == undefined) {
712                artikel[$(this).attr("zusatz_id")] = 0;
713            }
714            artikel[$(this).attr("zusatz_id")]++;
715        });
716    }
717
718
719    //Checkboxes - Foundation
720
721    try {
722        $.each($(".tableTicketZusatz .ttCell1 input[type='checkbox']"), function () {
723            startUpCheckboxes(this, "index.php");
724            $(this).foundation();
725        })
726
727    } catch (e) {
728        alert(window.dialog["ui_f6cc01cb7edb"]);
729        console.log(e)
730    }
731}
732
733function setFirstZahlart() {
734    var vZahlartID = parseInt(getRadioBoxValue("form[zahlart_id]"));
735    if (vZahlartID > 0) {
736        setZahlart();
737        return false;
738    }
739
740    var vBool1 = false;
741    //alert($("input:radio[name='form\\[zahlart_id\\]']").length);
742    $("input:radio[name='form\\[zahlart_id\\]']").each(function () {
743        if (vBool1 == false && $(this).is(':visible') == true) {
744            //alert($(this).attr("id"));
745            $(this).attr("checked", true);
746            vBool1 = true;
747            setZahlart();
748        }
749    });
750}
751
752function checkoutWarenkorbValid(url) {
753    setBlockUI();
754    $.post("ajax/onlinereservierung.php", {aktion: "checkoutWarenkorbValid"}, function (data) {
755        if (data == "OK") {
756            window.location.href = url;
757        } else {
758            window.location.href = "index_warenkorb.php?rand=" + Math.random();
759        }
760    });
761}
762
763function removeGutscheine() {
764    $('#gutscheincode').val('');
765    $(".gutscheincode_column input").not(":first").remove();
766    $(".gutscheincode_column input").val("");
767    $("#div_gutschein").removeClass("callout secondary");
768    $(".gsfilled").addClass("hide");
769
770    $.post("ajax/onlinereservierung.php", {aktion: "resetGutscheine"});
771    checkGutscheincode();
772    $(".gutscheincode_column input").first().focus();
773    calculate();
774}
775
776function checkGutscheincodeInputFrontend(obj,type) {
777    var inhalt = $(obj).closest(".gutscheincode_column").find(".gutscheincode").val();
778    if (inhalt == "") {
779        alert(dialog['code_eingeben']);
780        $(obj).closest(".gutscheincode_column").find(".gutscheincode").effect("shake").focus();
781        return false;
782    }
783    $("#gutschein_info").addClass("hide");
784    $(obj).closest(".gutscheincode_column").find(".gutscheincode").prop("readonly", true);
785    $(obj).closest(".gutscheincode_column").find(".buttonok").addClass("hide");
786
787    var c = 0;
788    var z = 0;
789    var codes = "";
790    $.each($(".gutscheincodeeingabecodes input.gutscheincode"), function () {
791
792        if ($(this).val() != "") {
793            if (c > 0) {
794                codes += ",";
795            }
796            codes += $(this).val();
797            c++;
798        } else if (z > 0) {
799            $(this).remove();
800        }
801        z++;
802    })
803    $("input#gutscheincode").val(codes);
804    setBlockUI();
805
806    $.ajax({
807        type: "POST",
808        url: "ajax/onlinereservierung.php",
809        data:
810            {
811                aktion: "checkGutscheinCodeFrontend",
812                code: codes,
813                type:type,
814                reservierung_id: $("#reservierung_id").val() ?? 0
815            }
816    })
817        .done(function (data) {
818
819            $.unblockUI();
820
821            var vRestwert = parseFloat(data["restwert"]);
822            var vGesamtbetrag = parseFloat($("#div_gutschein").attr("gesamtbetrag"));
823
824            $("#gutschein_info").removeClass("hide").find("span#gutscheinsumme").text(dbl2C(vRestwert));
825
826            //Gibt ein Restwert
827            if (vRestwert > 0) {
828                $("#hinweis_gutschein").removeClass("hide");
829                $("#button_einloesen").prop("disabled", false);
830            } else {
831                $("#hinweis_gutschein").addClass("hide");
832                $("#button_einloesen").prop("disabled", true);
833            }
834
835            if($("#div_gutschein.rabattcode_container").length>0 && vRestwert >0){
836                $("#addAon").removeClass("hide");
837            }
838            else if (vRestwert < vGesamtbetrag && vRestwert > 0) {
839                $("#addAon").removeClass("hide");
840            }
841
842            $("#gutscheincode_del").removeClass("hide");
843
844            if(data.meldung !== undefined && !(vRestwert > 0) && data.meldung != ""){
845                alert(data.meldung);
846            }
847
848        });
849}
850
851function removeGutscheineFrontend() {
852    $('#gutscheincode').val('');
853    $(".gutscheincodeeingabecodes").not(":first").remove();
854    $(".gutscheincode_column input.gutscheincode").val("").prop("readonly", false);
855    $("#button_einloesen").prop("disabled", true);
856    $("#gutschein_info").addClass("hide");
857    $(".buttonok").removeClass("hide");
858    $("#addAon").addClass("hide");
859
860    $(".gutscheincodeeingabecodes input").first().focus();
861}
862
863function AddGutscheinCode() {
864    var gs = $(".gutscheincode_column input").first().clone();
865    $(gs).val("");
866    $(".gutscheincode_column").append(gs);
867    $(gs).focus();
868}
869
870function AddGutscheinCodeFrontend() {
871    var gs = $(".gutscheincodeeingabecodes").last().clone();
872    $(gs).find(".gutscheincode").val("");
873    $(".gutscheincode_column").append(gs);
874    $(gs).find(".gutscheincode").prop("readonly", false).focus();
875    $(gs).find(".buttonok").removeClass("hide");
876    $("#addAon").addClass("hide");
877    $("#button_einloesen").prop("disabled", true);
878}
879
880function aufrufenWarenkorb() {
881    if (confirm(dialog['onlinebuchung_verlassen'])) {
882        showWaitingScreen();
883        window.location.href = "index_warenkorb.php";
884    }
885}
886
887function getEinzelverkaufArtikelPreis(vObj) {
888
889    var vInput = $(vObj).closest("tr.tr_einzelverkauf").find(".ttCell3 input");
890    var vPreis = C2dbl($(vInput).val());
891    var vArtikelID = parseInt($(vObj).closest("tr.tr_einzelverkauf").find(".ttCell2 select").val());
892    var vFreiPreis = $(vObj).closest("tr.tr_einzelverkauf").find(".ttCell2 select option:selected").attr("preis_freieingabe");
893    if ($(vObj).is("select") && vFreiPreis == "0") {
894        $(vInput).val("");
895    }
896
897    if (((vFreiPreis == "1" && vPreis == 0) || vFreiPreis == "0") && vArtikelID > 0) {
898        setBlockUI();
899        $.get("ajax/target.php", "aktion=getValue&tabelle=artikel&feld=betrag&ID=" + vArtikelID)
900            .done(function (data) {
901                $(vInput).val(data);
902                $.unblockUI();
903                calculate(true);
904            });
905    } else {
906        calculate(true);
907    }
908}
909
910function checkoutWarenkorb() {
911    //Online
912    if ($("#checkout").length == 0) {
913        checkoutWarenkorbValid("/customerauth");
914    }
915}
916
917function loadTextbloecke(user_id) {
918    $.post("ajax/onlinereservierung.php", {
919        aktion: "loadTextbloecke",
920        user_id: user_id
921    })
922        .done(function (data) {
923
924            try {
925                $.each(data, function (index, row) {
926                    $.each(row, function (index2, row2) {
927                        if (index == "kunde") {
928                            var selector = "input[name='tb[" + index2 + "]']";
929                        } else if (index == "intern") {
930                            var selector = "input[name='tb_intern[" + index2 + "]']";
931                        } else if (index == "crew") {
932                            var selector = "input[name='tb_crew[" + index2 + "]']";
933                        }
934                        $(selector).prop("checked", false);
935                        $(selector).trigger("click");
936                    });
937                });
938            } catch (e) {
939            }
940
941        });
942}
943
944function loadAnsprechpartner(user_id, feld) {
945    var obj = document.getElementById(feld);
946
947    if ($(obj).length == 0) {
948        return;
949    }
950
951    $.post("ajax/onlinereservierung.php", {
952        aktion: "loadAnsprechpartner",
953        user_id: user_id
954    })
955        .done(function (data) {
956            if (data.length > 0) {
957                $.each(data, function (index, row) {
958                    $(obj).append("<option value='" + row.ID + "'>" + row.vorname + " " + row.name + "</option>");
959                });
960
961                $(obj).closest("tr.ansprechpartner").removeClass("hide");
962            }
963        });
964}
965
966function cleanWarenkorb(vEintrag) {
967    if (vEintrag == undefined) {
968        var vEintrag = 0;
969    }
970
971    $.ajax({
972        type: "POST",
973        url: "ajax/onlinereservierung.php",
974        data: {aktion: "cleanWarenkorb", eintrag: vEintrag},
975        success: function (data) {
976            $('#div_warenkorb').remove();
977            $('#mySubmit').removeClass('hide');
978            $('#mySubmitW, .buchung_auswahl button').addClass('hide');
979
980            setBlockUI();
981            if (vEintrag === -1) {
982                window.location.href = "?rand=" + Math.random();
983            } else {
984                window.location.href = "index_warenkorb.php?rand=" + Math.random();
985            }
986
987        }
988    });
989}
990
991function setAbfahrtDatum(vDatum) {
992    var vUseDate = new Date(convertDeutschesDatumInObj(vDatum));
993    $("#cal_hinfahrt_datum").datepicker("setDate", vUseDate).trigger("change");
994    $("#cal_rueckfahrt_datum").datepicker("setDate", vUseDate).trigger("change");
995
996    $('.linie_auswahl #linie_id').val(0).trigger('chosen:updated');
997    $("#linie_id").val(0);
998    $('#linie_typ_id').val('0');
999    setBlockUI();
1000    getFahrt(13);
1001}
1002
1003function setHafenList() {
1004
1005    $("div.suchmaske.tour input.button").addClass("hide");
1006
1007    var Ziel = $("#destination_hafen_id");
1008    if (Ziel.length == 0 || parseInt($("#reservierung_id").val()) > 0 || $("#hafen_umstieg_id").length>0) {
1009        setAnsicht();
1010        return;
1011    }
1012    $.ajax({
1013        type: "POST",
1014        url: "ajax/onlinereservierung.php",
1015        data:
1016            {
1017                aktion: "hafen_list",
1018                datum: $("#hinfahrt_datum").val(),
1019                hafen_id: $("#hafen_id").val()
1020            }
1021        })
1022        .done(function (data) {
1023
1024            //Zielstationen darstellen
1025            var zielVal = parseInt($(Ziel).val());
1026            $(Ziel).find("option").not("[value='0']").remove();
1027            $(Ziel).val("0");
1028            $.each(data["hafen"], function () {
1029                $(Ziel).append("<option value='" + this.ID + "'>" + this.bezeichnung + "</option>");
1030            });
1031
1032            if (zielVal > 0 && $(Ziel).find("option[value='" + zielVal + "']").length > 0) {
1033                $(Ziel).val(zielVal);
1034            }
1035
1036            //Nur die Buttons anzeigen die es tatsächlich ab der gewählten Station gibt
1037            $("div.suchmaske.tour input.button").addClass("hide");
1038            var vAnzahl = 0;
1039            $.each(data["typen"], function () {
1040                $("div.suchmaske.tour input.button[linientyp_id='" + this + "']").removeClass("hide");
1041                vAnzahl++;
1042            });
1043            if (vAnzahl <= 1 && $("#buttonFinden").is(":visible")) {
1044                $("div.suchmaske.tour input.button").addClass("hide");
1045            }
1046
1047            setAnsicht();
1048        });
1049}
1050
1051function SetKlasseMouseOver() {
1052    var vKlasseShow = $("tr#tr_klasse").attr("klasse_id");
1053    var vKlasseSelect = $("#klasse_id").val();
1054    if (vKlasseShow != vKlasseSelect) {
1055        $("tr#tr_klasse").attr("klasse_id", vKlasseSelect);
1056
1057        $("img#klasse_info_box").attr("title", "");
1058        $.ajax({
1059            type: "GET",
1060            url: "ajax/onlinereservierung.php",
1061            data:
1062                {
1063                    aktion: "GetKlasseInfo",
1064                    klasse_id: vKlasseSelect
1065                }
1066        })
1067            .done(function (msg) {
1068                //alert( "Data Saved: " + msg );
1069                if (msg != "") {
1070                    $("img#klasse_info_box").attr("title", msg);
1071
1072                    try {
1073                        $("img#klasse_info_box").tooltip("destroy");
1074
1075                        $("img#klasse_info_box").tooltip({
1076                                position: {
1077                                    my: "center bottom-20",
1078                                    at: "center top",
1079                                    using: function (position, feedback) {
1080                                        $(this).css(position);
1081                                        $("<div>")
1082                                            .addClass("tooltipArrow")
1083                                            .addClass(feedback.vertical)
1084                                            .addClass(feedback.horizontal)
1085                                            .appendTo(this);
1086                                    }
1087                                }
1088                            }
1089                        );
1090                        $("img#klasse_info_box").css("display", "block");
1091                    } catch (e) {
1092                    }
1093                } else {
1094                    try {
1095                        $("img#klasse_info_box").tooltip("destroy");
1096                    } catch (e) {
1097                    }
1098
1099                    $("img#klasse_info_box").css("display", "none");
1100                }
1101
1102            });
1103    }
1104}
1105
1106function setTempSitzplatz() {
1107    if ($('table#table_sitzplatz').length > 0) {
1108        var vUniqueKey = $("#unique_key_sp").val();
1109
1110        //Hinfahrt
1111        var vHinfahrtChecked = [];
1112        var vHinfahrtVal = getRadioBoxValue("hinfahrt");
1113        if(vHinfahrtVal!==0){
1114            var vHinfahrtA = vHinfahrtVal.split("_");
1115            var hinfahrt_linie_hafen_start_id = vHinfahrtA[7];
1116            var hinfahrt_linie_hafen_id_stop = vHinfahrtA[8];
1117            var hinfahrt_fahrt = vHinfahrtA[3];
1118            $('table#table_sitzplatz tr[fahrt='+hinfahrt_fahrt+'][linie_hafen_start_id='+hinfahrt_linie_hafen_start_id+'][linie_hafen_stop_id='+hinfahrt_linie_hafen_id_stop+'] td input:checked').not(":disabled").each(function () {
1119                vHinfahrtChecked.push($(this).attr("pos"));
1120            });
1121        }
1122
1123        //Rückfahrt
1124        var vRueckfahrtChecked = [];
1125        var vRueckfahrtVal = getRadioBoxValue("rueckfahrt");
1126        if(vRueckfahrtVal!==0){
1127            var vRueckfahrtValA = vRueckfahrtVal.split("_");
1128            var rueckfahrt_linie_hafen_start_id = vRueckfahrtValA[7];
1129            var rueckfahrt_linie_hafen_id_stop = vRueckfahrtValA[8];
1130            var rueckfahrt_fahrt = vRueckfahrtValA[3];
1131            $('table#table_sitzplatz tr[fahrt='+rueckfahrt_fahrt+'][linie_hafen_start_id='+rueckfahrt_linie_hafen_start_id+'][linie_hafen_stop_id='+rueckfahrt_linie_hafen_id_stop+'] td input:checked').not(":disabled").each(function () {
1132                vRueckfahrtChecked.push($(this).attr("pos"));
1133            });
1134        }
1135
1136        $.ajax({
1137            type: "POST",
1138            url: "ajax/onlinereservierung.php",
1139            data:
1140                {
1141                    aktion: "TempSitzplatz",
1142                    tmp_key: vUniqueKey,
1143                    reservierung_id: $("#reservierung_id").val(),
1144                    hinfahrt: vHinfahrtVal,
1145                    rueckfahrt: vRueckfahrtVal,
1146                    klasse_id: $("#klasse_id").val(),
1147                    hinfahrt_plaetze: JSON.stringify(vHinfahrtChecked),
1148                    rueckfahrt_plaetze: JSON.stringify(vRueckfahrtChecked)
1149                }
1150        });
1151    }
1152}
1153
1154function openFahrtNewWindow() {
1155    //Auswahl mit Zielregion
1156    if (document.getElementById("zielregion_id") || $("#hafen_id").is("select")) {
1157        var vHafenStartID = $("#hafen_id").val();
1158        if ($("#destination_hafen_id").length > 0) {
1159            var vHafenStopID = $("#destination_hafen_id").val();
1160        } else {
1161            var vHafenStopID = $("#destination_hafen").val();
1162        }
1163    } else {
1164        var vHafenStartID = $("#von_hafen").val();
1165        var vHafenStopID = $("#destination_hafen").val();
1166    }
1167
1168    if ((vHafenStartID == 0 || vHafenStartID) == "" && (vHafenStopID == 0 || vHafenStopID == "")) {
1169        alert(dialog['station_auswaehlen']);
1170        return;
1171    }
1172    var vUrlAdd = "";
1173    if ($("#form\\[nur_hinfahrt\\]").val() == "1") {
1174        vUrlAdd += "&einfache_fahrt=true";
1175    }
1176    if ($.urlParam('erm') != "" && $.urlParam('erm') != undefined) {
1177        vUrlAdd += "&erm=" + $.urlParam('erm');
1178    }
1179
1180    var vVermittlerID = $("#provisionsempfaenger_id").val();
1181    if (parseInt(vVermittlerID) > 0) {
1182        vUrlAdd += "&vermittler_id=" + vVermittlerID;
1183    }
1184
1185    var vURL = "index.php?hide_frame=true&hinfahrt_datum=" + $("#hinfahrt_datum").val() + "&rueckfahrt_datum=" + $("#rueckfahrt_datum").val() + "&hafen=" + vHafenStartID + "&ziel_hafen=" + vHafenStopID + vUrlAdd;
1186
1187    window.open(vURL, '_blank');
1188    /*
1189
1190    var myWindow = window.open(vURL, 'win1', 'width=800,height=600,location=0,menubar=0,scrollbars=1,status=1,toolbar=0,resizable=1');
1191
1192    try {
1193        myWindow.focus();
1194    }
1195    catch (e) {
1196    }*/
1197
1198    $("#fehleranzeige_oben").html("");
1199}
1200
1201function setFahrgastInfo(vStartID, vStopID, Initial) {
1202    if ($("#suchergebnis_hinfahrt").length > 0 || $("#suchergebnis_rueckfahrt").length > 0) {
1203        Initial = "true";
1204    }
1205
1206    //Überprüfung ob Umstiegsverbindung
1207    var vHinfahrt = $(":radio[value='" + vStartID + "']").parent().parent().attr("attr_umstieg");
1208
1209    var vParentDivSoldOut = $(":radio[value='" + vStartID + "']").parent().parent().attr("soldout");
1210    if (vParentDivSoldOut == "true") {
1211        showDialog(dialog['fahrt_ausgebucht'],dialog['onlinebuchung_fahrt_ausgebucht']);
1212        $("#ButtonWeiterSeite2").css("display", "none");
1213        return false;
1214    } else {
1215        $("#ButtonWeiterSeite2").css("display", "");
1216        $('#ButtonWeiterSeite2').removeClass('hide');
1217    }
1218
1219    var vUmstieg = "false";
1220    if (typeof vHinfahrt != 'undefined' && vHinfahrt.length > 10) {
1221        vUmstieg = "true";
1222        $("#umstieg").val("true");
1223    } else {
1224        $("#umstieg").val("false");
1225    }
1226
1227    if(Initial==undefined){
1228        Initial = "";
1229    }
1230
1231    var nur_vormerkung = "0";
1232    if($("#nur_vormerkung").length > 0){
1233        nur_vormerkung = $("#nur_vormerkung").val();
1234    }
1235
1236    var vParameter = "aktion=setFahrgastInfo&start_id=" + vStartID + "&stop_id=" + vStopID + "&Initial=" + Initial + "&umstieg=" + vUmstieg + "&anschlussfahrt=" + $("#anschluss_fahrt").val() + "&nur_vormerkung=" + nur_vormerkung;
1237
1238
1239    if($("#login").val()=="true" && $("#buttons_linie_typ .button").length>0){
1240        setBlockUI();
1241    }
1242
1243    makeAction("setFahrgastInfo", vParameter);
1244
1245    //Anzeige im Title-Tag steuern
1246    if ($(".td_hinfahrt_anzeige #suchergebnis_ausgabe li.active").length > 0) {
1247        var vAbfahrt = "";
1248        var vRueckfahrt = "";
1249        vAbfahrt = $(".td_hinfahrt_anzeige #suchergebnis_ausgabe li.active .suchergebnis_abfahrt").text();
1250        if ($(".td_hinfahrt_anzeige #suchergebnis_ausgabe li.active").length > 0) {
1251            vRueckfahrt = $("#table_rueckfahrt #suchergebnis_ausgabe li.active .suchergebnis_abfahrt").text();
1252        }
1253        if (vRueckfahrt != "") {
1254            $(document).attr("title", vAbfahrt + "->" + vRueckfahrt);
1255        } else {
1256            $(document).attr("title", vAbfahrt);
1257        }
1258    }
1259
1260    //Onlinebuchung - Button Weiter auf Seite 1 aktivieren
1261    if (document.getElementById("ButtonWeiterSeite1")) {
1262        document.getElementById("ButtonWeiterSeite1").disabled = false;
1263        document.getElementById("ButtonWeiterSeite1").style.display = "inline";
1264        //Seite2();
1265    } else {
1266        $("#seite2,#seite3").css("display", "block");
1267    }
1268}
1269
1270function getAnzahlUnterschiedlicheRelationen(){
1271    var einzigartigeKombinationen = {};
1272
1273    // Gehe durch jedes Element, das sowohl hafen_id als auch zielhafen_id hat
1274    $('#suchergebnis_ausgabe ul.suchergebnis li[hafen_id][zielhafen_id]').each(function() {
1275        var hafenId = $(this).attr('hafen_id');
1276        var zielhafenId = $(this).attr('zielhafen_id');
1277        var kombination = hafenId + '-' + zielhafenId;
1278
1279        // Speichere jede einzigartige Kombination in einem Objekt
1280        einzigartigeKombinationen[kombination] = true;
1281    });
1282
1283    // Die Anzahl der Schlüssel in einzigartigeKombinationen entspricht der Anzahl unterschiedlicher Kombinationen
1284    return Object.keys(einzigartigeKombinationen).length;
1285}
1286
1287/**
1288 * Erzeugt ein jQuery-Container-Element mit WhatsApp-, Kopier- und E-Mail-Buttons.
1289 * @param {string} vURL – die zu teilende URL
1290 * @returns {jQuery} – ein <div> mit den Share-Buttons
1291 */
1292function generateShareButton(vURL) {
1293    var urlEncoded = encodeURIComponent(vURL);
1294    var subject    = encodeURIComponent(document.title || dialog['link_teilen']);
1295
1296    // Container für die Buttons
1297    var $container = $('<div class="share-buttons"></div>');
1298
1299    // WhatsApp-Button
1300    var $wa = $('<a>', {
1301        class:  'share-whatsapp button',
1302        href:   'https://api.whatsapp.com/send?text=' + urlEncoded,
1303        target: '_blank',
1304        html:   '<i class="fa-brands fa-whatsapp"></i> WhatsApp'
1305    });
1306
1307    // Kopier-Button
1308    var $copy = $('<button>', {
1309        class: 'share-copy button',
1310
1311        html:  '<i class="fa-solid fa-copy"></i> ' + dialog['link_kopieren']
1312    }).attr('url', vURL).attr('onclick', 'generateShareButtonCallCopy(this)');
1313
1314    // E-Mail-Button
1315    var $email = $('<a>', {
1316        class: 'share-email button',
1317        target: '_blank',
1318        href:  'mailto:?subject=' + subject + '&body=' + urlEncoded,
1319        html:  '<i class="fa-solid fa-envelope"></i> ' + dialog['email']
1320    });
1321
1322    // Element zusammenbauen und zurückgeben
1323    $container.append($wa, ' ', $copy, ' ', $email);
1324    return $container;
1325}
1326
1327
1328function generateShareButtonCallCopy(obj) {
1329    var $btn = $(obj);
1330    var text = $btn.attr('url');
1331
1332    // 1) Copy to clipboard (modern API oder Fallback)
1333    var copyPromise;
1334    if (navigator.clipboard && navigator.clipboard.writeText) {
1335        copyPromise = navigator.clipboard.writeText(text);
1336    } else {
1337        // Fallback
1338        var $tmp = $('<textarea>');
1339        $tmp.css({ position: 'absolute', left: '-9999px' }).val(text).appendTo('body').select();
1340        document.execCommand('copy');
1341        $tmp.remove();
1342        copyPromise = Promise.resolve();
1343    }
1344
1345    copyPromise.then(function() {
1346        // Speichere Original-Hintergrundfarbe
1347        var originalBg = $btn.css('background-color') || '';
1348
1349        // 2) Pulsierende Animation (Skalierung)
1350        $btn
1351            .stop(true)
1352            .animate({ fontSize: '1.2em' }, 150)
1353            .animate({ fontSize: '1em' }, 150);
1354
1355        // 3) Hintergrund-Farbwechsel (jQuery UI color animation)
1356        $btn
1357            .animate({ backgroundColor: "#28a745" }, 200)
1358            .delay(400)
1359            .animate({ backgroundColor: originalBg }, 200);
1360
1361        // 4) Tooltip „Kopiert!“
1362        var $tip = $('<span class="copy-tooltip">'+dialog['kopiert']+'!</span>').css({
1363            position:   'absolute',
1364            top:        '-1.5em',
1365            left:       '50%',
1366            transform:  'translateX(-50%)',
1367            padding:    '.2em .5em',
1368            fontSize:   '0.8em',
1369            background: '#333',
1370            color:      '#fff',
1371            borderRadius: '4px',
1372            opacity:    0,
1373            zIndex:     1000
1374        }).appendTo($btn);
1375
1376        $tip
1377            .animate({ top: '-2em', opacity: 1 }, 200)
1378            .delay(600)
1379            .animate({ top: '-2.5em', opacity: 0 }, 200, function() {
1380                $(this).remove();
1381            });
1382    }).catch(function(err) {
1383        console.error('Kopiervorgang fehlgeschlagen:', err);
1384    });
1385}
1386
1387function makeAction(vModus, vValue) {
1388
1389    if ($("#reservierung_div").length == 0 || $("#einzelverkauf").val() == "true") {
1390        return;
1391    }
1392
1393    //Bei Vormerkung bearbeiten, Linie-Attribut entfernen damit linienübergreifend gebucht werden kann
1394    if ($("#login").val() == "true" && parseInt($("#reservierung_id").val()) > 0 && $("#linie_id").attr("type") == "hidden" && $("#nur_vormerkung").length > 0 && $("#nur_vormerkung").val() == "1") {
1395        $("#form1 #linie_id").first().remove();
1396    }
1397
1398    if ($("#hafen_id").is("select")) {
1399        var abfahrthafen = getSelectBoxWertByID("hafen_id");
1400        if (document.getElementById("destination_hafen")) {
1401            var zielhafen = document.getElementById("destination_hafen").value;
1402        } else {
1403            var zielhafen = getSelectBoxWertByID("destination_hafen_id");
1404        }
1405
1406    } else {
1407        var abfahrthafen = $("#von_hafen").val();
1408        var zielhafen = $("#destination_hafen").val();
1409    }
1410
1411    if ($("#login").val() != "true" && parseInt($("#zielhafen_id_set").val()) > 0 && parseInt(zielhafen) == 0) {
1412        zielhafen = $("#zielhafen_id_set").val();
1413    }
1414
1415
1416    var linie_id = ($("#linie_id").val());
1417    if (linie_id == undefined) {
1418        linie_id = $(".suchergebnis_ausgabe li.active").attr("linie_id");
1419    }
1420    if (linie_id == undefined) {
1421        linie_id = 0;
1422    }
1423
1424    var start = document.getElementById("hinfahrt_datum").value;
1425
1426    var stop = 0;
1427    if (document.getElementById("rueckfahrt_datum")) {
1428        stop = document.getElementById("rueckfahrt_datum").value;
1429    } else {
1430        stop = start;
1431    }
1432
1433    if ($("#betreiber_id").length > 0) {
1434        var vBetreiberID = $("#betreiber_id").val();
1435    } else if ($("#only_betreiber_id").length > 0) {
1436        var vBetreiberID = $("#only_betreiber_id").val();
1437    } else {
1438        var vBetreiberID = 0;
1439    }
1440
1441    if (parseInt(vBetreiberID) > 0) {
1442        vBetreiberID = "&betreiber_id=" + vBetreiberID;
1443    } else {
1444        vBetreiberID = "";
1445    }
1446
1447    var nur_hinfahrt = document.getElementById("form[nur_hinfahrt]").value;
1448
1449    var vURL = "?hinfahrt_datum=" + convertTimestampToGerman(start) + "&hafen=" + abfahrthafen + "&ziel_hafen=" + zielhafen + "&einfache_fahrt=" + (nur_hinfahrt == "1" ? "true" : "");
1450
1451    if ($("#hafen_umstieg_id").length > 0) {
1452        var vUmstiegID = $("#hafen_umstieg_id").val();
1453        vURL += "&hafen_umstieg_id=" + vUmstiegID;
1454    }
1455
1456    var vSelectedLinieID = "";
1457    if ($("#suchergebnis_ausgabe ul li.active").length > 0) {
1458        vSelectedLinieID = $("#suchergebnis_ausgabe ul li.active").attr("linie_id");
1459        vURL += "&linie_id=" + vSelectedLinieID;
1460    }
1461
1462    if ($("#cb_filter_umstiegsverbindung:checked").length > 0) {
1463        vURL += "&use_umstieg=1";
1464    }
1465
1466    //GYG Link zusammenstellen
1467    var vGYG = "";
1468    var routeKeyJson = "";
1469    var datum = "";
1470    var lhf = "";
1471    var lhfz = "";
1472    if ($("#accountname").length > 0 && $("#suchergebnis_ausgabe ul li.active").length > 0) {
1473        var el = $("#suchergebnis_ausgabe ul li.active");
1474        datum = convertTimestampToGerman($(el).attr("datum"));
1475        vGYG += $("#accountname").val() + "-" + $(el).attr("linie_id");
1476        vGYG += "-" + $(el).attr("hafen_id") + "-" + $(el).attr("zielhafen_id");
1477
1478        if ($("#rueckfahrt_anzeige ul li.active").length > 0) {
1479            vGYG += "-" + $(el).attr("hafen_id");
1480        }
1481
1482        //Route-Key erstellen
1483        var linie_hafen_id_start = $(el).attr("linie_hafen_id_start");
1484        var fahrt = $(el).attr("fahrt");
1485        var route_key_linie_id = $(el).attr("linie_id");
1486
1487        var lhf = $(el).attr("linie_hafen_fahrplan_id");
1488        var lhfz = $(el).attr("linie_hafen_id_stop");
1489
1490        var routeKeyJson = '[[' + [linie_hafen_id_start, lhfz, fahrt, route_key_linie_id].join(',') + ']]';
1491    }
1492
1493    //Server und Domain hinzufügen
1494    vURL = "https://"+$("#http_host").val()+"/"+vURL;
1495
1496    $("div.kontingent span").text(datum+"-"+lhf+"-"+lhfz);
1497    $("div.kontingent_easy span").text(lhf+"-"+lhfz);
1498    $("#shortcut_suchergebnis .buchung_url span").text(vURL);
1499    $("#shortcut_suchergebnis div.gyg span").text(vGYG);
1500    $("#shortcut_suchergebnis div.route_key span").text(routeKeyJson);
1501    $("#shortcut_suchergebnis .share").html("").append(generateShareButton(vURL));
1502    $("#shortcut_suchergebnis").removeClass("hide");
1503
1504    if (vValue && vValue != "") {
1505        var vTagExtra = vValue.split("_")[10];
1506        if (vTagExtra && parseInt(vTagExtra) > 0 && vModus == "getRueckfahrt") {
1507            var vAnkunftTS = parseInt(vValue.split("_")[11]);
1508            if (stop < vAnkunftTS) {
1509                stop = vAnkunftTS;
1510            }
1511        }
1512    }
1513
1514    var region_id = getSelectBoxWertByID("region_id");
1515    if ($("#linie_typ_id").length > 0 && parseInt($("#linie_typ_id").val()) > 0) {
1516        var linie_typ_id = getSelectBoxWertByID("linie_typ_id");
1517    } else {
1518        var linie_typ_id = 0;
1519    }
1520
1521    var intoLinie = document.getElementById("intoLinie").value;
1522    var no_kombi = document.getElementById("no_kombi").value;
1523    var onlyTarifID = document.getElementById("onlyTarifID").value;
1524    var login = document.getElementById("login").value;
1525    var zufall = Math.round(Math.random() * 48 + 1);
1526
1527    if (document.getElementById("klasse_id")) {
1528        var klasse_id = getSelectBoxWertByID("klasse_id");
1529    } else {
1530        var klasse_id = 0;
1531    }
1532
1533    if (document.getElementById("reservierung_id")) {
1534        var reservierung_id = parseInt(document.getElementById("reservierung_id").value);
1535    } else {
1536        var reservierung_id = 0;
1537    }
1538
1539    if (document.getElementById("buchung_vergangenheit")) {
1540        var buchung_vergangenheit = document.getElementById("buchung_vergangenheit").value;
1541    } else {
1542        var buchung_vergangenheit = 0;
1543    }
1544
1545    var vUserTarifFreieingabe = 0;
1546    if ($("#user_tarif_freieingabe").length > 0) {
1547        vUserTarifFreieingabe = $("#user_tarif_freieingabe").val();
1548    }
1549
1550    var vSchiffID = 0;
1551    if ($("#only_schiff_id").length > 0) {
1552        vSchiffID = $("#only_schiff_id").val();
1553    }
1554
1555    var vParameterURL = "&abfahrthafen=" + encodeURIComponent(abfahrthafen) + "&start=" + start + "&stop=" + stop + "&zielhafen=" + encodeURIComponent(zielhafen) + "&linie_id=" + linie_id + "&region_id=" + region_id + "&linie_typ_id=" + linie_typ_id + "&intoLinie=" + intoLinie + "&no_kombi=" + no_kombi + "&buchung_vergangenheit=" + buchung_vergangenheit + "&login=" + login + "&klasse_id=" + klasse_id + "&reservierung_id=" + reservierung_id + "&zufall=" + zufall + "&onlyTarifID=" + onlyTarifID + "&nur_hinfahrt=" + nur_hinfahrt + "&user_tarif_freieingabe=" + vUserTarifFreieingabe + "&only_schiff_id=" + vSchiffID + vBetreiberID + "&linie_hafen_fahrplan_id=" + $("#linie_hafen_fahrplan_id").val();
1556
1557
1558    if (parseInt($("#only_fahrt").val()) > 0) {
1559        vParameterURL += "&only_fahrt=" + $("#only_fahrt").val();
1560    }
1561
1562    //Umstiegsverbindung
1563    if ($("#hafen_umstieg_id").length > 0 && parseInt($("#hafen_umstieg_id").val()) > 0) {
1564        vParameterURL += "&umstieg_hafen_id=" + $("#hafen_umstieg_id").val();
1565    }
1566
1567    if (document.getElementById("anzeige_tage") && $("#anzeige_tage").is("input")) {
1568        vParameterURL += "&anzeige_tage=" + $("#anzeige_tage").val();
1569    } else if (document.getElementById("anzeige_tage")) {
1570        vParameterURL += "&anzeige_tage=" + $("#slider-anzeige_tage").slider("value");
1571    }
1572
1573    if ($("#abfahrt_uhrzeit").val() != "") {
1574        vParameterURL += "&abfahrt_uhrzeit=" + $("#abfahrt_uhrzeit").val();
1575    }
1576
1577    vParameterURL+= "&lang="+$("body").attr("lang");
1578
1579    if (vModus == "setFahrgastInfo") {
1580        $("#reservierung_div_comp[data-booking-a11y='true']").data("a11yTicketLoading", true);
1581
1582        //Nur in der Onlinebuchung
1583        if ($("#login").val() != "true") {
1584            setBlockUI();
1585        }
1586
1587        $.get("ajax/onlinereservierung.php?" + vValue + vParameterURL, function (data) {
1588            if($("#seite1.showforbookingenginev4").length == 0){
1589                $.unblockUI();
1590            }
1591
1592            $("#mySubmit").css("display","");
1593            eval(data);
1594            $("#tr_fahrgaeste").css("display","");
1595
1596            //Textblöcke
1597            $(".textblockrow, .textblockkategorie").removeClass("hide");
1598            var li = $("td.td_hinfahrt_anzeige #suchergebnis_ausgabe ul li.active");
1599            if ($(".textblockrow").length > 0 && $(li).length > 0) {
1600                if (parseInt($(li).attr("linie_typ_id")) > 0) {
1601                    $(".textblockrow").not("[linientyp_id='0'],[linientyp_id='" + $(li).attr("linie_typ_id") + "']").addClass("hide");
1602                    $(".textblockkategorie").not("[linientyp_id='0'],[linientyp_id='" + $(li).attr("linie_typ_id") + "']").addClass("hide");
1603                }
1604
1605                if (parseInt($(li).attr("hafen_id")) > 0) {
1606                    $(".textblockrow").not("[hafen_start_id='0'],[hafen_start_id='" + $(li).attr("hafen_id") + "']").addClass("hide");
1607                }
1608
1609                if ($(".textblockkategorie.ui-tabs-active.hide").length > 0 && $(".textblockkategorie").not(".hide").length > 0) {
1610                    $(".textblockkategorie").not(".hide").first().find("a").trigger("click");
1611                }
1612
1613            }
1614
1615            //Acccordeon Extra
1616            if ($('.AccExtras').length > 0 && 5 == 2) {
1617                if ($('.AccExtras').hasClass('ui-accordion')) {
1618                    $('.AccExtras').accordion('destroy');
1619                }
1620                $('.AccExtras').accordion({
1621                    collapsible: true,
1622                    active: false,
1623                    heightStyle: "content"
1624                });
1625            }
1626
1627            $("#ticket_headline").removeClass("hide");
1628
1629            if ($("#login").val() != "true") {
1630
1631            } else if ($("#login").val() == "true") {
1632                //Zur Ticketauswahl (Preistypen) springen
1633                setTimeout(function () {
1634
1635                    if ($("div#ticket_headline").is(":visible")) {
1636                        if (scrolling == true) {
1637                            $('html, body').animate({
1638                                scrollTop: $("div#ticket_headline").offset().top
1639                            }, 500);
1640                        }
1641                    }
1642                }, 10);
1643            }
1644
1645            //Anzahal der verfügbaren Plätze darstellen
1646            var reservierung_id = 0;
1647            if($("#reservierung_id").length > 0 && parseInt($("#reservierung_id").val()) > 0){
1648                reservierung_id = parseInt($("#reservierung_id").val());
1649            }
1650
1651            if(reservierung_id == 0 && $("#koenigssee").length==0){
1652                var frei=0;
1653                $.each($(".td_hinfahrt_anzeige #suchergebnis_ausgabe li.active"), function () {
1654                    if($(this).attr("fr") != undefined && parseInt($(this).attr("fr")) > 0){
1655                        var temp_frei = parseInt($(this).attr("fr"));
1656                        if(temp_frei < frei || frei == 0){
1657                            frei = temp_frei;
1658                        }
1659                    }
1660                });
1661
1662                console.log("Frei Plätze: "+frei);
1663
1664                $(".anzahl_personen_preistyp_container select option").removeClass("hide");
1665                if(frei>0){
1666                    $.each($(".anzahl_personen_preistyp_container select option"),function () {
1667                        var wert = parseInt($(this).attr("value"));
1668                        if(wert > frei){
1669                            $(this).addClass("hide");
1670                        }
1671                    });
1672                }
1673            }
1674        }).always(function () {
1675            $("#reservierung_div_comp[data-booking-a11y='true']").removeData("a11yTicketLoading");
1676            updateOnlinebuchungAccessibility();
1677            focusOnlinebuchungStep();
1678        });
1679
1680        //Druckereinstellung
1681        if ($("#login").val() == "true" && $("#standard_drucker_spezial_id").length > 0) {
1682            if ($("td.td_hinfahrt_anzeige li.active").attr("use_spezialticket") == "1" && parseInt($("#standard_drucker_spezial_id").val()) > 0) {
1683                $("#ticketdrucker_id").val($("#standard_drucker_spezial_id").val());
1684            } else if (parseInt($("#standard_drucker_id").val()) > 0) {
1685                //alert($("#standard_drucker_id").val());
1686                $("#ticketdrucker_id").val($("#standard_drucker_id").val());
1687            }
1688        }
1689    } else if (vModus == "setAnsicht") {
1690
1691        if($("#hafen_umstieg_id").length>0 && parseInt($("#hafen_umstieg_id").val())>0){
1692            $(".suchmaske.tour").addClass("hide");
1693        }
1694        else{
1695            $(".suchmaske.tour").removeClass("hide");
1696        }
1697
1698        document.getElementById("tr_fahrgaeste").style.display = "none";
1699
1700        //Fahrt unsichtbar
1701        $("#f1, #f2, #rfdatum, #rf2, #rf3, #seite3, #mySubmit, #ButtonWeiterSeite1, #tr_fahrt, #DivNextStepFahrtFinden").css("display", "none");
1702        $("#buttons_linie_typ").addClass("hide");
1703        $("#tr_hafen").css("display", "");
1704        $("#td_destination_hafen").css("display", "");
1705        $("#tr_zielhafen").css("display", "");
1706
1707        if (document.getElementById("table_rueckfahrt") && reservierung_id == 0) {
1708            document.getElementById("table_rueckfahrt").style.display = "none";
1709        }
1710
1711        $("#shortcut_suchergebnis, #ticket_headline").addClass("hide");
1712
1713
1714        //Nur Hinfahrt anzeigen oder nicht
1715        if (document.getElementById("hide_nur_hinfahrt").value == "1") {
1716            $("#hinfahrt_2").css("display", "none");
1717            $("#hinfahrt_1").css("display", "none");
1718            nurHinfahrt = 1;
1719        } else {
1720            $("#hinfahrt_2").css("display", "");
1721            $("#hinfahrt_1").css("display", "");
1722        }
1723        //Fahrtanzeige
1724        if (nurHinfahrt && nurHinfahrt == 1) {
1725            $("#rf1").css("display", "none");
1726        } else {
1727            $("#rf1").css("display", "");
1728        }
1729        if ($("#suchergebnis_hinfahrt").length > 0 && $("#suchergebnis_hinfahrt").val() != "") {
1730            getFahrt(9);
1731        }
1732
1733    }
1734    //Hinfahrt
1735    else if (vModus == "getFahrt") {
1736
1737        $("#rueckfahrt_anzeige").html("");
1738        if (document.getElementById("ButtonWeiterSeite1")) {
1739            document.getElementById("ButtonWeiterSeite1").disabled = true;
1740        }
1741
1742        $("#seite2, #seite3").css("display", "none");
1743
1744        document.getElementById("rueckfahrt_anzeige_ziel").innerHTML = "";
1745        document.getElementById("tr_fahrgaeste").style.display = "none";
1746        document.getElementById('rf2').style.display = 'none';
1747        $("#rfdatum").css("display", "none");
1748        document.getElementById('rf3').style.display = 'none';
1749        document.getElementById("fehleranzeige_oben").style.display = '';
1750
1751        //Filterkriterium nach erstem Laden entfernen
1752        $("#linie_hafen_fahrplan_id").val(0);
1753
1754        if ((zielhafen == "" || zielhafen == "0" || zielhafen == 0) && (abfahrthafen == "" || abfahrthafen == "0" || abfahrthafen == 0) && region_id == 0 && (linie_typ_id == 0 || isNaN(linie_typ_id)) && document.getElementById("matchcode").value == "" && linie_id == 0) {
1755            document.getElementById("fehleranzeige_oben").innerHTML = ("<font color='red'>" + lang["suchkriterium_angeben"] + "</font>");
1756            $.unblockUI();
1757            showOnlinebuchungSearchError("#hafen_id, #von_hafen");
1758        } else if (document.getElementById("zielregion_id") && ($("#hafen_id").val() == 0 || $("#destination_hafen_id").val() == 0)) {
1759            document.getElementById("fehleranzeige_oben").innerHTML = ("<font color='red'>" + lang["abfahrt_zielhafen_angeben"] + "</font>");
1760            $.unblockUI();
1761            showOnlinebuchungSearchError("#hafen_id, #destination_hafen_id");
1762        } else if (
1763            $("#fahrt_suchen select#hafen_id").length > 0
1764            && parseInt($("#fahrt_suchen select#hafen_id").val()) == 0
1765            && (parseInt($("#fahrt_suchen select#destination_hafen").val()) == 0 || $("#fahrt_suchen select#destination_hafen").val() == undefined || isNaN(parseInt($("#fahrt_suchen select#destination_hafen").val())))) {
1766            document.getElementById("fehleranzeige_oben").innerHTML = ("<div class='callout secondary'><img src='images/fontawesome/info-circle.svg' class='IconSmall'/> " + lang["suchkriterium_angeben"] + "</div>");
1767            $.unblockUI();
1768            showOnlinebuchungSearchError("#hafen_id");
1769        } else if (($("#von_hafen").val() == "" && $("#destination_hafen").val() == "") && document.getElementById("matchcode").value == "" && !(parseInt($("#linie_id").val()) > 0)) {
1770            document.getElementById("fehleranzeige_oben").innerHTML = ("<font color='red'>" + lang["abfahrt_zielhafen_angeben"] + "</font>");
1771            $.unblockUI();
1772            showOnlinebuchungSearchError("#von_hafen, #destination_hafen");
1773        } else if (start == 0 || (document.getElementById("form[nur_hinfahrt]").value == 0 && stop == 0 && $("#hafen_rueckfahrt_row").length > 0)) {
1774            document.getElementById("fehleranzeige_oben").innerHTML = ("<font color='red'>" + lang["hin_und_rueckfahrt_datum_angeben"] + "</font>");
1775            $.unblockUI();
1776            showOnlinebuchungSearchError("#cal_hinfahrt_datum, #cal_rueckfahrt_datum");
1777        } else if (document.getElementById("form[nur_hinfahrt]").value == 0 && stop < start && $("#fahrt_suchen select#destination_hafen").length > 0) {
1778            document.getElementById("fehleranzeige_oben").innerHTML = ("<font color='red'>" + lang["datum_falsch"] + "</font>");
1779            $.unblockUI();
1780            showOnlinebuchungSearchError("#cal_rueckfahrt_datum");
1781        } else if ($("#zielstation_immer_waehlen").val() == "1" && (zielhafen == "" || zielhafen == "0" || zielhafen == 0) && $("#destination_hafen").val() == "") {
1782            document.getElementById("fehleranzeige_oben").innerHTML = ("<font color='red'>" + lang["abfahrt_zielhafen_angeben"] + "</font>");
1783            $.unblockUI();
1784            showOnlinebuchungSearchError("#destination_hafen_id, #destination_hafen");
1785        } else {
1786
1787            //In PopUp öffnen
1788            if (vOpenPopUp && vOpenPopUp == "true") {
1789                return;
1790            }
1791
1792
1793            document.getElementById("fehleranzeige_oben").style.display = 'none';
1794
1795            //Bei Umstiegsfahrt, Wartebildschirm
1796            if ($("#hafen_umstieg_id").length > 0 && parseInt($("#hafen_umstieg_id").val()) > 0) {
1797                setBlockUI();
1798            }
1799            else if($("#login").val()=="true" && $("#buttons_linie_typ .button").length>0){
1800                setBlockUI();
1801            }
1802
1803            $.post("ajax/onlinereservierung.php", "aktion=getFahrt&modus=hinfahrt&target_element_id=fahrt_anzeige" + vParameterURL, function (data) {
1804
1805                if($("#seite1.showforbookingenginev4").length == 0){
1806                    $.unblockUI();
1807                }
1808
1809                eval(data);
1810
1811                //Als Überschrift das Datum
1812                var text = $("#hinfahrt_anzeige").closest("table").find("#f2 #suchergebnis_ausgabe .suchergebnis_datum").first().text();
1813                $("#hinfahrt_anzeige").closest("table").find("h3").text(text);
1814
1815                if ($(".button_anzeigen input:button").length > 0) {
1816                    $("div.buchungbuttons").remove();
1817                }
1818
1819                //Bereits hinterlegtes Suchergebnis wurde hinterlegt, dieses markieren und anschließend lsöchen
1820                if ($("#suchergebnis_hinfahrt").length > 0 && $("#suchergebnis_hinfahrt").val() != "") {
1821                    var vObjRadio = $("input[type='radio'][value='" + $("#suchergebnis_hinfahrt").val() + "']");
1822                    if ($(vObjRadio).length == 0) {
1823                        alert(window.dialog["ui_fe58111aa38f"]);
1824                    } else {
1825                        $(vObjRadio).prop("checked", true);
1826                        $(vObjRadio).closest('li').trigger("click");
1827                    }
1828                }
1829                $("#suchergebnis_hinfahrt").remove();
1830                if ($("#cb_form\\[nur_hinfahrt\\]").is(":checked")) {
1831                    $("#suchergebnis_rueckfahrt").remove();
1832                }
1833
1834                if($("#seite1.showforbookingenginev4").length == 1 && $(".td_hinfahrt_anzeige #suchergebnis_ausgabe ul li").not(".hide").length==0){
1835                    $.unblockUI();
1836                    var html = dialog['tour_nicht_mehr_buchen']+"<br>"+"<br>"+"<a href='index.php' class='button '>"+dialog['zurueck']+"</a>";
1837                    $("#seite1").html(html);
1838                    $("#seite1").removeClass("hide").removeClass("showforbookingenginev4");
1839                }
1840
1841                //alert(getAnzahlUnterschiedlicheRelationen()+" "+$("#suchergebnis_ausgabe ul.suchergebnis li[hafen_id][zielhafen_id]")+"  "+$("#hafen_id option").length);
1842
1843                //In Tabs nach Zielstation darstellen
1844                if (
1845                    showTabs == 1
1846                    && (getAnzahlUnterschiedlicheRelationen()>1  || $("#koenigssee").length>0)
1847                    && $("#reservierung_id").val() == undefined
1848                ) {
1849                    var arrayHafen = {};
1850                    var arrayHafenS = [];
1851                    var arrayHafenB = [];
1852                    $.each($("#suchergebnis_ausgabe ul li"), function () {
1853
1854                        if ($(this).attr("linie_extra_tab") == "1") {
1855                            var hafen_id = "e";
1856                            var hafen = "<img src='images/fontawesome/search-plus.svg' class='IconSmall'/>";
1857                            var sort = 99;
1858                        } else {
1859                            var hafen_id = $(this).attr("zielhafen_id");
1860                            var hafen = decodeURIComponent($(this).attr("zielhafen"));
1861                            var sort = parseInt($(this).attr("zielstation_sort"));
1862                        }
1863
1864                        if (arrayHafen[hafen_id] == undefined) {
1865                            arrayHafen[hafen_id] = {};
1866
1867                            //Zielstation = Ausgangsstation - ganz nach vorne bringen
1868                            if (hafen_id == $("#hafen_id").val() && arrayHafenS.length > 0) {
1869                                arrayHafenS.unshift(hafen_id);
1870                            } else {
1871                                arrayHafenS.push(hafen_id);
1872                            }
1873                            arrayHafenB.push({"ID": hafen_id, "bezeichnung": hafen, "sort": sort});
1874                        }
1875
1876                        arrayHafen[hafen_id]["id"] = hafen_id;
1877                        arrayHafen[hafen_id]["bezeichnung"] = hafen;
1878                        if (arrayHafen[hafen_id]["zaehler"] == undefined) {
1879                            arrayHafen[hafen_id]["zaehler"] = 0;
1880                        }
1881                        arrayHafen[hafen_id]["zaehler"]++;
1882                    });
1883
1884                    if (arrayHafenS.length > 2 && $("#login").val() == "true") {
1885                        var hafen_id = "za";
1886                        var hafen = "<i class='fa-solid fa-circle-notch'></i>";
1887                        var sort = 199;
1888                        arrayHafenS.push(hafen_id);
1889                        arrayHafenB.push({"ID": hafen_id, "bezeichnung": hafen, "sort": sort});
1890                        arrayHafen[hafen_id] = {"id": hafen_id, "bezeichnung": hafen, "sort": sort, "zaehler": 1};
1891                    }
1892
1893                    if (Object.keys(arrayHafen).length > 0) {
1894                        var ulSuchergebnis = $("#suchergebnis_ausgabe ul.suchergebnis").detach();
1895
1896                        //In Tabs wrappen
1897                        var div = $("<div/>");
1898                        $(div).attr("id", "div-wrap-suchergebnis");
1899                        var ul = $("<ul/>");
1900                        $(ul).addClass("hide_booking_in_iframe");
1901                        $(div).append(ul);
1902
1903                        //Sortieren - Erster Eintrag ganz nach vorne
1904                        $.each(arrayHafenB, function (index, hafen) {
1905
1906                            if (hafen["ID"] == "za" || hafen["ID"]["bezeichnung"] == "e") {
1907                                arrayHafenB[index]["sortnow"] = "zzzzzz";
1908                            } else if (stationenSortVar) {
1909                                arrayHafenB[index]["sortnow"] = "1" + LeadingZero(arrayHafenB[index]["sort"], 3) + "-" + arrayHafenB[index]["bezeichnung"];
1910                            } else {
1911                                arrayHafenB[index]["sortnow"] = arrayHafenB[index]["bezeichnung"];
1912                            }
1913
1914                            if (parseInt(hafen["ID"]) == parseInt($("#hafen_id").val())) {
1915                                arrayHafenB[index]["sortnow"] = "0000-" + arrayHafenB[index]["bezeichnung"];
1916                            }
1917                        });
1918
1919                        var byName = arrayHafenB.slice(0);
1920                        byName.sort(function (a, b) {
1921                            var x = a.sortnow.toLowerCase();
1922                            var y = b.sortnow.toLowerCase();
1923                            return x < y ? -1 : x > y ? 1 : 0;
1924                        });
1925                        arrayHafenB = byName;
1926
1927                        var c = 0;
1928                        //Suchergebenis durchlaufen nach Sortierreihenfolge der Tabs
1929                        $.each(arrayHafenB, function (index, hafen) {
1930                            var id = hafen["ID"];
1931                            if (arrayHafen[id] == undefined) {
1932                                return;
1933                            }
1934
1935                            var divTab = $("<div id='tab-auswahl-" + id + "' hafen_id='" + id + "'></div>");
1936                            $(divTab).append("<ul/>");
1937                            if (c == 0) {
1938                                $(divTab).find("ul").append(ulSuchergebnis);
1939                            }
1940                            $(div).append(divTab);
1941
1942                            var bezeichnung = "";
1943                            if (parseInt(id) == parseInt($("#hafen_id").val())) {
1944                                bezeichnung += "<i class='fa-solid fa-arrow-rotate-left logo-rundfahrt' title='" + dialog['rf_rundfahrt'] + "'></i>&nbsp;";
1945                            }
1946                            bezeichnung += arrayHafen[id]["bezeichnung"];
1947                            if ($("#login").val() == "true") {
1948                                if (id == "za") {
1949                                    var vAnzahl = $(ulSuchergebnis).find("li").length;
1950                                } else if (id == "e") {
1951                                    var vAnzahl = $(ulSuchergebnis).find("li[linie_extra_tab='1']").length;
1952                                } else {
1953                                    var vAnzahl = $(ulSuchergebnis).find("li[zielhafen_id='" + id + "'][linie_extra_tab='0'][kombifehler='false']").length;
1954                                }
1955                                if(hafen["sort"]!=199){
1956                                    bezeichnung += " (" + vAnzahl + "x)";
1957                                }
1958                            }
1959
1960                            $(ul).append("<li hafen_id='" + id + "'><a href='#tab-auswahl-" + id + "'>" + bezeichnung + "</a></li>");
1961
1962                            c++;
1963                        });
1964
1965                        $(div).tabs({
1966                            active: false,
1967                            collapsible: true,
1968                            beforeActivate: function (event, ui) {
1969                                var hafenId = $(ui.newPanel).attr("hafen_id");
1970                                $(ulSuchergebnis).detach().appendTo($(ui.newPanel));
1971                                $(ulSuchergebnis).find("li").addClass("hide");
1972                                $(ulSuchergebnis).find("li").removeClass("even").removeClass("odd");
1973
1974                                if (hafenId == "za") {
1975                                    $(ulSuchergebnis).find("li").removeClass("hide");
1976                                } else if (hafenId == "e") {
1977                                    $(ulSuchergebnis).find("li[linie_extra_tab='1']").removeClass("hide");
1978                                } else {
1979                                    $(ulSuchergebnis).find("li[zielhafen_id='" + hafenId + "'][linie_extra_tab='0']").removeClass("hide");
1980                                }
1981
1982                                var c = true;
1983                                $.each($(ulSuchergebnis).find("li").not(".hide"), function () {
1984                                    if (c == true) {
1985                                        $(this).addClass("odd");
1986                                        c = false;
1987                                    } else {
1988                                        $(this).addClass("even");
1989                                        c = true;
1990                                    }
1991                                });
1992
1993                                //Maximale Anzahl Suchergebnisse einschränken
1994                                if(anzahlMaxSuchergebnisse !== undefined && anzahlMaxSuchergebnisse>0){
1995                                    //suchergebnisEinschraenken(ulSuchergebnis);
1996                                }
1997
1998                                //Markieren
1999                                if ($("#login").val() == "true") {
2000                                    setTimeout(function () {
2001                                        $("ul.suchergebnis li").not(".hide").not(".durchgestrichen").first().trigger("click");
2002                                    }, 30);
2003                                } else {
2004                                    var li = $("ul.suchergebnis li").not(".hide").not(".durchgestrichen").first();
2005
2006                                    //Es gibt eine Rückfahrt - Erstes Ergebnis markieren
2007                                    if ($(li).attr("nur_hinfahrt") == "0" && $(ui.newPanel).find("ul.suchergebnis li").not(".hide").not(".durchgestrichen").length == 1) {
2008                                        setBlockUI();
2009                                        $(li).trigger("click");
2010                                    } else {
2011                                        setEinfacheFahrt(true);
2012                                        $("#DivNextStepFahrtFinden input").prop("disabled", true);
2013                                    }
2014                                }
2015                                $("#f1").css("display", "");
2016                            }
2017                        });
2018
2019                        $("#suchergebnis_ausgabe").append(div);
2020                        $(div).tabs("option", "active", 0);
2021                        $(div).tabs("option", "collapsible", false);
2022                        $("#f1").css("display", "");
2023
2024                        //Hier Kapazitätsprüfung für die darunterliegenden Fahrten nachdem man den Tab gewechselt hat
2025                        $(div).on("tabsactivate", function (event, ui) {
2026                            var zielhafen_id = $(ui.newPanel).attr("hafen_id");
2027                            var target = $(ui.newPanel).find("li[zielhafen_id='"+zielhafen_id+"']").find("input.kapazitaetbutton, .container_kapazitaet").first();
2028                            if($(target).length>0){
2029                                var li = $(target).closest("li");
2030                                showKapazitaetV2(li);
2031                            }
2032                        });
2033
2034                        if ($("#login").val() == "true") {
2035                            var text = "";
2036                        } else if ($(arrayHafenB).length == 1) {
2037                            var text = dialog['fahrt_auswaehlen'];
2038                        } else {
2039                            var text = dialog['zielstation_auswaehlen'];
2040                        }
2041
2042                        if (text == "") {
2043                            $("#hinfahrt_anzeige").html("");
2044                            $("#hinfahrt_anzeige").addClass("hide");
2045                        } else {
2046                            $("#hinfahrt_anzeige").html("<div class='callout secondary' id='infotext_fahrt_auswaehlen'><p><img src='images/fontawesome/info-circle.svg' class='IconSmall'>
2046 " + text + "</p></div>");
2047                            $("#hinfahrt_anzeige").removeClass("hide");
2048                        }
2049
2050                    } else {
2051                        $("#hinfahrt_anzeige").addClass("hide");
2052                    }
2053                }
2054                //In Tabs nach Uhrzeiten darstellen
2055                else if(
2056                    showTabs == 1
2057                    && getAnzahlUnterschiedlicheRelationen()==1
2058                    && $("#suchergebnis_ausgabe ul.suchergebnis li[hafen_id][zielhafen_id]").length>10
2059                    && $("#reservierung_id").val() == undefined
2060                    && (
2061                        vProgrammModus == "ticket"
2062                        || $("#hafen_id option").length==1
2063                        || $("#zielhafen_id_set").val()!=""
2064                        || parseInt($("#destination_hafen_id").val())>0
2065                    )
2066                ) {
2067
2068                    $("#infotext_fahrt_auswaehlen").remove();
2069
2070                    $("#tabs").remove();
2071                    var htmlTabs = '<div id="tabs"><ul id="tabs-header"></ul></div>';
2072                    $('#suchergebnis_ausgabe').prepend(htmlTabs);
2073
2074                    var abfahrtszeiten = $('#suchergebnis_ausgabe ul.suchergebnis li').not("[kombifehler=true]");
2075                    var tabsContent = {};
2076                    var objAbfahrtszeiten={};
2077                    var tabIndex = 1;
2078
2079                    abfahrtszeiten.each(function () {
2080
2081                        var abfahrt = $(this).attr('abfahrt');
2082                        var stunde = parseInt(abfahrt.substring(0, 2), 10);
2083                        var minute = abfahrt.substring(2, 4);
2084                        var tabKey = Math.floor(stunde / 3); // Gruppierungsschlüssel basierend auf 3-Stunden-Intervall
2085
2086                        var text = stunde+":"+minute;
2087                        var frei  =$(this).attr("fr");
2088                        if($("#se_kap").length>0 && frei != undefined && parseInt(frei) > 0){
2089                            text += " ("+frei+ " "+dialog['frei_plaetze']+")";
2090                        }
2091
2092                        if (!tabsContent[tabKey]) {
2093                            tabsContent[tabKey] = [];
2094                            objAbfahrtszeiten[tabKey] = [];
2095                        }
2096                        objAbfahrtszeiten[tabKey].push(this);
2097                        tabsContent[tabKey].push(stunde);
2098                    });
2099
2100                    if(Object.keys(tabsContent).length<=1){
2101                        return;
2102                    }
2103
2104                    $.each(tabsContent, function (key, value) {
2105
2106                        var first = value[0];
2107                        var last = value[value.length-1];
2108                        var indexC = first;
2109                        if(last!=first){
2110                            indexC+="-"+last;
2111                        }
2112                        indexC+=" "+dialog['uhr'];
2113
2114                        var tabId = "tab-" + tabIndex;
2115                        $('#tabs-header').append('<li><a href="#' + tabId + '">' + indexC + '</a></li>');
2116                        $('#tabs').append('<div id="' + tabId + '" class="tab-content" data-tab-key="'+key+'"></div>');
2117                        tabIndex++;
2118                    });
2119                    $("ul.suchergebnis li").addClass("hide1");
2120                    $('#tabs').tabs({
2121                        beforeActivate: function( event, ui ) {
2122                            $("ul.suchergebnis li").addClass("hide1");
2123                            var tabKey = $(ui.newPanel).attr("data-tab-key");
2124                            $(objAbfahrtszeiten[tabKey]).removeClass("hide1");
2125                        },
2126                        create: function( event, ui ) {
2127                            var tabKey = $(ui.panel).attr("data-tab-key");
2128                            $(objAbfahrtszeiten[tabKey]).removeClass("hide1");
2129                        }
2130                    });
2131
2132                    //Vor den Tabs die Selectbox einfügen
2133                    $("#select-tabs-uhrzeiten").remove();
2134                    scrolling = false;
2135                }
2136
2137                //Scroll to Suchergebnis
2138                if (($("#buttonFinden").attr("isdirty") == "true" && scrolling == true && $("div.suchauswahl_buchungsmaske").length == 0) || $("#HTTP_USER_AGENT").val() == "iOSKassa") {
2139                    $('html, body').animate({
2140                        scrollTop: $("tr#f1 td h3").offset().top
2141                    }, 1000);
2142                }
2143
2144                //Erstes Ergebnis markieren Backend
2145                if ($("#login").val() == "true" && $("#reservierung_id").val() == undefined && $(".td_hinfahrt_anzeige #suchergebnis_ausgabe ul.suchergebnis li").length > 0 && $("#div-wrap-suchergebnis").length == 0) {
2146                    $(".td_hinfahrt_anzeige #suchergebnis_ausgabe ul li").not(".hide").first().trigger("click");
2147                }
2148                //Weiter Button
2149                if ($("#login").val() == "false" && $(".td_hinfahrt_anzeige #suchergebnis_ausgabe ul li.active").length == 1 && $("#div-wrap-suchergebnis").length == 0) {
2150                    $(".td_hinfahrt_anzeige #suchergebnis_ausgabe ul li:first-child").trigger("click");
2151                    $("#ButtonWeiterSeite1").prop("disabled", false);
2152
2153                } else if ($("ul.suchergebnis li.active").length == 1) {
2154                    $("#ButtonWeiterSeite1").prop("disabled", false);
2155                }
2156
2157                //Direkt weiter zur Auswahl der Personen (nur Online)
2158                if($("#login").val() == "false" && $("#seite1").attr("autocontinue")!="1"){
2159
2160                    //Hinfahrt 1 Ergebnis - Direkt weiter
2161                    var li = $(".td_hinfahrt_anzeige #suchergebnis_ausgabe ul.suchergebnis li");
2162                    if($(li).length==1 && ($(li).attr("nur_hinfahrt")=="1" || $("#einfache_fahrt").val()=="1") && $("div.suchauswahl_buchungsmaske").length==0 && $("#multi_day").val()!="1" && $("#return_url").val()!=""){
2163                        $("#seite1").attr("autocontinue","1");
2164                        Seite2();
2165                    }
2166                }
2167
2168                //Eventuell übergebene Abfahrt-Uhrzeit löschen
2169                $("#abfahrt_uhrzeit").val("");
2170
2171                if($("ul.suchergebnis li[kombifehler='true']").length==0){
2172                    $("#kombiticket_inaktiv").addClass("hide");
2173                }
2174                else{
2175                    $("#kombiticket_inaktiv").removeClass("hide");
2176                }
2177
2178                //Kombitickets ausblenden
2179                if($("#cb_kombiticket_inaktiv:checked").length==0){
2180                    $("ul.suchergebnis li[kombifehler='true']").addClass("hide1");
2181                }
2182
2183                //Kapazitätsprüfung - Kapazitätsdarstellung für die darunterliegenden Fahrten container_kapazitaet
2184                var vSelectorAdd = " td.td_hinfahrt_anzeige div#div-wrap-suchergebnis div[aria-hidden='false'] li:not(.hide) .container_kapazitaet,  td.td_hinfahrt_anzeige>#suchergebnis_ausgabe>ul.suchergebnis li:not(.hide) .container_kapazitaet";
2185                if($("#div-wrap-suchergebnis").length==0){
2186                    vSelectorAdd += ", td.td_hinfahrt_anzeige .suchergebnis_kapazitaet #se_kap.empty";
2187                }
2188                showKapazitaetV2($(vSelectorAdd).first().closest("li"));
2189            }).done(function () {
2190                updateOnlinebuchungAccessibility();
2191                var root = $("#reservierung_div_comp[data-booking-a11y='true']");
2192                root.find("#fahrt_anzeige").attr("aria-busy", "false");
2193                if (root.find("#seite1").is(":visible")) {
2194                    announceOnlinebuchungStatus($.trim(root.find("#booking_a11y_results").text()) + ": " + root.find("ul.suchergebnis > li[onclick]:visible").length);
2195                }
2196                focusOnlinebuchungStep();
2197            }).fail(function () {
2198                $("#reservierung_div_comp[data-booking-a11y='true'] #fahrt_anzeige").attr("aria-busy", "false");
2199                announceOnlinebuchungStatus("");
2200            });
2201        }
2202    }
2203    //Rückfahrt
2204    else if (vModus == "getRueckfahrt") {
2205
2206        //Bei Kettenbuchung - Anpassung 17.1.2021 - Nur einfache Fahrt anbieten
2207        if ($("#einfache_fahrt_initial").val() == "1") {
2208            setEinfacheFahrt(true);
2209            return;
2210        }
2211
2212        //Wenn an Zielstation nicht ausgestiegen werden kann, Einfache Fahrt Button herausnehmen
2213        if ($("td.td_hinfahrt_anzeige ul.suchergebnis li.active").attr("zielstation_kein_ausstieg") == "1") {
2214            $(".button_einfache_fahrt").closest(".row").addClass("hide");
2215            $(".einfache_fahrt_hinweis .hinweistext").html(dialog['auswahl_pflicht_rueckfahrt']);
2216        } else {
2217            $(".button_einfache_fahrt").closest(".row").removeClass("hide");
2218            $(".einfache_fahrt_hinweis .hinweistext").html(dialog['auswahl_rueckfahrt']);
2219        }
2220
2221        //Button wieder auf enabled
2222        $("#mySubmit").attr("disabled",false);
2223        if (document.getElementById("ButtonWeiterSeite1")) {
2224            document.getElementById("ButtonWeiterSeite1").disabled = true;
2225        }
2226
2227        if (document.getElementById("table_rueckfahrt")) {
2228            document.getElementById("table_rueckfahrt").style.display = "";
2229        }
2230
2231        //es wurde eine Eventfahrt ausgewählt - gleich weiter auf die nächste Seite
2232        if ($(".td_hinfahrt_anzeige li.free.active").attr("nur_hinfahrt") == 1 && $("#login").val() == "false" && $("#return_url").val()!="") {
2233            setFahrgastInfo(getRadioBoxValue('hinfahrt'), 0);
2234            Seite2();
2235        } else if (vValue && document.getElementById("form[nur_hinfahrt]").value == 0 && document.getElementById('einfache_fahrt').value == 0) {
2236
2237            //Variablen ermitteln
2238            $("#rueckfahrt_anzeige").html("");
2239            document.getElementById("tr_fahrgaeste").style.display = "none";
2240
2241            if (parseInt(start) < parseInt(document.getElementById('hinfahrt_ankunft').value)) {
2242                start = parseInt(document.getElementById('hinfahrt_ankunft').value);
2243            }
2244
2245            if (start == 0) {
2246                document.getElementById("fahrt_anzeige").innerHTML = ("<font color='red'>" + lang["hin_und_rueckfahrt_datum_angeben"] + "</font>");
2247            } else {
2248
2249                //Wartebildschirm bei der Auswahl der Rückfahrt deaktiviert, außer bei Umstiegsverbindungen
2250                //Bei Umstiegsfahrt, Wartebildschirm
2251                if ($("#hafen_umstieg_id").length > 0 && parseInt($("#hafen_umstieg_id").val()) > 0) {
2252                    setBlockUI();
2253                }
2254                else if($("#login").val()=="true" && $("#buttons_linie_typ .button").length>0){
2255                    setBlockUI();
2256                }
2257
2258                var parameter = "aktion=getFahrt&modus=rueckfahrt&target_element_id=rueckfahrt_anzeige" + vParameterURL + "&ds_id=" + vValue;
2259
2260                //Wenn Rückfahrt - Hash hinzugefügt wurde
2261                var rueckfahrtDirektUebergeben=false;
2262                if($("#rueckfahrt").length>0 && $("#rueckfahrt").val()!=""){
2263                    parameter+="&rueckfahrt="+$("#rueckfahrt").val();
2264                    rueckfahrtDirektUebergeben=true;
2265                }
2266
2267                $.post("ajax/onlinereservierung.php",parameter , function (data) {
2268                    $.unblockUI();
2269                    $("#rueckfahrt").remove();
2270                    eval(data);
2271
2272                    if ($("#rueckfahrt_anzeige ul.suchergebnis li").length == 0) {
2273                        $("#rf2, #seite2, #seite3").css("display", "none");
2274                    } else {
2275                        $("#rf2, #rf3").css("display", "");
2276                    }
2277
2278                    //Als Überschrift das Datum
2279                    var text = $("#rueckfahrt_anzeige").closest("table").find("#suchergebnis_ausgabe .suchergebnis_datum").first().text();
2280                    $("#rueckfahrt_anzeige").closest("table").find("h3").html(dialog['zf_rueckfahrt'] + " " + text);
2281
2282                    //Bereits hinterlegtes Suchergebnis wurde hinterlegt, dieses markieren und anschließend lsöchen
2283                    if ($("#suchergebnis_rueckfahrt").length > 0 && $("#suchergebnis_rueckfahrt").val() != "") {
2284                        var vObjRadio = $("input[type='radio'][value='" + $("#suchergebnis_rueckfahrt").val() + "']");
2285                        if ($(vObjRadio).length == 0) {
2286                            alert(window.dialog["ui_933b6f3b7dd3"]);
2287                        } else {
2288                            $(vObjRadio).prop("checked", true);
2289                            $(vObjRadio).closest('li').trigger("click");
2290                        }
2291                    }
2292                    $("#suchergebnis_rueckfahrt").remove();
2293
2294                    //Wenn nur eine Rückfahrt, dann markieren und Weiter Button
2295                    if ($("#rueckfahrt_anzeige ul.suchergebnis li:visible").length == 1) {
2296
2297                        $("#DivNextStepFahrtFinden, #ButtonWeiterSeite1").css("display", "");
2298                        $("#ButtonWeiterSeite1").prop("disabled", false);
2299                        $("#ButtonWeiterSeite1").removeAttr("onclick");
2300                        $("#ButtonWeiterSeite1").attr("onclick", "rueckfahrtFahrtCheck()");
2301                    }
2302
2303                    //Scrool to Suchergebnis
2304                    if ($("td#rueckfahrt_anzeige div#suchergebnis_ausgabe").find("ul li").length >= 1) {
2305                        if (scrolling == true && $(window).width() < 800) {
2306                            $('html, body').animate({
2307                                scrollTop: $("table#table_rueckfahrt").offset().top
2308                            }, 500);
2309                        }
2310                    }
2311
2312                    //Action an die Liste anhängen
2313                    if (document.getElementById("ButtonWeiterSeite1") && $("#rueckfahrt_anzeige #suchergebnis_ausgabe li.free").length > 0) {
2314                        $("#rueckfahrt_anzeige ul li.free").click(function () {
2315                            Seite2();
2316                        });
2317                    }
2318                    //Kapazitätsprüfung - Kapazitätsdarstellung für die darunterliegenden Fahrten
2319                    var vSelectorAdd = "#rueckfahrt_anzeige input.kapazitaetbutton, #rueckfahrt_anzeige .container_kapazitaet";
2320                    if($("#div-wrap-suchergebnis").length==0){
2321                        vSelectorAdd += ", #rueckfahrt_anzeige .suchergebnis_kapazitaet #se_kap.empty";
2322                    }
2323
2324                    //Kapazität für Rückfahrt berechnen
2325                    if($("#koenigssee").length==0 || $("#login").val()=="false"){
2326                        console.log("Kapazitätsprüfung - Selector: "+vSelectorAdd+" - Anzahl Elemente: "+$(vSelectorAdd).length);
2327                        showKapazitaetV2($(vSelectorAdd).first().closest("li"),
2328                            function(frei, obj){
2329                                //Rückfahrt 1 Ergebnis - Direkt weiter
2330                                if(
2331                                    frei>0
2332                                    && rueckfahrtDirektUebergeben
2333                                    && $("#login").val()=="false"
2334                                    && $("#rueckfahrt_anzeige #suchergebnis_ausgabe li").length==1
2335                                    && $("#seite1").attr("autocontinue")!="1"
2336                                    && $(".td_hinfahrt_anzeige #suchergebnis_ausgabe ul.suchergebnis li").length==1
2337                                ){
2338
2339                                    //Weiterspringen nur wenn die Rückfahrt konkret übergeben wurde
2340                                    $("#seite1").attr("autocontinue","1");
2341                                    $("#rueckfahrt_anzeige ul li").not(".hide").first().trigger("click");
2342                                    Seite2();
2343                                }
2344                            });
2345                    }
2346
2347                }).done(function () {
2348                    updateOnlinebuchungAccessibility();
2349                    if ($("#reservierung_div_comp[data-booking-a11y='true'] #seite1").is(":visible")) {
2350                        announceOnlinebuchungStatus(dialog['zf_rueckfahrt'] + ": " + $("#rueckfahrt_anzeige ul.suchergebnis > li[onclick]:visible").length);
2351                    }
2352                });
2353            }
2354        }
2355        //Einfache Fahrt
2356        else if (vValue && (document.getElementById("form[nur_hinfahrt]").value == 1 || document.getElementById('einfache_fahrt').value == 1)) {
2357
2358            setBlockUI();
2359            $("#rueckfahrt_anzeige").html("");
2360            $("#rf2, #rfdatum").css("display", "none");
2361            setFahrgastInfo(getRadioBoxValue('hinfahrt'), 0);
2362
2363            //Einfache Fahrt in der Onlinebuchung - Event setzen bei Auswahl zur nächsten Seite
2364            if (document.getElementById("ButtonWeiterSeite1")) {
2365                $("td.td_hinfahrt_anzeige #suchergebnis_ausgabe li.free").click(function () {
2366                    Seite2();
2367                });
2368
2369                if($("ul.suchergebnis li.active.justClicked").length==1) {
2370                    Seite2();
2371                }
2372            }
2373        }
2374    }
2375}
2376
2377function rueckfahrtFahrtCheck() {
2378
2379    if ($("#login").val() == "false" && $("ul.suchergebnis li.active[soldout='true']").length > 0) {
2380        showDialog(dialog['fahrt_ausgebucht'], "<div class='callout alert'>" + dialog['onlinebuchung_fahrt_ausgebucht'] + "</div>");
2381    } else if ($("#rueckfahrt_anzeige ul.suchergebnis li:visible").length == 1) {
2382        $("#rueckfahrt_anzeige ul.suchergebnis li:visible").trigger("click");
2383        Seite2();
2384    } else {
2385        Seite2();
2386    }
2387}
2388
2389
2390function setAnsicht() {
2391    makeAction("setAnsicht");
2392}
2393
2394function suchergebnisEinschraenken(obj=null)
2395{
2396    //Prüfung ob die Variable anzahlMaxSuchergebnisse definiert ist
2397    if(anzahlMaxSuchergebnisse===undefined || anzahlMaxSuchergebnisse==0){
2398        return;
2399    }
2400
2401    var reservierung_id = parseInt($("#reservierung_id").val());
2402    if(reservierung_id>0){
2403
2404        var scrollToEl = $(".td_hinfahrt_anzeige ul.suchergebnis li.active").first();
2405
2406        //Die vorherigen 3 lis noch anzeigen, die weiteren die davor sind die klasse hide und hidden_max_results geben
2407        var prevAll = $(scrollToEl).prevAll();
2408        $.each(prevAll, function(index){
2409            if(index>3){
2410                $(this).addClass("hide");
2411                $(this).addClass("hidden_max_results");
2412            }
2413        });
2414
2415        //DIe nachfolgenden 3 lis noch anzeigen, die weiteren die danach sind die klasse hide und hidden_max_results geben
2416        var nextAll = $(scrollToEl).nextAll();
2417        $.each(nextAll, function(index){
2418            if(index>3){
2419                $(this).addClass("hide");
2420                $(this).addClass("hidden_max_results");
2421            }
2422        });
2423    }
2424    else{
2425        if(obj==null){
2426            obj = $("ul.suchergebnis");
2427        }
2428        $(".hidden_max_results").removeClass("hidden_max_results");
2429        $("#zeige_alle_suchergebnisse").remove();
2430
2431        //Für Agenturen alles anzeigen
2432        if($("#warpper").attr("recht_id")=="5") {
2433            //console.log("hallo");
2434        }
2435        else{
2436            $.each($(obj),function(){
2437                var ul = $(this);
2438                var c = 0;
2439                //Alle mit 0 Kapazität ausblenden
2440                $(ul).find("li[hafen][cap_calculated='true'][fr='0']").addClass("hide");
2441
2442                //Die ersten 3 mit Kapazität einblenden
2443                $.each($(ul).find("li[hafen][cap_calculated='true']").not(".hide").not("[fr='0']"), function () {
2444                    if(c>=anzahlMaxSuchergebnisse){
2445                        $(this).addClass("hide");
2446                        $(this).addClass("hidden_max_results");
2447                    }
2448                    c++;
2449                });
2450            });
2451        }
2452    }
2453
2454    $("#zeige_alle_suchergebnisse").closest("div.text-center").remove();
2455    $("#suchergebnis_ausgabe").append('<div class="text-center"><input type="button" class="button small" id="zeige_alle_suchergebnisse" value="'+dialog['alles_anzeigen']+'" onclick="suchergebnisEinschraenkenShowAll()"/></div>');
2456}
2457
2458function suchergebnisEinschraenkenShowAll(){
2459
2460    $('.hidden_max_results').removeClass('hide');
2461    $("#zeige_alle_suchergebnisse").remove();
2462
2463    var scrollToEl = $(".td_hinfahrt_anzeige ul.suchergebnis li.active").first();
2464
2465    var zielhafen_id = $(scrollToEl).attr("zielhafen_id");
2466    $('ul.suchergebnis li[zielhafen_id='+zielhafen_id+'].hide').removeClass('hide');
2467
2468    $('html').animate(
2469        {
2470            scrollTop: scrollToEl.offset().top-200,
2471        },
2472        800 //speed
2473    );
2474}
2475
2476function getFahrt() {
2477
2478    clearOnlinebuchungSearchError();
2479    $("#reservierung_div_comp[data-booking-a11y='true'] #fahrt_anzeige").attr("aria-busy", "true");
2480    announceOnlinebuchungStatus(dialog['bitte_warten']);
2481    $(document).attr("title", "..." + dialog['fahrt_auswaehlen']);
2482    $("div.infokasten_ausgewaehlte-fahrt, div#zusammenfassung_fahrt").html("");
2483    makeAction("getFahrt");
2484}
2485
2486//Abschliessend Extras- Zusätze anpassen
2487function setExtrasWindow() {
2488    //Einzelne Checkboxen anzeigen
2489    $('.AccExtras').each(function () {
2490        var vSichtbar = parseInt($(this).find("tr[show='true']").length);
2491
2492        //Keine Einträge sichtbar - Ausblenden
2493        if (vSichtbar == 0) {
2494            $(this).parent().css("display", "none");
2495        } else {
2496            $(this).parent().css("display", "");
2497        }
2498    });
2499
2500}
2501
2502/////////////////////////////// FORMULARDARSTELLUNG ////////////////////////////////////////////////////
2503
2504function setEinfacheFahrt(vSet) {
2505
2506    if ($("#seite1").length == 0) {
2507        return;
2508    }
2509
2510    if (vSet == true) {
2511        setCheckBoxValue(true, "form[nur_hinfahrt]");
2512        var vDisplay = "none";
2513        $("#rueckfahrt_anzeige").html("");
2514        $("#rf2,#rf3, #rfdatum").css("display", "none");
2515    } else {
2516        setCheckBoxValue(false, "form[nur_hinfahrt]");
2517        var vDisplay = "";
2518    }
2519
2520    $("#rf1").css("display", vDisplay);
2521
2522    if ($("table.TableFahrtUmfassung tr#f2 td div#suchergebnis_ausgabe ul li").length == 0) {
2523        document.getElementById("f1").style.display = "none";
2524    } else {
2525        document.getElementById("f1").style.display = vDisplay;
2526    }
2527
2528    if (!getRadioBoxValue('hinfahrt') == 0 && vSet == true) //Bei ausgewählter Hinfahrt Preis gleich neu berechnen
2529    {
2530        setFahrgastInfo(getRadioBoxValue('hinfahrt'), getRadioBoxValue('rueckfahrt'));
2531
2532        //Gleich auf nächste Seite springen
2533        if (document.getElementById("ButtonWeiterSeite1") && $("div#div-wrap-suchergebnis").length == 0 && $("#return_url").val()!="") {
2534            Seite2();
2535        }
2536
2537    }
2538}
2539
2540function checkOnlineReservierungDatum() {
2541
2542    //Rückfahrtdatum kleiner Hinfahrtdatum
2543    var vHF = parseInt($("#hinfahrt_datum").val());
2544    var vRF = parseInt($("#rueckfahrt_datum").val());
2545    if (vRF < vHF && vHF > 0) {
2546        setBisDatum("hinfahrt_datum", "rueckfahrt_datum");
2547    }
2548    $("#abfahrt_uhrzeit").val("");
2549
2550    //Stationen Gültigkeit
2551    if($("#reservierung_id").val()===undefined){
2552
2553        $.post("ajax/onlinereservierung.php", {
2554            aktion: "checkValidStation",
2555            datum:vHF
2556        }).done(function (data) {
2557            var current_station_id = $("#hafen_id").val();
2558
2559            //Alle Options löschen die value > 0 haben
2560            $("#hafen_id option").each(function(){
2561                if(parseInt($(this).attr("value"))>0){
2562                    $(this).remove();
2563                }
2564            });
2565
2566            $.each(data, function(idx,station){
2567                var option = $("<option value='"+station["hafen_id"]+"'>"+station["bezeichnung"]+"</option>");
2568                $("#hafen_id").append(option);
2569            });
2570
2571            $("#hafen_id").val(current_station_id);
2572
2573        });
2574    }
2575
2576}
2577
2578function createSonderaktionAuswahlDialog(inhalt_html) {
2579    if ($("#sonderaktion_auswahl").length > 0) {
2580        $("#sonderaktion_auswahl").remove();
2581    }
2582    $('<div id="sonderaktion_auswahl"></div>').dialog({
2583        modal: true,
2584        title: dialog['sonderaktion'],
2585        open: function () {
2586            $(this).html(inhalt_html);
2587            $('#sonderaktion_id option[auto=1]').remove();
2588
2589            var vRechtID = $("#warpper").attr("recht_id");
2590            if (vRechtID == undefined) {
2591                vRechtID = 0;
2592            }
2593
2594            //Agentur - Online - Königssee - Ausblenden
2595            if (parseInt(vRechtID) == 5 || parseInt(vRechtID) == 0 || $("#koenigssee").length>0)
2596            {
2597                setBlockUI();
2598                setTimeout(function () {
2599                    $('div[aria-describedby="sonderaktion_auswahl"] .ui-button:contains("Ok")').click();
2600                    $.unblockUI();
2601                }, 30);
2602
2603            }
2604
2605        },
2606        close: function () {
2607            $(this).remove();
2608        },
2609        buttons: {
2610            Ok: function () {
2611
2612                if ($("#sonderaktion_id").length == 0) {
2613                    $("#form1").append("<select class='hide' name='sonderaktion_id' id='sonderaktion_id'><option value='0' selected>0</option></select>");
2614                    $(".tableTicket select").on("change", function () {
2615                        $('#sonderaktion_id').val(0);
2616                        calculate();
2617                    });
2618                }
2619
2620                var vSonderaktion = $("#sonderaktion_id");
2621                var vAktionSelectedID = $("ul.sonderaktion_list input[type='radio']:checked").val();
2622                var vOption = $("<option></option>");
2623                $(vOption).attr("value", vAktionSelectedID);
2624                $(vOption).text(decodeURIComponent($("label[aktion_id='" + vAktionSelectedID + "']").attr("caption")));
2625                $(vOption).attr("auto", 1);
2626                $(vSonderaktion).append(vOption);
2627                $(vSonderaktion).val(vAktionSelectedID);
2628                calculate(true);
2629
2630                $(this).dialog("close");
2631            }
2632        }
2633    });
2634}
2635
2636function formatOnlineGeburtsdatum(vObj) {
2637    var format = $(vObj).attr("data-date-format");
2638    var ziffern = String($(vObj).val()).replace(/\D/g, "").substring(0, 8);
2639    var wert = "";
2640
2641    if (format == "de") {
2642        wert = ziffern.substring(0, 2);
2643        if (ziffern.length > 2) {
2644            wert += "." + ziffern.substring(2, 4);
2645        }
2646        if (ziffern.length > 4) {
2647            wert += "." + ziffern.substring(4, 8);
2648        }
2649    }
2650    else {
2651        wert = ziffern.substring(0, 4);
2652        if (ziffern.length > 4) {
2653            wert += "-" + ziffern.substring(4, 6);
2654        }
2655        if (ziffern.length > 6) {
2656            wert += "-" + ziffern.substring(6, 8);
2657        }
2658    }
2659
2660    $(vObj).val(wert);
2661    checkOnlineGeburtsdatum(vObj, false);
2662}
2663
2664function checkOnlineGeburtsdatum(vObj, unvollstaendigAlsFehler) {
2665    var wert = String($(vObj).val());
2666    var format = $(vObj).attr("data-date-format");
2667    var treffer = format == "de"
2668        ? /^(\d{2})\.(\d{2})\.(\d{4})$/.exec(wert)
2669        : /^(\d{4})-(\d{2})-(\d{2})$/.exec(wert);
2670    var gueltig = false;
2671
2672    if (treffer) {
2673        var jahr = parseInt(format == "de" ? treffer[3] : treffer[1], 10);
2674        var monat = parseInt(treffer[2], 10);
2675        var tag = parseInt(format == "de" ? treffer[1] : treffer[3], 10);
2676        var datum = new Date(jahr, monat - 1, tag);
2677
2678        gueltig = jahr > 0
2679            && datum.getFullYear() == jahr
2680            && datum.getMonth() == monat - 1
2681            && datum.getDate() == tag;
2682    }
2683
2684    var istFehler = wert != "" && !gueltig && (unvollstaendigAlsFehler || wert.length == 10);
2685    vObj.setCustomValidity(istFehler ? $(vObj).attr("data-error-message") : "");
2686    $(vObj).toggleClass("is-invalid-input", istFehler);
2687
2688    return wert == "" || gueltig;
2689}
2690
2691function validateOnlineGeburtsdaten() {
2692    var erstesUngueltigesFeld = null;
2693
2694    $("input.online-geburtsdatum").each(function () {
2695        if (!checkOnlineGeburtsdatum(this, true) && erstesUngueltigesFeld == null) {
2696            erstesUngueltigesFeld = this;
2697        }
2698    });
2699
2700    if (erstesUngueltigesFeld != null) {
2701        erstesUngueltigesFeld.focus();
2702        if (erstesUngueltigesFeld.reportValidity) {
2703            erstesUngueltigesFeld.reportValidity();
2704        }
2705        return false;
2706    }
2707
2708    return true;
2709}
2710
2711function makeReservation(vAktion) {
2712    if ($("#target_iframe").length == 0) {
2713        $("div#reservierung_div").prepend('<iframe src="" id="target_iframe" name="target_iframe" style="display:none;"></iframe>');
2714    }
2715
2716    $(".fehler_td_onlinebuchung, .buchung_fehler").html("");
2717
2718    showWaitingScreen();
2719
2720    if ($("#freitextfelder").length > 0) {
2721
2722        //Wenn keine Vormerkung, Felder entfernen
2723        if ($("#nur_vormerkung").length > 0 && $("div.vormerkung_div input#nur_vormerkung").val() == "0") {
2724            $("#freitextfelder [vormerkung='true']").closest("div.column").remove();
2725        }
2726
2727        $("#freitextfelder_data").val($("#freitextfelder").find("input,select,textarea").serialize());
2728    }
2729
2730    if (vAktion == undefined) {
2731        vAktion = "make_reservation";
2732    }
2733
2734    //Anzahl verfügbare Sitzplätze mitsenden
2735    $("#anzahl_sitzplaetze_verfuegbar").remove();
2736    var anzahlSitzplaetze = $("input[type='checkbox'][checky='sitzplatz']").length;
2737    $("#form1").append("<input type='hidden' id='anzahl_sitzplaetze_verfuegbar' name='anzahl_sitzplaetze_verfuegbar' value='"+anzahlSitzplaetze+"'/>");
2738
2739    //Paxdaten vorhanden
2740    if ($("#isOnlineBuchungsMaske").val() == "true" && $("#login").val() == "false" && $('#table_persoenliche_daten tr.tr_pax_data td.paxdata_customer').find("input,select").length > 0 && $("#schritt2.allowed").length > 0) {
2741
2742        //Prüfung Kapazität
2743        if (onlinebuchungKapazitaetspruefungInline() == false) {
2744            $.unblockUI();
2745            return;
2746        }
2747
2748        $("div.callout.auswahlticketinfo").addClass("hide");
2749        $("#table_persoenliche_daten").removeClass("hide");
2750        $("#zeitstrahl_buchungsschritte ul li").removeClass("allowed");
2751        $("#zeitstrahl_buchungsschritte ul li#schritt2a").addClass("allowed");
2752        $("#tr_fahrgaeste td").find(".table_ticketoptionen, #fahrgaeste, #ausstattung, #hinfahrt_extra, #rueckfahrt_extra, #anzeige_gesamt, #linie_fahrgastinfo, .AccSitzplan").addClass("hide");
2753        setZeitstrahlBuchungsschritteLabels();
2754
2755        $("#button_datum_aendern").removeClass("hide");
2756
2757        $.unblockUI();
2758        return;
2759    } else if (
2760        $("#isOnlineBuchungsMaske").val() == "true"
2761        && $("#login").val() == "false"
2762        && $('#table_persoenliche_daten tr.tr_pax_data td.paxdata_customer').length > 0
2763        && $("#schritt2a.allowed").length > 0
2764        //Zusatzauswahl-3 ist kein Pflichtfeldd
2765        && $('#table_persoenliche_daten tr.tr_pax_data td.paxdata_customer').find("input").not("[zusatzauswahl='3']").filter(function () {
2766            return $(this).val().length === 0;
2767        }).length > 0
2768    ) {
2769        $(".buchung_fehler").html("<div class='callout alert'><p><i class='fa-solid fa-exclamation-circle'/> " + dialog['pax_data_fehlt'] + "</p></div>");
2770        $.unblockUI();
2771        return;
2772    }
2773    //Sitzplan vorhanden
2774    else if ($("#isOnlineBuchungsMaske").val() == "true" && $(".sitzplan_div div").length > 0 && $(".AccSitzplan.hide").length > 0 && $("#login").val() == "false") {
2775
2776        //Prüfung Kapazität
2777        if (onlinebuchungKapazitaetspruefungInline() == false) {
2778            $.unblockUI();
2779            return;
2780        }
2781
2782        //Sitzplan einblenden
2783        $(".AccSitzplan").removeClass("hide");
2784        $(".buchung_fehler").html("");
2785
2786        //Buchungs - Inhalt ausblenden
2787        $("#tr_fahrgaeste td").find(".table_ticketoptionen, #fahrgaeste, #ausstattung, #hinfahrt_extra, #rueckfahrt_extra, #anzeige_gesamt, #linie_fahrgastinfo, #table_persoenliche_daten").addClass("hide");
2788
2789        $("#zeitstrahl_buchungsschritte ul li").removeClass("allowed");
2790        $("#zeitstrahl_buchungsschritte ul li#schritt2b").addClass("allowed");
2791        setZeitstrahlBuchungsschritteLabels();
2792        $.unblockUI();
2793        return;
2794    }
2795
2796    if (validateOnlineGeburtsdaten() == false) {
2797        $.unblockUI();
2798        return;
2799    }
2800
2801    //Virtuellen Preistyp - Anzahl mitsenden
2802    $(".removeAfter").remove();
2803    if($(".tableTicketLinie.virtuell[anzahl]").length>0){
2804        $.each($(".tableTicketLinie.virtuell[anzahl]"),function(){
2805           //var json = JSON.parse(decodeURIComponent($(this).attr("anzahl")));
2806           var key = $(this).attr("keyk");
2807           $(this).find(".ttCell1").append("<input type='hidden' name='preistyp_aufteilung["+key+"]' value='"+$(this).attr("anzahl")+"' class='removeAfter'/>");
2808        });
2809    }
2810
2811    document.getElementById("aktion").value = vAktion;
2812    document.getElementById("form1").submit();
2813}
2814
2815function makeReservationExec(){
2816
2817    if($("#isOnlineBuchungsMaske").val() == "true" && checkInIframe() && $("#login").val() == "false"){
2818        $("#form1").attr("target","_parent");
2819        $("#form1").append("<input type='hidden' name='in_iframe' value='true'>");
2820    }
2821
2822    $("#form1").submit();
2823}
2824
2825function onlinebuchungKapazitaetspruefungInline() {
2826    var vAnzahlPax = 0;
2827    $.each($("div#fahrgaeste table.tableTicket .anzahl_personen_preistyp_container select"), function () {
2828        vAnzahlPax += parseInt($(this).val());
2829    });
2830    var fr = parseInt($(".td_hinfahrt_anzeige ul li.free.active").attr("fr"));
2831    if (vAnzahlPax > fr) {
2832        $(".fehler_td_onlinebuchung, .buchung_fehler").html("<div class='callout alert'><i class=\"fa-solid fa-exclamation-circle\"></i> " + dialog['ausgebucht_meldung'] + "</div>");
2833        return false;
2834    }
2835    return true;
2836}
2837
2838function setZahlart() {
2839    var vZahlart = getRadioBoxValue("form[zahlart_id]");
2840
2841    if ($(".zahlart_split").length > 0) {
2842        if (vZahlart == 6) {
2843            $("#tr_abgerechnet").removeClass("hide");
2844        } else {
2845            $("#tr_abgerechnet").addClass("hide");
2846        }
2847    } else {
2848
2849        if (document.getElementById("tr_bankeinzug")) document.getElementById("tr_bankeinzug").style.display = "none";
2850        if (document.getElementById("tr_kreditkarte")) document.getElementById("tr_kreditkarte").style.display = "none";
2851        if (document.getElementById("tr_kreditkarte_manuell")) document.getElementById("tr_kreditkarte_manuell").style.display = "none";
2852        if (document.getElementById("tr_bar")) document.getElementById("tr_bar").style.display = "none";
2853        if (document.getElementById("tr_ec_karte")) document.getElementById("tr_ec_karte").style.display = "none";
2854        if (document.getElementById("tr_abgerechnet")) document.getElementById("tr_abgerechnet").style.display = "none";
2855
2856        $(".zahlfrist_datum").addClass("hide");
2857
2858        //Bei Zahlart Rechnung, Ticket nicht drucken - Bei Kelheim immer drucken
2859        if (document.getElementById("print_ticket") && (vZahlart == 6 || vZahlart == 21 || vZahlart == 10 || vZahlart == 35) && $("body[kelheim_modus='true']").length == 0) {
2860            document.getElementById("print_ticket").value = '0';
2861            document.getElementById("cb_print_ticket").checked = false;
2862        } else if (document.getElementById("print_ticket")) {
2863            document.getElementById("print_ticket").value = '1';
2864            document.getElementById("cb_print_ticket").checked = true;
2865        }
2866
2867        if (vZahlart == 1 && document.getElementById("tr_kreditkarte")) //Kreditkarte
2868        {
2869            document.getElementById("tr_kreditkarte").style.display = "";
2870        } else if (vZahlart == 2 || vZahlart == 15) //Bankeinzug
2871        {
2872            document.getElementById("tr_bankeinzug").style.display = "";
2873        } else if (vZahlart == 4 && document.getElementById("tr_bar")) //Bar
2874        {
2875            document.getElementById("tr_bar").style.display = "";
2876            if (document.getElementById("print_ticket")) {
2877                document.getElementById("print_ticket").value = '1';
2878                document.getElementById("cb_print_ticket").checked = true;
2879            }
2880        } else if (vZahlart == 5 && document.getElementById("tr_ec_karte")) //EC
2881        {
2882            document.getElementById("tr_ec_karte").style.display = "";
2883            if (document.getElementById("print_ticket")) {
2884                document.getElementById("print_ticket").value = '1';
2885                document.getElementById("cb_print_ticket").checked = true;
2886            }
2887        }
2888        else if (vZahlart == 6 || vZahlart == 21) //Rechnung
2889        {
2890            $("#tr_abgerechnet").css("display","");
2891            $(".zahlfrist_datum").removeClass("hide");
2892
2893        } else if (vZahlart == 8 && document.getElementById("tr_kreditkarte_manuell")) {
2894            document.getElementById("tr_kreditkarte_manuell").style.display = "";
2895            if (document.getElementById("print_ticket")) {
2896                document.getElementById("print_ticket").value = '1';
2897                document.getElementById("cb_print_ticket").checked = true;
2898            }
2899        }
2900    }
2901
2902}
2903
2904function setAnsichtPersDaten() {
2905    var vAnsicht = getRadioBoxValue("kunde_auswahl");
2906    if (document.getElementById("tr_neuer_kunde_daten")) document.getElementById("tr_neuer_kunde_daten").style.display = "none";
2907
2908    if (document.getElementById("tr_bestandskunde")) document.getElementById("tr_bestandskunde").style.display = "none";
2909
2910    if (document.getElementById("tr_kundennr")) document.getElementById("tr_kundennr").style.display = "none";
2911
2912
2913    if ($("#laufkunde_email_row").length > 0) {
2914        $("#laufkunde_email_row").css("display", "none");
2915    }
2916
2917    if (vAnsicht == 1) //Bestandskunde
2918    {
2919        if (document.getElementById("tr_bestandskunde")) {
2920            document.getElementById("tr_bestandskunde").style.display = "";
2921        }
2922    } else if (vAnsicht == 2) //Neuer Kunde
2923    {
2924        document.getElementById("tr_neuer_kunde_daten").style.display = "";
2925        document.getElementById("form[vorname]").focus();
2926    } else if (vAnsicht == 3 || vAnsicht == 4) //Intern
2927    {
2928        if ($("#laufkunde_email_row").length > 0) {
2929            $("#laufkunde_email_row").css("display", "");
2930        }
2931    } else if (vAnsicht == 5) // Anmeldung mit Kundennummer / Name
2932    {
2933        document.getElementById("tr_kundennr").style.display = "";
2934        document.getElementById("anmeldung_kdnr").focus();
2935    }
2936}
2937
2938function loginSetVornameNachname() {
2939    var vDiv = $("<div class='row'></div>");
2940    $(vDiv).append($("<div class='small-12 medium-6 column'>" + window.dialog["ui_d2d77b6ffa70"] + "</div>"));
2941    $(vDiv).append($("<div class='small-12 medium-6 column'><input type='text' id='vorname'></div>"));
2942
2943    $(vDiv).append($("<div class='small-12 medium-6 column'>" + window.dialog["ui_b25358edd497"] + "</div>"));
2944    $(vDiv).append($("<div class='small-12 medium-6 column'><input type='text' id='nachname'></div>"));
2945
2946    var vDialog = $("<div class='dialog dialog_vor_nach'/>");
2947    $(vDialog).append(vDiv);
2948
2949    $(vDialog).dialog({
2950        modal: true,
2951        draggable: false,
2952        title: dialog['vor_nachname'],
2953        resizable: false,
2954        show: 'blind',
2955        hide: 'blind',
2956        width: 400,
2957        buttons: {
2958            "OK": function () {
2959
2960                if ($(".dialog_vor_nach #vorname").val() == "" || $(".dialog_vor_nach #nachname").val() == "") {
2961                    alert(dialog['vor_nachname']);
2962                    return;
2963                }
2964
2965                showWaitingScreen();
2966                $.ajax({
2967                    type: "POST",
2968                    url: "ajax/onlinereservierung.php",
2969                    data: {
2970                        aktion: "setVornameNachname",
2971                        vorname: $(".dialog_vor_nach #vorname").val(),
2972                        nachname: $(".dialog_vor_nach #nachname").val()
2973                    },
2974                    success: function (data) {
2975
2976                        //alert(data);
2977
2978                        hideWaitingScreen();
2979
2980                        $(vDialog).dialog("close");
2981                        $(vDialog).remove();
2982                    }
2983                });
2984            }
2985        }
2986    });
2987
2988
2989}
2990
2991function loginNameKdNr(vSilent) {
2992    if (!vSilent) {
2993        var vSilent = false;
2994    }
2995    var vKdNr = document.getElementById("anmeldung_kdnr").value;
2996    var vKdName = document.getElementById("anmeldung_name").value;
2997    if ((vKdNr == "" || vKdName == "") && vSilent == true) {
2998        return;
2999    } else if ((vKdNr == "" || vKdName == "") && vSilent == false) {
3000        alert(lang["einloggen_kunde_hinweis"]);
3001        document.getElementById("anmeldung_kdnr").focus();
3002        return false;
3003    }
3004
3005    //Hinfahrt mit anhängen
3006    var vHinfahrt = $("td.td_hinfahrt_anzeige div.suchergebnis_auswahl input[type='radio']:checked").val();
3007
3008    //Rueckfahrt
3009    var vRueckfahrt = "";
3010    var vObjRF = $("td#rueckfahrt_anzeige div.suchergebnis_auswahl input[type='radio']:checked");
3011    if ($(vObjRF).length > 0) {
3012        vRueckfahrt = $(vObjRF).val();
3013    }
3014    showWaitingScreen();
3015    vURL = "ajax/onlinereservierung-kundenlogin.php?aktion=loginNameKdNr&vKdNr=" + vKdNr + "&vKdName=" + encodeURIComponent(vKdName) + "&hinfahrt=" + vHinfahrt + "&rueckfahrt=" + vRueckfahrt;
3016
3017    $.get(vURL)
3018        .done(function (data) {
3019                hideWaitingScreen();
3020                eval(data);
3021            }
3022        );
3023}
3024
3025function FormFreitextRender() {
3026    //Rendern der Formularfelder
3027    if ($("div#freitextfelder").length > 0) {
3028        var felder = decodeURIComponent($("div#freitextfelder").attr("wert"));
3029
3030        $("div#freitextfelder").formRender({
3031            formData: felder,
3032            dataType: "xml",
3033            render: true,
3034            i18n: {
3035                locale: 'en-US',
3036                location: 'js/assets'
3037            }
3038        });
3039
3040        //Felder nach hafen - Linietyp filtern
3041        var HafenStartID = $("td.td_hinfahrt_anzeige li.active").attr("hafen_id");
3042        var LinieTypID = $("td.td_hinfahrt_anzeige li.active").attr("linie_typ_id");
3043
3044        $(".rendered-form .form-group").find("input,select,textarea,h1,h2,h3,h4,h5").each(function () {
3045
3046            var use = true;
3047            if ($(this)[0].hasAttribute("hafen")) {
3048                var attr = $(this).attr("hafen");
3049                var search = "hafen_" + HafenStartID;
3050                if (attr != "0" && attr != search) {
3051                    use = false;
3052                }
3053            }
3054
3055            if ($(this)[0].hasAttribute("linie_typ")) {
3056                var attr = $(this).attr("linie_typ");
3057                var search = "linie_typ_" + LinieTypID;
3058                if (attr != "0" && attr != search) {
3059                    use = false;
3060                }
3061            }
3062
3063            //Nicht verwenden, entfernen
3064            if (use == false) {
3065                //$(this).closest('.form-group').css("background","red");
3066                $(this).closest('.form-group').remove();
3067            }
3068
3069        });
3070
3071        //Ergebnis in Foundation Formar packen
3072        $(".rendered-form").addClass("row");
3073        $(".rendered-form>div").not(".form-group").addClass("small-12 column");
3074        $(".rendered-form .form-group").addClass("small-12 medium-6 large-4 column");
3075        $(".rendered-form").append("<div class='column'/>");
3076
3077        //Werte einspielen
3078        try {
3079            var data = $.parseJSON(decodeURIComponent($("div#freitextfelder").attr("data")));
3080        } catch (e) {
3081            var data = [];
3082        }
3083
3084        if (data && data != undefined && $(data).length > 0) {
3085            $.each(data, function (index, row) {
3086                var name = index; //row["name"];
3087                var val = row; //row["value"];
3088                //console.log(name);
3089
3090                var $el = $("div#freitextfelder").find('[name="' + name + '"], [id="' + name + '"]'),
3091                    type = $el.attr('type');
3092
3093
3094                switch (type) {
3095
3096                    case 'date':
3097                        console.log(name + " - " + val);
3098                        $el.attr('type', 'text');
3099                        $el.addClass('datepicker');
3100                        //alert($el.val() + convertDatumYYYYMMDDInGerman(val));
3101                        if (gueltigesDeutschesDatum(val) == false) {
3102                            $el.val(convertDatumYYYYMMDDInGerman(val));
3103                        } else {
3104                            $el.val(val);
3105                        }
3106                        $($el).datepicker();
3107
3108                    case 'checkbox':
3109                        $el.attr('checked', 'checked');
3110                        break;
3111                    case 'radio':
3112                        $el.filter('[value="' + val + '"]').attr('checked', 'checked');
3113                        break;
3114                    case 'select':
3115                        //console.log("SELECT"+$($el).attr("name")+" wert: "+val);
3116                        if ($($el).attr('multiple')) {
3117                            $el.find('option').prop('selected', false);
3118                            var array = String(val).split(",");
3119                            $.each(array, function (i) {
3120                                $el.find('option[value="' + array[i] + '"]').prop('selected', true);
3121                            });
3122                        } else {
3123                            $el.val(val);
3124                        }
3125                    default:
3126
3127                        $el.val(val);
3128                }
3129            });
3130        }
3131
3132
3133        //Vormerkungen ausblenden
3134        if ($("div.vormerkung_div #nur_vormerkung").length == 0 || $("div.vormerkung_div input#nur_vormerkung").val() == "0") {
3135            $("#freitextfelder [vormerkung='true']").closest("div.column").addClass("hide");
3136        }
3137
3138    }
3139
3140    if ($("div#freitextfelder div.form-group").not(".hide").length == 0) {
3141        $(".freitextbuchung").addClass("hide");
3142    } else {
3143        $(".freitextbuchung").removeClass("hide");
3144    }
3145
3146}
3147
3148function setVormerkung(vDo) {
3149
3150    if (vDo == true || vDo == 1) {
3151
3152        setCheckBoxValue(true, 'nur_vormerkung');
3153
3154        var vDisplay = "none";
3155
3156        $(".vormerkung_best_div").removeClass("hide");
3157        if ($("#mySubmitW").is(":visible") == false) {
3158            $("#mySubmit").removeClass("hide");
3159        }
3160        //$("#mySubmitW").addClass("hide"); //Warenkorb soll auch bei Vormkerungen erscheinen, Update am 24.10.19
3161        $("#zahlung_weiter").css("display", vDisplay);
3162        $("#table_bezahlung").css("display", vDisplay);
3163        $("#table_zahlungen").css("display", vDisplay);
3164
3165        //Wenn keine Vormerkung, Felder entfernen
3166        $("#freitextfelder [vormerkung='true']").closest("div.column").removeClass("hide");
3167
3168        $("#anzeige_artikel_vormerkung").removeClass("hide");
3169        $("#email_invoice_field").addClass("hide");
3170
3171        $(".gutschein_onlinebuchung").addClass("hide");
3172    } else {
3173        setCheckBoxValue(false, 'nur_vormerkung');
3174
3175        var vDisplay = "";
3176        $("#zahlart1_betrag").val(C2dbl($(".OnlinebuchungTabelleGesamt #tb_gesamtbetrag").val()));
3177        $(".vormerkung_best_div").addClass("hide");
3178        setCheckBoxValue(true, "print_ticket");
3179
3180        //erste Zahlart geht nur mit sichtabaren objekten
3181        $("#zahlung_weiter").css("display", vDisplay);
3182        $("#table_bezahlung").css("display", vDisplay);
3183        $("#table_zahlungen").css("display", vDisplay);
3184
3185        var use = false;
3186        if ($("#anzeige_artikel_vormerkung .tr_einzelverkauf .ttCell1 select").length > 0) {
3187            $("#anzeige_artikel_vormerkung .tr_einzelverkauf .ttCell1 select").each(function () {
3188                if (parseInt($(this).val()) > 0) {
3189                    use = true;
3190                }
3191            });
3192        }
3193        if (use == true) {
3194            $("#anzeige_artikel_vormerkung").removeClass("hide");
3195        } else {
3196            $("#anzeige_artikel_vormerkung").addClass("hide");
3197        }
3198
3199        $("#freitextfelder [vormerkung='true']").closest("div.column").addClass("hide");
3200        setFirstZahlart();
3201        $("#email_invoice_field").removeClass("hide");
3202        $(".gutschein_onlinebuchung").removeClass("hide");
3203    }
3204
3205    $(".zahlart_split").css("display", vDisplay);
3206    if ($("#HTTP_USER_AGENT").val() != "iOSKassa") {
3207        $("#div_ticket_print").css("display", vDisplay);
3208    }
3209    $("#table_bezahlung_headline, div#div_gutschein").css("display", vDisplay);
3210}
3211
3212function displaySitzplananzeige() {
3213    if (!(document.getElementById("sitzplatz_autovergabe"))) {
3214        $(".sitzplatz_auswahl").addClass("hide");
3215        return false;
3216    } else if (document.getElementById("sitzplatz_autovergabe").value == "1") {
3217        document.getElementById("table_sitzplatz").style.display = "none";
3218        $(".sitzplatz_auswahl").addClass("hide");
3219    } else {
3220        document.getElementById("table_sitzplatz").style.display = "";
3221        $(".sitzplatz_auswahl").removeClass("hide");
3222    }
3223}
3224
3225function checkoutEmailConfirmation() {
3226    var emailAP = $("#form\\[ansprechpartner_id\\] option:selected").attr("email");
3227    if (emailAP != "" && emailAP != undefined) {
3228        $("#email_confirm").removeClass("hide");
3229        $("#email_confirmation").prop("checked", false).trigger("click");
3230        $("#email_confirmation_adress").val($("#form\\[ansprechpartner_id\\] option:selected").attr("email"));
3231    } else if ($("#form\\[kunde_id\\]").attr("email") != "") {
3232        $("#email_confirm").removeClass("hide");
3233        $("#email_confirmation").prop("checked", false).trigger("click");
3234        $("#email_confirmation_adress").val($("#form\\[kunde_id\\]").attr("email"));
3235    }
3236}
3237
3238function selectNaechsteHinfahrt(anzahlPax){
3239    anzahlPax = parseInt(anzahlPax, 10) || 0;
3240
3241    const $el = $("td.td_hinfahrt_anzeige ul li.active");
3242
3243    //Alles anzeigen
3244    suchergebnisEinschraenkenShowAll();
3245
3246    // Kandidat: nächstes li mit fr >= anzahlPax (und nicht .hide)
3247    const $nextMatch = $el.nextAll("li").filter(function () {
3248        const v = parseInt($(this).attr("fr"));
3249        return !isNaN(v) && v >= anzahlPax && !$(this).hasClass("hide");
3250    }).first();
3251
3252    if ($nextMatch.length) {
3253        $nextMatch.first().trigger("click");
3254    } else {
3255        // Fallback: nächstes sichtbares li
3256        const $nextLi = $el.nextAll("li").not(".hide").first();
3257        if ($nextLi.length) {
3258            $nextLi.first().trigger("click");
3259        }
3260    }
3261}
3262
3263
3264
3265
3266/**
3267 * Erkennt alte Oberdeck-Einzelplätze, deren Positionsschlüssel beim Speichern
3268 * auf 222 Zeichen und damit innerhalb der Tisch-ID gekürzt wurde. Reguläre
3269 * Sitzplatzschlüssel werden weiterhin über die bestehenden Hash-Prüfungen
3270 * verglichen.
3271 */
3272function istAlterOberdeckEinzelplatzGespeichert(plaetze, deck, tischId, anzahl) {
3273    if (
3274        !plaetze
3275        || typeof plaetze !== "object"
3276        || !tischId
3277        || parseInt(anzahl, 10) !== 1
3278    ) {
3279        return false;
3280    }
3281
3282    var decodeMehrfach = function (value) {
3283        value = String(value || "");
3284
3285        for (var i = 0; i < 3; i++) {
3286            try {
3287                var decodedValue = decodeURIComponent(value);
3288                if (decodedValue === value) {
3289                    break;
3290                }
3291                value = decodedValue;
3292            }
3293            catch (e) {
3294                break;
3295            }
3296        }
3297
3298        return value;
3299    };
3300
3301    var getDeckBasis = function (value) {
3302        return decodeMehrfach(value)
3303            .replace(/\s*\(.*$/, "")
3304            .replace(/\s+/g, " ")
3305            .trim();
3306    };
3307
3308    if (getDeckBasis(deck) !== "Oberdeck") {
3309        return false;
3310    }
3311
3312    return Object.keys(plaetze).some(function (gespeichertePosition) {
3313        gespeichertePosition = String(gespeichertePosition);
3314
3315        // Die betroffenen Altdaten enden exakt an der DB-Grenze der pos-Spalte.
3316        if (gespeichertePosition.length !== 222) {
3317            return false;
3318        }
3319
3320        var decodedPosition = decodeMehrfach(gespeichertePosition);
3321        var trennzeichenPosition = decodedPosition.lastIndexOf("+");
3322
3323        if (trennzeichenPosition === -1) {
3324            return false;
3325        }
3326
3327        var gespeichertesDeck = decodedPosition.substring(
3328            0,
3329            trennzeichenPosition
3330        );
3331        var gespeicherteTischId = decodedPosition.substring(
3332            trennzeichenPosition + 1
3333        );
3334
3335        return getDeckBasis(gespeichertesDeck) === "Oberdeck"
3336            && gespeicherteTischId.indexOf("ui-id-") === 0
3337            && gespeicherteTischId.length >= 20
3338            && String(tischId).indexOf(gespeicherteTischId) === 0;
3339    });
3340}
3341
3342/**
3343 * Bereitet die vom Server gelieferten Sitzplatzschluessel fuer die Diagnose in
3344 * der Browserkonsole auf. Die Funktion beeinflusst die Sitzplatzpruefung nicht.
3345 */
3346function getSitzplatzDebugListe(plaetze) {
3347    if (!plaetze || typeof plaetze !== "object") {
3348        return [];
3349    }
3350
3351    return Object.keys(plaetze).map(function (position) {
3352        var dekodiert = String(position);
3353
3354        for (var i = 0; i < 3; i++) {
3355            try {
3356                var dekodierterWert = decodeURIComponent(dekodiert);
3357                if (dekodierterWert === dekodiert) {
3358                    break;
3359                }
3360                dekodiert = dekodierterWert;
3361            }
3362            catch (e) {
3363                break;
3364            }
3365        }
3366
3367        return {
3368            gespeichert: position,
3369            dekodiert: dekodiert,
3370            laenge: String(position).length,
3371            wert: plaetze[position]
3372        };
3373    });
3374}
3375
3376function showSitzplan() {
3377    if ($('.grid-stack-ausgabe').length == 0 || $('.grid-stack-ausgabe').attr('data') == undefined) {
3378        return;
3379    }
3380
3381    //Schritt Sitzplan - Einblenden
3382    try {
3383        parent.$('#schritt2b').removeClass('hide');
3384        parent.setZeitstrahlBuchungsschritteLabels();
3385    } catch (err) {
3386        $('#schritt2b').removeClass('hide');
3387        setZeitstrahlBuchungsschritteLabels();
3388    }
3389
3390
3391    var vOnlineModus = true;
3392    if ($("#login").val() != "false") {
3393        vOnlineModus = false;
3394    }
3395    $(".AccSitzplan").addClass("hide");
3396
3397    setBlockUI(dialog['sitzplan_laden']);
3398
3399    setTimeout(function () {
3400        var ausgabeZusatz = {};
3401        var vCounter = 0;
3402        var vDeckCounter = 0;
3403        var vSitzplatzDebug = {
3404            version: "2026-07-15-3",
3405            serverdaten: [],
3406            belegtePlaetze: [],
3407            freiePlaetze: [],
3408            gebuchteGewaehltPlaetze: []
3409        };
3410
3411        $('.grid-stack-ausgabe[data]').each(function () {
3412
3413            var vObj = this;
3414
3415            //Decks anbringen und Container für Grid vorbereiten
3416            var dataString = decodeURIComponent($(vObj).attr('data'));
3417            if (dataString == "") {
3418                return;
3419            }
3420            var vData = JSON.parse(decodeURIComponent(dataString));
3421
3422            var nur_deck = $(vObj).attr('nur_deck');
3423            if (nur_deck == undefined) {
3424                nur_deck = "";
3425            }
3426            var vDiv = $("<div></div>");
3427            var vIDDIV = randomString(12);
3428            $(vDiv).attr("id", vIDDIV);
3429            var vUL = $("<ul></ul>");
3430
3431            for (var i in vData["decks"]) {
3432
3433                var row = vData["decks"][i];
3434                if (nur_deck == "" || (nur_deck != "" && nur_deck == row["bezeichnung"])) {
3435                    $(vUL).append("<li><a href='#div-sitz-" + i + "'>" + row["bezeichnung"] + "</a>");
3436                    var vDivDetail = $("<div id='div-sitz-" + i + "' class='sitzplan_div sitzplan_deck'><div data='" + JSON.stringify(row["data"]) + "' deck='" + encodeURIComponent(row["bezeichnung"]) + "'></div></div>");
3437                    $(vDiv).append(vDivDetail);
3438                }
3439            }
3440
3441            $(vDiv).prepend(vUL);
3442            $(vObj).append(vDiv);
3443            $(vObj).after("<div style='clear:both;'></div>");
3444            $(vObj).removeClass("grid-stack").removeClass("grid-stack-ausgabe").addClass("container_around");
3445            $(vObj).find('div.sitzplan_div div').addClass("grid-stack").addClass("grid-stack-ausgabe");
3446
3447            var cellHeightSitzplan="25px";
3448            if($("#sitzplan_schiff").attr("sitzplatz_caption") == "1"){
3449                cellHeightSitzplan="75px";
3450            }
3451
3452            //Plan aktivieren
3453            var columns = parseInt($("body").attr("columnsGridstack"));
3454            var options = {
3455                "float": true,
3456                resizable: false,
3457                removable: false,
3458                cellHeight:cellHeightSitzplan,
3459                draggable: false,
3460                disableResize: true,
3461                disableDrag: true,
3462                alwaysShowResizeHandle: false,
3463                staticGrid: false,
3464                minW:"30px",
3465                disableOneColumnMode: true,
3466                verticalMargin: "3px",
3467                width: columns
3468            };
3469
3470            var vBuchungsklasseID = $(vObj).attr("buchung_klasse_id");
3471            $(vObj).find('div.sitzplan_div div').gridstack(options); //Gridstack initialisieren
3472
3473            //Einzelne Sitzpläne iterieren
3474            $(vObj).find('div.sitzplan_div div').each(function (key, value) {
3475
3476                var vGrid = this;
3477                var vHasPaidPlaetze = false;
3478                var vBelegtPlaetze = {};
3479                var vGewaehltPlaetze = {};
3480                try {
3481                    vBelegtPlaetze = JSON.parse(decodeURIComponent($(vGrid).closest(".container_around").attr("belegt_plaetze")));
3482                    //console.log(vBelegtPlaetze);
3483                    if (vBelegtPlaetze == undefined) {
3484                        vBelegtPlaetze = {};
3485                    }
3486                } catch (e) {
3487                    vBelegtPlaetze = {};
3488                }
3489
3490                try {
3491                    vGewaehltPlaetze = JSON.parse(decodeURIComponent($(vGrid).closest(".container_around").attr("gewaehlt_plaetze")));
3492                    if (vGewaehltPlaetze == undefined) {
3493                        vGewaehltPlaetze = {};
3494                    }
3495                } catch (e) {
3496                    vGewaehltPlaetze = {};
3497                }
3498
3499                var vDebugListeBelegt = getSitzplatzDebugListe(vBelegtPlaetze);
3500                var vDebugListeGewaehlt = getSitzplatzDebugListe(vGewaehltPlaetze);
3501
3502                vSitzplatzDebug.serverdaten.push({
3503                    deck: decodeURIComponent($(vGrid).attr("deck") || ""),
3504                    belegtePlaetze: vDebugListeBelegt,
3505                    gebuchteGewaehltPlaetze: vDebugListeGewaehlt,
3506                    belegtePlaetzeRohdaten: vBelegtPlaetze,
3507                    gebuchteGewaehltPlaetzeRohdaten: vGewaehltPlaetze
3508                });
3509
3510                new function () {
3511
3512                    this.grid = $(vGrid).data('gridstack');
3513
3514                    this.gridContent = function (bezeichnung, anzahl, tisch_id, deck, only_klasse_id, preistypen) {
3515
3516                        if($("#klasse_id").length>0 && $("#klasse_id option").length<=1){
3517                            only_klasse_id = 0;
3518                            vBuchungsklasseID = 0;
3519                        }
3520
3521                        //Keine Bezeichnung
3522                        var vBez = bezeichnung;
3523                        if ((anzahl > 0 && $("#sitzplan_schiff").attr("sitzplatz_caption") != "1") || !bezeichnung || bezeichnung == undefined) {
3524                            bezeichnung = "";
3525                        }
3526                        //Bezeichnung
3527                        else {
3528                            bezeichnung = bezeichnung.replace(/Tisch /g, "");
3529                            bezeichnung = "<span bezeichnung='" + encodeURIComponent(bezeichnung) + "' class='bezeichnung'>" + bezeichnung + "</span><br>";
3530                        }
3531
3532                        if (!preistypen || preistypen == undefined) {
3533                            preistypen = [];
3534                        }
3535
3536                        if (!only_klasse_id || only_klasse_id == undefined) {
3537                            only_klasse_id = 0;
3538                        }
3539
3540                        //Bei Falscher Klasse, nichts anzeigen
3541                        if(parseInt(only_klasse_id)>0 && $("#klasse_id").length>0 && $("#klasse_id").val()!=only_klasse_id){
3542                            return "";
3543                        }
3544
3545
3546                        var vClassExtra = "";
3547                        if (anzahl > 8) {
3548                            bezeichnung += '<div class="containerAround" onclick="openSitzplatzDialogAuswahl(this)"><i class="fa-regular fa-folder-open"></i>';
3549                            vClassExtra = "hide multipleSeats";
3550                        }
3551
3552                        bezeichnung += "<div class='sitzplatz_content "+vClassExtra+"'>";
3553                        for (var i = 1; i <= anzahl; i++) {
3554                            var vHash = encodeURI(deck) + "+" + tisch_id + "+" + i;
3555                            var vHash2 = encodeURIComponent(deck) + "+" + tisch_id + "+" + i;
3556                            var vHash3 = deck + "+" + tisch_id + "+" + i;
3557                            var vHash4 = decodeURIComponent(deck) + "+" + tisch_id + "+" + i;
3558                            var vHash6 = encodeURIComponent(encodeURIComponent(vHash3));
3559                            var vHash5 = vHash3.replace("/", '%2F');
3560                            var vHash7 = vHash3.replace("/", '%252F');
3561                            var vHash8 = vHash3.replace("(", '%2528');
3562                            var vHash9 = vHash3.substring(vHash3.indexOf("+")); //Nur den Teil nach dem ersten Plus verwenden
3563
3564                            vHash8 = vHash8.replace(")", '%2529');
3565                            vHash8 = vHash8.replace("%2F", '/');
3566
3567                            var vDebugHashVarianten = {
3568                                vHash: vHash,
3569                                vHash2: vHash2,
3570                                vHash3: vHash3,
3571                                vHash4: vHash4,
3572                                vHash5: vHash5,
3573                                vHash6: vHash6,
3574                                vHash7: vHash7,
3575                                vHash8: vHash8,
3576                                vHash9: vHash9
3577                            };
3578                            var vDebugBelegtTreffer = [];
3579                            var vDebugGewaehltTreffer = [];
3580
3581                            Object.keys(vDebugHashVarianten).forEach(function (hashName) {
3582                                var hashWert = vDebugHashVarianten[hashName];
3583
3584                                if (vBelegtPlaetze[hashWert] != undefined) {
3585                                    vDebugBelegtTreffer.push(hashName);
3586                                }
3587
3588                                // vHash9 gehoert nicht zur bestehenden Pruefung
3589                                // der aktuell gewaehlten Plaetze.
3590                                if (
3591                                    hashName !== "vHash9"
3592                                    && vGewaehltPlaetze[hashWert] != undefined
3593                                ) {
3594                                    vDebugGewaehltTreffer.push(hashName);
3595                                }
3596                            });
3597
3598                            var vDebugLegacyBelegtTreffer = istAlterOberdeckEinzelplatzGespeichert(
3599                                vBelegtPlaetze,
3600                                deck,
3601                                tisch_id,
3602                                anzahl
3603                            );
3604                            var vDebugLegacyGewaehltTreffer = istAlterOberdeckEinzelplatzGespeichert(
3605                                vGewaehltPlaetze,
3606                                deck,
3607                                tisch_id,
3608                                anzahl
3609                            );
3610                            var vDebugPasstZumTisch = function (position) {
3611                                if (
3612                                    position.gespeichert.indexOf("+" + tisch_id) !== -1
3613                                    || position.dekodiert.indexOf("+" + tisch_id) !== -1
3614                                ) {
3615                                    return true;
3616                                }
3617
3618                                var trennzeichenPosition = position.dekodiert.lastIndexOf("+");
3619                                var gespeicherteTischId = position.dekodiert.substring(
3620                                    trennzeichenPosition + 1
3621                                );
3622
3623                                return trennzeichenPosition !== -1
3624                                    && gespeicherteTischId.indexOf("ui-id-") === 0
3625                                    && gespeicherteTischId.length >= 20
3626                                    && String(tisch_id).indexOf(gespeicherteTischId) === 0;
3627                            };
3628                            var vDebugServerBelegt = vDebugListeBelegt.filter(function (position) {
3629                                return vDebugPasstZumTisch(position);
3630                            });
3631                            var vDebugServerGewaehlt = vDebugListeGewaehlt.filter(function (position) {
3632                                return vDebugPasstZumTisch(position);
3633                            });
3634                            var vDebugSitzplatz = {
3635                                bezeichnung: vBez,
3636                                deckGespeichert: deck,
3637                                deckDekodiert: decodeURIComponent(deck),
3638                                tischId: tisch_id,
3639                                platzNummer: i,
3640                                anzahlAmElement: anzahl,
3641                                hashVarianten: vDebugHashVarianten,
3642                                exakteBelegtTreffer: vDebugBelegtTreffer,
3643                                legacyBelegtTreffer: vDebugLegacyBelegtTreffer,
3644                                legacyGewaehltTreffer: vDebugLegacyGewaehltTreffer,
3645                                passendeBelegteServerwerte: vDebugServerBelegt,
3646                                passendeGebuchteServerwerte: vDebugServerGewaehlt
3647                            };
3648
3649                            if (vDebugBelegtTreffer.length > 0 || vDebugLegacyBelegtTreffer) {
3650                                vSitzplatzDebug.belegtePlaetze.push(vDebugSitzplatz);
3651                            }
3652                            else {
3653                                vSitzplatzDebug.freiePlaetze.push(vDebugSitzplatz);
3654                            }
3655
3656                            if (vDebugGewaehltTreffer.length > 0 || vDebugLegacyGewaehltTreffer) {
3657                                vSitzplatzDebug.gebuchteGewaehltPlaetze.push(vDebugSitzplatz);
3658                            }
3659
3660                            var vName = "platz[" + $(vGrid).closest(".tr_sitzplan").attr("key_fahrt") + "][" + vHash + "]";
3661
3662                            var vAttr = "";
3663                            //Platz ist bereits belegt
3664                            if (
3665                                vBelegtPlaetze[vHash] != undefined
3666                                || vBelegtPlaetze[vHash2] != undefined
3667                                || vBelegtPlaetze[vHash3] != undefined
3668                                || vBelegtPlaetze[vHash4] != undefined
3669                                || vBelegtPlaetze[vHash5] != undefined
3670                                || vBelegtPlaetze[vHash6] != undefined
3671                                || vBelegtPlaetze[vHash7] != undefined
3672                                || vBelegtPlaetze[vHash8] != undefined
3673                                || vBelegtPlaetze[vHash9] != undefined
3674                                || istAlterOberdeckEinzelplatzGespeichert(vBelegtPlaetze, deck, tisch_id, anzahl)
3675                            ) {
3676                                bezeichnung += "<i class='fa-solid fa-user sitzplatz_blocked'/>";
3677                            }
3678                            //Freier Platz
3679                            else {
3680                                if (only_klasse_id > 0 && vBuchungsklasseID != only_klasse_id) {
3681                                    vAttr += " class='hide' ";
3682                                }
3683                                else if (
3684                                    vGewaehltPlaetze[vHash] != undefined
3685                                    || vGewaehltPlaetze[vHash2] != undefined
3686                                    || vGewaehltPlaetze[vHash3] != undefined
3687                                    || vGewaehltPlaetze[vHash4] != undefined
3688                                    || vGewaehltPlaetze[vHash5] != undefined
3689                                    || vGewaehltPlaetze[vHash6] != undefined
3690                                    || vGewaehltPlaetze[vHash7] != undefined
3691                                    || vGewaehltPlaetze[vHash8] != undefined
3692                                    || istAlterOberdeckEinzelplatzGespeichert(vGewaehltPlaetze, deck, tisch_id, anzahl)
3693                                )
3694                                {
3695                                    vAttr += " checked ";
3696                                }
3697
3698                                var vJsAction = " onclick='";
3699
3700                                //Anzahl gewählter Personen ermitteln
3701                                vJsAction += "var vAnzahlPersonen = getAnzahlPreistypAuswahl(); var vSelected = $(this).closest(\".sitzplan_div\").find(\".grid-stack-item-content input:checked\").length; if(vSelected>vAnzahlPersonen) { this.checked=false; getAnzahlPreistypAuswahl(); return; } " ;
3702                                if (vCounter == 0 && $('.grid-stack-ausgabe').length > 1) {
3703                                    vJsAction += "setSamePlatzRueckfahrt(this);";
3704                                }
3705                                if ($('.grid-stack-ausgabe').length >= 1) {
3706                                    vJsAction += " getAnzahlPreistypAuswahl(true);";
3707                                    vJsAction += ' $(".sitzplatz_auswahl").find("select").val(""); ';
3708                                    vJsAction += ' setSitzplatzAuswahlCSS(); ';
3709                                    vJsAction += ' setSitzplatzLabelZuschlag(this); ';
3710
3711                                }
3712                                vJsAction += "'";
3713
3714                                if ($("#login").val() == "false") {
3715                                    bezeichnung += "<span class='sitzplatzauswahl'>";
3716                                    bezeichnung += "<input " + vJsAction + " type='checkbox' name='" + vName + "' id='" + vName + "' value='" + deck + encodeURIComponent(" " + vBez) + "' deck='" + deck + "' " + "tisch_id='" + tisch_id + "' only_preistypen='" + preistypen.join(",") + "' counter='" + i + "' bezeichnung='" + encodeURIComponent(vBez) + "' pos='" + vHash + "' " + vAttr + " checky='sitzplatz'/>";
3717                                    bezeichnung += '</span>';
3718                                } else {
3719                                    bezeichnung += "<input " + vJsAction + " type='checkbox' name='" + vName + "' id='" + vName + "' value='" + deck + encodeURIComponent(" " + vBez) + "' deck='" + deck + "' only_preistypen='" + preistypen + "' tisch_id='" + tisch_id + "' counter='" + i + "' bezeichnung='" + encodeURIComponent(vBez) + "' pos='" + vHash + "' " + vAttr + " checky='sitzplatz'/>";
3720                                }
3721                            }
3722
3723                        }
3724
3725                        if (anzahl > 8) {
3726                            bezeichnung += '</div>';
3727                        }
3728                        bezeichnung += "</div>";
3729                        return bezeichnung;
3730                    };
3731
3732                    this.loadGrid = function () {
3733                        this.grid.removeAll();
3734
3735                        var items = {};
3736                        if ($(vGrid).attr("data") != "" && $(vGrid).attr("data") != "undefined") {
3737                            var vJsonString = $(vGrid).attr("data");
3738                            vJsonString = decodeURIComponent(vJsonString);
3739                            items = JSON.parse(vJsonString);
3740                            if (typeof items != 'object') {
3741                                items = {};
3742                            }
3743                            $(vGrid).attr("data", "");
3744                        }
3745
3746                        //Sitzplätze prüfen nach bezahlten Zusatzplätzen - entsprechende Darstellung des Hinweis
3747                        var zusaetze = {};
3748                        $.each(items,function (){
3749                            if($(this["zusaetze"]).length>0){
3750                                vHasPaidPlaetze = true;
3751                                $.each(this["zusaetze"],function(){
3752                                    zusaetze[this]=true;
3753                                })
3754
3755                            }
3756                        });
3757
3758                        if(vHasPaidPlaetze){
3759                            var iz=0;
3760                            for (const [key, value] of Object.entries(zusaetze)) {
3761
3762                                var zusatz_id = key;
3763                                if($(".tableTicketZusatz[zusatz_id='"+zusatz_id+"']").length>0){
3764                                    var bezeichnung = decodeURIComponent($(".tableTicketZusatz[zusatz_id='"+zusatz_id+"']").attr("bezeichnung"));
3765                                    var farbe =$(".tableTicketZusatz[zusatz_id='"+zusatz_id+"']").attr("farbe");
3766                                    if(farbe==""){
3767                                        farbe = "#B0B0B0"; //Standardfarbe für Auswahl
3768                                        $(".tableTicketZusatz[zusatz_id='"+zusatz_id+"']").attr("farbe","#B0B0B0");
3769                                    }
3770                                    var style="";
3771                                    if(farbe!==""){
3772                                        style="border-color:"+farbe;
3773                                    }
3774                                    //Hinzufügen der Legende
3775                                    ausgabeZusatz[zusatz_id]="<div><div class='grid-stack-item-content-legende zusatzartikel zusatzartikel_"+iz+"' style='"+style+"' zusatz_id='"+zusatz_id+"'></div> "+bezeichnung+"<div style='clear:both;'></div></div>";
3776
3777                                    iz++;
3778                                }
3779                                else{
3780                                    console.log("Zuschlag "+zusatz_id+" nicht gefunden");
3781                                }
3782                            }
3783                        }
3784
3785                        var vCounter = 0;
3786                        var vCounterSitzplatz = 0;
3787                        _.each(items, function (node) {
3788
3789                            //Platz ist nicht fuer das Internet freigegeben
3790                            var vAnzahl = node.anzahl;
3791                            if (vOnlineModus == true && !(node.use_internet == undefined) && !(node.use_internet == "1")) {
3792                                vAnzahl = 0;
3793                            }
3794
3795                            //Für Agenturen ausblenden
3796                            if ($("#bodi.recht_5").length > 0 && !(node.hide_agentur == undefined) && (node.hide_agentur == "1")) {
3797                                vAnzahl = 0;
3798                            }
3799
3800                            if ((nur_deck == "" || (nur_deck != "" && nur_deck == $(vGrid).attr("deck")))) {
3801
3802                                var gesamtlaenge = node.gesamtlaenge==undefined?0:node.gesamtlaenge==undefined;
3803                                var vFarbe = "";
3804                                var vClassAdd = "";
3805                                if (node.farbe != undefined && node.farbe != "") {
3806                                    if ($("#login").val() != "false") {
3807                                        vFarbe = node.farbe;
3808                                    }
3809                                    vClassAdd += " special_mark ";
3810                                }
3811
3812                                //Zusatzklasse hinterlegen
3813                                var useZusatzId = "";
3814                                if($(node.zusaetze).length>0){
3815
3816                                    //Erster Zusatz
3817                                    var zusatz_id_key = Object.keys(node.zusaetze)[0];
3818                                    var zusatz_idXX = node.zusaetze[zusatz_id_key];
3819
3820                                    var iz=0;
3821                                    for (const [key, value] of Object.entries(zusaetze)) {
3822                                        var zusatz_id = key;
3823                                        if(zusatz_idXX==zusatz_id && $(".tableTicketZusatz[zusatz_id='"+zusatz_id+"']").length>0){
3824
3825                                            vFarbe =$(".tableTicketZusatz[zusatz_id='"+zusatz_id+"']").attr("farbe");
3826                                            vClassAdd+= " zusatzartikel zusatzartikel_"+iz;
3827                                            useZusatzId = zusatz_id;
3828                                        }
3829                                        iz++;
3830                                    }
3831                                }
3832
3833                                var vFarbeStyle="";
3834                                if(vFarbe!==""){
3835                                    vFarbeStyle = "border-color: "+vFarbe;
3836                                }
3837
3838                                if(node.css != undefined && node.css != ""){
3839                                    vClassAdd += " "+node.css;
3840                                }
3841
3842                                var vObjContent = $('<div><div class="grid-stack-item-content ' + vClassAdd + '" farbe="'+vFarbe+'" style="' + vFarbeStyle + '" tisch_id="' + $(node).attr("id") + '" gesamtlaenge="'+gesamtlaenge+'" zusatz_id="'+useZusatzId+'">' + this.gridContent(
3843                                    node.bezeichnung,
3844                                    vAnzahl,
3845                                    $(node).attr("id"),
3846                                    $(vGrid).attr("deck"),
3847                                    node.klasse,
3848                                    node.preistypen
3849                                ) + '</div></div>');
3850
3851                                var ObjThis = this;
3852                                setTimeout(function () {
3853                                    ObjThis.grid.addWidget(vObjContent, node.x, node.y, node.width,node.height);
3854
3855                                    //Resizable Elemente entfernen
3856                                    $(".ui-resizable-handle").remove();
3857
3858                                    //Zähler iterieren
3859                                    vCounterSitzplatz++;
3860
3861                                    //Wenn alle Sitzpläne gezeichnet sind, neu berechnen
3862                                    if (vCounterSitzplatz == $(items).length) {
3863                                        vDeckCounter++;
3864                                        if ($('.sitzplan_deck').length == vDeckCounter) {
3865                                            console.log("Sitzplan komplett fertig gezeichnet");
3866
3867                                            if ($("input[checky='sitzplatz']:checked").length > 0) {
3868                                                calculate();
3869                                            }
3870
3871
3872                                            //Css rendern
3873                                            setSitzplatzAuswahlCSS();
3874
3875                                            //Wenn in die Zelle geklickt wurde, Aktion der Checkbox ausführen
3876                                            $(".grid-stack-item-content input[name^='platz']").closest(".grid-stack-item-content.singleplace").on("click",function(){
3877                                                $(this).find("input[name^='platz']").not(":focus").trigger("click");
3878                                            })
3879
3880                                            $("#table_sitzplatz").removeClass("hide");
3881
3882                                            if ($("#login").val() != "true") {
3883                                                $(".grid-stack-item-content.not_available").css("border","");
3884                                            }
3885
3886                                            //Wenn es keine Anklickbaren Checkboxen gibt, Tab ausblenden
3887                                            if($('div.AccSitzplan div.sitzplan_div input[type="checkbox"]').length>0){
3888                                                $.each($('div.AccSitzplan div.sitzplan_div'),function() {
3889
3890                                                    if($(this).find("input[type='checkbox'], .sitzplatz_blocked").length==0){
3891                                                        var tabbar = $(this).closest(".ui-tabs");
3892                                                        var tabPanelId = $(this).attr("aria-labelledby");
3893
3894                                                        //Tab Panel entfernen
3895                                                        $(this).addClass("hide");
3896                                                        $("li[aria-labelledby='"+tabPanelId+"']",tabbar).addClass("hide");
3897
3898                                                        //Ersten sichtbaren Tab aktivieren
3899                                                        var vFirstVisibleTab = $("ul.ui-tabs-nav li:not(.hide) a",tabbar).first();
3900                                                        $(vFirstVisibleTab).trigger("click");
3901                                                        return;
3902                                                    }
3903                                                });
3904                                            }
3905                                        }
3906                                    }
3907                                }, 400);
3908                                vCounter++;
3909                            }
3910                        }, this);
3911
3912                        return false;
3913                    }.bind(this);
3914
3915                    //Beim initialisieren, Daten laden
3916                    this.loadGrid();
3917                };
3918            });
3919
3920            //Lassoauswahl
3921            if ($("#login").val() == "true") {
3922                $(vObj).find('.sitzplan_div div.grid-stack-ausgabe').selectable({
3923                    filter: ":checkbox",
3924                    cancel: "i, input, .grid-stack-item",
3925                    start: function () {
3926                        $(".sitzplatz_content.multipleSeats").removeClass("hide");
3927                        $(".grid-stack-item-content.singleplace").removeClass("singleplace").addClass("singleplaceRunning");
3928                    },
3929                    stop: function () {
3930                        $(".sitzplatz_content.multipleSeats").addClass("hide");
3931                        $(".grid-stack-item-content.singleplaceRunning").removeClass("singleplaceRunning").addClass("singleplace");
3932
3933                        //Anzahl gewählter Personen ermitteln
3934                        var vAnzahlPersonen = getAnzahlPreistypAuswahl();
3935                        var vSelected = $(this).find("input[type='checkbox']:checked").length;
3936                        console.log("Anzahl Personen: " + vAnzahlPersonen + "Anzahl ausgewählt: " + vSelected);
3937
3938                        $(".ui-selected", this).each(function () {
3939
3940                            if ($(this).attr("type") == "checkbox" && $(this).is(":checked")) {
3941                                $(this).prop("checked", false);
3942                                vSelected--;
3943
3944                            } else if ($(this).attr("type") == "checkbox" && vSelected < vAnzahlPersonen) {
3945                                $(this).prop("checked", true);
3946
3947                                if ($(this).closest("tr").attr("fahrt_nr") == "0") {
3948                                    setSamePlatzRueckfahrt(this);
3949                                }
3950
3951                                vSelected++;
3952                            }
3953                        });
3954
3955                        $(".ui-selected").removeClass("ui-selected");
3956                        getAnzahlPreistypAuswahl(true);
3957                        setSitzplatzAuswahlCSS();
3958                    }
3959                });
3960            }
3961
3962            $(vObj).removeAttr("data");
3963            $("#" + vIDDIV).tabs({heightStyle: "content"});
3964
3965            //Legende anzeigen, wenn es Zusätze gibt
3966            if(Object. keys(ausgabeZusatz). length === 0){
3967                $(".column.legende").addClass("hide");
3968            }
3969            else{
3970                var objLegende = $(vObj).closest("tr.tr_sitzplan").find(".legende");
3971                var ausgabeZusatzString = "<div class='labelbeschr'>"+dialog['sitzplatz_auswaehlen_aufschlag']+"</div>";
3972
3973                var artikelIds = [];
3974                $.each($("tr.extra_zusatz[nur_auswahl_sitzplatz='1']"),function(){
3975                    var artikel_id = $(this).attr("artikel_id");
3976
3977                    //Wenn der Artikel nicht existiert oder schon hinzugefügt wurde, überspringen
3978                    if(artikel_id == undefined || artikel_id == "" || artikelIds.includes(artikel_id)){
3979                        console.log("Artikel "+artikel_id+" existiert nicht oder wurde schon hinzugefügt");
3980                        return;
3981                    }
3982
3983                    if (ausgabeZusatz.hasOwnProperty(artikel_id)) {
3984                        ausgabeZusatzString+=ausgabeZusatz[artikel_id];
3985                        artikelIds.push(artikel_id);
3986                    }
3987                });
3988
3989                $(objLegende).html(ausgabeZusatzString);
3990                $(objLegende).removeClass("hide");
3991            }
3992
3993            vCounter++;
3994        });
3995
3996        if (vOnlineModus == false) {
3997            $(".AccSitzplan").removeClass("hide");
3998        }
3999
4000        if($("#table_sitzplatz .container_around ul.ui-tabs-nav>li").length==1){
4001            $("#table_sitzplatz .container_around ul.ui-tabs-nav>li").addClass("hide");
4002        }
4003
4004        vSitzplatzDebug.zusammenfassung = {
4005            serverDecks: vSitzplatzDebug.serverdaten.length,
4006            belegtePlaetze: vSitzplatzDebug.belegtePlaetze.length,
4007            freiePlaetze: vSitzplatzDebug.freiePlaetze.length,
4008            gebuchteGewaehltPlaetze: vSitzplatzDebug.gebuchteGewaehltPlaetze.length
4009        };
4010        //console.log("[Sitzplan][GESAMTDIAGNOSE]", vSitzplatzDebug);
4011
4012        hideWaitingScreen();
4013    }, 300);
4014}
4015function setPaxListeHandy(handy_nr){
4016    if(handy_nr!=""){
4017        if($("#form\\[mobil\\]").val()==""){
4018            $("#form\\[mobil\\]").val(handy_nr);
4019        }
4020        if($("#form\\[handy_nr\\]").val()==""){
4021            $("#form\\[handy_nr\\]").val(handy_nr);
4022        }
4023    }
4024}
4025function setSitzplatzPaxListe() {
4026
4027    var vChanged = false;
4028    var vChangedVollst = true;
4029
4030    var vArraySelector = [".sitzplatz_auswahl1 select", ".sitzplatz_auswahl2 select"];
4031
4032    var arrayLength = vArraySelector.length;
4033    for (var i = 0; i < arrayLength; i++) {
4034        var vSelector = vArraySelector[i];
4035
4036        var vSitzplatzDoppelt = {};
4037        var SitzplatzFehlt = false;
4038        var SitzplatzDoppelt = false;
4039        $(vSelector).each(function () {
4040            if ($(this).val() == "") {
4041                SitzplatzFehlt = true;
4042            }
4043
4044            //Init
4045            if (isNaN(vSitzplatzDoppelt[$(this).attr("name")])) {
4046                vSitzplatzDoppelt[$(this).attr("name")] = 0;
4047            }
4048
4049            vSitzplatzDoppelt[$(this).attr("name")]++;
4050            if ($(this).val() != "" && vSitzplatzDoppelt[$(this).attr("name")] > 1) {
4051                SitzplatzDoppelt = true;
4052            }
4053        });
4054
4055        //Neuzuweisung der Plätze
4056        if (SitzplatzFehlt == true || SitzplatzDoppelt == true) {
4057            var vCounter = 1;
4058            $(vSelector).find("option").removeAttr("selected");
4059            $(vSelector).each(function () {
4060
4061                $(this).find("option:eq(" + vCounter + ")").prop("selected", true);
4062                vCounter++;
4063            });
4064            console.log("Sitzplatz doppelt");
4065            vChanged = true;
4066        }
4067
4068        //Prüfung ob noch Plätze fehlen
4069        if (vChanged == true) {
4070            $(vSelector).each(function () {
4071                if ($(this).val() == "") {
4072                    console.log("Fehlen noch Plätze");
4073                    vChangedVollst = false;
4074                }
4075            });
4076        }
4077    }
4078
4079    //Wenn sich die Ergebnisse geändert haben und der Focus nicht in der Passagierliste ist
4080    if (vChanged == true && vChangedVollst == true && $("table#table_persoenliche_daten").find("input:focus, select:focus").length == 0) {
4081        //Hat eine Endlosschleife produziert.. Herausgenommen am 2.3.26
4082        //calculate();
4083        $("#mySubmit").attr("isdirty", true);
4084    }
4085}
4086
4087function openSitzplatzDialogAuswahl(obj){
4088
4089    $(obj).closest("div").find(".sitzplatz_content").removeClass("hide");
4090    $(obj).closest("div").find(".sitzplatz_content").dialog({
4091        modal: true,
4092        title: dialog['sitzplatz_auswaehlen'],
4093        open: function() {
4094        },
4095        close: function() {
4096            $( this ).dialog( "destroy" );
4097            $(obj).closest("div").find(".sitzplatz_content").addClass("hide");
4098            getAnzahlPreistypAuswahl(true);
4099        }});
4100}
4101
4102function SitzplatzZuweisen(vObj) {
4103    $(vObj).find("input[type='checkbox'][checky='sitzplatz']").prop("checked", false);
4104    $(vObj).find(".sitzplatz_auswahl select").val("");
4105
4106    var isHinfahrt;
4107    var fahrt_nr = $(vObj).closest(".tr_sitzplan").attr("fahrt_nr");
4108    if(fahrt_nr=="0"){
4109        isHinfahrt=true;
4110    }
4111    else{
4112        isHinfahrt=false;
4113    }
4114
4115    //In Paxliste ist ein Sitzplatz pro Person auswählbar
4116    if($("#table_persoenliche_daten").length>0 && $(".sitzplatz_auswahl select").length>0){
4117
4118        $($(".paxlisterow.sitzplatz")).each(function () {
4119            var preistyp_id = $(this).attr("preistyp_id");
4120            var row=(this);
4121
4122            var selected=false;
4123            $(vObj).find("input[type='checkbox'][checky='sitzplatz']:visible").not(":checked").each(function(){
4124                if(selected){
4125                    return;
4126                }
4127                var allow=false;
4128                if($(this).attr("only_preistypen")!=""){
4129                    var p = $(this).attr("only_preistypen").split(",");
4130                    if(p.includes(preistyp_id)){
4131                        allow=true;
4132                    }
4133                }
4134                else{
4135                    allow=true;
4136                }
4137
4138                //Platz kann verwendet werden
4139                if(allow==true){
4140                    $(this).prop("checked", true);
4141
4142                    if(isHinfahrt){
4143                        var selector = "sitzplatz_auswahl1";
4144                    }
4145                    else{
4146                        var selector = "sitzplatz_auswahl2";
4147                    }
4148                    var id = decodeURIComponent($(this).attr("pos"));
4149                    var val = decodeURIComponent($(this).attr("value"));
4150                    $(row).find("div."+selector+" select option").remove();
4151                    $(row).find("div."+selector+" select").append("<option value='"+id+"'>
4151"+val+"</option>");
4152                    $(row).find("div."+selector+" select").val(id);
4153
4154                    selected=true;
4155                }
4156            });
4157        });
4158    }
4159    else{
4160        //Automatische Zuweisung
4161        $(vObj).find("input[type='checkbox'][checky='sitzplatz']:visible").slice(0, getAnzahlPreistypAuswahl()).prop("checked", true);
4162
4163        setBlockUI();
4164        getAnzahlPreistypAuswahl();
4165
4166        setTimeout(function () {
4167            calculate();
4168        }, 500);
4169    }
4170
4171    setSitzplatzAuswahlCSS();
4172}
4173
4174
4175function setSitzplatzLabelZuschlag(obj){
4176
4177    var container = $(obj).closest(".zusatzartikel");
4178    var zusatz_id = $(container).attr("zusatz_id");
4179    var farbe = $(container).attr("farbe");
4180    if(zusatz_id !=""){
4181        var objLegende = $(".grid-stack-item-content-legende.zusatzartikel[zusatz_id='"+zusatz_id+"']");
4182        var options = {  };
4183        if(farbe!=""){
4184            options = { color: farbe };
4185        }
4186        $(objLegende).effect( "highlight", options, 1500);
4187    }
4188}
4189
4190function setSitzplatzAuswahlCSS(){
4191
4192    $(".grid-stack-item-content input[name^='platz']").closest('.grid-stack-item-content').removeClass('not_selected').removeClass('selected').removeClass('not_available').removeClass("singleplace");
4193    $(".grid-stack-item-content input[name^='platz']").not(":checked").closest('.grid-stack-item-content').addClass('not_selected');
4194    $(".grid-stack-item-content input[name^='platz']:checked").closest('.grid-stack-item-content').addClass('selected');
4195    $(".grid-stack-item-content .sitzplatz_blocked").closest('.grid-stack-item-content').addClass('not_selected').addClass('not_available').removeClass('selected'); //Bereits ausgewählte Plätze
4196
4197    //Plätze bei denen nichts ausgewählt werden kann (z.B. Platzhalter)
4198    $.each($(".grid-stack-item-content").not(".not_available"),function(){
4199        if($(this).find("input[name^='platz']").length==0){
4200            $(this).addClass("not_available");
4201        }
4202    });
4203
4204    //Hintergrundfarbe für selektierte Boxen
4205    $(".grid-stack-item-content").css("background-color","");
4206    $.each($(".grid-stack-item-content.selected"),function(){
4207        if($(this).attr("farbe")!==""){
4208            $(this).css("background-color",$(this).attr("farbe"));
4209        }
4210    });
4211
4212    //Plätze mit mehr als Ein Platz, besonders markieren
4213    $.each($(".grid-stack-item-content").not(".not_available"),function(){
4214        if($(this).find("input[name^='platz']").length == 1){
4215            $(this).addClass("singleplace");
4216        }
4217    });
4218
4219    //Plätze in denen die Platzauswahl in einem extra Fenster ist weil mehr als x plätze pro tisch
4220    $.each($(".grid-stack-item-content .containerAround .fa-folder-open"),function(){
4221        $(this).closest(".not_available").removeClass("not_available");
4222    });
4223}
4224
4225function getAnzahlPreistypAuswahl(vCalculate) {
4226    if (vCalculate === undefined) {
4227        var vCalculate = false;
4228    }
4229
4230    var vAnzahlPersonen = 0;
4231    $("div.anzahl_personen_preistyp_container.sitzplatz select[name*='personen']").each(function () {
4232        var vName = $(this).attr("name");
4233
4234        //Ist ausgewählt
4235        if (parseInt($(this).val()) > 0) {
4236
4237            //Personen-Bemerkung ist Teilnehmerzahl
4238            var objAnzahlPersonenBem = $(this).closest("tr").find("td input[type='number'][name*='personen_bemerkung']");
4239            if($(objAnzahlPersonenBem).length>0){
4240                vAnzahlPersonen += parseInt($(objAnzahlPersonenBem).val()) * parseInt($(this).val());
4241                return;
4242            }
4243
4244            //Ausnahme Familienticket
4245            var vNameFT = String(vName).replace("personen", "personen_preistyp_1");
4246            vNameFT = String(vNameFT).replace("[", "\\[");
4247            vNameFT = String(vNameFT).replace("]", "\\]");
4248
4249            var vNameFT2 = String(vName).replace("personen", "personen_preistyp_2");
4250            vNameFT2 = String(vNameFT2).replace("[", "\\[");
4251            vNameFT2 = String(vNameFT2).replace("]", "\\]");
4252
4253
4254
4255            var vPreistypID = vName.match(/\d+/)[0];
4256            var anzahlFix = parseInt($("#tr_preistyp_"+vPreistypID+"_1").attr("fixe_anzahl"));
4257            if(anzahlFix>0){
4258                vAnzahlPersonen += (parseInt($(this).val())*anzahlFix);
4259            }
4260            else if ($("#" + vNameFT).length > 0) {
4261                vAnzahlPersonen += parseInt($("#" + vNameFT).val());
4262                vAnzahlPersonen += parseInt($("#" + vNameFT2).val());
4263            } else {
4264                vAnzahlPersonen += parseInt($(this).val());
4265            }
4266        }
4267    });
4268
4269    //Darstellung der Zuweisung
4270    $("div.container_around").each(function () {
4271        var vAnzahl = $(this).find("input[type='checkbox']:checked").length;
4272        var vString = String(vAnzahl) + "/" + String(vAnzahlPersonen);
4273        $(this).closest("td").find("span.anzahl_pax").html(vString);
4274        $(this).closest("td").find(".anzahl_pax_container").removeClass("hide");
4275    });
4276
4277    if (vCalculate == true) {
4278        setBlockUI();
4279        calculate(true);
4280        setTimeout(function(){
4281            calculate(true);
4282        },600);
4283    }
4284
4285    return vAnzahlPersonen;
4286}
4287
4288function exportVorgangSDS(vBuchungID, vKundeID) {
4289    if ($("#cb_nur_vormerkung").attr("checked") == true) {
4290        alert(window.dialog["ui_969b75739210"]);
4291        return;
4292    } else if (vKundeID != undefined && parseInt(vKundeID) == 0) {
4293        alert(window.dialog["ui_663b6c35a26b"]);
4294        return;
4295    } else if (document.getElementById('form[kunde_id]') && parseInt(document.getElementById('form[kunde_id]').value) == 0) {
4296        alert(window.dialog["ui_663b6c35a26b"]);
4297        return;
4298    }
4299
4300    $.post("ajax/onlinereservierung.php", {aktion: "export_sds", reservierung_id: vBuchungID})
4301        .done(function (data) {
4302
4303            if (data.fehler == true) {
4304                alert(data.fehlermeldung);
4305            } else {
4306                alert(data.hinweis);
4307            }
4308        });
4309}
4310
4311function setSamePlatzRueckfahrt(vObj) {
4312    var vTisch = $(vObj).attr("tisch_id");
4313    var vDeck = $(vObj).attr("deck");
4314    if ($("input[tisch_id='" + vTisch + "'][deck='" + vDeck + "']").length == 2 && $("tr.tr_sitzplan").length == 2) {
4315        $("input[tisch_id='" + vTisch + "'][deck='" + vDeck + "']").last().prop("checked", $(vObj).is(":checked"));
4316
4317        //Tab aktivieren
4318        var vTabID = $("input[tisch_id='" + vTisch + "'][deck='" + vDeck + "']").last().closest(".ui-tabs-panel").attr("id");
4319        $("a.ui-tabs-anchor[href='#" + vTabID + "']").click();
4320    }
4321    setTempSitzplatz();
4322}
4323
4324function Seite1() {
4325
4326    //Ist auf dem Sitzplatz - und möchte da zurück
4327    if ($("#zeitstrahl_buchungsschritte ul li#schritt2b.allowed").length > 0 && $("#seite4").css("display") == "none") {
4328        $("#zeitstrahl_buchungsschritte ul li").removeClass("allowed");
4329        $("#zeitstrahl_buchungsschritte ul li#schritt2").addClass("allowed");
4330        setZeitstrahlBuchungsschritteLabels();
4331
4332        $(".AccSitzplan").addClass("hide");
4333
4334        //Buchungs - Inhalt einblenden
4335        $("#tr_fahrgaeste td").find(".table_ticketoptionen, #fahrgaeste, #ausstattung, #hinfahrt_extra, #rueckfahrt_extra, #anzeige_gesamt, #linie_fahrgastinfo").removeClass("hide");
4336        return;
4337    }
4338
4339    //Ist auf Paxdaten und möchte zurück
4340    if ($("#zeitstrahl_buchungsschritte ul li#schritt2a.allowed").length > 0) {
4341        $("#zeitstrahl_buchungsschritte ul li").removeClass("allowed");
4342        $("#zeitstrahl_buchungsschritte ul li#schritt2").addClass("allowed");
4343        setZeitstrahlBuchungsschritteLabels();
4344
4345        $("#table_persoenliche_daten").addClass("hide");
4346
4347        //Buchungs - Inhalt einblenden
4348        $("#tr_fahrgaeste td").find(".table_ticketoptionen, #fahrgaeste, #ausstattung, #hinfahrt_extra, #rueckfahrt_extra, #anzeige_gesamt, #linie_fahrgastinfo").removeClass("hide");
4349        return;
4350    }
4351
4352    //Seite 1 Einblenden
4353    document.getElementById("seite1").style.display = "block";
4354
4355    $("#ButtonWeiterSeite1,#mySubmit").attr("disabled", false);
4356
4357    $("#zeitstrahl_buchungsschritte ul li").removeClass("allowed");
4358    $("#zeitstrahl_buchungsschritte ul li#schritt1").addClass("allowed");
4359    setZeitstrahlBuchungsschritteLabels();
4360    $("#tr_fahrgaeste td").find(".table_ticketoptionen, #fahrgaeste, #ausstattung, #hinfahrt_extra, #rueckfahrt_extra, #anzeige_gesamt, #linie_fahrgastinfo").removeClass("hide");
4361
4362    //Seiten Ausblenden
4363    $("#seite2,#seite3,#seite4").css("display", "none");
4364
4365    if (scrolling == true) {
4366        $("html, body").animate({scrollTop: 0}, "fast");
4367    }
4368
4369    $('#warpper,#form1').css("display", "");
4370
4371    //In der Onlinebuchung wenn eine Linie mit übergeben wurde
4372    if (
4373        $("#hide_tourfinder").val() != "true"
4374        && $("#login").val() == "false"
4375        && parseInt($("#linie_id").val()) > 0
4376        && $("#linie_id").attr("datum") == ""
4377        && checkInIframe() == false
4378        && ($("#hafen_id").val() == $("#destination_hafen_id").val() || $("#destination_hafen_id").val() == "0")
4379    ) {
4380        OnlinebuchungLoadLinieSuche($("#linie_id").val());
4381    }
4382}
4383
4384function InWartelisteUebernehmen(){
4385    if($("#vor_nachname").val()=="" || $("#warteliste_email").val()==""){
4386        alert(dialog['zielfelder_ausfuellen']);
4387        return;
4388    }
4389    else if(isEmail($("#warteliste_email").val())==false){
4390        $("#warteliste_email").focus();
4391        alert(dialog['email_fehlt']);
4392        return;
4393    }
4394
4395    var li = $("td.td_hinfahrt_anzeige .suchergebnis li.active");
4396    if($(li).length>0){
4397        var para = {
4398            "aktion":"insertWarteliste",
4399            "name":$("#vor_nachname").val(),
4400            "email":$("#warteliste_email").val(),
4401            "linie_id":$(li).attr("linie_id"),
4402            "lhf_id":$(li).attr("linie_hafen_fahrplan_id"),
4403            "station_start_id":$(li).attr("hafen_id"),
4404            "station_stop_id":$(li).attr("zielhafen_id"),
4405            "datum":$(li).attr("datum"),
4406            "fahrt":$(li).attr("fahrt")
4407        };
4408
4409        setBlockUI();
4410        $.post("ajax/onlinereservierung.php",para).done(function(data)
4411        {
4412            $.unblockUI();
4413            $(".dialog_meldung_popup").remove();
4414            alert(dialog['warteliste_erfolgreich']);
4415        });
4416    }
4417
4418
4419
4420}
4421
4422function InWarteliste(){
4423    var div=$("<div class='row' id='warteliste_uebernehmen'/>");
4424    $(div).append("<div class='small-12 column'>"+dialog['kunde_name']+": <input type='text' id='vor_nachname' autocomplete='name'></div>");
4425    $(div).append("<div class='small-12 column'>"+dialog['email']+": <input type='email' id='warteliste_email' autocomplete='email'></div>");
4426    $(div).append("<div class='small-12 column'><input type='button' class='button' onclick='InWartelisteUebernehmen();' value='"+dialog['warteliste_uebernahme']+"'></div>");
4427    $(".dialog_meldung_popup").remove();
4428    showDialog(dialog['fahrt_ausgebucht'],div);
4429}
4430/**
4431 * Diese Funktion wird nur in der Onlinebuchung aufgerufen
4432 * @constructor
4433 */
4434function Seite2() {
4435
4436    //Überprüfung ob ausgebuchte Fahrt gewählt wurde
4437    var li = $("div.suchergebnis_auswahl input[type='radio']:checked").closest("li");
4438    if (
4439        $(li).attr("nicht_einbuchen") == "true"
4440        || $(li).attr("soldout") == "true"
4441        || ($(li).attr("fr")=="0" && $(li).attr("cap_calculated")=="true" && $(li).attr("kombiticket")!="1")
4442    ) {
4443        if($("#seite1").attr("sdsmodus")=="true"){
4444            return;
4445        }
4446        else if($("#has_warteliste").length>0){
4447            var text = "<div>"+dialog['nicht_einbuchen_ausgewaehlt']+".</div>";
4448            text+="<br><br><div class='text-center'><input type='button' class='button' value='"+dialog['warteliste_uebernahme']+"' onclick='InWarteliste()'/></div><br>";
4449            showDialog(dialog['fahrt_ausgebucht'],text);
4450        }
4451        else{
4452            setBlockUI();
4453            setTimeout(function(){
4454                showDialog(dialog['fahrt_ausgebucht'],dialog['nicht_einbuchen_ausgewaehlt']);
4455                $.unblockUI();
4456            },500);
4457        }
4458        return;
4459    }
4460
4461    //Individuelle JS Aktion
4462    if ($("div.suchergebnis_auswahl input[type='radio']:checked").closest("li").attr("jsaction") != "") {
4463        try {
4464            var js = decodeURIComponent($("div.suchergebnis_auswahl input[type='radio']:checked").closest("li").attr("jsaction"));
4465            eval(js);
4466        } catch (e) {
4467        }
4468    }
4469
4470    document.getElementById("seite1").style.display = "none";
4471    document.getElementById("seite2").style.display = "block";
4472
4473    $("#zeitstrahl_buchungsschritte ul li").removeClass("allowed");
4474    $("#zeitstrahl_buchungsschritte ul li#schritt2").addClass("allowed");
4475    setZeitstrahlBuchungsschritteLabels();
4476    $("#seite4").css("display","none");
4477
4478    //Wenn Sitzplan Online einzelstehend ist
4479    if ($("#zeitstrahl_buchungsschritte ul li#schritt2b").length > 0) {
4480        $("#tr_fahrgaeste td").find(".table_ticketoptionen, #fahrgaeste, #ausstattung, #hinfahrt_extra, #rueckfahrt_extra, #anzeige_gesamt, #linie_fahrgastinfo").removeClass("hide");
4481    }
4482
4483    //Wenn man im iFrame in WP Ist, Button Label ändern
4484    if($("#onlinebuchung_bemerkung").length ==0 && ($("#table_persoenliche_daten tr.tr_pax_data").length || $("#table_persoenliche_daten.hide").length==1) && $("#warenkorb_foreign_id").val()!=""){
4485
4486        if($("#use_shop_remark").val()=="1"){
4487            $("#ButtonWeiterSeite2").val(dialog['go_on']);
4488        }
4489        else{
4490            $("#ButtonWeiterSeite2").val(dialog['in_warenkorb']);
4491        }
4492        $('#ButtonWeiterSeite2').removeClass('hide');
4493    }
4494
4495    //Paxdaten ausblenden
4496    $("#table_persoenliche_daten").addClass("hide");
4497
4498    //In einer Sekunde neu laden
4499    showWaitingScreen();
4500
4501    $(".callout.auswahlticketinfo").removeClass("hide");
4502
4503    //Fahrtinfos laden
4504    window.setTimeout("setFahrtInfo();", 400);
4505
4506    //Waiting Screen wieder ausblenden
4507    window.setTimeout(function () {
4508        hideWaitingScreen();
4509        focusOnlinebuchungStep();
4510    }, 800);
4511
4512
4513    if (scrolling == true) {
4514        $("html, body").animate({scrollTop: 0}, "fast");
4515    }
4516}
4517
4518function Seite4() {
4519    $("#seite2,#seite3,#seite1").css("display", "none");
4520    $("#seite4").css("display","");
4521    setFahrtInfo();
4522
4523    $("#zeitstrahl_buchungsschritte ul li").removeClass("allowed");
4524    $("#zeitstrahl_buchungsschritte ul li#schritt3").addClass("allowed");
4525    setZeitstrahlBuchungsschritteLabels();
4526
4527    if($(".freitext").length == 0 && $("#onlinebuchung_bemerkung").length ==0 && ($("#table_persoenliche_daten tr.tr_pax_data").length || $("#table_persoenliche_daten.hide").length==1)){
4528        $("#seite4 .SubmitButton.button").trigger("click");
4529        $("#reservierung_div_comp").addClass("hide");
4530    }
4531    else{
4532
4533        if (scrolling == true) {
4534            $("html, body").animate({scrollTop: 0}, "fast");
4535        }
4536
4537        hideWaitingScreen();
4538    }
4539}
4540
4541function setZeitstrahlBuchungsschritteLabels() {
4542
4543    var root = $("#reservierung_div_comp[data-booking-a11y='true']");
4544    var stepIcons = {
4545        "#schritt1": "fa-magnifying-glass",
4546        "#schritt2": "fa-ticket",
4547        "#schritt2a": "fa-users",
4548        "#schritt2b": "fa-chair",
4549        "#schritt3": "fa-credit-card"
4550    };
4551
4552    //Alles leeren
4553    $("#zeitstrahl_buchungsschritte .marker").html("");
4554
4555    var steps = [];
4556    steps.push("#schritt1");
4557    steps.push("#schritt2");
4558    if ($("#schritt2a.hide").length == 0) {
4559        steps.push("#schritt2a");
4560    }
4561    if ($("#schritt2b").length > 0 && $("#schritt2b.hide").length == 0) {
4562        steps.push("#schritt2b");
4563    }
4564    steps.push("#schritt3");
4565
4566    var current_step = $("#zeitstrahl_buchungsschritte .allowed").attr("id");
4567    if(current_step!=""){
4568        $('#step').val(current_step);
4569    }
4570    var counter = 1;
4571    var stepGot = false;
4572    for (step of steps) {
4573        if (step == "#" + current_step) {
4574            stepGot = true;
4575        }
4576        if (!stepGot) {
4577            var icon = "<i class=\"fa-solid fa-circle-check\"></i>";
4578        } else {
4579            var icon = "<span class='rund'><i class=\"fa-solid fa-" + counter + "\"></i></span>";
4580        }
4581        if (root.length) {
4582            $(step).toggleClass("buchung-schritt-abgeschlossen", !stepGot);
4583            if (stepGot) {
4584                icon = "<i class=\"fa-solid " + stepIcons[step] + "\"></i>";
4585            }
4586        }
4587        $(step).find(".marker").html(icon);
4588        counter++;
4589    }
4590    if (root.length) {
4591        $(".shop-kopfleiste").toggleClass("shop-kopfleiste-buchung", ["schritt2", "schritt2a", "schritt2b", "schritt3"].indexOf(current_step) !== -1);
4592        var previous = root.data("a11yCurrentStep");
4593        root.data("a11yCurrentStep", current_step);
4594        if (previous && current_step && previous != current_step) {
4595            root.data("a11yFocusStep", current_step);
4596            root.data("a11yFocusStarted", Date.now());
4597            announceOnlinebuchungStatus("");
4598            window.setTimeout(focusOnlinebuchungStep, 0);
4599        }
4600        updateOnlinebuchungAccessibility();
4601    }
4602}
4603
4604// Gestaltet nur die Frontend-Ausgabe. Auswahl, Berechnung und Checkout-Daten bleiben unverändert.
4605function gestalteOnlinebuchungZusammenfassung(html, daten, rueck) {
4606    if (!$("#reservierung_div_comp[data-booking-a11y='true']").length) {
4607        return html;
4608    }
4609
4610    var fahrtIcon = $("#reservierung_div_comp").attr('data-booking-fahrt-icon');
4611    if (['fa-ship', 'fa-ticket', 'fa-bus', 'fa-train', 'fa-plane'].indexOf(fahrtIcon) === -1) { fahrtIcon = 'fa-ship'; }
4612    var ausgabe = $("<div>").html(html);
4613    var zusammenfassung = ausgabe.children(".ausgewaehlte-fahrt").addClass("buchung-zusammenfassung");
4614    var fahrten = $("<div class='buchung-zusammenfassung-fahrten'>");
4615    var hinfahrt = daten.hinfahrt;
4616    var segmente = [{
4617        titel: hinfahrt.headline,
4618        datum: hinfahrt.datum,
4619        abfahrt: hinfahrt.abfahrt,
4620        ankunft: hinfahrt.ankunft,
4621        start: hinfahrt.startstation,
4622        ziel: hinfahrt.zielstation,
4623        linie: hinfahrt.linie
4624    }];
4625    if (rueck.length) {
4626        segmente.push({
4627            titel: dialog['zf_rueckfahrt'],
4628            datum: daten.rueckfahrt.datum,
4629            abfahrt: daten.rueckfahrt.uhrzeit,
4630            ankunft: daten.rueckfahrt.ankunft,
4631            start: decodeURIComponent(rueck.attr('hafen') || ''),
4632            ziel: decodeURIComponent(rueck.attr('zielhafen') || ''),
4633            linie: rueck.find(".buchung-fahrt-name").first().text() || rueck.find(".suchergebnis_linie span").text()
4634        });
4635    }
4636
4637    $.each(segmente, function (index, segment) {
4638        var karte = $("<section class='buchung-zusammenfassung-fahrt'>");
4639        $("<h4>").append($("<i class='fa-solid' aria-hidden='true'>").addClass(fahrtIcon))
4640            .append($("<span>").text(segment.titel)).appendTo(karte);
4641        var strecke = $("<div class='buchung-zusammenfassung-strecke'>");
4642        if (segment.start) {
4643            strecke.append($("<span>").text(segment.start));
4644        }
4645        if (segment.start && segment.ziel && segment.start !== segment.ziel) {
4646            strecke.append("<i class='fa-solid fa-arrow-right' aria-hidden='true'></i>");
4647        }
4648        if (segment.ziel && segment.ziel !== segment.start) {
4649            strecke.append($("<span>").text(segment.ziel));
4650        }
4651        if (!segment.start && !segment.ziel) {
4652            strecke.text(segment.linie);
4653        }
4654        strecke.appendTo(karte);
4655        if (segment.linie && segment.linie !== segment.start + ' - ' + segment.ziel) {
4656            $("<div class='buchung-zusammenfassung-linie'>").text(segment.linie).appendTo(karte);
4657        }
4658        $("<div class='buchung-zusammenfassung-datum'>")
4659            .append("<i class='fa-solid fa-calendar-days' aria-hidden='true'></i>")
4660            .append($("<span>").text(segment.datum)).appendTo(karte);
4661
4662        var zeiten = $("<div class='buchung-zusammenfassung-zeiten'>");
4663        var abfahrt = $("<span class='buchung-zusammenfassung-zeit'>").attr('title', dialog['zf_abfahrt']);
4664        abfahrt.append("<i class='fa-solid fa-arrow-right-from-bracket' aria-hidden='true'></i>")
4665            .append($("<span class='show-for-sr'>").text(dialog['zf_abfahrt'] + ' '))
4666            .append($("<strong>").text(segment.abfahrt)).appendTo(zeiten);
4667        if (segment.ankunft) {
4668            var ankunft = $("<span class='buchung-zusammenfassung-zeit'>").attr('title', dialog['zf_ankunft']);
4669            ankunft.append("<i class='fa-solid fa-arrow-right-to-bracket' aria-hidden='true'></i>")
4670                .append($("<span class='show-for-sr'>").text(dialog['zf_ankunft'] + ' '))
4671                .append($("<strong>").text(segment.ankunft)).appendTo(zeiten);
4672        }
4673        zeiten.appendTo(karte);
4674        karte.appendTo(fahrten);
4675    });
4676    zusammenfassung.children(".row").first().replaceWith(fahrten);
4677
4678    var tickets = zusammenfassung.children(".buchung_auswahl");
4679    tickets.children("h4").prepend("<i class='fa-solid fa-ticket' aria-hidden='true'></i>");
4680    tickets.find("li").each(function () {
4681        var position = $(this);
4682        var preis = position.children(".einzelbetrag").detach();
4683        var waehrung = (daten.waehrung || '').trim();
4684        var preistext = preis.text();
4685        if (waehrung && preistext.endsWith(waehrung)) {
4686            preis.text(preistext.slice(0, -waehrung.length).trim() + ' ' + waehrung);
4687        }
4688        var bezeichnung = $("<span class='buchung-zusammenfassung-position'>").append(position.contents());
4689        position.append("<i class='fa-solid fa-ticket' aria-hidden='true'></i>").append(bezeichnung).append(preis);
4690    });
4691
4692    var gesamt = tickets.children(".gesamtbetrag");
4693    if (gesamt.length) {
4694        // Den bereits formatierten Tabellenbetrag anzeigen, ohne ihn erneut als Zahl zu interpretieren.
4695        var betrag = $(".OnlinebuchungTabelleGesamt .ttCell4 input").first().val();
4696        var waehrung = $("#waehrung_id option:selected").text();
4697        gesamt.removeClass("alignleft").empty()
4698            .append($("<span>").append("<i class='fa-solid fa-wallet' aria-hidden='true'></i>")
4699                .append($("<span>").text($(".OnlinebuchungTabelleGesamt .ttCell2").first().text())))
4700            .append($("<strong>").text(betrag + (waehrung ? ' ' + waehrung : '')));
4701    }
4702    return ausgabe.html();
4703}
4704
4705function setFahrtInfo() {
4706    var vHTML = "",
4707        vHTMLSmall = "",
4708        vHTMLAuswahl = "",
4709    vAuswahlData = {};
4710
4711    // Hinfahrt li.active
4712    var hin = $("td.td_hinfahrt_anzeige")
4713        .find("div#suchergebnis_ausgabe li.active");
4714
4715    if (hin.length) {
4716        // ggf. Rückfahrt li.active
4717        var rueck = $("table#table_rueckfahrt")
4718                .find("div#suchergebnis_ausgabe li.active"),
4719            linie_id = hin.attr("linie_id");
4720
4721        vHTML += "<div class='ausgewaehlte-fahrt' linie_id='" + linie_id + "'>";
4722        vHTML += "<div class='row'><div class='small-12 medium-6 column'>";
4723
4724        // Überschrift
4725        vAuswahlData["hinfahrt"] = {};
4726        vAuswahlData["rueckfahrt"] = {};
4727
4728        if (rueck.length) {
4729            vHTML += "<h4>" + dialog['zf_hinfahrt'] + "</h4>";
4730            vHTMLSmall += dialog['zf_hinfahrt'] + ": ";
4731            vAuswahlData["hinfahrt"]["headline"] = dialog['zf_hinfahrt'];
4732        } else {
4733            vHTML += "<h4>" + dialog['auswahl'] + "</h4>";
4734            vHTMLSmall += dialog['auswahl'] + ": ";
4735            vAuswahlData["hinfahrt"]["headline"] = dialog['auswahl'];
4736        }
4737
4738        // === Hinfahrt-Segment ===
4739        // Datum
4740        var dateStr = hin.attr('datum_format');
4741        vAuswahlData["hinfahrt"]["datum"] = dateStr;
4742
4743        // Abfahrt
4744        var rawAbf  = hin.attr('abfahrt').toString().padStart(4,'0');
4745        var timeAbf = rawAbf.substr(0,2) + ':' + rawAbf.substr(2,2);
4746        vAuswahlData["hinfahrt"]["abfahrt"] = timeAbf;
4747
4748        var station = decodeURIComponent(hin.attr('zielhafen'));
4749        vAuswahlData["hinfahrt"]["startstation"] = decodeURIComponent(hin.attr('hafen'));
4750        vAuswahlData["hinfahrt"]["zielstation"] = station;
4751
4752        var linie = $(hin).find(".buchung-fahrt-name").first().text() || $(hin).find(".suchergebnis_linie span").text();
4753        vAuswahlData["hinfahrt"]["linie"] = linie;
4754
4755        //Wenn der stationsname in der linie enthalten ist, dann  linie = ""
4756        if (linie.indexOf(station) !== -1) {
4757            linie = "";
4758        }
4759        else{
4760            linie = "<br>(" + linie + ")";
4761        }
4762
4763        vHTML += "<p>";
4764        vHTML += "<span class='linienbezeichnung'>"
4765            + station
4766            + linie
4767            + "</span><br>";
4768        vHTML += dateStr + " ";
4769        vHTML += "<span class='zeitanzeige'>" + timeAbf + "</span>";
4770
4771        vHTMLSmall += dateStr + " " + timeAbf;
4772
4773        // Ankunft (falls vorhanden)
4774        if (hin.attr('ankunft') && hin.attr('keine_ankunft_zeigen')!="1") {
4775            var rawAnk  = hin.attr('ankunft').toString().padStart(4,'0');
4776            var timeAnk = rawAnk.substr(0,2) + ':' + rawAnk.substr(2,2);
4777            vHTML += " <span class='ankunft'>"
4778                + dialog['zf_ankunft'] + " "
4779                + "<span class='zeitanzeige'>" + timeAnk + "</span>"
4780                + "</span>";
4781            vAuswahlData["hinfahrt"]["ankunft"] = timeAnk;
4782        }
4783        else{
4784            vAuswahlData["hinfahrt"]["ankunft"] = null;
4785        }
4786        vHTML += "</p>";
4787        vHTML += "</div>"; // .column
4788
4789        // === Rückfahrt-Segment (falls ausgewählt) ===
4790        if (rueck.length) {
4791            var linie2 = rueck.attr("linie_id");
4792            vHTML += "<div class='small-12 medium-6 column rueckfahrt' linie_id='" + linie2 + "'>";
4793            vHTML += "<h4>" + dialog['zf_rueckfahrt'] + "</h4><p>";
4794
4795            // Datum Rückfahrt
4796            var dateStr2 = rueck.attr('datum_format');
4797
4798            // Abfahrt Rückfahrt
4799            var rawAbf2  = rueck.attr('abfahrt').toString().padStart(4,'0');
4800            var timeAbf2 = rawAbf2.substr(0,2) + ':' + rawAbf2.substr(2,2);
4801
4802            vHTML += dateStr2 + " ";
4803            vHTML += "<span class='zeitanzeige'>" + timeAbf2 +"</span>";
4804
4805            vHTMLSmall += "<br>" + dialog['zf_rueckfahrt'] + ": " + dateStr2 + " <span class='rueckfahrt_uhrzeit'>" + timeAbf2 + "</span>";
4806
4807            // Ankunft Rückfahrt
4808            var timeAnk2="";
4809            if (rueck.attr('ankunft') && rueck.attr('keine_ankunft_zeigen')!="1") {
4810                var rawAnk2  = rueck.attr('ankunft').toString().padStart(4,'0');
4811                timeAnk2 = rawAnk2.substr(0,2) + ':' + rawAnk2.substr(2,2);
4812                vHTML += " <span class='ankunft'>"
4813                    + dialog['zf_ankunft'] + " "
4814                    + "<span class='zeitanzeige'>" + timeAnk2 + "</span>"
4815                    + "</span>";
4816            }
4817            vHTML += "</p></div>";
4818
4819
4820            vAuswahlData["rueckfahrt"]["datum"] = dateStr2;
4821            vAuswahlData["rueckfahrt"]["uhrzeit"] = timeAbf2;
4822            vAuswahlData["rueckfahrt"]["ankunft"] = timeAnk2;
4823        }
4824
4825        vHTML += "</div>"; // .row
4826
4827        //Inhalt für ZF-Box rechts
4828        vHTMLAuswahl = "";
4829        vHTMLAuswahl += "<div class='buchung_auswahl'><h4>" + dialog['zf_ticket'] + "</h4><ul>";
4830        var vCounter = 0;
4831
4832        //Artikel-Vormerkung Gesamtpreis
4833        var vGesamtbetragVormerkung = 0;
4834        $("#table_artikel_ev_vormerkung").find("tr .ttCell1").each(function () {
4835            var vObj = $(this).closest("tr");
4836            var vAnzahl = parseInt($(vObj).find(".ttCell1").find("input, select").val());
4837            var vBetrag = $(vObj).find(".ttCell3 input").val();
4838            $(vObj).find(".ttCell4 input").val(dbl2C(vAnzahl * vBetrag));
4839            vGesamtbetragVormerkung += vAnzahl * vBetrag;
4840        });
4841
4842        var hasPflichtartikel = false;
4843        $("table.tableTicket").find("tr .ttCell1").each(function () {
4844            if ($(this).closest("tr").find("input[type='checkbox']:checked, td.ttCell1 input[type='text'], td.ttCell1 input[type='number'], td.ttCell1 select").length > 0) {
4845                if ($(this).closest("tr").is(".pflichtartikel")) {
4846                    hasPflichtartikel = true;
4847                }
4848            }
4849        });
4850        var vWaehrung = $(".OnlinebuchungTabelleGesamt .waehrung_symbol").text();
4851        var vBezeichnungLog = "";
4852
4853
4854        vAuswahlData["bezeichnung"]=dialog['zf_ticket'];
4855        vAuswahlData["waehrung"]=vWaehrung;
4856        vAuswahlData["positionen"]=[];
4857
4858        var vBezeichnungLogArray = [];
4859        $("table.tableTicket").find("tr .ttCell1").each(function () {
4860
4861            if ($(this).closest("tr").find("input[type='checkbox']:checked, td.ttCell1 input[type='text'], td.ttCell1 input[type='number'], td.ttCell1 select").length > 0) {
4862
4863                //Pflichtartikel nicht in der Übersicht listen
4864                if ($(this).closest("tr").not("[nur_auswahl_sitzplatz=1]").is(".pflichtartikel")) {
4865                    return;
4866                }
4867
4868                //Extra - Zusatz ist ausgeblendet
4869                if ($(this).closest("tr.extra_zusatz.hide").not("[nur_auswahl_sitzplatz=1]").length > 0) {
4870                    return;
4871                }
4872
4873                var vObj = $(this).closest("tr");
4874                if ($(vObj).find(".ttCell2 select").length > 0) {
4875                    var vBezeichnung = $.trim($(vObj).find(".ttCell2 select option:selected").text());
4876                }
4877                else if($(vObj).find(".ttCell2 span.bezeichnung").length > 0){
4878                    var vBezeichnung = $(vObj).find(".ttCell2 span.bezeichnung").text();
4879                }
4880                else {
4881                    var cell = $(vObj).find(".ttCell2").clone();
4882                    $(cell).find("div,span").remove();
4883                    var vBezeichnung = $.trim($(cell).text());
4884                }
4885
4886                var vAnzahl = parseInt($(vObj).find(".ttCell1").find("input, select").val());
4887                var vBetrag = $(vObj).find(".ttCell4 input").val();
4888
4889                if (vAnzahl > 0) {
4890                    vBezeichnungLog += vAnzahl + "x " + vBezeichnung + " " + vBetrag + "<br>";
4891                    if (
4892                        $("#table_ticket").attr("ist_kombitarif") == "1"
4893                        && $(this).closest("#hinfahrt_extra, #rueckfahrt_extra").length>0
4894                        && $(this).find("tr.pflichtartikel.extra_zusatz").not("[nur_auswahl_sitzplatz=1]").length > 0)
4895                    {
4896                        //Nicht auflisten
4897                        console.log("Kombitarif mit Extra-Zusatz - nicht auflisten");
4898                    } else {
4899                        if(vBezeichnungLogArray.includes(vBezeichnung)){
4900                            //Artikel schon gelistet - nicht nochmal auflisten
4901                            console.log("Artikel schon gelistet - nicht nochmal auflisten: " + vBezeichnung);
4902                            return;
4903                        }
4904
4905
4906                        vHTMLAuswahl += "<li>";
4907                        //console.log($(this));
4908                        if ($(vObj).find(".ttCell1 input[type='checkbox']").length == 0) {
4909                            vHTMLAuswahl += vAnzahl + "x ";
4910                        }
4911
4912                        //Extra für Hinfahrt
4913                        vHTMLAuswahl += vBezeichnung;
4914
4915                        if ($("#table_ticket").attr("ist_kombitarif") == "0" && hasPflichtartikel == false) {
4916                            vHTMLAuswahl += " <span class='einzelbetrag'>" + vBetrag + "" + vWaehrung + "</span>";
4917                        }
4918
4919                        vHTMLAuswahl += "</li>";
4920
4921                        vBezeichnungLogArray.push(vBezeichnung);
4922                    }
4923
4924                    vCounter++;
4925
4926                    var anzahl = parseInt(vAnzahl);
4927                    vAuswahlData["positionen"].push({
4928                        anzahl: anzahl,
4929                        bezeichnung: vBezeichnung,
4930                        einzelpreis: parseFloat(C2dbl(vBetrag)/anzahl),
4931                        gesamtpreis: parseFloat((C2dbl(vBetrag)))
4932                    })
4933
4934                }
4935            }
4936        });
4937
4938        //Rabattierung
4939        if ($("tr.OnlinebuchungRabatt").is(":visible") || parseInt($("tr.OnlinebuchungRabatt .ttCell4 input").val()) < 0) {
4940            var rabattBetrag = $("tr.OnlinebuchungRabatt .ttCell4 input").val();
4941            vHTMLAuswahl += "<li>" + $("tr.OnlinebuchungRabatt .ttCell2").text() + " " + rabattBetrag + "" + vWaehrung + "</li>";
4942
4943            vAuswahlData["positionen"].push({
4944                anzahl: 1,
4945                bezeichnung: $("tr.OnlinebuchungRabatt .ttCell2").text(),
4946                einzelpreis: C2dbl(rabattBetrag),
4947                gesamtpreis: C2dbl(rabattBetrag)
4948            });
4949
4950        }
4951
4952        vHTMLAuswahl += "</ul>";
4953
4954        //Es besteht eine Auswahl
4955        vAuswahlData["gesamtbetrag"]=0;
4956        vAuswahlData["zahlart"]="";
4957        if (vCounter > 0) {
4958
4959
4960            vAuswahlData["gesamtbetrag"]=C2dbl($("#tb_gesamtbetrag").val());
4961            var betrag = 0;
4962            if($("html").attr("lang")=="en"){
4963                betrag = C2dbl($(".OnlinebuchungTabelleGesamt .ttCell4 input").val()).toFixed(2);
4964            }
4965            else{
4966                betrag = $(".OnlinebuchungTabelleGesamt .ttCell4 input").val();
4967            }
4968
4969
4970            if ($("body").attr("login") == "true") {
4971                //Zahlart
4972                if ($("#nur_vormerkung").val() == "1") {
4973                    vHTMLAuswahl += "<div class='row column'>" + dialog['vormerkung'] + "</div>";
4974                } else {
4975                    var zahlart_id = getRadioBoxValue("form[zahlart_id]");
4976                    var t = $("tr[zahlart_id='"+zahlart_id+"'] label").clone();
4977                    $(t).find("div").remove();
4978                    var zahlart = $(t).text();
4979                    vAuswahlData["zahlart"] = zahlart;
4980                    vHTMLAuswahl += "<div class='row column'>" + zahlart + "</div>";
4981                }
4982
4983                //Verkaufsbutton rechts oben anbringen
4984                if ($("#link_warenkorb").length > 0 && $("#mySubmitW").length > 0) {
4985                    var button = $("#mySubmitW").first().clone();
4986                } else {
4987                    var button = $("#mySubmit").first().clone();
4988                }
4989                $(button).prop("id", "");
4990                $(button).addClass("button").addClass("success");
4991
4992                if (vGesamtbetragVormerkung > 0) {
4993                    var vText = $(button).text() + " + " + dbl2C(vGesamtbetragVormerkung) + "" + vWaehrung;
4994                    $(button).text(vText);
4995                }
4996
4997                var htmlButton = $(button).wrap("<div/>").closest("div").html();
4998                if(htmlButton!==undefined){
4999                    vHTMLAuswahl += "<div class='hideKassenScreen'><hr><div class='row column text-center'>" + htmlButton + "</div></div>";
5000                }
5001
5002                //Diese Ausgabe - nur für den Kassenbildschirm
5003                vHTMLAuswahl += "<div class='onlyKassenScreen hide'><hr>";
5004
5005                vHTMLAuswahl += "</div>";
5006
5007            } else {
5008                var content = "";
5009                if($(".OnlinebuchungTabelleGesamt .ttCell2").length>0 && betrag !== undefined) {
5010                    content = $(".OnlinebuchungTabelleGesamt .ttCell2").text() + ": " + betrag + "" + $("#waehrung_id option:selected").text();
5011                }
5012                vHTMLAuswahl += "<hr><div class='gesamtbetrag alignleft'>" + content + "</div>";
5013            }
5014            vHTMLAuswahl += "</div>";
5015        } else {
5016            vHTMLAuswahl = "";
5017        }
5018
5019
5020        vHTML += vHTMLAuswahl;
5021        vHTML += "</div>";
5022        vHTML = gestalteOnlinebuchungZusammenfassung(vHTML, vAuswahlData, rueck);
5023
5024        // Ausgabe
5025        var mobileZusammenfassung = $("div.infokasten_ausgewaehlte-fahrt-small").html(vHTMLSmall);
5026        if ($("#reservierung_div_comp[data-booking-a11y='true']").length) {
5027            var kurzfassung = $("<div class='buchung-zusammenfassung buchung-zusammenfassung-mobil'>")
5028                .append($("<div>").html(vHTML).find(".buchung-zusammenfassung-fahrten"));
5029            kurzfassung.find(".buchung-zusammenfassung-fahrt").each(function () {
5030                var karte = $(this);
5031                var linie = karte.find('.buchung-zusammenfassung-linie');
5032                if (linie.length) {
5033                    // Der gewählte Fahrtname ersetzt die wenig aussagekräftige Überschrift „Auswahl“.
5034                    if (!rueck.length) { karte.find('h4 > span').text(linie.text()); }
5035                    else { karte.find('.buchung-zusammenfassung-strecke').text(linie.text()); }
5036                    linie.remove();
5037                }
5038            });
5039            kurzfassung.find(".buchung-zusammenfassung-zeit + .buchung-zusammenfassung-zeit").remove();
5040            mobileZusammenfassung.addClass("buchung-zusammenfassung-mobil-container").html(kurzfassung);
5041        }
5042        $("div.infokasten_ausgewaehlte-fahrt, div#zusammenfassung_fahrt")
5043            .html(vHTML)
5044            .find(".medium-6").removeClass("medium-6");
5045    }
5046
5047    updateOnlinebuchungAccessibility();
5048    focusOnlinebuchungStep();
5049
5050    //Kassenbildschirm
5051    if ($("#login").val() == "true" && $("#checkout_verkaufsstelle_id").length>0) {
5052        console.log(vAuswahlData);
5053        sendMsg2CheckoutScreen(JSON.stringify(vAuswahlData),'buchung');
5054    }
5055}
5056
5057function setFirstTarifFromTab(obj) {
5058    if ($(obj["newPanel"][0]).length > 0) {
5059        $(obj["newPanel"][0]).find("input:radio").first().prop("checked", true);
5060        calculate();
5061    }
5062}
5063
5064/*Sitzplatzauswahl - Zusammenhänge Buchungen markieren*/
5065function SelectSPAuswahl(vResID) {
5066    DeSelectSPAuswahl();
5067    $("img.CBSitzplatzauswahl[res_id='" + vResID + "']").parent("div").addClass("SitzplatzauswahlZusammen");
5068}
5069
5070function DeSelectSPAuswahl() {
5071    $("img.CBSitzplatzauswahl").parent("div").removeClass("SitzplatzauswahlZusammen");
5072}
5073
5074function setAnzahlBerechnenTB(vObjektID, vWert) {
5075    vObjektID = vObjektID.replace("_bemerkung", "");
5076
5077    if (parseInt(vWert) > 0) {
5078        setSelectBoxWert(vObjektID, 1);
5079    } else {
5080        setSelectBoxWert(vObjektID, 0);
5081    }
5082    //alert(vObjektID+"---"+vWert);
5083}
5084
5085function setSitzplatzOnRueckfahrt(vPos, vChecked) {
5086    if ($('table#table_sitzplatz tr[fahrt_nr=0]').attr('same_seat') == "true") {
5087        console.log("Same Sitzplatz!!");
5088        var vObj = $('table#table_sitzplatz tr[fahrt_nr=1] td input[pos=\"' + vPos + '\"]');
5089        //alert( 'Handler for .click() called.'+vObj+' ---'+$(vObj).attr('pos') );
5090        //vObj.checked=true;
5091        $(vObj).prop("checked", vChecked);
5092
5093        //Verbundenes Textfeld setzten
5094        if (vChecked == true) {
5095            $(vObj).next().val(1);
5096        } else {
5097            $(vObj).next().val(0);
5098        }
5099    }
5100    //$(vObj).parent().css('background-color','green');
5101}
5102
5103function setGutscheinAnzahl(obj, alwaysSet) {
5104    if (alwaysSet == undefined) {
5105        alwaysSet = false;
5106    }
5107
5108    $('.einzelverkauf_artikelanzahl.gutschein').val(0);
5109    $("input.gutschein_auswahl").not(obj).removeClass("hollow").val(dialog['ausw_onlinebuchung']);
5110
5111    //Auswahl entfernen
5112    if ($(obj).hasClass('hollow') && alwaysSet == false) {
5113        $(obj).removeClass('hollow');
5114        $(obj).val(dialog['ausw_onlinebuchung']);
5115    }
5116    //Auswahl hinzufügen
5117    else {
5118        $(obj).closest('div').find('.einzelverkauf_artikelanzahl').val(1);
5119        $(obj).addClass('hollow');
5120        $(obj).val(dialog['ausw_remove']);
5121    }
5122}
5123
5124//BERECHNUNG UND KALKULATION
5125var calculateXHR = null;
5126function calculate(recalculate, initial) {
5127
5128    if (vActiveCalc == true) {
5129        console.log("Calc läuft bereits");
5130        return;
5131    }
5132
5133    if (initial && (initial == true || initial == "true")) {
5134        document.getElementById("aktion").value = "calculateInitial";
5135    } else if (recalculate && recalculate == true) {
5136        document.getElementById("aktion").value = "calculatePriceNew";
5137    } else if (!document.getElementById("aktion")) {
5138        return;
5139    } else {
5140        document.getElementById("aktion").value = "calculatePrice";
5141    }
5142
5143    //Bei Vormerkungartikel - Freipreiseingabe
5144    $.each($("#table_artikel_ev_vormerkung select"), function () {
5145
5146        if ($(this).find("option:selected").attr("preis_freieingabe") == "1") {
5147            $(this).closest(".tr_einzelverkauf").find(".ttCell3 input").removeAttr("readonly");
5148        } else {
5149            $(this).closest(".tr_einzelverkauf").find(".ttCell3 input").attr("readonly", true);
5150        }
5151    });
5152
5153    var vTarifID = parseInt(getRadioBoxValue("tarif_id"));
5154    if (vTarifID == 0) {
5155        $("input[name='tarif_id']").first().prop("checked", true);
5156    }
5157
5158    $("#anzeige_artikel, #anzeige_artikel_vormerkung").find("td.ttCell2 select").each(function () {
5159
5160        if ($(this).is(".choseninit") || $("#HTTP_USER_AGENT").val() == "iOSKassa" || $("#HTTP_USER_AGENT").val() == "TicketApp") {
5161
5162        } else {
5163            var vVal = parseInt($(this).val());
5164            var vSelect = $(this);
5165            $(vSelect).find("option[value=0]").remove();
5166
5167            var vTD = $(this).closest("div.column");
5168            $(vTD).html("");
5169            $(vTD).append(vSelect);
5170
5171            $(vSelect).wrap("<div/>");
5172            if (isNaN(vVal) == false && vVal > 0) {
5173                $(vSelect).val(vVal);
5174            }
5175
5176            $(vSelect).addClass("choseninit");
5177            $(vSelect).chosen({no_results_text: window.dialog["ui_f190853c24e3"], 
5178                allow_single_deselect: true,
5179                placeholder_text_single: dialog['bitte_auswaehlen'],
5180                width: "100%",
5181                search_contains: true
5182            });
5183
5184            $(vSelect).on('chosen:showing_dropdown', function (evt, params) {
5185                //alert(evt);
5186                $(vTD).find(".chosen-search-input").val("");
5187                $(vTD).find(".chosen-search-input").trigger("keyup");
5188            });
5189
5190
5191            $(vSelect).trigger('chosen:updated');
5192        }
5193
5194    });
5195
5196    if ($("#sonderaktion_id").length > 0) {
5197        var vTarifID = getRadioBoxValue("tarif_id");
5198        var vAktionID = $("#sonderaktion_id").val();
5199
5200
5201        //Sonderaktionen die an Tarife gebunden sind, ausblenden
5202        $("#sonderaktion_id").find("option[tarif_id]").each(function (index) {
5203            console.log(vTarifID,this);
5204
5205            //Tarif - ID in $(this).attr("tarif_id") ist ein csv, getrennt mit Komma, in array überführen
5206            var tarif_ids = $(this).attr("tarif_id").toString().split(",");
5207            var tarif_match = false;
5208            for(var i=0;i<tarif_ids.length;i++){
5209                if(tarif_ids[i]==vTarifID){
5210                    tarif_match = true;
5211                    break;
5212                }
5213            }
5214
5215            if (!tarif_match) {
5216                $(this).addClass("hide");
5217                if (vAktionID == $(this).attr("value")) {
5218                    $("#sonderaktion_id").val(0);
5219                }
5220            } else {
5221                $(this).removeClass("hide");
5222            }
5223        });
5224
5225        if (parseInt(vAktionID) > 0 && $("#sonderaktion_id option:selected").attr("rabatt_code") == "true") {
5226            $("#tr_sonderaktion_rabatt_code").removeClass("hide");
5227        } else {
5228            $("#tr_sonderaktion_rabatt_code").addClass("hide");
5229            $("#rabatt_code").val("");
5230        }
5231    }
5232
5233    if ($("#target_iframe").length == 0) {
5234        $("div#reservierung_div").prepend('<iframe src="" id="target_iframe" name="target_iframe" style="display:none;"></iframe>');
5235    }
5236
5237    //Sitzplan Länge
5238    $("input[name='hinfahrt_sitzplan_kategorie_id'],input[name='rueckfahrt_sitzplan_kategorie_id']").remove();
5239    if ($(".tr_sitzplan").length > 0) {
5240        $("#form1").append("<input type='hidden' name='hinfahrt_sitzplan_kategorie_id' value='" + $(".tr_sitzplan").first().attr("sitzplatz_kategorie_id") + "'>");
5241        if ($(".tr_sitzplan").length > 1) {
5242            $("#form1").append("<input type='hidden' name='rueckfahrt_sitzplan_kategorie_id' value='" + $(".tr_sitzplan").last().attr("sitzplatz_kategorie_id") + "'>");
5243        }
5244    }
5245
5246    var data= $("#form1").serialize();
5247    if($(".tableTicketLinie.virtuell").length>0){
5248        var ptMax = {};
5249        $.each($("div.anzahl_personen_preistyp_container select[max_value]"),function(){
5250            ptMax[$(this).attr("preistyp_id")]=$(this).attr("max_value");
5251        });
5252        data+="&preistypen_max_values="+encodeURIComponent(JSON.stringify(ptMax));
5253    }
5254
5255    calculateXHR = $.ajax({
5256        type: "POST",
5257        url: $("#form1").attr("action"),
5258        data: data,
5259        success: function (data) {
5260
5261            if($("#login").val() == "true"){
5262                $.unblockUI();
5263            }
5264
5265            try {
5266                eval(data);
5267            } catch (e) {
5268                console.log(e);
5269            }
5270
5271            vActiveCalc = false;
5272
5273            getAnzahlPreistypAuswahl(false);
5274
5275            setFahrtInfo();
5276
5277            //Gesamtbetrag bei Teilzahlung in erstes Feld eingeben
5278            if ($("#zahlart1_betrag").length > 0 && $("#zahlart1_betrag").val() == "") {
5279                $("#zahlart1_betrag").val(C2dbl($(".OnlinebuchungTabelleGesamt #tb_gesamtbetrag").val()));
5280            }
5281
5282            $.unblockUI();
5283            var root = $("#reservierung_div_comp[data-booking-a11y='true']");
5284            if (root.find("#seite2").is(":visible") && !root.data("a11yTicketLoading") && !root.data("a11yFocusStep")) {
5285                var price = root.find(".OnlinebuchungTabelleGesamt input[type='text']").first().val();
5286                if (price !== undefined) {
5287                    announceOnlinebuchungStatus($.trim(root.find("#booking_a11y_total").text()) + ": " + price + " " + $.trim(root.find("#waehrung_id option:selected").text()));
5288                }
5289            }
5290            focusOnlinebuchungStep();
5291        }
5292    });
5293
5294    //Gutscheincode
5295    if ($("#login").val() != "false") {
5296        setTimeout(function () {
5297            checkGutscheincode();
5298        }, 800);
5299    }
5300}
5301
5302function abortCalculate() {
5303
5304    if (calculateXHR) {
5305
5306        calculateXHR.abort();
5307
5308        calculateXHR = null;
5309
5310    }
5311
5312    vActiveCalc = false;
5313
5314    $.unblockUI();
5315
5316    console.log("Calculate abgebrochen");
5317
5318}
5319
5320function calculateOnlineEinzelverkauf() {
5321    $("div.einzelverkauf_unten").addClass("hide");
5322    var vGesamtbetrag = 0;
5323    var vWaehrung = $(".artikel_auswahl").attr("waehrung");
5324    var vAusgabeGesamt = "<ul>";
5325    var vAnzahlGesamt=0;
5326    $("div#online_einzelverkauf_artikelauswahl select.einzelverkauf_artikelanzahl_auswahl, div#online_einzelverkauf_artikelauswahl input.einzelverkauf_artikelanzahl:not(.gutschein):not(.guthaben)").each(function (key, vObj) {
5327
5328        //Artikel-ID
5329        var vArtikelID = $(vObj).attr("artikel_id");
5330
5331        //Anzahl
5332        var vAnzahl = $(vObj).val();
5333        if (isNaN(vAnzahl)) {
5334            vAnzahl = 0;
5335        }
5336        vAnzahl = parseInt(vAnzahl);
5337        vAnzahlGesamt+=vAnzahl;
5338        var istGutschein = $(vObj).hasClass("gutschein") || $(vObj).attr("ist_gutsc
5338hein")=="1";
5339        if (vAnzahl > 0 && istGutschein) {
5340            $("div.einzelverkauf_unten").removeClass("hide");
5341        }
5342
5343        //Betrag
5344        var vObjBetrag = $(".artikel_betrag[artikel_id='" + vArtikelID + "']");
5345        if (vObjBetrag.is('input') || vObjBetrag.is('select')) {
5346            var vBetrag = $(vObjBetrag).val();
5347            var vBetragInd = parseFloat($(vObjBetrag).closest('.column').find(".betrag_individuell").val());
5348            if(vBetrag==0 && vBetragInd>0){
5349                vBetrag  = vBetragInd;
5350            }
5351        } else {
5352            var vBetrag = $(vObjBetrag).attr("betrag");
5353        }
5354        //Betrag prüfen und korrigieren
5355        if (isNaN(C2dbl(vBetrag))) {
5356            vBetrag = 0;
5357        } else {
5358            vBetrag = parseFloat(C2dbl(vBetrag));
5359        }
5360
5361        if (vObjBetrag.is('input')) {
5362            $(vObjBetrag).val(vBetrag);
5363        } else {
5364            $(vObjBetrag).attr("betrag", vBetrag);
5365        }
5366
5367        //Gesamtbetrag
5368        vGesamtbetrag += (vBetrag * vAnzahl);
5369
5370        //Übersicht
5371        if (vAnzahl > 0) {
5372            vAusgabeGesamt += "<li>" + vAnzahl + "x " + $(".artikel_bezeichnung[artikel_id='" + vArtikelID + "']").text() + " " + dbl2C(vBetrag) + vWaehrung + "</li>";
5373        }
5374    });
5375    vAusgabeGesamt += "</ul>";
5376
5377    if (vGesamtbetrag > 0) {
5378        $("#onlineverkauf_gesamt").removeClass("hide");
5379
5380        $("div.onlineverkauf_uebersicht").html(vAusgabeGesamt);
5381        $(".button.warenkorb").val(dbl2C(vGesamtbetrag) + " - " + $(".button.warenkorb").first().attr("dialog"));
5382        $(".button.warenkorb").removeClass("hide");
5383    } else {
5384        $("#onlineverkauf_gesamt").addClass("hide");
5385        $(".onlineverkauf_uebersicht").html(dialog['hinzufuegen_artikel']);
5386        $(".button.warenkorb").addClass("hide");
5387    }
5388
5389    $(".online_einzelverkauf_gesamtbetrag").text(dialog['in_warenkorb']+" "+dbl2C(vGesamtbetrag) + vWaehrung);
5390
5391    if(vAnzahlGesamt>0){
5392        $(".online_einzelverkauf_gesamtbetrag").removeAttr("disabled");
5393    }
5394    else{
5395        $(".online_einzelverkauf_gesamtbetrag").attr("disabled",true);
5396    }
5397
5398    setFahrtInfo();
5399
5400}
5401
5402function OnlinebuchungLoadLinieSuche(use_linie_id) {
5403    if (use_linie_id === undefined) {
5404        use_linie_id = $(".linie_auswahl #linie_id").val();
5405    }
5406
5407    if (use_linie_id == undefined || use_linie_id == "") {
5408        return;
5409    }
5410
5411
5412    if ($("#login").val() == "false") {
5413        $("#seite1").addClass("hide");
5414    }
5415
5416    var useHafenID = "";
5417    if ($("#hafen_id_set").val() != "") {
5418        useHafenID = $("#hafen_id_set").val();
5419    }
5420    setBlockUI();
5421    $.post("ajax/onlinereservierung.php",
5422        {
5423            aktion: "fahrt_von_linie_finden",
5424            hafen_id: useHafenID,
5425            linie_id: use_linie_id,
5426            matchcode: $("#matchcode").val(),
5427            vergangenheit: $("#form\\[nur_hinfahrt\\]").val()
5428        },
5429        function (data) {
5430            $.unblockUI();
5431
5432            if ($("#login").val() == "false") {
5433                $("#seite1").removeClass("hide");
5434                $("#seite1").css("display","");
5435            }
5436
5437            if (parseInt(data.anzahl_gesamt) > 0) {
5438                setCheckBoxValue(false, 'form[nur_hinfahrt]');
5439
5440                var div = $("<div/>");
5441                $(div).addClass("suchauswahl_buchungsmaske");
5442                var vLinie = "";
5443
5444                var days = [];
5445                var hafen = data["hafen"];
5446                var hafen_id = data["hafen_id"];
5447                $.each(data, function (index, row) {
5448                    if (isNaN(index) == false) {
5449                        days.push($.datepicker.formatDate('yy-mm-dd', accountDate(row["abfahrt_datum_format_en"])));
5450                    }
5451                });
5452
5453                //Anzahl der Monate darstellen
5454                var months = 1;
5455                if (Foundation.MediaQuery.atLeast('large')) {
5456                    months = 2;
5457                } else if (Foundation.MediaQuery.atLeast('medium')) {
5458                    months = 2;
5459                }
5460
5461                if (vProgrammModus != "ticket") {
5462                    $(div).append("<div class='callout secondary'><p>" + dialog['datum_waehlen_liniensuche'] + "</p></div>");
5463                }
5464
5465                //Ausgabe mit Datumsauswahl
5466                if (Boolean(data.kalender) == true && $(".fahrtgefunden").length == 0) {
5467                    //Keine Rückinformationen - Abbruch
5468                    if (data === undefined || data[0] === undefined || data[0]["datum_aktuell_format"] === undefined) {
5469                        return;
5470                    }
5471
5472                    var datepicker = $("<div class='datepickerauswahl'/>");
5473                    var minDate = data[0]["datum_aktuell_format"];
5474
5475                    if (data["linie"] !== undefined) {
5476                        vLinie = data["linie"];
5477                    }
5478
5479                    $(datepicker).datepicker({
5480                        minDate: accountDate(minDate),
5481                        maxDate: accountDate(data["datum_max"]),
5482                        numberOfMonths: months,
5483                        beforeShowDay: function (day) {
5484
5485                            var vDay = $.datepicker.formatDate('yy-mm-dd', day);
5486
5487                            if ($.inArray(vDay, days) == -1) {
5488                                return [false];
5489                            } else {
5490                                return [true];
5491                            }
5492                        },
5493                        onSelect: function (day) {
5494
5495                            //Hafen
5496
5497                            if ($("#von_hafen").attr("type") == "text") {
5498                                $("#von_hafen").val(hafen);
5499                            } else if (parseInt(useHafenID) > 0) {
5500                                $("#hafen_id").val(useHafenID);
5501                            } else {
5502                                if (parseInt(data["anzahl_stationen"]) > 3 && parseInt($("#hafen_id").val()) == 0) {
5503                                    $("#hafen_id").val(0);
5504                                } else if (parseInt(hafen_id) > 0) {
5505
5506                                    //Neuen EIntrag in der Liste gibt es nicht
5507                                    if($("#hafen_id option[value='"+hafen_id+"']").length==0){
5508                                        $("#hafen_id").append("<option value='"+hafen_id+"'>"+hafen_id+"</option>");
5509                                    }
5510                                    if($("#destination_hafen_id option[value='"+hafen_id+"']").length==0){
5511                                        $("#destination_hafen_id").append("<option value='"+hafen_id+"'>"+hafen_id+"</option>");
5512                                    }
5513                                    $("#destination_hafen_id").val(0);
5514                                    $("#hafen_id").val(hafen_id);
5515                                }
5516                            }
5517
5518                            //Linie-ID
5519                            if ($('.linie_auswahl #linie_id').length > 0) {
5520                                $('.linie_auswahl #linie_id').val(use_linie_id).trigger('chosen:updated');
5521                            }
5522                            $('#linie_typ_id').val(0);
5523
5524                            //Datum
5525                            var dateObj = $(datepicker).datepicker( "getDate" );
5526                            var vDay = $.datepicker.formatDate('dd.mm.yy', dateObj);
5527                            $('#cal_hinfahrt_datum').val(vDay);
5528
5529                            HTML_Calendar_Change($('#cal_hinfahrt_datum')[0]);
5530                            setBisDatum("hinfahrt_datum", "rueckfahrt_datum");
5531
5532                            if ($("#login").val() != "true") {
5533                                $("#hide_tourfinder").val("true");
5534                                Seite1();
5535                            }
5536
5537                            //Fahrt suchen
5538                            setBlockUI();
5539                            getFahrt(10);
5540
5541                            $(div).dialog("close");
5542
5543                        }
5544                    });
5545
5546                    $(div).append(datepicker);
5547
5548                    //Datepicker zentrieren
5549                    $(div).css("text-align", "center");
5550                    $(div).find(".ui-datepicker").css("display", "inline-block").css("margin", "0 auto");
5551                }
5552                //Ausgabe in Liste
5553                else {
5554                    $.each(data, function (index, row) {
5555                        if (isNaN(index) == false) {
5556                            var string = row["abfahrt_wochentag"] + ", " + row["datum_aktuell_format"] + " " + row["abfahrt_uhrzeit"];
5557
5558                            //Anderes Ziel
5559                            if (row["stationen"] != row["hafen"]) {
5560                                string += " - " + row["hafen"];
5561                                string += "️";
5562                                string += " " + row["ankunft_uhrzeit"];
5563                                string += " " + row["stationen"];
5564                            } else {
5565                                string += "-" + row["ankunft_uhrzeit"];
5566                                string += " &bullet; " + row["hafen"];
5567                            }
5568                            //string+=" &bullet; " + row["linie_bezeichnung_de_kurz"];
5569                            if($("#bodi").attr("lang")=="en" && row["bezeichnung_en"]!=""){
5570                                vLinie = row["bezeichnung_en"];
5571                            }
5572                            else{
5573                                vLinie = row["linie_bezeichnung_de_kurz"];
5574                            }
5575
5576                            if (row["schiff_anzeige_buchungsmaske"] == "1") {
5577                                string += " &bullet; " + row["schiff"];
5578                            }
5579
5580                            var vAttr = "";
5581                            if (parseInt(row["frei"]) > 10) {
5582                                var vKlasse = "success";
5583                            } else if (parseInt(row["frei"]) > 0) {
5584                                var vKlasse = "warning";
5585                            } else {
5586                                var vKlasse = "alert";
5587                            }
5588
5589                            var button = $("<button class='button " + vKlasse + " expanded large' "+vAttr+"/>");
5590                            $(button).html(string);
5591                            $(button).on("click", function () {
5592
5593                                $(div).dialog("close");
5594
5595                                setTimeout(function () {
5596
5597                                    //Teileinlösung- Dialog
5598                                    if ($(".fahrtgefunden").length > 0) {
5599                                        $(".fahrtgefunden").removeClass("hide");
5600                                        TicketTeilentwertung(row);
5601                                    } else {
5602
5603                                        //Hafen
5604                                        if ($("#von_hafen").attr("type") == "text") {
5605                                            $("#von_hafen").val(row["hafen"]);
5606
5607                                        }
5608                                        else {
5609                                            //Neuen EIntrag in der Liste gibt es nicht
5610                                            if($("#hafen_id option[value='"+row["hafen_id"]+"']").length==0){
5611                                                $("#hafen_id").append("<option value='"+row["hafen_id"]+"'>"+row["hafen_id"]+"</option>");
5612                                            }
5613                                            if($("#destination_hafen_id option[value='"+row["hafen_id"]+"']").length==0){
5614                                                $("#destination_hafen_id").append("<option value='"+row["hafen_id"]+"'>"+row["hafen_id"]+"</option>");
5615                                            }
5616                                            $("#destination_hafen_id").val(0);
5617                                            $("#hafen_id").val(row["hafen_id"]);
5618                                        }
5619
5620                                        //Linie-ID
5621                                        if ($('.linie_auswahl #linie_id').length > 0) {
5622                                            $('.linie_auswahl #linie_id').val(row["linie_id"]).trigger('chosen:updated');
5623                                        }
5624                                        $('#linie_typ_id').val(0);
5625
5626                                        //Datum von
5627                                        $('#cal_hinfahrt_datum').val(row["datum_aktuell_format"]);
5628                                        HTML_Calendar_Change($('#cal_hinfahrt_datum')[0]);
5629                                        setBisDatum("hinfahrt_datum", "rueckfahrt_datum");
5630
5631                                        //Fahrt suchen
5632                                        getFahrt(11);
5633                                    }
5634
5635
5636                                }, 100);
5637                            });
5638                            $(div).append(button);
5639                        }
5640                    });
5641
5642                    if (data.anzahl_gesamt >= 100) {
5643                        $(div).append("<div class='Warnung'><br>" + dialog['anzeige_eingeschraenkt_ds_100'] + "</div>");
5644                    }
5645
5646                    $(div).append("<div class='row column'></div>");
5647                }
5648
5649                //Wenn es nur eine Station gibt, bitte auswählen entfernen
5650                if ($("#hafen_id option").length == 2 && $("#hafen_id option[value=0]").length == 1) {
5651                    $("#hafen_id option[value=0]").remove();
5652                }
5653
5654                $(div).append("<div class='row column'></div>");
5655
5656                var button = $("<button class='button alert'>" + ($("#login").val() == "false" && use_linie_id != -1 ? "← " + dialog['zurueck'] : dialog['abbrechen']) + "</button>");
5657                $(button).on("click", function () {
5658                    if ($("#login").val() == "false" && $("#referer").val() != "") {
5659                        setBlockUI();
5660                        window.history.back();
5661                        //window.location.href=$("#referer").val();
5662                    } else {
5663                        $(div).dialog("close");
5664                    }
5665                });
5666                $(button).css("float", "left");
5667                $(div).append("<hr>");
5668                $(div).append(button);
5669
5670                if (vLinie != "") {
5671                    $(div).prepend("<h2>"+vLinie+"</h2>");
5672                }
5673                var vTitle = dialog['dialog_title_fahrtauswahl'];
5674
5675                $('html, body').animate({
5676                    scrollTop: $("body").offset().top
5677                }, 200);
5678
5679                //Ausgabe in Dialog anzeigen
5680                $(div).dialog({
5681                    height: 'auto', width: 'auto',
5682                    maxHeight: $(window).height() * 0.9,
5683                    autoResize: true,
5684                    title: vTitle,
5685                    position: {
5686                        my: "center",
5687                        at: "center",
5688                        of: window
5689                    },
5690                    modal: true,
5691                    open: function (event, ui) {
5692                        $("body").css({overflow: 'hidden'});
5693                        if ($("#login").val() == "false") {
5694                            $(".ui-dialog-titlebar-close").addClass("hide");
5695                        }
5696
5697                        $('html, body').animate({
5698                            scrollTop: $("body").offset().top
5699                        }, 200);
5700
5701                    },
5702                    close: function (event, ui) {
5703                        $("body").css({overflow: 'inherit'});
5704                        $(".linie_auswahl #linie_id").val("0").trigger('chosen:updated');
5705                        $(this).remove();
5706                    }
5707                });
5708            } else {
5709                showDialog(dialog['not_found2'],dialog['keine_fahrt']);
5710            }
5711        });
5712}
5713
5714function TicketTeilentwertung(row) {
5715    //console.log(row);
5716    $("#buchung_data").val(JSON.stringify(row));
5717
5718    $.post("ajax/onlinereservierung.php",
5719        {
5720            aktion: "teilentwertung",
5721            data: row,
5722            preistyp_id: $("#preistyp_id").val(),
5723            tarif_id: $("#tarif_id").val()
5724        },
5725        function (data) {
5726            $("#new_einzelbetrag").text(dbl2C(data.betrag));
5727            var vDiff = data.betrag - $("#einzelbetrag").val();
5728            $("#new_differenz_feld").val(vDiff);
5729            $("#new_differenz").text(dbl2C(vDiff));
5730        });
5731}
5732
5733function TicketTeilentwertungExec() {
5734    setBlockUI();
5735    $.post("ajax/onlinereservierung.php",
5736        {
5737            aktion: "teilentwertung_exec",
5738            new_fahrt: JSON.parse($("#buchung_data").val()),
5739            preistyp_id: $("#preistyp_id").val(),
5740            code: $("#code").val(),
5741            kunde_id: $("#kunde_id").val(),
5742            tarif_id: $("#tarif_id").val(),
5743            differenz: $("#new_differenz_feld").val(),
5744            mwst_satz: $("#mwst_satz").val(),
5745            old_reservierung: JSON.parse(decodeURIComponent($("#old_reservierung").val()))
5746        },
5747        function (data) {
5748
5749            //Einzelverkaufs-Vorgang
5750            var vAusgabe = "<div class='OK'>" + window.dialog["ui_b5e73fadb843"] + "</div>";
5751            if (parseInt(data.ev_reservierung_id) > 0) {
5752                vAusgabe += "<br><br><a target='_blank' href='run_rechnung.php?aktion=finden&suche_vorgang_nr=" + data.ev_vorgang_nr + "'>" + window.dialog["ui_ee4c34ccca32"].replace("%s", function () { return data.ev_vorgang_nr; }) + "</a>";
5753            }
5754
5755            if (data.gutschein_code != "") {
5756                vAusgabe += "<br><br><a target='_blank' href='gutschein.php?aktion=finden&gutschein_code=" + data.gutschein_code + "'>" + window.dialog["ui_68684402213b"] + "</a>";
5757            }
5758
5759            if (parseInt(data.new_vorgang_nr) > 0) {
5760                vAusgabe += "<br><br><a target='_blank' href='run_reservierungslistev3.php?aktion=finden&suche_vorgang_nr=" + data.new_vorgang_nr + "'>" + window.dialog["ui_0c53aea543e1"].replace("%s", function () { return data.new_vorgang_nr; }) + "</a>";
5761            }
5762
5763            $("#booking_container").html(vAusgabe);
5764
5765            $.unblockUI();
5766        });
5767}
5768
5769function QuittungDrucken(reservierung_id, drucker_id, quittung_formular_id) {
5770    setBlockUI();
5771    $.get("ajax/onlinereservierung.php?aktion=QuittungDrucken&reservierung_id=" + reservierung_id + "&drucker_id=" + drucker_id + "&quittung_formular_id=" + quittung_formular_id,
5772        function (data) {
5773            $.unblockUI();
5774            if (data.typ == "javascript") {
5775                eval(data.ausgabe);
5776            } else {
5777                if ($("#div_content").length > 0) {
5778                    var obj = $("#div_content");
5779                } else {
5780                    var obj = $("body");
5781                }
5782                $(obj).append($("<div/>").html(data.ausgabe));
5783            }
5784        }
5785    );
5786}
5787
5788function showKapazitaetV2(obj,callback=null) {
5789
5790    if( $(obj).length==0){
5791        console.log("Objekt für Kapazitätsprüfung nicht gefunden. Abbruch.");
5792        return;
5793    }
5794
5795    var zielhafen_id = $(obj).attr("zielhafen_id");
5796    var hafen_id = $(obj).attr("hafen_id");
5797
5798    //Prüfung ob Kapazität bereits übergeben wurde
5799    if($("li[linie_hafen_fahrplan_id][zielhafen_id='" + zielhafen_id + "'][hafen_id='" + hafen_id + "'][kapazitaet_beruecksichtigt='true']").length>0){
5800        return;
5801    }
5802
5803    //Alle Objekte mit gleicher Zielhafen und Hafen ID laden
5804    var linie_hafen_fahrplan_id = [];
5805
5806    if($("#bodi").attr("login")=="true"){
5807        var selector = "li[linie_hafen_fahrplan_id][zielhafen_id][hafen_id][kombiticket='0']:not(.hide)[keine_kapazitaet=0]";
5808    }
5809    else{
5810        var selector = "li[linie_hafen_fahrplan_id][zielhafen_id][hafen_id]:not(.hide)[keine_kapazitaet=0]";
5811    }
5812
5813    $(selector).each(function(){
5814        linie_hafen_fahrplan_id.push($(this).attr("linie_hafen_fahrplan_id"));
5815    });
5816
5817    //Keine Ergebnisse gefunden
5818    if($(linie_hafen_fahrplan_id).length==0){
5819        return;
5820    }
5821
5822    //Alle unterschiedlichen Zielhäfen des Selectors in array
5823    var zielhafen_id =  $(selector).map(function(){ return $(this).attr("zielhafen_id"); }).get();
5824    zielhafen_id = $.grep(zielhafen_id, function(v, k){
5825        return $.inArray(v , zielhafen_id) === k;
5826    });
5827
5828    //Alle unterschiedlichen Zielhäfen des Selectors in array
5829    var hafen_id =  $(selector).map(function(){ return $(this).attr("hafen_id"); }).get();
5830    hafen_id = $.grep(hafen_id, function(v, k){
5831        return $.inArray(v , hafen_id) === k;
5832    });
5833
5834    var parameter = {
5835        aktion: "kapazitaetspruefungV2",
5836        datum: $(obj).attr("datum"),
5837        zielhafen_id: zielhafen_id,
5838        hafen_id: hafen_id,
5839        linie_hafen_fahrplan_id: linie_hafen_fahrplan_id,
5840        reservierung_id: 0//$("#reservierung_div_comp").attr("reservierung_id")
5841    };
5842
5843    $.post("ajax/onlinereservierung.php",parameter)
5844    .done(function( data ) {
5845
5846        $.each(data,function(){
5847            var lhf_id = $(this).attr("lhf_id");
5848            var hafen_id = $(this).attr("hafen_start_id");
5849            var zielstation_id = $(this).attr("zielstation_id");
5850            var lh_id_stop = $(this).attr("lh_id_stop");
5851            var kapazitaet = $(this).attr("kapazitaet");
5852            var frei = parseInt($(this).attr("frei"));
5853            var fahrt = parseInt($(this).attr("fahrt"));
5854            var datum = parseInt($(this).attr("datum"));
5855
5856           var selector = "li[linie_hafen_fahrplan_id='"+lhf_id+"'][hafen_id='"+hafen_id+"'][zielhafen_id='" + zielstation_id + "'][fahrt='"+fahrt+"'][linie_hafen_id_stop='" + lh_id_stop + "'][datum='" + datum + "']";
5857           var li = $(selector).not(".durchgestrichen");
5858
5859           //Bei Kombitickets mit Kapazität nachladen Button
5860            if($(li).find('.button.kapazitaet').length>0){
5861                return;
5862            }
5863
5864           if($(li).length==0){
5865               //console.log("Selector not found: ",selector);
5866               return;
5867           }
5868
5869           $(li).attr("cap_calculated","true");
5870           $(li).attr("fr",frei);
5871           var kap = $(li).find(".suchergebnis_kapazitaet, .container_kapazitaet").first();
5872
5873            //Ansicht Online mit Kapazität
5874            if($("#login").val() == "false" && kapazitaet != null){
5875                $(kap).html(frei+"/"+kapazitaet);
5876            }
5877            //Ansicht Bckend mit Kapazität
5878            else if(kapazitaet != null && $("#login").val() == "true" && $(kap).find("#se_kap").length>0){
5879
5880                //Button zum Nachladen der Kapazität bei Mehrklassen-Konfiguration
5881                if($(li).find(".button.kapazitaetloading").length>0) {
5882                    $(li).find(".button.kapazitaetloading").val(frei+"/"+kapazitaet).removeClass("hide");
5883                }
5884                else{
5885                    $(kap).find("#se_kap").html(frei+"/"+kapazitaet);
5886                }
5887
5888                $(li).attr("fr",frei);
5889                $(li).attr("bel",kapazitaet - frei);
5890
5891                $(li).removeClass("free").removeClass("kapazitaet_notok");
5892                if(frei==0){
5893                    $(li).addClass("kapazitaet_notok");
5894                }
5895                else{
5896                    $(li).addClass("free");
5897                }
5898            }
5899            //Online
5900            else if($("#login").val() != "true" || $("#warpper").attr("recht_id")=="5") {
5901
5902                if (frei > 10) {
5903                    var icon = "<i class='fa-solid fa-check-circle kapazitaet capacityicon'></i>";
5904                    $(li).attr("soldout","false");
5905                }
5906                else if (frei > 0){
5907                    var icon = "<i class='fa-solid fa-exclamation-circle kapazitaet capacityicon'></i>";
5908                    $(li).attr("soldout","false");
5909                }
5910                else if($(li).attr("kombiticket")!="1"){
5911                    var icon = "<i class='fa-solid fa-circle-exclamation kapazitaet capacityicon'></i>";
5912                    $(li).attr("soldout","true");
5913                }
5914                $(kap).html(icon);
5915            }
5916
5917            if (typeof callback === "function") {
5918                callback(frei, obj);
5919            }
5920        });
5921
5922        //Kombiticket - Online
5923        if($("#login").val() != "true" || $("#warpper").attr("recht_id") == "5"){
5924            var divF = $("li[kombiticket='1'] div.container_kapazitaet").not(".dirty");
5925            $.each($(divF),function(){
5926                var icon = "<i class='fa-solid fa-check-double kapazitaet capacityicon'></i>";
5927                $(this).html(icon);
5928                $(this).closest("li").attr("soldout", "false").addClass("dirty");
5929            });
5930        }
5931
5932        if($("#koenigssee").length>0 && $("#login").val() == "true" && $("#reservierung_div_comp").attr("reservierung_id")=="0"){
5933
5934            var anzahlAusgebucht = $("li[fr='0']:visible").length;
5935            var anzahlFrei = $("li[fr]").filter(function () {
5936                return parseInt($(this).attr("fr"), 10) > 0;
5937            }).length;
5938
5939            if(anzahlFrei>0){
5940                suchergebnisEinschraenken($(".td_hinfahrt_anzeige ul.suchergebnis"));
5941                var el = $(".td_hinfahrt_anzeige ul.suchergebnis li.free:visible").first();
5942                if (el.length > 0 && !el.hasClass("justClicked") && !el.hasClass("active")) {
5943                    el.trigger("click");
5944                }
5945            }
5946
5947        }
5948
5949    });
5950}
5951
5952function showKapazitaet(button) {
5953    var obj = $(button).closest("li");
5954
5955    if($(obj).length==0){
5956        console.log("Objekt für Kapazitätsprüfung nicht gefunden");
5957        return;
5958    }
5959
5960    setBlockUI();
5961    $.get("ajax/onlinereservierung.php",
5962        {
5963            aktion: "kapazitaetspruefung",
5964            datum: $(obj).attr("datum"),
5965            zielhafen_id: $(obj).attr("zielhafen_id"),
5966            hafen_id: $(obj).attr("hafen_id"),
5967            linie_hafen_fahrplan_id: $(obj).attr("linie_hafen_fahrplan_id"),
5968            reservierung_id: $("#reservierung_div_comp").attr("reservierung_id")
5969        }
5970    )
5971    .done(function (data) {
5972        var row = $(obj).find(".container_kapazitaet");
5973        $(row).html(data.ausgabe);
5974        $(obj).attr("fr",data.data.frei);
5975        $(obj).attr("bel",data.data.belegung);
5976        $.unblockUI();
5977    });
5978
5979}
5980
5981function checkOnlineGutscheincode(obj) {
5982    var objG = $(obj).closest(".artikel_auswahl").find(".gutscheincode_aufladen");
5983    var code = $(objG).val();
5984
5985    if (code == "") {
5986        alert(dialog['gutschein_code']);
5987        $(objG).effect("shake").focus();
5988        return false;
5989    }
5990
5991    //Online den Gutscheincode prüfen
5992    setBlockUI();
5993    var result = getValueSync("ajax/onlinereservierung.php?aktion=checkGutscheinCode&code=" + code);
5994    $.unblockUI();
5995    if (result == "false") {
5996        alert(dialog['gutschein_code_invalid']);
5997        $(objG).effect("shake").focus();
5998    }
5999    return result == "true";
6000}
6001
6002function checkOnlineEinzelverkaufZusatzArtikel(obj) {
6003    if($(obj).closest(".row").find(".gueltigkeitsdatum[required]").length>0 && $(obj).closest(".row").find(".gueltigkeitsdatum[required]").val()==""){
6004        alert(dialog['datum_waehlen_liniensuche']);
6005        $(obj).closest(".row").find(".gueltigkeitsdatum").effect("shake").focus();
6006        return false;
6007    }
6008    return true;
6009}
6010
6011
6012function addOnlineEinzelverkaufZusatzArtikel(obj) {
6013
6014    var artikel_id = $(obj).attr("zusatzartikel_id");
6015    if (parseInt(artikel_id) > 0 && $(obj).attr("zusatzartikel_anzahl") == "1") {
6016        $("select[artikel_id='" + artikel_id + "']").val($(obj).val());
6017    } else if (parseInt(artikel_id) > 0) {
6018        $("select[artikel_id='" + artikel_id + "']").val(1);
6019    }
6020
6021    //Gutscheincode - Feld Readonly
6022    if ($(obj).closest("div.row").find(".einzelverkauf_artikelanzahl").val() == "0") {
6023        $(obj).closest(".artikel_auswahl").find(".gutscheincode_aufladen").prop("readonly", true);
6024    } else {
6025        $(obj).closest(".artikel_auswahl").find(".gutscheincode_aufladen").prop("readonly", false);
6026    }
6027
6028}
6029
6030var gastrobestellung_warenkorb = {};
6031
6032function gastrobestellungAddItem(artikel_id, bezeichnung) {
6033    if (gastrobestellung_warenkorb[artikel_id] == undefined) {
6034        gastrobestellung_warenkorb[artikel_id] = {anzahl: 0, bezeichnung: bezeichnung};
6035    }
6036    gastrobestellung_warenkorb[artikel_id]["anzahl"]++;
6037    gastrobestellungUebersicht();
6038}
6039
6040
6041function gastrobestellungRemoveItem(artikel_id) {
6042    gastrobestellung_warenkorb[artikel_id]["anzahl"]--;
6043    gastrobestellungUebersicht();
6044}
6045
6046function gastrobestellungUebersicht(showCheckout) {
6047
6048    if(showCheckout == undefined){
6049        showCheckout = false;
6050    }
6051
6052    var gesamtbetrag = 0;
6053    var waehrung = $("#waehrung").val();
6054
6055    if (gastrobestellung_warenkorb.length == 0) {
6056        $(".warenkorbrechts div").html("");
6057    } else {
6058        var anzahlAktiv = 0;
6059        var ausgabe = "<ul class='warenkorbliste'>";
6060
6061        $.each(gastrobestellung_warenkorb, function (artikel_id, item) {
6062
6063            var obj = $(".gastrobox[artikeL_id='"+artikel_id+"']");
6064            var preis = parseFloat($(obj).attr("betrag"));
6065            var anzahl = parseInt(item["anzahl"]);
6066
6067            if (anzahl > 0) {
6068                ausgabe += "" +
6069                    "<li class='dialogshadow'>" +
6070                    "<div class='row'>" +
6071                    "<div class='small-8 column'>" +
6072                    "" + item["anzahl"] + "x " + item["bezeichnung"] + "" +
6073                    //"<input type='text' name='bemerkung' artikel_id='"+artikel_id+"' value='' placeholder='"+dialog['bemerkung']+"'/>" +
6074                    "</div>" +
6075                    "<div class='small-4 column buttonaddremove'>" +
6076                    "<i class=\"fa-solid fa-minus buttonitem\" onclick=\"gastrobestellungRemoveItem(" + artikel_id + ");\"></i>" +
6077                    "<i class=\"fa-solid fa-plus buttonitem\" onclick=\"gastrobestellungAddItem(" + artikel_id + ");\"></i>" +
6078                    "</div>" +
6079                    "</div>" +
6080                    "</li>";
6081                anzahlAktiv++;
6082
6083                gesamtbetrag+=anzahl*preis;
6084                $(obj).find(".buttonitem span").text(anzahl);
6085                $(obj).find(".buttonitem span").removeClass("hide");
6086                $(obj).find(".buttonitem i").addClass("hide");
6087            }
6088            else{
6089                $(obj).find(".buttonitem span").addClass("hide");
6090                $(obj).find(".buttonitem i").removeClass("hide");
6091            }
6092
6093        });
6094
6095        if (anzahlAktiv > 0) {
6096            $(".button_warenkorb").attr("disabled",false);
6097
6098            ausgabe += "</ul>";
6099            ausgabe += "<div class='text-right'>" +
6100                "<button onclick='gastrobestellungAusfuehren();' class='button warenkorbdialog button_warenkorb'>" +
6101                "<i class='fa-solid fa-basket-shopping'></i>" +
6102                ""+dialog['in_warenkorb']+"" +
6103                "<span class='gesamtbetrag_auswahl'></span>"+
6104                "</button></div>";
6105
6106            $("#warenkorb_zusammenfassung").html(ausgabe);
6107
6108            if(showCheckout){
6109                $("#warenkorb_zusammenfassung").removeClass("hide");
6110                var vWidth = window.innerWidth;
6111                if(vWidth>600){
6112                    vWidth = 600;
6113                }
6114                else if(vWidth<360){
6115                    vWidth = 360;
6116                }
6117
6118                $("#warenkorb_zusammenfassung").dialog({
6119                    title: dialog['artikel_pruefen'],
6120                    width: vWidth,
6121                    classes: {
6122                        "ui-dialog": "dialogshadow"
6123                    },
6124                    modal: true,
6125                    open: function (event, ui) {
6126                        // Position des Dialogs ermitteln
6127                        var dialogPosition = $(this).offset().top-110;
6128                        // Scrollen Sie zum Dialog
6129                        $('html, body').animate({
6130                            scrollTop: dialogPosition
6131                        }, 1000); // 1000 ms für die Animation
6132                    },
6133                    close: function (event, ui) {
6134                        $("#warenkorb_zusammenfassung").html("").addClass("hide");
6135                    }
6136                });
6137            }
6138
6139        }
6140
6141        //Gesamtbetrag anbringen
6142        $(".gesamtbetrag_auswahl").text(dbl2C(gesamtbetrag)+" "+waehrung);
6143    }
6144
6145    if(gesamtbetrag == 0){
6146        if($("#warenkorb_zusammenfassung.ui-dialog-content").length>0){
6147            $("#warenkorb_zusammenfassung").dialog("destroy");
6148            $("#warenkorb_zusammenfassung").html("").addClass("hide");
6149        }
6150        $(".button_warenkorb").attr("disabled",true);
6151    }
6152}
6153
6154function gastrobestellungAusfuehren() {
6155
6156    setBlockUI();
6157    $.post("ajax/onlinereservierung-gastro.php", {
6158        aktion: "addBestellung",
6159        tisch_id: $("#tisch_id").val(),
6160        verkaufsstelle_id: $("#verkaufsstelle_id").val(),
6161        data: gastrobestellung_warenkorb
6162    })
6163    .done(function (data) {
6164        //$.unblockUI();
6165        window.location.href='/basket';
6166    })
6167    .fail(function(error) {
6168        $.unblockUI();
6169        if(error.responseJSON && error.responseJSON.message){
6170            alert(error.responseJSON.message);
6171            return;
6172        }
6173        // Action 2: Aktion bei Misserfolg
6174        alert(window.dialog["ui_804165c5e6bf"]);
6175        console.error("Fehler: ", error);
6176        // Führen Sie hier Ihre Aktion bei einem Fehler aus
6177    });
6178
6179}
6180
6181function showPaxDataSaveMessage(obj)
6182{
6183    var message = (typeof dialog !== "undefined" && dialog["speichern_erfolgreich"]) ? dialog["speichern_erfolgreich"] : "";
6184    if(message === ""){
6185        return;
6186    }
6187
6188    var $obj = $(obj);
6189    var $message = $obj.closest("td,div,p,li").find(".paxdata-save-message").first();
6190    if($message.length === 0){
6191        $message = $("<div class='paxdata-save-message callout success'/>").css({
6192            "display": "none",
6193            "margin": "6px 0 0 0",
6194            "padding": "6px 8px",
6195            "font-size": "0.9em"
6196        });
6197        $obj.after($message);
6198    }
6199
6200    $message.stop(true, true)
6201        .html("<i class='fa-solid fa-circle-check'></i> " + message)
6202        .fadeIn(120)
6203        .delay(2600)
6204        .fadeOut(300);
6205}
6206
6207function ChangePaxData(obj,unique_id,buchungscode){
6208    if ($(obj).hasClass("online-geburtsdatum") && checkOnlineGeburtsdatum(obj, true) == false) {
6209        if (obj.reportValidity) {
6210            obj.reportValidity();
6211        }
6212        return;
6213    }
6214
6215    setBlockUI();
6216    $.post("ajax/onlinereservierung.php", {
6217        aktion: "changePaxData",
6218        unique_id: unique_id,
6219        buchungscode: buchungscode,
6220        wert: $(obj).val(),
6221        name: $(obj).attr("name")
6222    })
6223    .done(function (data) {
6224        $.unblockUI();
6225        showPaxDataSaveMessage(obj);
6226    })
6227    .fail(function(error) {
6228        $.unblockUI();
6229        alert(window.dialog["ui_804165c5e6bf"]);
6230    });
6231}
6232
6233function setNewsletterActive(checked){
6234    $.post("ajax/onlinereservierung.php", {
6235        aktion: "setNewsletterActive",
6236        active: checked ? 1 : 0
6237    })
6238    .done(function (data) {
6239
6240    });
6241}
6242
6243
6244function sendHeight() {
6245
6246    if($("#return_url").length>0 || $("#embed").length>0){
6247
6248        setTimeout(sendHeight, 1000);
6249
6250        var height = $("body").height();
6251
6252        if(heightWindow == height){
6253            return;
6254        }
6255
6256        if($("#referer").length>0 && $("#referer").val()!=""){
6257            var str = $("#referer").val();
6258        }
6259        else {
6260            var str = $("#return_url").val();
6261        }
6262
6263        var targetOrigin = new URL(str).origin;
6264        var element_id = $("#embed").length>0 ? $("#embed").val() : null;
6265
6266        heightWindow = height;
6267        window.parent.postMessage(
6268            {
6269                type: "resize",
6270                height: height,
6271                element_id: element_id
6272            },
6273            targetOrigin
6274        );
6275    }
6276}
6277
6278function showButtonSchnelleingabe(){
6279
6280    if($(".schnellauswahl").length==0){
6281        return;
6282    }
6283    $(".schnellauswahl[preistyp_id]").removeClass("hide");
6284    $("table.tableTicket tr[counter_invalid_1='none'][preistyp_id]").each(function(){
6285        var preistyp_id = $(this).attr("preistyp_id");
6286        $(".schnellauswahl[preistyp_id='"+preistyp_id+"']").addClass("hide");
6287    });
6288}
6289
6290async function qrCodeEingeben(obj) {
6291    var $input = $(obj).closest(".td_paxdata_code").find("input").first();
6292    if ($input.length === 0) {
6293        return;
6294    }
6295
6296    if (
6297        window.isSecureContext === false
6298        || !navigator.mediaDevices
6299        || !navigator.mediaDevices.getUserMedia
6300    ) {
6301        alert(dialog['qr_code_scanner_nicht_verfuegbar']);
6302        return;
6303    }
6304
6305    if (typeof jsQR !== "function") {
6306        alert(dialog['qr_code_scanner_fehler']);
6307        return;
6308    }
6309
6310    var stream = null;
6311    var scanInterval = null;
6312    var scannerClosed = false;
6313    var canvas = document.createElement("canvas");
6314    var canvasContext = canvas.getContext("2d", {willReadFrequently: true});
6315    var $dialog = $("<div class='qr_code_scanner_dialog'/>");
6316    var $video = $("<video autoplay playsinline/>").css({
6317        "display": "block",
6318        "width": "100%",
6319        "max-height": "70vh",
6320        "background": "#000"
6321    });
6322
6323    $dialog.append($video).dialog({
6324        title: dialog['qr_code_scannen'],
6325        modal: true,
6326        width: Math.min($(window).width() - 30, 500),
6327        position: {
6328            my: "center top",
6329            at: "center bottom+10",
6330            of: obj,
6331            collision: "flipfit"
6332        },
6333        open: function () {
6334            var dialogElement = this;
6335            window.setTimeout(function () {
6336                dialogElement.scrollIntoView({
6337                    behavior: "smooth",
6338                    block: "center"
6339                });
6340            }, 0);
6341        },
6342        close: function () {
6343            scannerClosed = true;
6344
6345            if (scanInterval !== null) {
6346                window.clearInterval(scanInterval);
6347            }
6348
6349            if (stream !== null) {
6350                stream.getTracks().forEach(function (track) {
6351                    track.stop();
6352                });
6353            }
6354
6355            $(this).remove();
6356        }
6357    });
6358
6359    try {
6360        stream = await navigator.mediaDevices.getUserMedia({
6361            video: {
6362                facingMode: {
6363                    ideal: "environment"
6364                }
6365            },
6366            audio: false
6367        });
6368
6369        if (scannerClosed) {
6370            stream.getTracks().forEach(function (track) {
6371                track.stop();
6372            });
6373            return;
6374        }
6375
6376        $video[0].srcObject = stream;
6377        await $video[0].play();
6378
6379        scanInterval = window.setInterval(function () {
6380            if (scannerClosed || $video[0].readyState < HTMLMediaElement.HAVE_ENOUGH_DATA) {
6381                return;
6382            }
6383
6384            if ($video[0].videoWidth === 0 || $video[0].videoHeight === 0) {
6385                return;
6386            }
6387
6388            if (canvas.width !== $video[0].videoWidth || canvas.height !== $video[0].videoHeight) {
6389                canvas.width = $video[0].videoWidth;
6390                canvas.height = $video[0].videoHeight;
6391            }
6392
6393            canvasContext.drawImage($video[0], 0, 0, canvas.width, canvas.height);
6394            var imageData = canvasContext.getImageData(0, 0, canvas.width, canvas.height);
6395            var code = jsQR(imageData.data, imageData.width, imageData.height, {inversionAttempts: "dontInvert"});
6396
6397            if (code !== null && code.data !== "") {
6398                $input.val(code.data).trigger("change").trigger("blur");
6399                $dialog.dialog("close");
6400            }
6401        }, 200);
6402    } catch (error) {
6403        $dialog.dialog("close");
6404        alert(error.name === "NotAllowedError" ? dialog['qr_code_kamera_zugriff_verweigert'] : dialog['qr_code_scanner_fehler']);
6405    }
6406}
6407
6408var pdfJsQrCodePromise = null;
6409
6410function pdfJsFuerQrCodeLaden() {
6411    if (pdfJsQrCodePromise === null) {
6412        var pdfJsBasisUrl = new URL("js/pdfjs/", document.baseURI);
6413        pdfJsQrCodePromise = import(new URL("pdf-5.7.284.mjs", pdfJsBasisUrl).href)
6414            .then(function (pdfjsLib) {
6415                pdfjsLib.GlobalWorkerOptions.workerSrc = new URL("pdf.worker-5.7.284.mjs", pdfJsBasisUrl).href;
6416                return pdfjsLib;
6417            })
6418            .catch(function (error) {
6419                pdfJsQrCodePromise = null;
6420                throw error;
6421            });
6422    }
6423
6424    return pdfJsQrCodePromise;
6425}
6426
6427function dateiAlsArrayBufferLesen(file) {
6428    return new Promise(function (resolve, reject) {
6429        var reader = new FileReader();
6430        reader.onload = function () {
6431            resolve(reader.result);
6432        };
6433        reader.onerror = function () {
6434            reject(reader.error);
6435        };
6436        reader.readAsArrayBuffer(file);
6437    });
6438}
6439
6440function qrCodeAusCanvasLesen(canvas) {
6441    var canvasContext = canvas.getContext("2d", {willReadFrequently: true});
6442    var imageData = canvasContext.getImageData(0, 0, canvas.width, canvas.height);
6443    var code = jsQR(imageData.data, imageData.width, imageData.height, {inversionAttempts: "attemptBoth"});
6444    return code !== null && code.data !== "" ? code.data : null;
6445}
6446
6447function qrCodeAusBilddateiLesen(file) {
6448    return new Promise(function (resolve, reject) {
6449        var imageUrl = URL.createObjectURL(file);
6450        var image = new Image();
6451
6452        image.onload = function () {
6453            try {
6454                var maxDimension = 2048;
6455                var scale = Math.min(1, maxDimension / Math.max(image.naturalWi
6455dth, image.naturalHeight));
6456                var canvas = document.createElement("canvas");
6457                canvas.width = Math.max(1, Math.round(image.naturalWidth * scale));
6458                canvas.height = Math.max(1, Math.round(image.naturalHeight * scale));
6459                canvas.getContext("2d").drawImage(image, 0, 0, canvas.width, canvas.height);
6460                resolve(qrCodeAusCanvasLesen(canvas));
6461            } catch (error) {
6462                reject(error);
6463            } finally {
6464                URL.revokeObjectURL(imageUrl);
6465            }
6466        };
6467
6468        image.onerror = function () {
6469            URL.revokeObjectURL(imageUrl);
6470            reject(new Error(window.dialog["ui_6f623377310d"]));
6471        };
6472
6473        image.src = imageUrl;
6474    });
6475}
6476
6477async function qrCodeAusPdfDateiLesen(file) {
6478    var pdfjsLib = await pdfJsFuerQrCodeLaden();
6479    var pdfJsBasisUrl = new URL("js/pdfjs/", document.baseURI);
6480    var dateiInhalt = await dateiAlsArrayBufferLesen(file);
6481    var loadingTask = pdfjsLib.getDocument({
6482        data: new Uint8Array(dateiInhalt),
6483        isEvalSupported: false,
6484        standardFontDataUrl: new URL("standard_fonts/", pdfJsBasisUrl).href,
6485        wasmUrl: new URL("wasm/", pdfJsBasisUrl).href
6486    });
6487    var pdfDocument = null;
6488
6489    try {
6490        pdfDocument = await loadingTask.promise;
6491
6492        for (var seite = 1; seite <= pdfDocument.numPages; seite++) {
6493            var pdfPage = await pdfDocument.getPage(seite);
6494            var basisViewport = pdfPage.getViewport({scale: 1});
6495            var renderScale = Math.max(0.1, Math.min(3, 2048 / Math.max(basisViewport.width, basisViewport.height)));
6496            var viewport = pdfPage.getViewport({scale: renderScale});
6497            var canvas = document.createElement("canvas");
6498            canvas.width = Math.max(1, Math.floor(viewport.width));
6499            canvas.height = Math.max(1, Math.floor(viewport.height));
6500
6501            var canvasContext = canvas.getContext("2d", {willReadFrequently: true});
6502            canvasContext.fillStyle = "#fff";
6503            canvasContext.fillRect(0, 0, canvas.width, canvas.height);
6504
6505            await pdfPage.render({
6506                canvasContext: canvasContext,
6507                viewport: viewport
6508            }).promise;
6509
6510            var qrCode = qrCodeAusCanvasLesen(canvas);
6511            pdfPage.cleanup();
6512            canvas.width = 0;
6513            canvas.height = 0;
6514
6515            if (qrCode !== null) {
6516                return qrCode;
6517            }
6518        }
6519
6520        return null;
6521    } finally {
6522        if (pdfDocument !== null) {
6523            await pdfDocument.destroy();
6524        } else if (typeof loadingTask.destroy === "function") {
6525            await loadingTask.destroy();
6526        }
6527    }
6528}
6529
6530function qrCodeAusBildEinlesen(obj) {
6531    var $input = $(obj).closest(".td_paxdata_code").find("input").first();
6532    if ($input.length === 0) {
6533        return;
6534    }
6535
6536    if (typeof jsQR !== "function") {
6537        alert(dialog['qr_code_datei_fehler']);
6538        return;
6539    }
6540
6541    var fileInput = document.createElement("input");
6542    fileInput.type = "file";
6543    fileInput.accept = "image/*,application/pdf,.pdf";
6544    fileInput.style.display = "none";
6545
6546    $(fileInput).on("change", async function () {
6547        var file = fileInput.files && fileInput.files[0];
6548        if (!file) {
6549            $(fileInput).remove();
6550            return;
6551        }
6552
6553        setBlockUI();
6554
6555        try {
6556            var istPdf = file.type === "application/pdf" || /\.pdf$/i.test(file.name);
6557            var qrCode = istPdf
6558                ? await qrCodeAusPdfDateiLesen(file)
6559                : await qrCodeAusBilddateiLesen(file);
6560
6561            if (qrCode !== null) {
6562                $input.val(qrCode).trigger("change").trigger("blur");
6563            } else {
6564                alert(dialog['qr_code_datei_kein_code']);
6565            }
6566        } catch (error) {
6567            alert(dialog['qr_code_datei_fehler']);
6568        } finally {
6569            $.unblockUI();
6570            $(fileInput).remove();
6571        }
6572    });
6573
6574    document.body.appendChild(fileInput);
6575    fileInput.click();
6576}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.