var timer_count = Cookies.get('checkout_timer');
var timer_available = true;
var paymentManager = (function (window, document, $, undefined) {
var _paymentProcessor = null;
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
function (c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
$(function () {
initCountryCodes();
$('#CheckoutId').val(uuidv4());
$('.sidebar #policy').toggle();
$('.sidebar #apply-coupon').toggle();
$('.mobile-view #policy').toggle();
timer_count = Cookies.get('checkout_timer');
if (timer_count == 0) {
timer_available = false;
}
$('.modal').modal({
show: true,
keyboard: false,
backdrop: 'static'
});
$('.coupon_input').off('keyup');
$('.coupon_input').on('keyup', function () {
var coupCode = $(this).val();
if (coupCode !== null && coupCode.trim().length > 2) {
$('#apply_coupon_button,#apply_coupon_button_mobile').removeAttr('disabled');
} else {
$('#apply_coupon_button,#apply_coupon_button_mobile').attr('disabled', 'disabled');
}
});
$('.coupon_input').off('change');
$('.coupon_input').on('change', function () {
var coupCode = $(this).val();
if (coupCode !== null && coupCode.trim().length > 2) {
$('#apply_coupon_button,#apply_coupon_button_mobile').removeAttr('disabled');
} else {
$('#apply_coupon_button,#apply_coupon_button_mobile').attr('disabled', 'disabled');
}
});
$('#apply_coupon_button,#apply_coupon_button_mobile').off('click');
$('#apply_coupon_button,#apply_coupon_button_mobile').on('click', function () {
var preBookId = $("#PreBookId");
var coupCode = $("#CouponCode");
var pbJson = $("#PreBookCouponJson");
var totalSaleSpan = $(".total_sale_amount");
var discountDiv = $(".coupon_discount_div");
var discountSpan = $(".coupon_discount_amount");
var cVal = coupCode.val().trim();
if (cVal === "") {
coupCode.val($("#MobileCouponCode").val());
cVal = coupCode.val().trim();
}
var pbVal = preBookId.val();
var couponFBDiv = $(".coupon_feedback_div");
var couponFBSpan = $(".coupon_feedback_span");
$.post('/Coupon/ApplyCoupon', {
'couponCode': cVal,
'preBookId': pbVal
}).done(function (data) {
if (data.errorMessage) {
couponFBDiv.removeClass('hide');
couponFBSpan.removeClass('couponValid');
couponFBSpan.addClass('couponError');
couponFBSpan.text(data.errorMessage);
coupCode.css('border', '1px solid #ba1515');
} else {
//$('.coupon_input_div').addClass('hide');
//couponFBDiv.addClass('hide');
couponFBDiv.addClass('hide');
couponFBSpan.addClass('couponValid');
couponFBSpan.removeClass('couponError');
discountDiv.removeClass('hide');
discountSpan.text("- " + data.displayDiscount);
totalSaleSpan.text(data.displayTotal);
pbJson.val(JSON.stringify(data));
coupCode.css('border', '1px solid rgb(221, 221, 221)');
}
});
});
$('form input[type=text]').keypress(function (e) {
var charCode = !e.charCode ? e.which : e.charCode;
if (charCode == 13)
e.preventDefault();
if ($(this).val().length == 0 && charCode == 32)
e.preventDefault();
});
var currentform;
$('#book_button')
.on('click', function (e) {
e.preventDefault();
$(this).attr('disabled', 'disabled');
$(".rcomui-overlay").addClass('show');
if ($(this).closest('form').valid()) {
if (paymentManager) {
paymentManager.processPayment(handlePayment);
}
} else {
var errors = paymentManager.getErrorsMessages();
if (errors) {
for (var i = 0; i < errors.length; i++) {
var item = '
' + errors[i] + '';
$("#checkoutValidationDiv ul").append(item);
}
}
if ($(".input-validation-error").length > 0) {
$(".validateErrorCounts").html($(".input-validation-error").length);
$('#firstInvalidField').on('click',
function () {
var ctrlId = "#" + $(".input-validation-error")[0].id;
$(ctrlId).focus();
});
$("#checkoutValidationDiv").show();
$('html, body').animate({
scrollTop: parseInt($("#checkoutValidationDiv").offset().top)
},
1000);
}
$(this).removeAttr('disabled');
$(".rcomui-overlay").removeClass('show');
}
});
function handlePayment(isValid) {
if (isValid) {
Cookies.set('checkout_timer', 900);
timer_available = true;
$('#checkout-form').submit();
} else {
var errors = paymentManager.getErrorsMessages();
if (errors) {
var vaDiv = $("#checkoutValidationDiv");
vaDiv.removeClass();
vaDiv.addClass('text-danger');
vaDiv.addClass('validation-summary-errors');
var valULLI = $("#checkoutValidationDiv ul li");
valULLI.remove();
var valUL = $("#checkoutValidationDiv ul");
for (var i = 0; i < errors.length; i++) {
valUL.append('' + errors[i] + '');
}
}
$('#book_button').removeAttr('disabled');
$(".rcomui-overlay").removeClass('show');
}
}
$("#sidebaropen")
.click(function () {
if (windowWidth = jQuery(window).outerWidth(), $(".home").length) var e = $("#sidebar_area").offset().top - 60;
else var e = $("#sidebar_area").offset().top;
if (windowWidth >= 991) {
!$(this).hasClass("active") && $(this).hasClass("side-search") ? ($("#reservations").fadeOut(), $("#sidenav-form").fadeIn()) : !$(this).hasClass("active") && $(this).hasClass("side-reservations") && ($("#sidenav-form").fadeOut(), $("#reservations").fadeIn()), $("#sidebar_area .side-search, #sidebar_area .side-map, #sidebar_area .side-reservations").removeClass("active"), $(this).addClass("active"), $("#sidenav").css("position", "absolute"), $("#sidebar_area").css("top", e + "px"), $("#sidebar_area").animate({
right: "0px"
}, 500, function () {
$(".side-close").animate({
opacity: "1"
},
500,
function () { })
});
var i = $("#sidebar_area").offset().top + $("#sidenav-form").height() + 220 - $("#footer_area").offset().top;
i > $("#footer_area").height() && $("#footer").css("height", i + "px")
} else $(this).hasClass("side-search") ? $(this).hasClass("active") ? ($("#sidenav-form").slideUp(), $(this).removeClass("active")) : ($("#sidenav-form").slideDown(), $("#reservations").slideUp(), $("#sidebar_area nav ul li.side-search, #sidebar_area nav ul li.side-map, #sidebar_area nav ul li.side-reservations").removeClass("active"), $(this).addClass("active")) : $(this).hasClass("side-reservations") && ($(this).hasClass("active") ? ($("#sidebaropen").slideUp(), $(this).removeClass("active")) : ($("#sidebaropen").slideDown(), $("#sidenav-form").slideUp(), $("#sidebar_area .side-search, #sidebar_area .side-map, #sidebar_area .side-reservations").removeClass("active"), $(this).addClass("active")))
});
$("#sideclose")
.click(function () {
if ($("#searchopen, #sidebaropen").removeClass("active"), $(".home").length) {
$(window).scrollTop() - $("#sidebar_area").offset().top + 60
} else {
$(window).scrollTop() - $("#sidebar_area").offset().top + 130;
}
$("#sidebar_area").animate({
right: "-300px"
},
500,
function () {
$("#sidebar_area").css("position", "absolute"), $("#sidebar_area").css("top", "65px"), $(
".side-close").animate({
opacity: "0"
},
500,
function () { }), $("#reservations").hide(), $("#sidenav-form").hide()
});
});
if ($('#countryselect select').val() === 'US' || $('#countryselect select').val() === 'CA' || $('#countryselect select').val() === 'AU') {
$('#stateselect').css('display', 'block');
} else {
$('#stateselect').css('display', 'none');
}
fillStates($("#Country").val());
function fillStates(country) {
var statesHTML = '';
var countrySpecificState = $.map(statesList, function (val) {
if (val.countryCode === country) return val;
});
if (countrySpecificState) {
countrySpecificState.forEach((state) => {
statesHTML += '';
});
}
$("#State").html('' + statesHTML);
}
$('#countryselect select')
.on('change', function () {
var country = $(this).val();
fillStates(country);
if ($('#countryselect select').val() === 'US' || $('#countryselect select').val() === 'CA' || $('#countryselect select').val() === 'AU') {
$('#stateselect').css('display', 'block');
} else {
$('#stateselect select').removeClass('input-validation-error');
$('#stateselect').css('display', 'none');
}
});
$('#cardselect select')
.on('change', function () {
$(".payment-type-message").hide();
$(".paymentType" + $(this).val()).show();
});
$('#CreditCardExpirationMonth').on('change', function () {
$("#CreditCardExpirationYear").blur();
});
$('#CreditCardExpirationYear').on('change', function () {
$("#CreditCardExpirationMonth").blur();
});
if (document.querySelector('#tel')) {
document.querySelector("#tel").addEventListener("keypress",
function (evt) {
if (evt.which < 48 || evt.which > 57) {
evt.preventDefault();
}
});
var phone = document.getElementById('tel'), cleanPhoneNumber;
// below function prevent alphanumeric copy paste. ex 123-45-678 convert into 12345678
cleanPhoneNumber = function (e) {
e.preventDefault();
var pastedText = '';
if (window.clipboardData && window.clipboardData.getData) { // IE
pastedText = window.clipboardData.getData('Text');
} else if (e.clipboardData && e.clipboardData.getData) {
pastedText = e.clipboardData.getData('text/plain');
}
this.value = pastedText.replace(/\D/g, '');
};
phone.onpaste = cleanPhoneNumber;
}
// cctype
$("#CreditCardNumber").change(function () {
if ($("#CreditCardNumber").val().length < 1) {
$("#cardlogo").removeClass("amex");
$("#cardlogo").removeClass("master");
$("#cardlogo").removeClass("visa");
$("#cardlogo").removeClass("discover");
$("#cardlogo").removeClass("jcb");
$("#cardlogo").removeClass("diners");
}
});
$("#CreditCardNumber").focusout(function () {
setCardVerificationError();
});
$("#CreditCardIdentifer").focusout(function () {
setCardVerificationError();
});
$("#CreditCardNumber").blur(function () {
setCardVerificationError();
});
$("#CreditCardIdentifer").blur(function () {
setCardVerificationError();
});
$("#CreditCardIdentifer").focusin(function () {
setCardVerificationError();
});
jQuery.validator.addMethod("cardfirstname", function (value, element, param) {
return ($("#FirstName").val().trim().length > 0);
}, 'The cardholder first name is required.');
jQuery.validator.unobtrusive.adapters.addBool("cardfirstname");
jQuery.validator.addMethod("cardlastname", function (value, element, param) {
return ($("#LastName").val().trim().length > 0);
}, 'The cardholder last name is required.');
jQuery.validator.unobtrusive.adapters.addBool("cardlastname");
jQuery.validator.addMethod("cardnumber", function (value, element, param) {
var result = $("#CreditCardNumber").validateCreditCard();
var cardType = "";
if (result.card_type && result.valid && (result.card_type.name === "visa" || result.card_type.name === "mastercard" || result.card_type.name === "discover" || result.card_type.name === "amex" || result.card_type.name === "diners_club_international" || result.card_type.name === "diners_club_carte_blanche" || result.card_type.name === "jcb")) {
cardType = result.card_type.name;
}
if (cardType) {
securityCodeLen = (cardType == "amex") ? 4 : 3;
$("#CreditCardIdentifer").attr({
"minlength": securityCodeLen,
"maxlength": securityCodeLen,
"minlength-error": securityCodeLen + " size",
"maxlength-error": securityCodeLen + " size",
"size": securityCodeLen
});
}
$("#cardlogo").removeClass("amex");
$("#cardlogo").removeClass("master");
$("#cardlogo").removeClass("visa");
$("#cardlogo").removeClass("discover");
$("#cardlogo").removeClass("jcb");
$("#cardlogo").removeClass("diners");
$("#card_type").val(cardType);
if (cardType == "amex") {
$("#CreditCardType").val("AE");
$("#cardlogo").addClass("amex");
} else if (cardType == "mastercard" || cardType == "master") {
$("#CreditCardType").val("MC");
$("#cardlogo").addClass("master");
} else if (cardType == "visa") {
$("#CreditCardType").val("VI");
$("#cardlogo").addClass("visa");
} else if (cardType == "discover") {
$("#CreditCardType").val("DI");
$("#cardlogo").addClass("discover");
} else if (cardType == "jcb") {
$("#CreditCardType").val("JC");
$("#cardlogo").addClass("jcb");
} else if (cardType == "diners_club_international" || cardType == "diners_club_carte_blanche") {
$("#CreditCardType").val("DC");
$("#cardlogo").addClass("diners");
} else {
$("#CreditCardType").val("");
}
var ccNumber = $("#CreditCardNumber").val().replace(/\s+/g, '');
$("#CreditCardNumber").val(ccNumber);
if (cardType !== "") {
$("#CreditCardNumber").removeClass('input-validation-error');
} else {
if (!$("#CreditCardNumber").hasClass('input-validation-error')) {
$("#CreditCardNumber").addClass('input-validation-error');
}
}
return (cardType != '');
}, 'Please enter a valid credit card number.');
jQuery.validator.unobtrusive.adapters.addBool("cardnumber");
//end of cctype
jQuery.validator.addMethod("expiredate", function (value, element, param) {
var year = $("#CreditCardExpirationYear").val();
var month = $("#CreditCardExpirationMonth").val();
var today, someday;
today = new Date();
someday = new Date();
someday.setFullYear(year, month, 1);
if (someday > today) {
$("#CreditCardExpirationYear").removeClass('input-validation-error');
$("#CreditCardExpirationMonth").removeClass('input-validation-error');
return true;
} else {
if (!$("#CreditCardExpirationYear").hasClass('input-validation-error'))
$("#CreditCardExpirationYear").addClass('input-validation-error');
if (!$("#CreditCardExpirationMonth").hasClass('input-validation-error'))
$("#CreditCardExpirationMonth").addClass('input-validation-error');
}
return false;
});
jQuery.validator.unobtrusive.adapters.addBool("expiredate");
setInterval(tick, 1000);
$('.sidebar #policybutton')
.click(function () {
$('.sidebar #policy').slideToggle();
$('.sidebar #sChIn').toggle();
});
$('.sidebar #couponButton')
.click(function () {
$('.sidebar #apply-coupon').slideToggle();
});
$('.mobile-view #policybutton')
.click(function () {
$('.mobile-view #policy').slideToggle();
$('.mobile-view #sChIn').toggle();
});
//SPECIAL CHECK IN TRUNCATED TEXT CODE JS
$(".sidebar .read-more").click(function () {
$('.sidebar .more-text').show();
$(this).remove();
});
$(".mobile-view .mobile-read-more").click(function () {
$(".mobile-view .mobile-more-text").show();
$(this).remove();
});
$('.modal .close').on('click', function () {
// history.back();
});
if (doScroll) {
setTimeout(function () {
$('html, body').animate({
scrollTop: $('.checkout-inner').offset().top - 20
}, 'slow');
}, 1000);
}
});
function setPaymentProcessor(paymentProcessor) {
_paymentProcessor = paymentProcessor;
}
function processPayment(paymentCallback) {
return _paymentProcessor.processPayment(paymentCallback);
}
function getErrors() {
var validationElements = _paymentProcessor.validationElements;
var errors = _paymentProcessor.errors;
var errArray = [];
for (var i = 0; i < 3; i++) {
if (validationElements == null || validationElements[i] == null || (validationElements[i].error == null && validationElements[i].empty)) {
// updateRequiredFields(i, errArray);
} else if ((validationElements && validationElements[i] != null) &&
(validationElements[i].error == null && validationElements[i].complete == false)) {
updateIncompleteFields(i, errArray);
} else if (errors[i] != null) {
errArray.push(errors[i]);
}
}
return errArray;
}
function updateRequiredFields(i, errors) {
switch (i) {
case 0:
errors.push('The card number is required.');
break;
case 1:
errors.push('The card expiration date is required.');
break;
case 2:
errors.push('The card security code is required.');
break;
}
}
function updateIncompleteFields(i, errors) {
switch (i) {
case 0:
errors.push('Credit card number is incomplete.');
break;
case 1:
errors.push('Expiration date is incomplete.');
break;
case 2:
errors.push('CVV is incomplete.');
break;
}
}
return {
processPayment: processPayment,
setPaymentProcessor: setPaymentProcessor,
getErrorsMessages: getErrors
};
})(window, document, window.jQuery);
function setCardVerificationError() {
if (!$("#CreditCardIdentifer-error").length || !$("#CreditCardIdentifer").val()) {
return;
}
var maxLength = $("#CreditCardIdentifer").attr('maxlength');
var minLength = $("#CreditCardIdentifer").attr('minlength');
setTimeout(function () {
$("#CreditCardIdentifer").valid();
if ($("#CreditCardIdentifer").parents(".form-group").hasClass("has-success")) {
$("#CreditCardIdentifer-error").html('');
} else {
if (maxLength != minLength) {
$("#CreditCardIdentifer-error").html("Card security code must be 3 or 4 digits");
} else {
$("#CreditCardIdentifer-error").html("Card security code must be " + minLength + " digits");
}
}
}, 10);
}
function validateCardnumber() {
if ($("#CreditCardNumber").val().length > 0) {
$("#checkout-form").validate().element("#CreditCardNumber");
} else {
$("#cardlogo").removeClass("amex");
$("#cardlogo").removeClass("master");
$("#cardlogo").removeClass("visa");
$("#cardlogo").removeClass("discover");
$("#cardlogo").removeClass("jcb");
$("#cardlogo").removeClass("diners");
}
if ($("#CreditCardIdentifer").val().length > 0) {
$("#checkout-form").validate().element("#CreditCardIdentifer");
setCardVerificationError();
}
}
function tick() {
if (timer_available) {
timer_count = Cookies.get('checkout_timer');
if (timer_count) {
timer_count -= 1;
let minutes = Math.floor(timer_count / 60);
let sec = timer_count % 60;
minutes = minutes < 10 ? '0' + minutes : minutes;
sec = sec < 10 ? '0' + sec : sec;
$('.timer_area .time').html(minutes + ':' + sec);
Cookies.set('checkout_timer', timer_count);
if (timer_count <= 0) {
//window.history.back();
timer_available = false;
}
} else {
$('.timer_area .time').html('00:00');
Cookies.set('checkout_timer', 0);
timer_available = false;
}
} else {
if (timer_count) {
let minutes = Math.floor(timer_count / 60);
let sec = timer_count % 60;
minutes = minutes < 10 ? '0' + minutes : minutes;
sec = sec < 10 ? '0' + sec : sec;
$('.timer_area .time').html(minutes + ':' + sec);
} else {
$('.timer_area .time').html('00:00');
}
}
};
function formatCountryCode() {
var countryCode = $('#bill_phone').val().toString();
var formatCode = countryCode.substring(countryCode.length - 2, countryCode.length).toUpperCase();
}
function initCountryCodes() {
var billPhoneHTML = '';
PhoneNumbersConstant.forEach((pn) => {
billPhoneHTML += '';
});
$("#bill_phone").html(billPhoneHTML);
}