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.down_payment + ':
' + vals.down + ' %'; dpshow2 = '' + details.down_payment_amount + ':
' + vals.moneydown2 + ''; loanAfterdp = '' + details.loan_after_down + ':
' + vals.mortgage2 + ''; } var detailsTable = '

' + headers.loan_text + '

' + '' + '' + dpshow1 + '' + '' + '' + '' + loanAfterdp + dpshow2 + '' + '' + '
' + details.original + ':
' + vals.price2 + '
' + details.interest + ':
' + vals.interest + ' %
' + details.term + ':
' + vals.term + ' ' + vals.cycle_text + '
' + details.monthly_payment + ':
' + vals.monthly_payment2 + '
' + details.total_payments + ':
' + vals.total_payments + '
'; // Taxes Insurance & PMI (TIP) var tip = ''; if (vals.enable_insurance == 'yes' || vals.enable_pmi == 'yes' || vals.enable_taxes == 'yes' ) { tip += '

' + vals.otherfactors + '

' + '' + '

' + vals.total_monthlies + '

' + '

'; } else { tip += '

'; } // Schedule if (headers.show_schedule != 'no') { var schedule = '

' + headers.schedule_text + '

' + '' + '' + ''; $.each( payment, function( k, v) { schedule += ''; }); 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 + '
'; } // Disclaimer if (headers.show_disclaimer != 'no') { var disclaimerDiv = '
' + details.disclaimer + '
'; } if (location == 'inline') { var inlineDiv = $('#shmac-inline-' + currentForm); $('.shmac-div.divfrom-' + currentForm).mCustomScrollbar("destroy"); inlineDiv.empty(); //clear it out first $(detailsTable).appendTo(inlineDiv); $(tip).appendTo(inlineDiv); $(schedule).appendTo(inlineDiv); $(disclaimerDiv).appendTo(inlineDiv); $(inlineDiv).css('padding', '0px').css('max-height', '500px'); $(inlineDiv).addClass('shmac-div').addClass('divfrom-' + currentForm); divScroll(currentForm); } else { // modal popup var modalE1 = document.createElement('div'); $(detailsTable).appendTo(modalE1); $(tip).appendTo(modalE1); $(schedule).appendTo(modalE1); $(disclaimerDiv).appendTo(modalE1); $(modalE1).css('padding', '20px').css('width', '75%').css('height', '75%').css('margin', '100px auto'); $(modalE1).css('overflow', 'hidden').addClass('shmac-div').addClass('divfrom-' + currentForm); // show modal mui.overlay('on', modalE1); modalScroll(); } } /* load scrollbar inline */ function divScroll(currentForm) { $('.shmac-div.divfrom-' + currentForm).mCustomScrollbar({ live: "on", theme: 'minimal-dark', advanced: { updateOnContentResize: true, }, callbacks: { onInit: function() { $('.shmac-div.divfrom-' + currentForm).css('overflow','auto'); // set overflow auto after init to avoid normal scroll from appearing $('.shmac-div.divfrom-' + currentForm + ' .disclaimer').css('margin-bottom', '0px'); $('.shmac-div.divfrom-' + currentForm + ' .disclaimer').css('margin-bottom', '20px'); var firstRow = $('.shmac-div-' + currentForm + ' .schedule-table tr').eq(1).clone(); var lastRow = $('.shmac-div-' + currentForm + ' .schedule-table tr:last').clone(); $('
') .appendTo('.shmac-div.divfrom-' + currentForm).hide(); $('.divfrom-' + currentForm + ' .schedule-head').clone().appendTo('.divfrom-' + currentForm + ' .schedule-head-fixed .schedule-table'); $('.divfrom-' + currentForm + ' .schedule-head-fixed .schedule-table').append(firstRow).append(lastRow); }, whileScrolling: function() { var $window = $(window); var windowsize = $window.width(); if (windowsize > 768 && $('.divfrom-' + currentForm + ' .schedule-head').length ) { var schedulePos = $('.divfrom-' + currentForm + ' .schedule-head').offset().top - $('.shmac-div.divfrom-' + currentForm).offset().top; if (schedulePos < 0) { $('.divfrom-' + currentForm + ' .schedule-head-fixed').show(); } else { $('.divfrom-' + currentForm + ' .schedule-head-fixed').hide(); } } else { $('.divfrom-' + currentForm + ' .schedule-head-fixed').hide(); } } } }); } /* load scrollbar on modal div */ function modalScroll() { $('.shmac-div').mCustomScrollbar({ live: "on", theme: 'minimal-dark', callbacks: { onInit: function() { $('.shmac-div').css('overflow','auto'); // set overflow auto after init to avoid normal scroll from appearing var firstRow = $('.schedule-table tr').eq(1).clone(); var lastRow = $('.schedule-table tr:last').clone(); $('
') .appendTo('.shmac-div').hide(); $('.schedule-head').clone().appendTo('.schedule-head-fixed .schedule-table'); $('.schedule-head-fixed .schedule-table').append(firstRow).append(lastRow); }, whileScrolling: function() { var $window = $(window); var windowsize = $window.width(); if (windowsize > 768 && $('.schedule-head').length ) { var schedulePos = $('.schedule-head').offset().top - $('.shmac-div').offset().top; if (schedulePos < 0) { $('.schedule-head-fixed').show(); } else { $('.schedule-head-fixed').hide(); } } else { $('.schedule-head-fixed').hide(); } } } }); } /* Number & Char limiting for field inputs */ $('.shmac-form .mort-amount').autoNumeric('init'); $('.shmac-form .interest').autoNumeric('init'); $('.shmac-form .downpay').autoNumeric('init'); $('.shmac-form .term').autoNumeric('init'); /* Random String Generation */ function randomString() { var result = (Math.random()*1e32).toString(36); return result; } /*Adding Class for Non-empty Inputs */ jQuery("input.mui-form-control").blur(function(){ if(jQuery.trim(jQuery(this).val())!=''){ if(!jQuery(this).next(".mui-form-floating-label").hasClass('non-empty-ipt')) jQuery(this).next(".mui-form-floating-label").addClass('non-empty-ipt'); }else{ if(jQuery(this).next(".mui-form-floating-label").hasClass('non-empty-ipt')) jQuery(this).next(".mui-form-floating-label").removeClass('non-empty-ipt'); } }); });