/////* ============================================================================== ////// Scripts for the theme ////// ============================================================================== */ ////$(function () { //// // sidebar menus //// Sidebar.initialize(); //// // tooltips //// $("[data-bs-toggle='tooltip']").tooltip(); //// // retina display //// if (window.devicePixelRatio >= 1.2) { //// $("[data-2x]").each(function () { //// if (this.tagName == "IMG") { //// $(this).attr("src", $(this).attr("data-2x")); //// } else { //// $(this).css({ "background-image": "url(" + $(this).attr("data-2x") + ")" }); //// } //// }); //// } //// Number.prototype.formatMoney = function (c, d, t) { //// var n = this, //// c = isNaN(c = Math.abs(c)) ? 2 : c, //// d = d == undefined ? "." : d, //// t = t == undefined ? "," : t, //// s = n < 0 ? "-" : "", //// i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", //// j = (j = i.length) > 3 ? j % 3 : 0; //// return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); //// }; //// $("[data-switch]").bootstrapSwitch({ //// "size": "small" //// }); //// // Wave Effect //// Waves.attach('.waves-effect', ['waves-block', 'waves-ripple']); //// Waves.init(); ////}); ////var Sidebar = { //// initialize: function () { //// var $sidebar_menu = $(".main-sidebar"); //// // my account dropdown menu //// var $account_menu = $sidebar_menu.find(".current-user .menu"); //// $(".current-user .name").click(function (e) { //// console.log('getting into current user click'); //// e.preventDefault(); //// e.stopPropagation(); //// $account_menu.toggleClass("active"); //// }); //// $account_menu.click(function (e) { e.stopPropagation() }); //// $("body").click(function () { $account_menu.removeClass("active") }); //// // sidebar menu dropdown levels //// var $dropdown_triggers = $sidebar_menu.find("[data-bs-toggle~='sidebar']"); //// $dropdown_triggers.click(function (e) { //// e.preventDefault(); //// if (!utils.isTablet()) { //// // reset other dropdown menus //// if (!$(this).closest(".submenu").length) { //// $dropdown_triggers.not(this).removeClass("toggled").siblings(".submenu").slideUp(300, check_height); //// } //// var $trigger = $(this); //// var $dropdown = $(this).siblings(".submenu"); //// $trigger.toggleClass("toggled"); //// if ($trigger.hasClass("toggled")) { //// $dropdown.slideDown(300, check_height); //// } else { //// $dropdown.slideUp(300, check_height); //// } //// } //// }); //// var check_height = function () { //// var height = $("body").height(); //// $(".main-sidebar").css("bottom", "auto"); //// var sidebar_height = $(".main-sidebar").height(); //// if (height > sidebar_height) { //// $(".main-sidebar").css("bottom", 0); //// } else { //// $(".main-sidebar").css("bottom", "auto"); //// } //// }; //// // mobile sidebar toggler //// var $mobile_toggler = $("#content .sidebar-toggler"); //// $mobile_toggler.click(function (e) { //// e.stopPropagation(); //// $("body").toggleClass("open-sidebar"); //// }); //// $("#content").click(function () { //// $("body").removeClass("open-sidebar"); //// }) //// } ////}; ////window.utils = { //// isFirefox: function () { //// return navigator.userAgent.toLowerCase().indexOf('firefox') > -1; //// }, //// animation_ends: function () { //// return "animationend webkitAnimationEnd oAnimationEnd"; //// }, //// isTablet: function () { //// return ($(".main-sidebar").width() < 100); //// }, //// get_timestamp: function (less_days) { //// return moment().subtract('days', less_days).toDate().getTime(); //// } ////}; var $document = $(document); $document.ready(function () { // MISC: Use 'data-modalfocus' attribute on textbox which should gain focus on load $(".modal").on('shown.bs.modal', function () { $("[data-modalfocus]", this).focus(); }); // MISC: Toggle active class on selected item in list groups $(document).on('click', ".list-group .list-group-item", function () { $(this).siblings().removeClass('active'); $(this).addClass('active'); }); // MISC: Start NProgress progress bar $(document).on('click', '.finished', function () { NProgress.start(); }); // MISC: Initialize the masked inputs $(".phoneMask").mask("(999) 999-9999"); $(".expirationMonthMask").mask("?99"); $(".expirationYearMask").mask("9999"); //$(".securityCodeMask").mask("?9999"); $(".cardNumberMask").mask("?9999 9999 9999 9999"); // MISC: Initialize the datepicker controls $("#editClosingDateDatepicker").datepicker({ minDate: 1, showOtherMonths: true }); $("#txtHvacInspectionCompletionDate").datepicker({ minDate: 1, showOtherMonths: true }); // ACCOUNT: Reset Password show $('.resetPassword').click(function () { if($('#hidAccountExistsEmailAddress').val()) { $('#txtResetPasswordEmailAddress').val($('#hidAccountExistsEmailAddress').val()); } $('.bs-reset-password-email-modal-md').modal('show'); }); // ACCOUNT: Reset Password Submit Email Address Call $document.on('click', '#resetPasswordSubmitEmailAddress', function () { var emailAddress = $('#txtResetPasswordEmailAddress').val(); $('#txtResetPasswordEmailAddress').val(''); var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if (!regex.test(emailAddress)) { $('#resetPasswordEmailValidator').show(); return false; } else { $('#resetPasswordEmailValidator').hide(); var url = $(this).data('request-url'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ emailAddress: emailAddress }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { $('.bs-reset-password-email-modal-md').modal('hide'); toastr.success('Thank you! Your password has been reset and an email has been sent with your temporary password and instructions.', 'Reset Password', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { toastr.error(response.ErrorMessage + '

Please try another email address or call our Agent Services Department at 800.795.9595 for assistance.', 'Reset Password', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { toastr.error('We\'re sorry. An error occurred while resetting your password. Please try again later, or call our Agent Services Department at 800.795.9595 for assistance.', 'Reset Password', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // REGISTER: Submit Temporary Agent and Office Details $document.on('click', '#officeDetailsManualEntrySubmit', function () { var formHasErrors = false; var firstName = $('#txtOfficeDetailsAgentFirstName'); if (!firstName.val()) { formHasErrors = true; firstName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { firstName.closest('.form-group').removeClass('has-error'); } var lastName = $('#txtOfficeDetailsAgentLastName'); if (!lastName.val()) { formHasErrors = true; lastName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { lastName.closest('.form-group').removeClass('has-error'); } var agentPhone = $('#txtOfficeDetailsAgentPhone'); if (!agentPhone.val()) { formHasErrors = true; agentPhone.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { agentPhone.closest('.form-group').removeClass('has-error'); } var officeName = $('#txtOfficeDetailsOfficeName'); if (!officeName.val()) { formHasErrors = true; officeName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { officeName.closest('.form-group').removeClass('has-error'); } var officeAddress = $('#txtOfficeDetailsOfficeAddress'); if (!officeAddress.val()) { formHasErrors = true; officeAddress.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { officeAddress.closest('.form-group').removeClass('has-error'); } var officeCity = $('#txtOfficeDetailsOfficeCity'); if (!officeCity.val()) { formHasErrors = true; officeCity.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { officeCity.closest('.form-group').removeClass('has-error'); } var officeState = $('#ddlOfficeDetailsOfficeState'); if (!officeState.val() || officeState.val() == '-1') { formHasErrors = true; officeState.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { officeState.closest('.form-group').removeClass('has-error'); } var officeZip = $('#txtOfficeDetailsOfficeZip'); if (!officeZip.val()) { formHasErrors = true; officeZip.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { officeZip.closest('.form-group').removeClass('has-error'); } var agentEmailAddress = $('#hidAgentEmailAddress'); if (!formHasErrors) { var url = $(this).data('request-url'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ agentFirstName: firstName.val(), agentLastName: lastName.val(), agentPhone: agentPhone.val(), agentEmailAddress: agentEmailAddress.val(), officeName: officeName.val(), officeAddress: officeAddress.val(), officeCity: officeCity.val(), officeState: officeState.val(), officeZip: officeZip.val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { firstName.val(''); lastName.val(''); agentPhone.val(''); officeName.val(''); officeAddress.val(''); officeCity.val(''); officeState.val(''); officeZip.val(''); agentEmailAddress.val(''); $('.bs-enter-office-details-modal-md').modal('hide'); if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { window.location.href = response.RedirectUrl; } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Register Account', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { $('.bs-enter-office-details-modal-md').modal('hide'); toastr.error('We\'re sorry. An error occurred while saving your account details. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Register Account', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // REGISTER: Submit Temporary Agent Details $document.on('click', '#agentDetailsManualEntrySubmit', function () { var formHasErrors = false; var firstName = $('#txtAgentDetailsAgentFirstName'); if (!firstName.val()) { formHasErrors = true; firstName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { firstName.closest('.form-group').removeClass('has-error'); } var lastName = $('#txtAgentDetailsAgentLastName'); if (!lastName.val()) { formHasErrors = true; lastName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { lastName.closest('.form-group').removeClass('has-error'); } if (!formHasErrors) { var url = $(this).data('request-url'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ agentFirstName: firstName.val(), agentLastName: lastName.val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { $('.bs-enter-agent-details-modal-md').modal('hide'); firstName.val(''); lastName.val(''); if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { window.location.href = response.RedirectUrl; } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Register Account', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { $('.bs-enter-agent-details-modal-md').modal('hide'); toastr.error('We\'re sorry. An error occurred while saving your account details. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Register Account', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // SERVICE AGREEMENT: Edit Primary Homeowner Details $document.on('click', '#editPrimaryHomeownerDetails', function () { var formHasErrors = false; var warrantyKey = $('#txtWarrantyKey').val(); var primaryHomeownerFirstName = $('#txtPrimaryHomeownerFirstName'); var primaryHomeownerLastName = $('#txtPrimaryHomeownerLastName'); var primaryHomeownerHomePhone = $('#txtPrimaryHomePhone').val(); var primaryHomeownerOfficePhone = $('#txtPrimaryOfficePhone').val(); var primaryHomeownerMobilePhone = $('#txtPrimaryMobilePhone').val(); // Validate the email address value var emailAddressField = $('#txtPrimaryEmailAddress'); var emailAddress = emailAddressField.val(); var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if (emailAddress && !regex.test(emailAddress)) { formHasErrors = true; emailAddressField.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { emailAddressField.closest('.form-group').removeClass('has-error'); } // Now, validate the contact first and last name if (!primaryHomeownerFirstName.val()) { formHasErrors = true; primaryHomeownerFirstName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { primaryHomeownerFirstName.closest('.form-group').removeClass('has-error'); } if (!primaryHomeownerLastName.val()) { formHasErrors = true; primaryHomeownerLastName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { primaryHomeownerLastName.closest('.form-group').removeClass('has-error'); } if(!formHasErrors) { var url = $(this).data('request-url'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ warrantyKey: warrantyKey, primaryOrSecondaryHomeowner: 'Primary', homeownerFirstName: primaryHomeownerFirstName.val(), homeownerLastName: primaryHomeownerLastName.val(), homePhoneEdit: primaryHomeownerHomePhone, officePhoneEdit: primaryHomeownerOfficePhone, mobilePhoneEdit: primaryHomeownerMobilePhone, emailAddressEdit: emailAddress }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { $('.bs-edit-primary-homeowner-details-modal').modal('hide'); toastr.options.onHidden = function () { window.location.href = response.RedirectUrl; }; toastr.success('Thank you! The homeowner details have been saved.

This page will now refresh.', 'Edit Homeowner', { timeOut: 2000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Edit Homeowner', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { toastr.error('We\'re sorry. An error occurred while saving homeowner details. Please try again later, or call our Agent Services Department at 800.795.9595 for assistance.', 'Edit Homeowner', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // SERVICE AGREEMENT: Edit Secondary Homeowner Details $document.on('click', '#editSecondaryHomeownerDetails', function () { var formHasErrors = false; var warrantyKey = $('#txtWarrantyKey').val(); var secondaryHomeownerFirstName = $('#txtSecondaryHomeownerFirstName'); var secondaryHomeownerLastName = $('#txtSecondaryHomeownerLastName'); var secondaryHomeownerHomePhone = $('#txtSecondaryHomePhone').val(); var secondaryHomeownerOfficePhone = $('#txtSecondaryOfficePhone').val(); var secondaryHomeownerMobilePhone = $('#txtSecondaryMobilePhone').val(); // Validate the email address value var emailAddressField = $('#txtSecondaryEmailAddress'); var emailAddress = emailAddressField.val(); var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if (emailAddress && !regex.test(emailAddress)) { formHasErrors = true; emailAddressField.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { emailAddressField.closest('.form-group').removeClass('has-error'); } // Now, validate the contact first and last name if (!secondaryHomeownerFirstName.val()) { formHasErrors = true; secondaryHomeownerFirstName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { secondaryHomeownerFirstName.closest('.form-group').removeClass('has-error'); } if (!secondaryHomeownerLastName.val()) { formHasErrors = true; secondaryHomeownerLastName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { secondaryHomeownerLastName.closest('.form-group').removeClass('has-error'); } if (!formHasErrors) { var url = $(this).data('request-url'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ warrantyKey: warrantyKey, primaryOrSecondaryHomeowner: 'Secondary', homeownerFirstName: secondaryHomeownerFirstName.val(), homeownerLastName: secondaryHomeownerLastName.val(), homePhoneEdit: secondaryHomeownerHomePhone, officePhoneEdit: secondaryHomeownerOfficePhone, mobilePhoneEdit: secondaryHomeownerMobilePhone, emailAddressEdit: emailAddress }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { $('.bs-edit-secondary-homeowner-details-modal').modal('hide'); toastr.options.onHidden = function () { window.location.href = response.RedirectUrl; }; toastr.success('Thank you! The homeowner details have been saved.

This page will now refresh.', 'Edit Homeowner', { timeOut: 2000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Edit Homeowner', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { toastr.error('We\'re sorry. An error occurred while saving homeowner details. Please try again later, or call our Agent Services Department at 800.795.9595 for assistance.', 'Edit Homeowner', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // SERVICE AGREEMENT: Edit Closing Date $document.on('click', '#editClosingDate', function () { var warrantyKey = $('#editClosingDateWarrantyKey').val(); var url = $(this).data('request-url'); var newClosingDate = $('#editClosingDateDatepicker').val(); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ warrantyKey: warrantyKey, newClosingDate: newClosingDate }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { $('.bs-edit-closing-date-modal').modal('hide'); toastr.options.onHidden = function () { window.location.href = response.RedirectUrl; }; toastr.success('Thank you! The closing date for this service agreement has been updated.

This page will now refresh.', 'Edit Closing Date', { timeOut: 2000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Edit Closing Date', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { toastr.error('We\'re sorry. An error occurred while saving the updated closing date. Please try again later, or call our Agent Services Department at 800.795.9595 for assistance.', 'Edit Closing Date', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); }); // SERVICE AGREEMENT: Resend Confirmation Email $document.on('click', '#resendConfirmationEmail', function () { var warrantyKey = $('#resendConfirmationEmailWarrantyKey').val(); var url = $(this).data('request-url'); var newClosingDate = $('#editClosingDateDatepicker').val(); var emailAddresses = $('#txtResendConfirmationEmail'); if (!emailAddresses.val()) { emailAddresses.closest('.form-group').removeClass('has-success').addClass('has-error'); return false; } else { emailAddresses.closest('.form-group').removeClass('has-error'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ warrantyKey: warrantyKey, emailAddresses: emailAddresses.val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { emailAddresses.val(''); $('.bs-resend-confirmation-email-modal').modal('hide'); toastr.success('Thank you! A copy of the confirmation email has been resent to your requested email addresses.', 'Resend Confirmation Email', { timeOut: 3000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Resend Confirmation Email', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { toastr.error('We\'re sorry. An error occurred while resending copies of the confirmation email. Please try again later, or call our Agent Services Department at 800.795.9595 for assistance.', 'Resend Confirmation Email', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // SERVICE AGREEMENT: Resend Escrow Demand select event handler $("select#txtResendEscrowDeliveryType").change(function () { var deliveryType = $('#txtResendEscrowDeliveryType'); var companyName = $('#txtResendEscrowCompanyName'); var attention = $('#txtResendEscrowAttention'); var phoneNumber = $('#txtResendEscrowPhoneNumber'); var faxNumber = $('#txtResendEscrowFaxNumber'); var emailAddress = $('#txtResendEscrowEmailAddress'); if ($(this).val() == 'Fax') { companyName.removeAttr('disabled'); attention.removeAttr('disabled'); phoneNumber.removeAttr('disabled'); faxNumber.removeAttr('disabled'); emailAddress.attr("disabled", "disabled"); emailAddress.closest('.form-group').removeClass('has-error'); } else { emailAddress.removeAttr('disabled'); companyName.removeAttr('disabled'); attention.removeAttr('disabled'); phoneNumber.removeAttr('disabled'); faxNumber.attr("disabled", "disabled"); phoneNumber.closest('.form-group').removeClass('has-error'); faxNumber.closest('.form-group').removeClass('has-error'); } }); // SERVICE AGREEMENT: Add Optional Coverage - Display Pay Now Popup $document.on('click', '#addOptionPayNow', function () { // Populate the modal controls and show the popup $('#hidAddOptionsPayNowWarrantyKey').val($('#hidAddOptionsWarrantyKey').val()); $('#hidAddOptionsPayNowOptionKey').val($('#hidAddOptionsOptionKey').val()); $('#hidAddOptionsPayNowPrice').val($('#lblAddOptionsPrice').text()); $('#hidAddOptionsPayNowTax').val($('#lblAddOptionsTax').text()); $('#spnAddOptionsPayNowGrandTotal').text($('#lblAddOptionsTotal').text()); $('.bs-add-options-pay-now-modal').modal('show'); }); // SERVICE AGREEMENT: Add Optional Coverage - Pay Now with Cybersource $document.on('click', '#btnAddOptionsPayNowSubmit', function () { var formHasErrors = false; var url = $(this).data('request-url'); var warrantyKey = $('#hidAddOptionsPayNowWarrantyKey').val(); var optionKey = $('#hidAddOptionsPayNowOptionKey').val(); var optionPrice = $('#hidAddOptionsPayNowPrice').val(); var optionTax = $('#hidAddOptionsPayNowTax').val(); var firstName = $('#txtAddOptionsPayNowFirstName'); if (!firstName.val()) { formHasErrors = true; firstName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { firstName.closest('.form-group').removeClass('has-error'); } var lastName = $('#txtAddOptionsPayNowLastName'); if (!lastName.val()) { formHasErrors = true; lastName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { lastName.closest('.form-group').removeClass('has-error'); } var billingAddress1 = $('#txtAddOptionsPayNowBillingAddress1'); var billingAddress2 = $('#txtAddOptionsPayNowBillingAddress2'); if (!billingAddress1.val()) { formHasErrors = true; billingAddress1.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { billingAddress1.closest('.form-group').removeClass('has-error'); } var city = $('#txtAddOptionsPayNowCity'); if (!city.val()) { formHasErrors = true; city.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { city.closest('.form-group').removeClass('has-error'); } var state = $('#ddlAddOptionsPayNowState'); if (!state.val() || state.val() == '-1') { formHasErrors = true; state.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { state.closest('.form-group').removeClass('has-error'); } var zip = $('#txtAddOptionsPayNowZip'); if (!zip.val()) { formHasErrors = true; zip.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { zip.closest('.form-group').removeClass('has-error'); } var cardType = $('#ddlAddOptionsPayNowCardType'); if (!cardType.val() || cardType.val() == '-1') { formHasErrors = true; cardType.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { cardType.closest('.form-group').removeClass('has-error'); } var cardNumber = $('#txtAddOptionsPayNowCardNumber'); if (!cardNumber.val()) { formHasErrors = true; cardNumber.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { cardNumber.closest('.form-group').removeClass('has-error'); } var expirationMonth = $('#txtAddOptionsPayNowExpMonth'); var expirationYear = $('#txtAddOptionsPayNowExpYear'); if (!expirationMonth.val() || !expirationYear.val()) { formHasErrors = true; expirationMonth.closest('.form-group').removeClass('has-success').addClass('has-error'); expirationYear.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { expirationMonth.closest('.form-group').removeClass('has-error'); expirationYear.closest('.form-group').removeClass('has-error'); } //var securityCode = $('#txtAddOptionsPayNowSecurityCode'); //if (!securityCode.val()) { // formHasErrors = true; // securityCode.closest('.form-group').removeClass('has-success').addClass('has-error'); //} else { // securityCode.closest('.form-group').removeClass('has-error'); //} if (!formHasErrors) { // Flip the cursor to progress and disable the 'Submit' button while processing $('body').css({ 'cursor': 'progress' }); $('#btnAddOptionsPayNowSubmit').prop('disabled', true); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ firstName: firstName.val(), lastName: lastName.val(), billingAddress1: billingAddress1.val(), billingAddress2: billingAddress2.val(), city: city.val(), state: state.val(), zip: zip.val(), cardType: cardType.val(), cardNumber: cardNumber.val(), expirationMonth: expirationMonth.val(), expirationYear: expirationYear.val(), warrantyKey: warrantyKey, optionKey: optionKey, optionPrice: optionPrice, optionTax: optionTax }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { NProgress.done(); $('.bs-add-options-pay-now-modal').modal('hide'); toastr.options.onHidden = function () { window.location.href = response.RedirectUrl; }; toastr.success('Thank you! This optional coverage has been paid in full and added to the enrollment.

This page will now refresh.', 'Add Optional Coverage', { timeOut: 2500, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { NProgress.done(); $('body').css({ 'cursor': 'default' }); $('#btnAddOptionsPayNowSubmit').prop('disabled', false); $('.bs-add-options-pay-now-modal').modal('hide'); toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Add Optional Coverage', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { NProgress.done(); $('body').css({ 'cursor': 'default' }); $('#btnAddOptionsPayNowSubmit').prop('disabled', false); $('.bs-add-options-pay-now-modal').modal('hide'); toastr.error('We\'re sorry. An error occurred while adding this optional coverage. Please try again later, or call our Agent Services Department at 800.795.9595 for assistance.', 'Add Optional Coverage', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } else { NProgress.done(); } }); // SERVICE AGREEMENT: Add Optional Coverage - Pay At Closing $document.on('click', '#addOptionPayAtClosing', function () { var url = $(this).data('request-url'); var warrantyKey = $('#hidAddOptionsWarrantyKey').val(); var optionKey = $('#hidAddOptionsOptionKey').val(); var optionPrice = $('#lblAddOptionsPrice').text(); var optionTax = $('#lblAddOptionsTax').text(); // Flip the cursor to progress and disable the 'Submit' button while processing $('body').css({ 'cursor': 'progress' }); $('#addOptionPayAtClosing').prop('disabled', true); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ warrantyKey: warrantyKey, optionKey: optionKey, optionPrice: optionPrice, optionTax: optionTax }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { NProgress.done(); $('.bs-add-options-modal').modal('hide'); toastr.options.onHidden = function () { window.location.href = response.RedirectUrl; }; toastr.success('Thank you! This optional coverage has been successfully added.

This page will now refresh.', 'Add Optional Coverage', { timeOut: 2500, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { NProgress.done(); $('body').css({ 'cursor': 'default' }); $('#addOptionPayAtClosing').prop('disabled', false); $('.bs-add-options-modal').modal('hide'); toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Add Optional Coverage', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { NProgress.done(); $('body').css({ 'cursor': 'default' }); $('#addOptionPayAtClosing').prop('disabled', false); $('.bs-add-options-modal').modal('hide'); toastr.error('We\'re sorry. An error occurred while adding this optional coverage. Please try again later, or call our Agent Services Department at 800.795.9595 for assistance.', 'Add Optional Coverage', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); }); // SERVICE AGREEMENT: Resend Escrow Demand $document.on('click', '#resendConfirmationAndEscrowDemand', function () { var warrantyKey = $('#resendEscrowDemandWarrantyKey').val(); var url = $(this).data('request-url'); var formHasErrors = false; // Validate all required fields var deliveryType = $('#txtResendEscrowDeliveryType'); var companyName = $('#txtResendEscrowCompanyName'); var attention = $('#txtResendEscrowAttention'); var phoneNumber = $('#txtResendEscrowPhoneNumber'); var faxNumber = $('#txtResendEscrowFaxNumber'); var emailAddress = $('#txtResendEscrowEmailAddress'); if (deliveryType.val() == 'Fax') { if (!companyName.val()) { formHasErrors = true; companyName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { companyName.closest('.form-group').removeClass('has-error'); } if (!attention.val()) { formHasErrors = true; attention.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { attention.closest('.form-group').removeClass('has-error'); } if (!phoneNumber.val()) { formHasErrors = true; phoneNumber.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { phoneNumber.closest('.form-group').removeClass('has-error'); } if (!faxNumber.val()) { formHasErrors = true; faxNumber.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { faxNumber.closest('.form-group').removeClass('has-error'); } } else if (deliveryType.val() == 'Email') { if (!companyName.val()) { formHasErrors = true; companyName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { companyName.closest('.form-group').removeClass('has-error'); } if (!attention.val()) { formHasErrors = true; attention.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { attention.closest('.form-group').removeClass('has-error'); } if (!emailAddress.val()) { formHasErrors = true; emailAddress.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if (!regex.test(emailAddress.val())) { formHasErrors = true; emailAddress.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { emailAddress.closest('.form-group').removeClass('has-error'); } } } if (!formHasErrors) { $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ warrantyKey: warrantyKey, deliveryType: deliveryType.val(), companyName: companyName.val(), attention: attention.val(), phoneNumber: phoneNumber.val(), faxNumber: faxNumber.val(), emailAddress: emailAddress.val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { companyName.val(''); attention.val(''); phoneNumber.val(''); faxNumber.val(''); emailAddress.val(''); $('.bs-resend-escrow-demand-modal').modal('hide'); toastr.success('Thank you! A copy of the escrow demand has been resent to your requested recipient.', 'Resend Confirmation Email', { timeOut: 5000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Resend Confirmation Email', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { toastr.error('We\'re sorry. An error occurred while resending copies of the escrow demand. Please try again later, or call our Agent Services Department at 800.795.9595 for assistance.', 'Resend Confirmation Email', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); //// ENROLL: Choose Listing or Closing //$(document).on('click', '#btnEnrollListing', function () { // console.log('getting here'); // NProgress.start(); // var url = $(this).data('request-url') + '?contractType=listing'; // window.location.href = url; //}); //$document.on('click', '#btnEnrollClosing', function () { // NProgress.start(); // var url = $(this).data('request-url') + '?contractType=closing'; // window.location.href = url; //}); // ENROLL: Disable double-click on QAS Picklist - it causes different anchor to be selected $('.addressLookupItem').click(function () { $('.addressLookupItem').click(function (e) { e.preventDefault(); }); }); // ENROLL: Handle Verified Address from QAS Picklist $(document).on('click', '.addressLookupItem', function () { // Hide the modal, since they've selected $('.bs-enroll-choose-address-modal').modal('hide'); var selectedAddressFull = $(this).text(); var selectedAddressArray = selectedAddressFull.split(','); var cityStateArray = []; var zipCode = ''; var state = ''; var city = ''; var streetAddress2 = ''; var streetAddress1 = ''; // First, parse the address string that the user selected if (selectedAddressArray.length == 2) { // Only an AddressLine1 - first, parse out the five digit zip code zipCode = selectedAddressArray[1].substr(selectedAddressArray[1].length - 10); zipCode = zipCode.substr(0, 5); // Next, parse out the city and state selectedAddressArray[1] = selectedAddressArray[1].substr(0, selectedAddressArray[1].length - 10); city = selectedAddressArray[1].trim().substr(0, selectedAddressArray[1].trim().length - 2).trim(); state = selectedAddressArray[1].trim().substr(selectedAddressArray[1].trim().length - 2).trim(); // Finally, parse out the street address streetAddress1 = selectedAddressArray[0].trim(); } else if (selectedAddressArray.length == 3) { // There's an AddressLine2 field - first, parse out the five digit zip code zipCode = selectedAddressArray[2].substr(selectedAddressArray[2].length - 10); zipCode = zipCode.substr(0, 5); // Next, parse out the city and state selectedAddressArray[2] = selectedAddressArray[2].substr(0, selectedAddressArray[2].length - 10); city = selectedAddressArray[2].trim().substr(0, selectedAddressArray[2].trim().length - 2).trim(); state = selectedAddressArray[2].trim().substr(selectedAddressArray[2].trim().length - 2).trim(); // Parse out the street address 2 streetAddress2 = selectedAddressArray[1].trim(); // Finally, parse out the street address 1 streetAddress1 = selectedAddressArray[0].trim(); } // Finally, pump the values back into the form and notify the user $('#txtEnrollStreetAddress1').val(streetAddress1); $('#txtEnrollStreetAddress2').val(streetAddress2); $('#txtEnrollCity').val(city); $('#txtEnrollState').val(state); $('#txtEnrollZip').val(zipCode); toastr.success('Address verified!', 'Lookup Address', { timeOut: 5000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); viewModel.SetVerifiedAddress(); }); // ENROLL: Save New Construction Effective Term $document.on('click', '#btnSaveNewHomeTerm', function () { var formHasErrors = false; var newConstructionTerm; var chkNewConstructionYearsOneThroughThree = $('#chkNewConstructionYearsOneThroughThree'); var chkNewConstructionYearsTwoThroughFour = $('#chkNewConstructionYearsTwoThroughFour'); if (!chkNewConstructionYearsOneThroughThree.is(':checked') && !chkNewConstructionYearsTwoThroughFour.is(':checked')) { formHasErrors = true; chkNewConstructionYearsOneThroughThree.closest('.form-group').removeClass('has-success').addClass('has-error'); chkNewConstructionYearsTwoThroughFour.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { chkNewConstructionYearsOneThroughThree.closest('.form-group').removeClass('has-error'); chkNewConstructionYearsTwoThroughFour.closest('.form-group').removeClass('has-error'); if (chkNewConstructionYearsOneThroughThree.is(':checked')) newConstructionTerm = '1-3'; else newConstructionTerm = '2-4'; } if (!formHasErrors) { var url = $(this).data('request-url'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ newConstructionTerm: newConstructionTerm }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { chkNewConstructionYearsOneThroughThree.prop('checked', false); chkNewConstructionYearsTwoThroughFour.prop('checked', false); $('.bs-enroll-new-home-term-modal').modal('hide'); } }); } }); // ENROLL: Save Corresponding Agent Information $document.on('click', '#btnSaveCorrespondingAgent', function () { var formHasErrors = false; var firstName = $('#txtCorrespondingAgentFirstName'); if (!firstName.val()) { formHasErrors = true; firstName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { firstName.closest('.form-group').removeClass('has-error'); } var lastName = $('#txtCorrespondingAgentLastName'); if (!lastName.val()) { formHasErrors = true; lastName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { lastName.closest('.form-group').removeClass('has-error'); } var officeName = $('#txtCorrespondingAgentCompany'); if (!officeName.val()) { formHasErrors = true; officeName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { officeName.closest('.form-group').removeClass('has-error'); } var agentPhone = $('#txtCorrespondingAgentPhone'); if (!agentPhone.val()) { formHasErrors = true; agentPhone.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { agentPhone.closest('.form-group').removeClass('has-error'); } var agentEmailAddress = $('#txtCorrespondingAgentEmail'); if (!agentEmailAddress.val()) { formHasErrors = true; agentEmailAddress.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { agentEmailAddress.closest('.form-group').removeClass('has-error'); } if (!formHasErrors) { var url = $(this).data('request-url'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ agentFirstName: firstName.val(), agentLastName: lastName.val(), officeName: officeName.val(), agentPhone: agentPhone.val(), agentEmailAddress: agentEmailAddress.val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { firstName.val(''); lastName.val(''); agentPhone.val(''); officeName.val(''); agentEmailAddress.val(''); $('.bs-corresponding-agent-modal').modal('hide'); if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { toastr.success('Cooperating agent details saved. Thank you!', 'Enroll Service Agreement', { timeOut: 3000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { toastr.error(response.ErrorMessage + '

You may still proceed with your new service agreement enrollment.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { $('.bs-corresponding-agent-modal').modal('hide'); toastr.error('We\'re sorry. An error occurred while saving cooperating agent information. You may still proceed with your new service agreement enrollment.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // ENROLL: Save Corresondence Address $document.on('click', '#btnSaveCorrespondenceAddress', function () { var formHasErrors = false; var country = $('#ddlCorrespondenceCountry'); if (!country.val() || country.val() == '-Select-') { formHasErrors = true; country.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { country.closest('.form-group').removeClass('has-error'); } var street1 = $('#txtCorrespondenceStreet1'); if (!street1.val()) { formHasErrors = true; street1.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { street1.closest('.form-group').removeClass('has-error'); } var street2 = $('#txtCorrespondenceStreet2'); var city = $('#txtCorrespondenceCity'); if (!city.val()) { formHasErrors = true; city.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { city.closest('.form-group').removeClass('has-error'); } var state = $('#txtCorrespondenceState'); if (!state.val()) { formHasErrors = true; state.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { state.closest('.form-group').removeClass('has-error'); } var zip = $('#txtCorrespondenceZip'); if (!zip.val()) { formHasErrors = true; zip.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { zip.closest('.form-group').removeClass('has-error'); } if (!formHasErrors) { var url = $(this).data('request-url'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ country: country.val(), street1: street1.val(), street2: street2.val(), city: city.val(), state: state.val(), zip: zip.val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { country.val(''); street1.val(''); street2.val(''); city.val(''); state.val(''); zip.val(''); if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { $('.bs-enter-correspondence-address-modal').modal('hide'); toastr.success('Correspondence address saved. Thank you!', 'Enroll Service Agreement', { timeOut: 3000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { $('.bs-enter-correspondence-address-modal').modal('hide'); toastr.error(response.ErrorMessage + '

You may still proceed with your new service agreement enrollment.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { $('.bs-enter-correspondence-address-modal').modal('hide'); toastr.error('We\'re sorry. An error occurred while saving the correspondence address. You may still proceed with your new service agreement enrollment.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // ENROLL: Pay Now $document.on('click', '#btnPayNowSubmit', function () { var formHasErrors = false; var firstName = $('#txtPayNowFirstName'); if (!firstName.val()) { formHasErrors = true; firstName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { firstName.closest('.form-group').removeClass('has-error'); } var lastName = $('#txtPayNowLastName'); if (!lastName.val()) { formHasErrors = true; lastName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { lastName.closest('.form-group').removeClass('has-error'); } var billingAddress1 = $('#txtPayNowBillingAddress1'); var billingAddress2 = $('#txtPayNowBillingAddress2'); if (!billingAddress1.val()) { formHasErrors = true; billingAddress1.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { billingAddress1.closest('.form-group').removeClass('has-error'); } var city = $('#txtPayNowCity'); if (!city.val()) { formHasErrors = true; city.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { city.closest('.form-group').removeClass('has-error'); } var state = $('#ddlPayNowState'); if (!state.val() || state.val() == '-1') { formHasErrors = true; state.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { state.closest('.form-group').removeClass('has-error'); } var zip = $('#txtPayNowZip'); if (!zip.val()) { formHasErrors = true; zip.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { zip.closest('.form-group').removeClass('has-error'); } var cardType = $('#ddlPayNowCardType'); if (!cardType.val() || cardType.val() == '-1') { formHasErrors = true; cardType.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { cardType.closest('.form-group').removeClass('has-error'); } var cardNumber = $('#txtPayNowCardNumber'); if (!cardNumber.val()) { formHasErrors = true; cardNumber.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { cardNumber.closest('.form-group').removeClass('has-error'); } var expirationMonth = $('#txtPayNowExpMonth'); var expirationYear = $('#txtPayNowExpYear'); if (!expirationMonth.val() || !expirationYear.val()) { formHasErrors = true; expirationMonth.closest('.form-group').removeClass('has-success').addClass('has-error'); expirationYear.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { expirationMonth.closest('.form-group').removeClass('has-error'); expirationYear.closest('.form-group').removeClass('has-error'); } //var securityCode = $('#txtPayNowSecurityCode'); //if (!securityCode.val()) { // formHasErrors = true; // securityCode.closest('.form-group').removeClass('has-success').addClass('has-error'); //} else { // securityCode.closest('.form-group').removeClass('has-error'); //} if (!formHasErrors) { // Flip the cursor to progress and disable the 'Submit' button while processing $('body').css({ 'cursor': 'progress' }); $('#btnPayNowSubmit').prop('disabled', true); viewModel.SubmitPayNow(firstName.val(), lastName.val(), billingAddress1.val(), billingAddress2.val(), city.val(), state.val(), zip.val(), cardType.val(), cardNumber.val(), expirationMonth.val(), expirationYear.val()); } }); // ENROLL: Pay At Closing - Load Title Companies $("#ddlPayClosingSendCopyBy").change(function () { if ($('#ddlPayClosingSendCopyBy').val() == 'Fax Number' || $('#ddlPayClosingSendCopyBy').val() == 'Email Address') { $("#ddlPayClosingSendCopyBy").closest('.form-group').removeClass('has-error'); $('#lblPayClosingFaxEmail').text($('#ddlPayClosingSendCopyBy').val()) var url = $('#lnkPayClosingCompaniesUrl').attr('href'); // Go out and get the current agent's associated Title Companies $.ajax({ type: 'POST', url: url, cache: false, dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { $('#ddlPayClosingTitleCompanies').children().remove(); // Load up the dropdown list with the agent's title companies var json = $.parseJSON(response.Data); var titleCompanyListItems = ''; $.each(json, function (key, value) { titleCompanyListItems += ''; }); $('#ddlPayClosingTitleCompanies').append(titleCompanyListItems); $('#ddlPayClosingTitleCompanies').prop('disabled', false); $('#ddlPayClosingAttention').prop('disabled', true); $('#ddlPayClosingFaxEmail').prop('disabled', true); $('#btnPayClosingAddNewContact').prop('disabled', true); $('#btnPayClosingAddNewFaxEmail').prop('disabled', true); $('#btnPayClosingSubmit').prop('disabled', true); $('#divPayClosingTitleCompanyFields').show(); } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { toastr.error('We\'re sorry. An error occurred while gathering title company information. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } else if ($('#ddlPayClosingSendCopyBy').val() == 'None') { $("#ddlPayClosingSendCopyBy").closest('.form-group').removeClass('has-error'); $('#divPayClosingTitleCompanyFields').hide(); $('#btnPayClosingSubmit').prop('disabled', false); } }); // ENROLL: Pay At Closing - Load Title Company Contacts $("#ddlPayClosingTitleCompanies").change(function () { if ($("#ddlPayClosingTitleCompanies").val() == '-1') return; var url = $('#lnkPayClosingContactsUrl').attr('href'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ titleCompanyKey: $("#ddlPayClosingTitleCompanies").val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { $('#ddlPayClosingAttention').children().remove(); // Load up the dropdown list with the agent's title companies var json = $.parseJSON(response.Data); var titleCompanyContactListItems = ''; $.each(json, function (key, value) { titleCompanyContactListItems += ''; }); $('#ddlPayClosingAttention').append(titleCompanyContactListItems); $('#ddlPayClosingAttention').prop('disabled', false); $('#btnPayClosingAddNewContact').prop('disabled', false); $('#btnPayClosingSubmit').prop('disabled', true); } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { toastr.error('We\'re sorry. An error occurred while gathering title company information. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); }); // ENROLL: Pay At Closing - Load Title Company Contact Fax/Email $("#ddlPayClosingAttention").change(function () { if ($("#ddlPayClosingAttention").val() == '-1') return; var url = $('#lnkPayClosingFaxEmailUrl').attr('href'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ titleCompanyKey: $("#ddlPayClosingTitleCompanies").val(), titleCompanyContactKey: $("#ddlPayClosingAttention").val(), faxOrEmail: $('#ddlPayClosingSendCopyBy').val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { $('#ddlPayClosingFaxEmail').children().remove(); // Load up the dropdown list with the agent's title companies var json = $.parseJSON(response.Data); var titleCompanyContactFaxEmailListItems = ''; $.each(json, function (key, value) { titleCompanyContactFaxEmailListItems += ''; }); $('#ddlPayClosingFaxEmail').append(titleCompanyContactFaxEmailListItems); $('#ddlPayClosingFaxEmail').prop('disabled', false); $('#btnPayClosingAddNewFaxEmail').prop('disabled', false); $('#btnPayClosingSubmit').prop('disabled', true); } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { toastr.error('We\'re sorry. An error occurred while gathering title company information. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); }); // ENROLL: Pay At Closing - Save Title Company details $("#ddlPayClosingFaxEmail").change(function () { if ($("#ddlPayClosingFaxEmail").val() == '-1') return; // Enable the main 'Submit' button, now that our form is completed $('#btnPayClosingSubmit').prop('disabled', false); var url = $('#lnkAddSelectedTitleCompanyToSession').attr('href'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ titleCompanyKey: $("#ddlPayClosingTitleCompanies").val(), titleCompanyContactKey: $("#ddlPayClosingAttention").val(), titleCompanyContactFaxEmail: $('#ddlPayClosingFaxEmail').val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { toastr.error('We\'re sorry. An error occurred while gathering title company information. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); }); // ENROLL: Pay At Closing - Display Add New Title Company Modal $document.on('click', '#btnPayClosingAddNewTitleCompany', function () { $('.bs-pay-closing-add-company-modal').modal('show'); }); // ENROLL: Pay At Closing - Save New Title Company $document.on('click', '#btnPayClosingAddCompany', function () { var formHasErrors = false; var companyName = $('#txtPayClosingAddCompanyName'); if (!companyName.val()) { formHasErrors = true; companyName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { companyName.closest('.form-group').removeClass('has-error'); } var companyFax = $('#txtPayClosingAddCompanyFax'); if (!formHasErrors) { var url = $('#lnkSaveNewTitleCompany').attr('href'); $('body').css('cursor', 'progress'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ titleCompanyName: companyName.val(), titleCompanyFax: companyFax.val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { $('body').css('cursor', 'auto'); if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { // Reload the title company list with our newly added title company $('#ddlPayClosingTitleCompanies').children().remove(); var json = $.parseJSON(response.Data); var titleCompanyListItems = ''; $.each(json, function (key, value) { titleCompanyListItems += ''; }); $('#ddlPayClosingTitleCompanies').append(titleCompanyListItems); $('#ddlPayClosingTitleCompanies').prop('disabled', false); $('#ddlPayClosingAttention').prop('disabled', true); $('#ddlPayClosingFaxEmail').prop('disabled', true); $('#btnPayClosingAddNewContact').prop('disabled', true); $('#btnPayClosingAddNewFaxEmail').prop('disabled', true); toastr.success('New title company successfully saved.', 'Enroll Service Agreement', { timeOut: 5000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); $('.bs-pay-closing-add-company-modal').modal('hide'); } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { $('body').css('cursor', 'auto'); toastr.error('We\'re sorry. An error occurred while saving title company information. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // ENROLL: Pay At Closing - Display Add New Title Company Contact Modal $document.on('click', '#btnPayClosingAddNewContact', function () { $('#txtPayClosingAddContactName').closest('.form-group').removeClass('has-error'); $('.bs-pay-closing-add-contact-modal').modal('show'); }); // ENROLL: Pay At Closing - Save New Title Company Contact $document.on('click', '#btnPayClosingAddContact', function () { var formHasErrors = false; var contactName = $('#txtPayClosingAddContactName'); if (!contactName.val()) { formHasErrors = true; contactName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { contactName.closest('.form-group').removeClass('has-error'); } var titleCompany = $("#ddlPayClosingTitleCompanies"); var contactPhone = $('#txtPayClosingAddContactPhone'); var contactEmail = $('#txtPayClosingAddContactEmail'); if (!formHasErrors) { var url = $('#lnkSaveNewTitleCompanyContact').attr('href'); $('body').css('cursor', 'progress'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ titleCompanyKey: titleCompany.val(), contactName: contactName.val(), contactPhone: contactPhone.val(), contactEmail: contactEmail.val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { $('body').css('cursor', 'auto'); if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { // Reload the contact list with our newly added title company $('#ddlPayClosingAttention').children().remove(); var json = $.parseJSON(response.Data); var titleCompanyContactListItems = ''; $.each(json, function (key, value) { titleCompanyContactListItems += ''; }); $('#ddlPayClosingAttention').append(titleCompanyContactListItems); $('#ddlPayClosingAttention').prop('disabled', false); $('#btnPayClosingAddNewContact').prop('disabled', false); toastr.success('New contact successfully saved.', 'Enroll Service Agreement', { timeOut: 5000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); $('.bs-pay-closing-add-contact-modal').modal('hide'); } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { $('body').css('cursor', 'auto'); toastr.error('We\'re sorry. An error occurred while saving title company information. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // ENROLL: Pay At Closing - Display Add New Title Company Contact Fax/Email Modal $document.on('click', '#btnPayClosingAddNewFaxEmail', function () { if ($('#ddlPayClosingSendCopyBy').val() == 'Fax Number') { $('#divAddContactFax').show(); $('#divAddContactEmail').hide(); } else if ($('#ddlPayClosingSendCopyBy').val() == 'Email Address') { $('#divAddContactEmail').show(); $('#divAddContactFax').hide(); } $('.bs-pay-closing-add-fax-email-modal').modal('show'); }); // ENROLL: Pay At Closing - Save New Title Company Contact Fax/Email $document.on('click', '#btnPayClosingAddContactFaxEmail', function () { var formHasErrors = false; var faxOrEmail = $('#ddlPayClosingSendCopyBy').val(); var faxNumberEmailAddress; if ($('#ddlPayClosingSendCopyBy').val() == 'Fax Number') { var faxNumber = $('#txtPayClosingAddContactNewFax'); if (!faxNumber.val()) { formHasErrors = true; faxNumber.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { faxNumber.closest('.form-group').removeClass('has-error'); faxNumberEmailAddress = faxNumber.val(); } } else if ($('#ddlPayClosingSendCopyBy').val() == 'Email Address') { var emailAddress = $('#txtPayClosingAddContactNewEmail'); if (!emailAddress.val()) { formHasErrors = true; emailAddress.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { emailAddress.closest('.form-group').removeClass('has-error'); faxNumberEmailAddress = emailAddress.val(); } } var titleCompany = $("#ddlPayClosingTitleCompanies"); var titleCompanyContact = $("#ddlPayClosingAttention"); if (!formHasErrors) { var url = $('#lnkSaveNewTitleCompanyContactFaxEmail').attr('href'); $('body').css('cursor', 'progress'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ titleCompanyKey: titleCompany.val(), titleCompanyContactKey: titleCompanyContact.val(), faxOrEmail: faxOrEmail, faxNumberEmailAddress: faxNumberEmailAddress }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { $('body').css('cursor', 'auto'); if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { // Reload the fax/email list with our newly added fax/email $('#ddlPayClosingFaxEmail').children().remove(); var json = $.parseJSON(response.Data); var titleCompanyContactFaxEmailListItems = ''; $.each(json, function (key, value) { titleCompanyContactFaxEmailListItems += ''; }); $('#ddlPayClosingFaxEmail').append(titleCompanyContactFaxEmailListItems); $('#ddlPayClosingFaxEmail').prop('disabled', false); $('#btnPayClosingAddNewFaxEmail').prop('disabled', false); toastr.success('New fax/email successfully saved.', 'Enroll Service Agreement', { timeOut: 5000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); $('.bs-pay-closing-add-fax-email-modal').modal('hide'); } else { toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { $('body').css('cursor', 'auto'); toastr.error('We\'re sorry. An error occurred while saving title company information. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Enroll Service Agreement', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // ENROLL: Pay At Closing $document.on('click', '#btnPayClosingSubmit', function () { // Make sure the user has selected a delivery method var sendCopyBy = $("#ddlPayClosingSendCopyBy"); if (sendCopyBy.val() == '-1') { NProgress.done(); sendCopyBy.closest('.form-group').removeClass('has-success').addClass('has-error'); return; } else { sendCopyBy.closest('.form-group').removeClass('has-error'); } var method = $('#ddlPayClosingSendCopyBy').val(); var companyName = $("#ddlPayClosingTitleCompanies option:selected").text(); var attention = $("#ddlPayClosingAttention option:selected").text(); var faxEmail = $('#ddlPayClosingFaxEmail').val(); var notes = $('#txtPayClosingNotes').val(); // Flip the cursor to progress and disable the 'Submit' button while processing $('body').css({ 'cursor': 'progress' }); $('#btnPayNowSubmit').prop('disabled', true); viewModel.SubmitPayAtClosing(method, companyName, attention, faxEmail, notes); }); // ENROLL: Switch to Supreme coverage $(document).on('click', '.switchSupremeCoverage', function () { $("input:radio").each(function () { // Select the highest priority Supreme product and return if ($(this).siblings("input[name='hidProductDisplayName']").val().toLowerCase().indexOf('supreme') >= 0) { $(this).prop("checked", true).trigger("click"); return false; } }); }); // ADMIN TOOLS: Set Super User Agent $document.on('click', '#btnSetSuperUserAgent', function () { var url = $(this).data('request-url'); NProgress.start(); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ agentRelationKey: $('#hidSuperUserAgentRelationKey').val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { $('.bs-super-user-notification-modal').modal('hide'); window.location.href = response.RedirectUrl; } else { NProgress.done(); $('.bs-super-user-notification-modal').modal('hide'); toastr.error(response.ErrorMessage + '

Please click Chat Now or call our Agent Services Department at 800.795.9595 for assistance.', 'Super User', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { NProgress.done(); $('.bs-super-user-notification-modal').modal('hide'); toastr.error('We\'re sorry. An error occurred while setting your Super User agent. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Super User', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); }); // ADMIN TOOLS: End Super User Session $document.on('click', '#btnEndSuperUserSession', function () { var url = $(this).data('request-url'); NProgress.start(); $.ajax({ type: 'POST', url: url, cache: false, dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { $('.bs-end-super-user-session-modal').modal('hide'); window.location.href = response.RedirectUrl; } else { NProgress.done(); $('.bs-end-super-user-session-modal').modal('hide'); toastr.error(response.ErrorMessage, 'Super User', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { NProgress.done(); $('.bs-end-super-user-session-modal').modal('hide'); toastr.error('We\'re sorry. An error occurred while saving title company information. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Super User', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); }); // EXPRESS PROTECTION: Enroll Express Listings $document.on('click', '#enrollExpressProtection', function () { var batchListingKey = $('#hidBatchListingKey').val(); var url = $(this).data('request-url'); var formHasErrors = false; // Validate all required fields var homeownerFirstName = $('#txtExpressHomeownerFirstName'); var homeownerLastName = $('#txtExpressHomeownerLastName'); var homeownerEmail = $('#txtExpressHomeownerEmail'); var sellerCommitted = $('#chkExpressSellerCommitted'); var buyerCommitted = $('#chkExpressBuyerCommitted'); var agentCommitted = $('#chkExpressAgentCommitted'); var includeSellerAcHeatPumpOption; var sellerAcHeatPumpCheckbox = $('#chkIncludeSellerAcHeatPumpOption'); if (sellerAcHeatPumpCheckbox && sellerAcHeatPumpCheckbox.is(':checked')) includeSellerAcHeatPumpOption = true; else includeSellerAcHeatPumpOption = false; if (!homeownerFirstName.val()) { formHasErrors = true; homeownerFirstName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { homeownerFirstName.closest('.form-group').removeClass('has-error'); } if (!homeownerLastName.val()) { formHasErrors = true; homeownerLastName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { homeownerLastName.closest('.form-group').removeClass('has-error'); } if (homeownerEmail.val()) { var expressEmailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if (!expressEmailRegex.test(homeownerEmail.val())) { formHasErrors = true; homeownerEmail.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { homeownerEmail.closest('.form-group').removeClass('has-error'); } } // Make sure user selects at least one and a maximum of two if ((!sellerCommitted.is(':checked') && !buyerCommitted.is(':checked') && !agentCommitted.is(':checked')) || (sellerCommitted.is(':checked') && buyerCommitted.is(':checked') && agentCommitted.is(':checked'))) { formHasErrors = true; sellerCommitted.closest('.form-group').removeClass('has-success').addClass('has-error'); buyerCommitted.closest('.form-group').removeClass('has-success').addClass('has-error'); agentCommitted.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { sellerCommitted.closest('.form-group').removeClass('has-error'); buyerCommitted.closest('.form-group').removeClass('has-error'); agentCommitted.closest('.form-group').removeClass('has-error'); } if (!formHasErrors) { NProgress.start(); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ batchListingKey: batchListingKey, homeownerFirstName: homeownerFirstName.val(), homeownerLastName: homeownerLastName.val(), homeownerEmail: homeownerEmail.val(), includeSellerAcHeatPumpOption: includeSellerAcHeatPumpOption }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { NProgress.done(); homeownerFirstName.val(''); homeownerLastName.val(''); sellerCommitted.prop('checked', false); buyerCommitted.prop('checked', false); agentCommitted.prop('checked', false); $('.bs-express-protection-enroll-modal-md').modal('hide'); // Notify the user and reload the Express Protection page toastr.options.onHidden = function () { window.location.href = response.RedirectUrl; }; toastr.success('Thank you! This listing is now protected.', 'Express Protection', { timeOut: 2500, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { NProgress.done(); toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Express Protection', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { NProgress.done(); toastr.error('We\'re sorry. An error occurred while enrolling Express Protection. Please try again later, or call our Agent Services Department at 800.795.9595 for assistance.', 'Express Protection', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // EXPRESS PROTECTION: Decline Coverage (Deactive Batch Listing) $document.on('click', '#deactivateExpressListing', function () { var batchListingKey = $('#hidDeactivateBatchListingKey').val(); var url = $(this).data('request-url'); NProgress.start(); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ batchListingKey: batchListingKey }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { NProgress.done(); $('.bs-express-protection-decline-coverage-modal-md').modal('hide'); // Notify the user and reload the Express Protection page toastr.options.onHidden = function () { window.location.reload(true); }; toastr.success('Decline successful.', 'Express Protection', { timeOut: 1000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } else { NProgress.done(); toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'Express Protection', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { NProgress.done(); toastr.error('We\'re sorry. An error occurred while declining Express Protection. Please try again later, or call our Agent Services Department at 800.795.9595 for assistance.', 'Express Protection', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); }); // HVAC Certification: Schedule Appointment $document.on('click', '#scheduleHvacCertification', function () { var formHasErrors = false; var url = $(this).data('request-url'); var warrantyKey = $('#hidHvacModalWarrantyKey'); var scheduledContractor = $('#lblHvacScheduledContractor'); var otherContractorSelected = $('#ddlHvacOtherContractors'); var contactFirstName = $('#txtHvacContactFirstName'); if (!contactFirstName.val()) { formHasErrors = true; contactFirstName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { contactFirstName.closest('.form-group').removeClass('has-error'); } var contactLastName = $('#txtHvacContactLastName'); if (!contactLastName.val()) { formHasErrors = true; contactLastName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { contactLastName.closest('.form-group').removeClass('has-error'); } var contactPhone = $('#txtHvacContactPhone'); if (!contactPhone.val()) { formHasErrors = true; contactPhone.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { contactPhone.closest('.form-group').removeClass('has-error'); } var contactEmail = $('#txtHvacContactEmail'); if (!contactEmail.val()) { formHasErrors = true; contactEmail.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { contactEmail.closest('.form-group').removeClass('has-error'); } var inspectionCompletionDate = $('#txtHvacInspectionCompletionDate'); if (!inspectionCompletionDate.val()) { formHasErrors = true; inspectionCompletionDate.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { inspectionCompletionDate.closest('.form-group').removeClass('has-error'); } if (!formHasErrors) { NProgress.start(); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ warrantyKey: warrantyKey.val(), scheduledContractor: scheduledContractor.text(), otherContractorSelected: otherContractorSelected.val(), contactFirstName: contactFirstName.val(), contactLastName: contactLastName.val(), contactPhone: contactPhone.val(), contactEmail: contactEmail.val(), inspectionCompletionDate: inspectionCompletionDate.val() }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response != null) { if (response.IsSuccess != null && response.IsSuccess) { NProgress.done(); $('#chkOrderHvacCertification').attr('disabled', true); toastr.success('Thank you! This HVAC Certification has been successfully scheduled.

The contractor will be notified of this request within one business day.', 'HVAC Certification', { timeOut: 5000, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); $('.bs-hvac-certification-schedule-modal-md').modal('hide'); } else { NProgress.done(); toastr.error(response.ErrorMessage + '

Please call our Agent Services Department at 800.795.9595 for assistance.', 'HVAC Certification', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } } }, error: function (jqXHR, textStatus, errorThrown) { NProgress.done(); toastr.error('We\'re sorry. An error occurred while scheduling this HVAC Certification. Please call our Agent Services Department at 800.795.9595 for assistance.', 'HVAC Certification', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); // HVAC Certification: Cancel $document.on('click', '.cancelHvacCertification', function () { $('#chkOrderHvacCertification').attr('checked', false); }); // Buyer Email for Payment $document.on('click', '#btnSendBuyerEmailSubmit', function () { var formHasErrors = false; var buyerEmailHomeownerFirstName = $('#txtBuyerPaymentHomeownerFirstName'); var buyerEmailHomeownerLastName = $('#txtBuyerPaymentHomeownerLastName'); var buyerEmailAddressField = $('#txtBuyerPaymentEmailAddress'); var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if (!buyerEmailHomeownerFirstName.val()) { formHasErrors = true; buyerEmailHomeownerFirstName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { buyerEmailHomeownerFirstName.closest('.form-group').removeClass('has-error'); } if (!buyerEmailHomeownerLastName.val()) { formHasErrors = true; buyerEmailHomeownerLastName.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { buyerEmailHomeownerLastName.closest('.form-group').removeClass('has-error'); } if (!buyerEmailAddressField.val() || !regex.test(buyerEmailAddressField.val())) { formHasErrors = true; buyerEmailAddressField.closest('.form-group').removeClass('has-success').addClass('has-error'); } else { buyerEmailAddressField.closest('.form-group').removeClass('has-error'); } var buyerPaymentHomeownerName = buyerEmailHomeownerFirstName.val() + ' ' + buyerEmailHomeownerLastName.val(); var buyerPaymentHomeownerEmail = buyerEmailAddressField.val(); var saveOnlyDeliveryDetailsIndc = $('#hidOnlySaveDeliveryDetailsIndc').val(); var warrantyKey = $('#hidWarrantyKeyVal').val(); var sourceName = $('#hidSource').val(); if (!formHasErrors) { if (saveOnlyDeliveryDetailsIndc == "Y") { if (sourceName == "ServiceAgreement") { serviceAgreementViewModel.SubmitDeliveryDetailsBuyerPayment(buyerEmailHomeownerFirstName.val(), buyerEmailHomeownerLastName.val(), buyerPaymentHomeownerEmail, warrantyKey); } else if (sourceName == "Confirmation") { viewModel.SubmitDeliveryDetailsBuyerPayment(buyerEmailHomeownerFirstName.val(), buyerEmailHomeownerLastName.val(), buyerPaymentHomeownerEmail, warrantyKey); } } else if (saveOnlyDeliveryDetailsIndc == "N") { viewModel.SubmitEmailBuyerPayment(buyerEmailHomeownerFirstName.val(), buyerEmailHomeownerLastName.val(), buyerPaymentHomeownerEmail); } } }); // ASURION HOME+: Email Customer Offer $document.on('click', '#btnEmailOffer', function () { var formHasErrors = false; var asurionEmailOfferHomeownerFirstName = $('#txtAsurionEmailOfferHomeownerFirstName'); var asurionEmailOfferHomeownerLastName = $('#txtAsurionEmailOfferHomeownerLastName'); var emailAddressField = $('#txtAsurionEmailOfferEmailAddress'); var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if (!asurionEmailOfferHomeownerFirstName.val() || !asurionEmailOfferHomeownerLastName.val() || !emailAddressField.val() || !regex.test(emailAddressField.val())) { $('#verifyAsurionEmailOfferDetailsError').show(); formHasErrors = true; } else { $('#verifyAsurionEmailOfferDetailsError').hide(); } var agentEmailAddress = $('#hiddenAgentEmailAddress').val(); var agentRelationKey = $('#hiddenAgentKey').val(); var agentKey = ""; if (agentEmailAddress) { agentKey = agentEmailAddress; } else if (agentRelationKey) { agentKey = agentRelationKey; } var warrantyKeyValue = $('#hiddenWarrantyKeyValue').val(); if (warrantyKeyValue) { warrantyKey = warrantyKeyValue; } else { warrantyKey = null; } if (!formHasErrors) { var url = $(this).data('request-url'); $.ajax({ type: 'POST', url: url, cache: false, data: JSON.stringify({ asurionEmailFirstName: asurionEmailOfferHomeownerFirstName.val(), asurionEmailLastName: asurionEmailOfferHomeownerLastName.val(), asurionEmailAddress: emailAddressField.val(), agentKey: agentKey, warrantyKey: warrantyKey }), dataType: 'json', contentType: 'application/json; charset=utf-8', success: function (response) { if (response == true) { //If success $('.bs-email-special-offer-asurion-type-modal').modal('hide'); asurionEmailOfferHomeownerFirstName.val(''); asurionEmailOfferHomeownerLastName.val(''); emailAddressField.val(''); $('#hiddenAgentEmailAddress').val(''); $('#hiddenAgentKey').val(''); $('#hiddenWarrantyKeyValue').val(''); } else { toastr.error('We\'re sorry. An error occurred while trying to send an email. Please call our Agent Services Department at 800.795.9595 for assistance.', 'Asurion Home+', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }, error: function (jqXHR, textStatus, errorThrown) { // Code if failure toastr.error('We\'re sorry. An error occurred while trying to send an email. Please call our Agent Services Department at 800.795.9595 for assistance.', 'AsurionHome+', { timeOut: 0, closeButton: true, positionClass: 'toast-bottom-right', progressBar: true }); } }); } }); });