var $defaultReturnVal = '';
var setDefaultReturn = function () {
$('select#pickup-default option').prop('disabled', false);
$('select#pickup-default option[selected]').removeAttr('selected');
$('select#pickup-default option').each(function () {
if ($(this).data('note').indexOf('Motueka -') == 0 || $(this).data('note').indexOf('Nelson -') == 0) {
$(this).prop('disabled', true);
}
})
$('select#pickup-default option[value="' + $defaultReturnVal + '"]').prop('selected', true);
pickupResponseReset();
}
var setMotuekaReturn = function () {
$('select#item-unit-return-bus-from-nelson').prop('disabled', true);
$('select#pickup-default option').prop('disabled', false);
$('select#pickup-default option[selected]').removeAttr('selected');
$('select#pickup-default option').each(function () {
if ($(this).data('note').indexOf('Motueka -') < 0) {
$(this).prop('disabled', true);
}
})
$('select#pickup-default option:enabled:first').prop('selected', true);
pickupResponseReset();
}
var setNelsonReturn = function () {
$('select#item-unit-return-bus-from-motueka').prop('disabled', true);
$('select#pickup-default option').prop('disabled', false);
$('select#pickup-default option[selected]').removeAttr('selected');
$('select#pickup-default option').each(function () {
if ($(this).data('note').indexOf('Nelson -') < 0) {
$(this).prop('disabled', true);
}
})
pickupResponseReset();
}
var pickupResponseReset = function () {
$('#pickup-response-extra').remove();
$('#pickup-response').text($('select#pickup-default option:enabled:first').data('note'));
}
var contentUpdated2 = false,
contentUpdated3 = false;
var force2Pax = function () {
//$('#item-unit-adult option[value="1"]').prop('disabled', true).removeAttr('selected').removeProp('selected').prop('selected', false);
$('#item-unit-adult option[value="1"], #item-unit-adult---upgrade-to-water-taxi-return option[value="1"]').prop('disabled', true).prop('selected', false);
$('#item-unit-adult-option-2---upgrade-to-freedom-kayak option[value="1"]').prop('disabled', true).prop('selected', false);
if (contentUpdated2 == false) {
if (contentUpdated3 == false) {
$('#item-unit-adult option[value="2"]').attr('selected', 'selected').prop('selected', true).trigger('change');
contentUpdated3 = true;
}
contentUpdated2 = true;
setTimeout(function () {
contentUpdated2 = false;
}, 200)
}
}
$(window).load(function () {
if ($('#DepartureCode').length) {
if (($('#DepartureCode').val().toLowerCase().indexOf('.2dayfree.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.3dayfree.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.4dayfree.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.5dayfree.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.bss.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.fa.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.freeisland.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.ft.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.ftot.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.tf.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.2daywint.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.3daywint.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.4daywint.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.5daywint.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.fawint.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.freewint.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.ftotwint.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.ftwint.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.tfwint.') > 0)) {
$('#item-unit-adult option[value="1"]').prop('disabled', true).removeAttr('selected').removeProp('selected').prop('selected', false);
}
if ($('#DepartureCode').val().toLowerCase().indexOf('.fa.') > 0) {
if ($('#item-unit-adult').find('option:selected').val() > 0) {
$('#item-unit-adult---upgrade-to-water-taxi-return option').removeAttr('selected').removeProp('selected').prop('selected', false);
$('#item-unit-adult---upgrade-to-water-taxi-return option[value="1"]').prop('disabled', true).removeAttr('selected').removeProp('selected').prop('selected', false);
$('#item-unit-adult---upgrade-to-water-taxi-return option[value="0"]').attr('selected', 'selected').prop('selected', true);
} else {
$('#item-unit-adult option').removeAttr('selected').removeProp('selected').prop('selected', false);
$('#item-unit-adult option[value="0"]').attr('selected', 'selected').prop('selected', true);
}
}
};
})
$(function () {
$defaultReturnVal = $('select#pickup-default option[selected]').val();
$('.header-optional-extras').text('Please select your option');
$('#frm-edit-booking .col-xs-12:first .booking-options:first label').text('Departure Point');
setDefaultReturn();
//$('#frm-edit-booking > div > div:nth-child(2) > div.col-md-5.col-md-push-7.col-sm-12.col-xs-12.col-xxs-12.col-xxs-push-0.col-xxxs-12.col-xxxs-push-0.pad-left0.pad-right0 > div:nth-child(2) > div > div > label').text('Return Water Taxi');
/* case 20997 buy gift voucher button */
if (location.href.indexOf('/Booking/') > 0) {
$('.hidden-md .add-voucher').text('Buy as gift voucher');
$.fn.swapWith = function (to) {
return this.each(function () {
var copy_to = $(to).clone(true);
var copy_from = $(this).clone(true);
$(to).replaceWith(copy_from);
$(this).replaceWith(copy_to);
});
};
$('.hidden-md .add-voucher').swapWith('.hidden-md .booking-add-cart');
};
var today = new Date()
var todayDate = today.getDate()
var todayMonth = today.getMonth()
if (todayMonth > 3 && todayMonth < 9) {
if ($('body').find('.departure-body-no-avail').length > 0 && $('body').find('.departure-body-no-avail').text().indexOf('No departures available') > 0) {
$('.departure-body-no-avail').html('Available in summer only (01st October- 30th April). Click here to view other products');
}
}
/* case 21170 custom continue shoppping behaviour */
$('.btn-continue-shopping a').data('href', '');
$('.btn-continue-shopping a').click(function () {
top.location.replace('https://www.abeltasman.com/shop');
})
/* working out if today is out of the season */
if (todayMonth > 3 && todayMonth < 9) {
var contentUpdated = false;
if (location.href.toLowerCase().indexOf('/departures?productcode=ate') > 0 || location.href.toLowerCase().indexOf('/departures?productcode=bobw') > 0 || location.href.toLowerCase().indexOf('/departures?productcode=hb') > 0 || location.href.toLowerCase().indexOf('/departures?productcode=mmr') > 0 || location.href.toLowerCase().indexOf('/departures?productcode=ma') > 0 || location.href.toLowerCase().indexOf('/departures?productcode=mre') > 0 || location.href.toLowerCase().indexOf('/departures?productcode=mmro') > 0 || location.href.toLowerCase().indexOf('/departures?productcode=paw') > 0 || location.href.toLowerCase().indexOf('/departures?productcode=pmp') > 0) {
// Select the node that will be observed for mutations
var targetNode = document.querySelector('#departure-partial');
// Options for the observer (which mutations to observe)
var config = { attributes: true, childList: true, subtree: true };
// Callback function to execute when mutations are observed
var callback = function (mutationsList, observer) {
for(var mutation of mutationsList) {
if (mutation.type == 'childList') {
if ($('body').find('.departure-body-no-avail').length > 0 && contentUpdated == false && $('body').find('.departure-body-no-avail').text().indexOf('No departures available') > 0) {
$('.departure-body-no-avail').html('Available in summer only (01st October- 30th April). Click here to view other products');
contentUpdated = true;
setTimeout(function () {
contentUpdated = false;
}, 200)
}
}
}
};
// Create an observer instance linked to the callback function
var observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
};
}
/* case 23539 hide 1 pax for Ngaio Island */
var option1Removed = false;
var removeOption1 = function () {
if (location.href.toLowerCase().indexOf('/booking/new') > -1) {
if (location.href.toLowerCase().indexOf('.ngaio..') > 1) {
$('#item-unit-adult option[value=1]').remove();
if (option1Removed == false) {
$('#item-unit-adult option[value=2]').prop('selected', true).trigger('change');
option1Removed = true;
}
}
}
}
$('body').on('ibEventBookingUnitChange', function () {
removeOption1();
})
if ($('#DepartureCode').length) {
/* DISABLING OPTION "1"" FOR MINIMUM 2 PAX PRODUCTS */
if (($('#DepartureCode').val().toLowerCase().indexOf('.2dayfree.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.3dayfree.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.4dayfree.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.5dayfree.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.bss.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.fa.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.freeisland.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.ft.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.ftot.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.tf.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.scoast.') > 0)) {
$('body').on('ibEventBookingUnitChange', function () {
force2Pax();
})
};
/* CASE 26057 - DISABLING OPTION "1"" FOR MINIMUM 2 PAX "UPGRADE TO FREEDOM KAYAK" PLUS LIMIT THE OPTIONS TO THE SAME NUMBER OR BELOW AS THE FIRST ADULT PRODUCT */
var contentUpdated2 = false;
if (($('#DepartureCode').val().toLowerCase().indexOf('.mmro.') > 0) || ($('#DepartureCode').val().toLowerCase().indexOf('.hb.') > 0)) {
$('body').on('ibEventBookingUnitChange', function () {
if (contentUpdated2 == false) {
var itemUnit = $('#item-unit-adult option:selected').val();
$('#item-unit-adult-option-2---upgrade-to-freedom-kayak option').each(function () {
if ($(this).val() == 1) {
$(this).prop('disabled', true);
} else if ($(this).val() > itemUnit) {
$(this).prop('disabled', true);
} else {
$(this).prop('disabled', false);
}
})
contentUpdated2 = true;
setTimeout(function () {
contentUpdated2 = false;
}, 200)
}
})
};
};
/* Case 24099 - Environmental Access Fee - compulsory option same amount as pax */
if ((location.href.toLowerCase().indexOf('/booking/new') > -1 || location.href.toLowerCase().indexOf('/booking/edit') > -1) && ($('select[data-item-id="eaf"]').length > 0 || $('select[data-item-id="eaftaxi"]').length > 0 || $('select[data-item-id="eafchild"]').length > 0)) {
var $changedOnce = false;
var $valAdult = parseInt($('select[data-item-id="adult"] option:selected').val() != undefined ? $('select[data-item-id="adult"] option:selected').val() : 0);
$valAdult += parseInt($('select[data-item-id="owad"] option:selected').val() != undefined ? $('select[data-item-id="owad"] option:selected').val() : 0);
var $valAdultTaxi = $('select[data-item-id="faupgrade"] option:selected').val() != undefined ? $('select[data-item-id="faupgrade"] option:selected').val() : 0;
var $valChild = parseInt($('select[data-item-id="child"] option:selected').val() != undefined ? $('select[data-item-id="child"] option:selected').val() : 0);
$valChild += parseInt($('select[data-item-id="owch"] option:selected').val() != undefined ? $('select[data-item-id="owch"] option:selected').val() : 0);
function adjustEAF($val, $target) {
$($target + ' option[value=' + $val + ']').prop('selected', true);
$changedOnce = true;
}
adjustEAF($valAdult, 'select[data-item-id="eaf"]');
adjustEAF($valAdultTaxi, 'select[data-item-id="eaftaxi"]');
adjustEAF($valChild, 'select[data-item-id="eafchild"]');
$('body').on('ibEventBookingUnitChange', function () {
if ($changedOnce == false) {
$valAdult = parseInt($('select[data-item-id="adult"] option:selected').val() != undefined ? $('select[data-item-id="adult"] option:selected').val() : 0);
$valAdult += parseInt($('select[data-item-id="owad"] option:selected').val() != undefined ? $('select[data-item-id="owad"] option:selected').val() : 0);
$valAdultTaxi = $('select[data-item-id="faupgrade"] option:selected').val() != undefined ? $('select[data-item-id="faupgrade"] option:selected').val() : 0;
$valChild = parseInt($('select[data-item-id="child"] option:selected').val() != undefined ? $('select[data-item-id="child"] option:selected').val() : 0);
$valChild += parseInt($('select[data-item-id="owch"] option:selected').val() != undefined ? $('select[data-item-id="owch"] option:selected').val() : 0);
adjustEAF($valAdult, 'select[data-item-id="eaf"]');
adjustEAF($valAdultTaxi, 'select[data-item-id="eaftaxi"]');
adjustEAF($valChild, 'select[data-item-id="eafchild"]');
$('#EditItemsPartial select').eq(0).trigger('change');
} else {
$('select[data-item-id="eaf"] option').not(':selected').remove();
$('select[data-item-id="eaftaxi"] option').not(':selected').remove();
$('select[data-item-id="eafchild"] option').not(':selected').remove();
$changedOnce = false;
}
})
}
/* Case 24436 - Primary product needs to be selected to upgrade */
if (location.href.toLowerCase().indexOf('.fa..')) {
function upgradeControl() {
var primaryProdNum = $('[data-item-id="adult"] option:selected').val(),
upgradeProdNum = $('[data-item-id="faupgrade"] option:selected').val();
$('[data-item-id="faupgrade"] option').each(function () {
if ($(this).val() > primaryProdNum) {
$(this).prop('disabled', true);
}
})
if (upgradeProdNum > primaryProdNum) {
$('[data-item-id="faupgrade"] option[value=' + primaryProdNum + ']').prop('selected', true);
$('[data-item-id="faupgrade"]').trigger('change');
}
}
upgradeControl();
$('body').on('ibEventBookingUnitChange', function () {
upgradeControl();
})
}
})
$(document).on('change', 'select#item-unit-return-bus-from-motueka', function () {
if ($(this).val() > 0) {
setMotuekaReturn();
} else {
setDefaultReturn();
}
})
$(document).on('change', 'select#item-unit-return-bus-from-nelson', function () {
if ($(this).val() > 0) {
setNelsonReturn();
} else {
setDefaultReturn();
}
})