var abfragecounter = 0;
(function ($) {
function calendar_view_step(el, direction) {
var active_element = el.parent().find(".view.active");
if (direction == 'next') {
var next_item = active_element.next(".view");
if (next_item.next(".view").length != 0) {
next_item.toggleClass('active')
active_element.toggleClass('active');
}
}
if (direction == 'prev') {
var prev_item = active_element.prev(".view");
if (prev_item.prev(".view").length != 0) {
prev_item.toggleClass('active')
active_element.toggleClass('active');
}
}
}
function set_the_daterange_humanreadable(el) {
var popover_fieldname = $(el).closest(".tt-popover").attr('name');
var date_from = $(el).closest(".controls").find("input[name=departure]").attr('value');
var date_to = $(el).closest(".controls").find("input[name=arrival]").attr('value');
if (date_from == 0 && date_to == 0) {
return;
}
$(el).closest(".controls").find("input[name=departure]").attr('value', date_from);
var fromdate = $.datepicker.formatDate("dd.mm.yy", new Date(date_from * 1000));
$(".detail-booking-configurator .popover-field[name='" + popover_fieldname + "'] > span").html(fromdate);
if (date_to > 0) {
var todate = $.datepicker.formatDate("dd.mm.yy", new Date(date_to * 1000));
$(".detail-booking-configurator .popover-field[name='" + popover_fieldname + "'] > span").append(' - ' + todate);
}
}
/**
* sets the traveldate
* @param el
*/
function set_traveldate(el) {
$(el).closest(".controls").find(".calendar .day").removeClass("selected");
$(el).closest(".controls").find("input[name=departure]").attr('value', $(el).attr("data-date"));
$(el).closest(".controls").find("input[name=arrival]").attr('value', $(el).attr("data-value-to"));
// close the popover
var popover_fieldname = $(el).closest(".controls").find("input[name=departure]").closest(".tt-popover").attr('name');
set_the_daterange_humanreadable(el);
mark_the_days(el);
toggle_box($(".detail-booking-configurator .popover-field[name='" + popover_fieldname + "']"));
$(el).closest(".controls").find("input[name=departure]").trigger('change');
$(el).closest(".controls").find("input[name=arrival]").trigger('change');
}
function mark_the_days(el) {
var date_from = $(el).closest(".controls").find("input[name=departure]").attr('value');
var date_to = $(el).closest(".controls").find("input[name=arrival]").attr('value');
if (date_from != undefined && date_to != undefined && date_from.length > 0 && date_to.length > 0) {
$(el).closest(".controls").find(".calendar .day").each(function () {
if (parseInt($(this).attr("data-date")) >= date_from && parseInt($(this).attr("data-date")) <= date_to) {
$(this).addClass('selected');
}
});
}
}
function calendar_init() {
$(".calendar").each(function () {
var el = $(this).find(".day")[0];
mark_the_days(el);
set_the_daterange_humanreadable(el);
initPopoverFields();
});
}
// add current url to each booking link
function set_booking_url(){
var current_url = window.location.href;
$('.booking-url').each(function(){
var url = $(this).attr('href');
var pos = url.indexOf('url=');
if(pos > 0){
url = url.substr(0, pos - 1);
}
var n_url = url + '&url=' + encodeURIComponent(current_url);
$(this).attr('href', n_url);
});
}
$(document).ready(function () {
$('.booking-row .zusatzleistung-outer').hide();
$( ".weiterezusatzleistungen" ).click(function() {
$( this ).find("i").toggleClass( "fa-minus" );
$( this ).toggleClass( "active" );
id = $(this).attr("data-id");
$( "#"+id ).toggle("slow");
});
function toggle_filter(el) {
$(el).closest('.toggle-cat').find("li").removeClass('active');
$(el).closest("li").addClass('active');
var allcat = $.map($(el).closest('.panel-body').children(".toggle-cat"), function (n) {
return $(n).data('togglecat');
});
var activemonth = 'all';
var activeroom = 'all';
activemonth = $(el).closest('.panel-body').find(".toggle-cat[data-togglecat='month'] li.active .toggle-src").data('togglesrc');
activeroom = $(el).closest('.panel-body').find(".toggle-cat[data-togglecat='room'] li.active .toggle-src").data('togglesrc');
$(el).closest('.panel-body').find(".tab-content .booking-row").each(function () {
$(this).slideUp();
});
if (activemonth == "all" && activeroom == "all") {
$(el).closest('.panel-body').find(".tab-content .booking-row").each(function () {
$(this).delay(300).slideDown();
});
} else if (activemonth != "all" && activeroom == "all") {
$(el).closest('.panel-body').find(".tab-content .booking-row[data-month='" + activemonth + "']").each(function () {
$(this).delay(300).slideDown();
});
} else if (activemonth == "all" && activeroom != "all") {
$(el).closest('.panel-body').find(".tab-content .booking-row[data-room='" + activeroom + "']").each(function () {
$(this).delay(300).slideDown();
});
} else if (activemonth != "all" && activeroom != "all") {
$(el).closest('.panel-body').find(".tab-content .booking-row[data-month='" + activemonth + "'][data-room='" + activeroom + "']").each(function () {
$(this).delay(300).slideDown();
});
}
}
$(".detail-booking .toggle-src").on('click touch', function () {
toggle_filter($(this));
return false;
});
$(".detail-booking .panel-body .toggle-cat").each(function () {
$optionsize = $(this).children("li").length;
if ($optionsize > 2) {
$cur_el = $(this).children("li:nth-child(2)");
toggle_filter($cur_el);
}
});
$(".month_selectbox .toggle-src").on('click touch', function () {
$month_select = $(this).attr('data-value');
$(".month_selectbox .select-wrapper .form-control").text( $month_select );
$(".month_selectbox .tt-popover").fadeOut();
$(".month_selectbox .select-wrapper").removeClass("active");
return false;
});
$(".room_selectbox .toggle-src").on('click touch', function () {
$room_select = $(this).html();
$(".room_selectbox .select-wrapper .form-control").text( $room_select );
$(".room_selectbox .tt-popover").fadeOut();
$(".room_selectbox .select-wrapper").removeClass("active");
return false;
});
$(".detail-booking .option-group-filter").on('click touch', function () {
// control the popover
$(this).closest('form').find('.select-wrapper .form-control').html($(this).html());
$(this).closest('form').find('.tt-popover').fadeOut();
$(this).closest('form').find('.select-wrapper').removeClass("active");
$(this).closest('.group-filter-list').find("li").removeClass('active');
$(this).closest("li").addClass('active');
option_filter(this);
return false;
});
/*$(".detail-booking .panel-body .group-filter-list li.active a").each(function () {
option_filter(this);
return false;
});*/
function option_filter(el){
var month_filter = $(el).closest('.panel-body').find('.filter_selectbox div[name=month_selectbox] li.active a').data('value');
var boarding_filter = $(el).closest('.panel-body').find('.filter_selectbox div[name=boarding_selectbox] li.active a').data('value');
var person_filter = $(el).closest('.panel-body').find('.filter_selectbox div[name=person_selectbox] li.active a').data('value');
// fst hide date rows
$(el).closest('.panel-body').find(".booking-row").each(function () {
$(this).slideUp();
});
// hide options in date row
$(el).closest('.panel-body').find(".booking-row .option").each(function () {
if($('.person_selectbox').length > 0)
{
$(this).hide();
}
});
// show filter options
$(el).closest('.panel-body').find('.booking-row .row.data').filter(function(){
$(this).hide();
$('.schiffsdeck').hide();
$('.kabinenauswahl').find('i').removeClass('fa-minus');
if (boarding_filter !== undefined)
{
if(boarding_filter === 'all'){
if(parseInt($(this).find('.option').data('occupancy')) <= parseInt(person_filter))
{
$(this).show();
}
}
else if(boarding_filter !== 'all'){
if(parseInt($(this).find('.option').data('occupancy')) <= parseInt(person_filter) && $(this).find('.option').data('boarding') === boarding_filter)
{
$(this).show();
}
}
else{
if (boarding_filter === undefined && person_filter === undefined)
{
$(this).show();
}
}
}
else
{
if(person_filter !== undefined)
{
if (parseInt(person_filter) > 0)
{
if(parseInt($(this).find('.option').data('occupancy')) <= parseInt(person_filter))
{
$(this).show();
}
}
}
else
{
$(this).show();
}
}
});//.show();
// show date rows
$(el).closest('.panel-body').find('.booking-row').filter(function(){
if(month_filter == 'all'){
return true;
}
return $(this).data('month') == month_filter;
}).delay(300).slideDown();
}
// bind the current url even on hash change to the booking urls
$(window).on("hashchange", function() {
set_booking_url();
});
// Calendar switch month
$(document).on("click", ".detail-booking-configurator .tt-popover .calendar a.left", function () {
calendar_view_step($(this), 'prev');
return false;
});
// Calendar switch month
$(document).on("click", ".detail-booking-configurator .tt-popover .calendar a.right", function () {
calendar_view_step($(this), 'next');
return false;
});
// Calendar click on one day, set the daterange
//$(".detail-booking-configurator .tt-popover .calendar .day").click(function () {
$(document).on("click touchend", ".detail-booking-configurator .tt-popover .calendar .day", function (event) {
event.preventDefault();
if($(this).hasClass('selectable') === false){
return false;
}
set_traveldate($(this));
return false;
});
// Calendar mark the daterange on hover
$(document).on("mouseenter", ".detail-booking-configurator .tt-popover .calendar .day", function () {
// mark the days
var cur_date_ts = $(this).attr("data-date");
var date_to = $(this).attr("data-value-to");
if (date_to) {
$(this).closest(".controls").find(".calendar .day").each(function () {
if (parseInt($(this).attr("data-date")) >= cur_date_ts && parseInt($(this).attr("data-date")) <= date_to) {
$(this).toggleClass('marked');
}
});
}
return false;
});
$(document).on("mouseleave", ".detail-booking-configurator .tt-popover .calendar .day", function () {
$(this).closest(".controls").find(".day").removeClass("marked");
return false;
});
$(".detail-booking-configurator").on("change", "select[name=transport_type],input[name=arrival],select[name=id_housing_option],select[name=id_booking_package],select[name=id_housing_package]", function (event) {
event.preventDefault();
// set an loading animation
$(this).closest(".ajax-configurator").find('.price').html(' Aktualisiere Preis...');
// if the date changes, the housing option is not valid
if($(this).attr('name') == 'arrival'){
$(this).closest(".ajax-configurator").find('select[name=id_housing_option]').val(0);
}
if($(this).attr('name') == 'id_booking_package'){
$(this).closest(".ajax-configurator").find('select[name=id_housing_option]').val(0);
$(this).closest(".ajax-configurator").find('select[name=id_housing_package]').val(0);
$(this).closest(".ajax-configurator").find('input[name=id_housing_package]').val(0); // the hidden field
$(this).closest(".ajax-configurator").find('input[name=departure]').val(0);
$(this).closest(".ajax-configurator").find('input[name=arrival]').val(0);
$(this).closest(".ajax-configurator").find('select[name=id_housing_option]').val(0);
}
if($(this).attr('name') == 'id_housing_package'){
$(this).closest(".ajax-configurator").find('select[name=id_housing_option]').val(0);
$(this).closest(".ajax-configurator").find('input[name=departure]').val(0);
$(this).closest(".ajax-configurator").find('input[name=arrival]').val(0);
$(this).closest(".ajax-configurator").find('select[name=id_housing_option]').val(0);
}
// if the id_transport_type changes, the depature, arrival and housing option is not valid
if($(this).attr('name') == 'transport_type'){
$(this).closest(".ajax-configurator").find('input[name=departure]').val(0);
$(this).closest(".ajax-configurator").find('input[name=arrival]').val(0);
$(this).closest(".ajax-configurator").find('select[name=id_housing_option]').val(0);
}
var content_div = $(this).closest(".ajax-configurator");
var r = $.post(FLBuilderLayoutConfig.paths.wpAjaxUrl, {
action: 'tt_booking_configurator',
formdata: $(this).closest('form').serialize()
},
function (data) {
},'html').done(function (data) {
var h = content_div.html(data);
// set the current price to the panel heading
var id_booking_package = content_div.attr('data-booking-package');
content_div.closest(".panel").find("div[href=#booking_package_"+id_booking_package+"] .duration").html(content_div.find(".panelinfo-duration").html());
content_div.closest(".panel").find("div[href=#booking_package_"+id_booking_package+"] .price").html(content_div.find(".panelinfo-price").html());
content_div.closest(".panel").find("div[href=#booking_package_"+id_booking_package+"] .name").html(content_div.find(".panelinfo-name").html());
calendar_init();
set_booking_url();
});
});
$(document).on('change', '.detail-booking .housing-option-group select', function(){
var button = $(this).closest('form').find('a.ibe');
// calc the price
var price = 0;
$(this).closest('.booking-row').find('select').each(function(){
price += parseFloat($(this).data('price')) * parseFloat($(this).val());
});
if(price > 0){
var price_hr = moneyFormat.to(price);
} else{
var price_hr = '';
}
$(this).closest('.booking-row').find('.price.main-price span').html(price_hr);
$(this).removeClass('error');
$(this).closest('.housing-option-group').find('.msg').hide().html('');
reset_booking_button(button)
// BEGIN TS: Kabinenauswahl Button nur anzeigen, wenn eine Anzahl gewählt wurde
if (this.value !== '0') {
$(this).closest('.row.data').find('.kabinenauswahl a.kabinendeck').addClass('active');
} else {
$(this).closest('.row.data').find('.kabinenauswahl a.kabinendeck').removeClass('active');
}
// END TS: Kabinenauswahl Button nur anzeigen, wenn eine Anzahl gewählt wurde
});
function reset_booking_button(button){
var spinner = button.find('i');
var label = button.find('span');
//label.html('Verfügbarkeit prüfen');
spinner.hide();
button.removeClass('disabled');
//button.removeClass('booking-possible');
//button.removeClass('booking-request-possible');
button.removeClass('disabled');
button.attr('style', '');
$(".booking-btn-section").attr('style', '');
var url = button.data('booking-url');
button.closest('form').find('select').each(function(){
var amount = parseInt($(this).val());
if(amount > 0){
var v = $(this).data('value');
url += '&iho[' + v.id + ']=' + amount;
button.attr('href', url);
bmsg = 'Die Reise ist online buchbar.';
}
});
button.closest('.booking-btn-section').find('.booking-info').show().html('');
}
var kontingent;
var konti;
var kabinenauswahl;
var deckauswahl;
var selectedValues = [];
let selection = {}
$('.housing-option-group select').on('change', function () {
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
var data_id_option = $(this).closest('.housing-option-group').attr('data-id-option');
var data_room = $(this).closest('.row.option').attr('data-room');
var isCabinSelection = $('.kabinenauswahl:visible').length;
var button = $(this).closest('.booking-row').find(".booking-url.booking-possible");
const kabs = selection[data_room] ? selection[data_room].kabs : []
let isSelectionComplete = true
selection[data_room] = {
count: parseInt(this.value),
data_id: data_id_option,
kabs: kabs
}
if (isCabinSelection) {
for (const [key, value] of Object.entries(selection)) {
isSelectionComplete = selection[key].count !== value.kabs.length ? false : !isSelectionComplete ? false : true
}
if (!isSelectionComplete) {
setTimeout(function () {
var bookingmsg = 'Bitte eine Kabine auswählen!';
button.closest('.booking-btn-section').find('.booking-info').html(bookingmsg);
button.addClass('disabled');
button.attr('disabled', 'disabled');
button.attr('style', 'pointer-events: none !important');
return;
}, 500);
}
} else {
if (valueSelected === "0") {
setTimeout(function () {
var bookingmsg = 'Bitte eine Kabine auswählen!';
button.closest('.booking-btn-section').find('.booking-info').html(bookingmsg);
button.addClass('disabled');
button.attr('disabled', 'disabled');
button.attr('style', 'pointer-events: none !important');
return;
}, 500);
} else {
setTimeout(function () {
button.closest('.booking-btn-section').find('.booking-info').html('');
button.removeClass('disabled');
button.removeAttr('disabled');
button.attr('style', '');
return;
}, 500);
}
}
//selectedValues.push({data_id_option, valueSelected});
});
$(document).on('click', '.booking-btn-section a.ibe' , function(event) {
var button = $(this);
if(button.hasClass('booking-possible') === true || button.hasClass('booking-request-possible') === true ){
return;
}
event.preventDefault();
var spinner = button.find('i');
var label = button.find('span');
var request = button.data('request');
var is_housing_group_request = false;
if(button.hasClass('housing-group-request') === true){
is_housing_group_request = true;
var c = 0;
request.BookingRequestVO.Options = [];
// Each Select-Field
button.closest('form').find('select').each(function(){
if(button.hasClass('firstamount') === true){
var amount = 1
button.removeClass('firstamount');
}
else
{
var amount = parseInt($(this).val());
}
if(amount > 0){
c++;
var v = $(this).data('value');
v.amount = parseInt($(this).val());;
v.type = 'housing_option';
request.BookingRequestVO.Options.push(v);
}
});
if(c == 0){
var bookingmsg = 'Bitte mind. 1 Zimmer wählen.';
button.closest('.booking-btn-section').find('.booking-info').show().html(bookingmsg);
return;
}
}
spinner.show();
label.html('Prüfe Status');
var endamount = 0;
var data_request = $(this).attr('data-request');
data_request = JSON.parse(data_request);
var von = data_request.BookingRequestVO.date_from;
var bis = data_request.BookingRequestVO.date_to;
// 2020-05-02T00:00:00.000Z
var r = $.post(FLBuilderLayoutConfig.paths.wpAjaxUrl, request,
function (data) {},
'json').done(function (data) {
// Verfügbarkeits-Ampel
var vakanz = data.log[2].Vakanz;
var felder = button.parent().parent().parent().parent();
if (data.kabinen[1]) {
function parseXml(xml, arrayTags) {
let dom = null;
if (window.DOMParser) dom = (new DOMParser()).parseFromString(xml, "text/xml");
else if (window.ActiveXObject) {
dom = new ActiveXObject('Microsoft.XMLDOM');
dom.async = false;
if (!dom.loadXML(xml)) throw dom.parseError.reason + " " + dom.parseError.srcText;
}
else throw new Error("cannot parse xml string!");
function parseNode(xmlNode, result) {
if (xmlNode.nodeName == "#text") {
let v = xmlNode.nodeValue;
if (v.trim()) result['#text'] = v;
return;
}
let jsonNode = {},
existing = result[xmlNode.nodeName];
if (existing) {
if (!Array.isArray(existing)) result[xmlNode.nodeName] = [existing, jsonNode];
else result[xmlNode.nodeName].push(jsonNode);
}
else {
if (arrayTags && arrayTags.indexOf(xmlNode.nodeName) != -1) result[xmlNode.nodeName] = [jsonNode];
else result[xmlNode.nodeName] = jsonNode;
}
if (xmlNode.attributes) for (let attribute of xmlNode.attributes) jsonNode[attribute.nodeName] = attribute.nodeValue;
for (let node of xmlNode.childNodes) parseNode(node, jsonNode);
}
let result = {};
for (let node of dom.childNodes) parseNode(node, result);
return result;
}
var kabinen = data.kabinen[1].Kabinen;
var deck = '';
var alldecks = [];
var b = [];
$.each(kabinen, function (k, v) {
if (v) {
$('.kabinenauswahl').show();
}
var kabinen_decks_ID = v.kabinen_decks_ID;
var svg_base64 = v.SVG_BASE64;
var svg = atob(svg_base64);
var json = parseXml(svg);
let imageObject = json.hmReports.page.object.find(item => item.type === 'picture')
let deckObjects = json.hmReports.page.object.filter(item => item.type !== 'picture')
var image = imageObject['#text'];
var pathpart = "";
// 8bitColor = ((16bitColor + 1)*256) - 1
function bcolor(eins6) {
if (parseInt(eins6) != 0) {
return (((parseInt(eins6) + 1) / 256) - 1);
}
else {
return '0';
}
}
/*