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 });
}
});
}
});
});