jQuery(function ($) { // use $ for jQuery "use strict"; /* Calculator Email Field Display */ $(document).on('click', '.checkflip', function() { if ($(this).is(':checked')) { $(this).closest('.shmac-form').find('.shmac-email').slideDown('fast'); } else { $(this).closest('.shmac-form').find('.shmac-email').slideUp('fast'); } }); /* Process calculator results */ $(document).on('click', '.submit-shmac', function() { var mprogresso; var currentForm = $(this).closest('.shmac-sc').attr('class').split(' ')[2]; // get the current form $('.submit-shmac').prop('disabled', true); /* Progress bar */ mprogresso = new Mprogress({ //start: true, // start it now parent: '.' + currentForm + ' .progresso', template: 3 }); mprogresso.start(); var mailaddress = ''; if ( $(this).closest('.shmac-form').find('.send-email').is(':checked')) { var sendemail = 'true'; mailaddress = $(this).closest('.shmac-form').find('.shmac-email-input').val(); } else { var sendemail = 'false'; } var termcycle = $(this).closest('.shmac-form').data('year_label'); var termType = 'years'; if ( $(this).closest('.shmac-form').find('.term-months').is(':checked')) { termcycle = $(this).closest('.shmac-form').data('month_label'); termType = 'months'; } var amount = $(this).closest('.shmac-form').find('.mort-amount').val(); var interest = $(this).closest('.shmac-form').find('.interest').val(); var downpay = $(this).closest('.shmac-form').find('.downpay').val(); var term = $(this).closest('.shmac-form').find('.term').val(); // Overrides var override = {}; override.enableinsurance = $(this).closest('.shmac-form').data('enableinsurance'); override.insuranceamountpercent = $(this).closest('.shmac-form').data('insuranceamountpercent'); override.monthlyinsurance = $(this).closest('.shmac-form').data('monthlyinsurance'); override.enablepmi = $(this).closest('.shmac-form').data('enablepmi'); override.monthlypmi = $(this).closest('.shmac-form').data('monthlypmi'); override.enabletaxes = $(this).closest('.shmac-form').data('enabletaxes'); override.taxesperthou = $(this).closest('.shmac-form').data('taxesperthou'); override.disclaimer = $(this).closest('.shmac-form').data('disclaimer'); override.currencysymbol = $(this).closest('.shmac-form').data('currencysymbol'); override.currencyside = $(this).closest('.shmac-form').data('currencyside'); override.currencyformat = $(this).closest('.shmac-form').data('currencyformat'); override.downpaytype = $(this).closest('.shmac-form').data('downpaytype'); override.bccemail = $(this).closest('.shmac-form').data('bccemail'); override.fromemail = $(this).closest('.shmac-form').data('fromemail'); override.emailsubject = $(this).closest('.shmac-form').data('emailsubject'); override.emailcontent = $(this).closest('.shmac-form').data('emailcontent'); override.pdfcolor = $(this).closest('.shmac-form').data('pdfcolor'); override.pdflogo = $(this).closest('.shmac-form').data('pdflogo'); override.pdfheader = $(this).closest('.shmac-form').data('pdfheader'); override.downpayshow = $(this).closest('.shmac-form').data('downpayshow'); override.location = $(this).closest('.shmac-form').data('location'); // schedule overrides override.detail_original = $(this).closest('.shmac-form').data('detail_original'); override.detail_down_payment = $(this).closest('.shmac-form').data('detail_down_payment'); override.detail_interest = $(this).closest('.shmac-form').data('detail_interest'); override.detail_term = $(this).closest('.shmac-form').data('detail_term'); override.detail_loan_after_down = $(this).closest('.shmac-form').data('detail_loan_after_down'); override.detail_down_payment_amount = $(this).closest('.shmac-form').data('detail_down_payment_amount'); override.detail_monthly_payment = $(this).closest('.shmac-form').data('detail_monthly_payment'); override.detail_total_payments = $(this).closest('.shmac-form').data('detail_total_payments'); override.header_payment = $(this).closest('.shmac-form').data('header_payment'); override.header_payment_amount = $(this).closest('.shmac-form').data('header_payment_amount'); override.header_interest = $(this).closest('.shmac-form').data('header_interest'); override.header_total_interest = $(this).closest('.shmac-form').data('header_total_interest'); override.header_principal = $(this).closest('.shmac-form').data('header_principal'); override.header_balance = $(this).closest('.shmac-form').data('header_balance'); override.header_loan_text = $(this).closest('.shmac-form').data('header_loan_text'); override.header_schedule_text = $(this).closest('.shmac-form').data('header_schedule_text'); override.otherfactors = $(this).closest('.shmac-form').data('otherfactors'); override.down_factor_1 = $(this).closest('.shmac-form').data('down_factor_1'); override.down_factor_2 = $(this).closest('.shmac-form').data('down_factor_2'); override.tax_factor = $(this).closest('.shmac-form').data('tax_factor'); override.insurance_factor = $(this).closest('.shmac-form').data('insurance_factor'); override.factor_summary = $(this).closest('.shmac-form').data('factor_summary'); override.disclaimer = $(this).closest('.shmac-form').data('disclaimer'); $.post(SHMAC_Ajax.ajaxurl, { action: 'ajax-shmacfrontend', // vars process : 'true', nextNonce : SHMAC_Ajax.nextNonce, sendemail : sendemail, mailaddress: mailaddress, amount : amount, interest : interest, downpay : downpay, termcycle : termcycle, termtype : termType, term : term, override : override }, function(response) { mprogresso.end(); $('.submit-shmac').prop('disabled', false); if (response.error == '1') { // Handle Errors if (response.error_field == 'amount') { $('.' + currentForm).find('.mort-amount').addClass('error-field'); $('.' + currentForm).find('.mort-amount').closest('.mui-form-group').find('.err-msg').text(response.message); } else if (response.error_field == 'interest') { $('.' + currentForm).find('.interest').addClass('error-field'); $('.' + currentForm).find('.interest').closest('.mui-form-group').find('.err-msg').text(response.message); } else if (response.error_field == 'down') { $('.' + currentForm).find('.downpay').addClass('error-field'); $('.' + currentForm).find('.downpay').closest('.mui-form-group').find('.err-msg').text(response.message); } else if (response.error_field == 'term') { $('.' + currentForm).find('.term').addClass('error-field'); $('.' + currentForm).find('.term').closest('.mui-form-group').find('.err-msg').text(response.message); } else if (response.error_field == 'email') { $('.' + currentForm).find('.shmac-email-input').addClass('error-field'); $('.' + currentForm).find('.shmac-email-input').closest('.mui-form-group').find('.err-msg') .text(response.message); } } else { activateModalorDiv(response.payment, response.headers, response.vals, response.details, currentForm, response.location); } }); return false; }); /* Remove error messages and styling on focus */ $(document).on('focus', '.shmac-form input', function() { $(this).removeClass('error-field'); $(this).closest('.mui-form-group').find('.err-msg').text(''); }); /* Hide email field if open on reset along with clearing fields */ $(document).on('click', '.shmac-reset', function() { if ($(this).closest('.shmac-form').find('.shmac-check').is(":visible")) { // only if optional send pdf shown $(this).closest('.shmac-form').find('.shmac-email').slideUp('fast'); } $(this).closest('.shmac-form').find('.term-years').prop('checked', true); $(this).closest('.shmac-form').find('.term-months').prop('checked', false); $(this).closest('.shmac-form').find('input').each( function() { $(this).removeClass('error-field'); $(this).closest('.mui-form-group').find('.err-msg').text(''); }); var currentForm = $(this).closest('.shmac-sc').attr('class').split(' ')[2]; // get the current form var inlineDiv = $('#shmac-inline-' + currentForm); $('.shmac-div.divfrom-' + currentForm).mCustomScrollbar("destroy"); inlineDiv.empty().removeClass().addClass('shmac-inline-form'); //clear it out and reset display form }); /* Term selection Years & Months */ $(document).ready(function() { if ($('.term-years').length) { $('.term-years').prop('checked', true); $('.term-months').prop('checked', false); } else { $('.term-months').prop('checked', true); } }); $(".term-group").each(function() { $(this).change(function() { $(this).closest('.shmac-form').find(".term-group").prop('checked',false); $(this).prop('checked',true); }); }); /* Don't respond to clicks on tooltips */ $(document).on('click', '.shmac-tip', function() { return false; }); /* Results Modal function */ function activateModalorDiv(payment, headers, vals, details, currentForm, location) { // initialize modal element // Details var dpshow1=''; var dpshow2=''; var loanAfterdp=''; if(vals.downpayshow=='yes'){ dpshow1 = '
' + details.original + ': ' + vals.price2 + ' | '
+ dpshow1
+ '' + details.interest + ': ' + vals.interest + ' % | '
+ '' + details.term + ': ' + vals.term + ' ' + vals.cycle_text + ' | '
+ '
' + details.monthly_payment + ': ' + vals.monthly_payment2 + ' | '
+ '' + details.total_payments + ': ' + vals.total_payments + ' | '
+ '
' + vals.otherfactors + '
' + '' + vals.total_monthlies + '
' + ''; } else { tip += ''; } // Schedule if (headers.show_schedule != 'no') { var schedule = '' + headers.payment + ' | ' + headers.payment_amount + ' | ' + headers.principal + ' | ' + headers.interest + ' | ' + headers.total_interest + ' | ' + headers.balance + ' | |
---|---|---|---|---|---|---|
' + v.value + ' | ' + vals.monthly_payment2 + ' | ' + v.principal + ' | ' + v.interest + ' | ' + v.total_interest + ' | ' + v.newMortgage + ' |