// Do not reference this script file directly via /rates.js // pull this resource from /mamscripts?siteId={yourGuid} to dynamically generate a script file for your site var MAM = { siteId: 'C97A3015-EB09-4350-8EDF-BC7A8455B5E5', apiRootUrl : 'https://api.memberadvantagemortgage.com/', calcRootUrl: 'https://calc.memberadvantagemortgage.com/', calcOptions: { Title: 'Payment Calculator', VeteranQuestionText: 'Are you Active Duty Military or Veteran?' }, renderCalculator: function ( target, options) { if (!target) { target = '#mam-calculator'; } if (!jQuery(target).length) { console.log('unable to render calculator. `target` required but was not found.'); return; } if (options) { if (options.Title) this.calcOptions.Title = options.Title; if (options.VeteranQuestionText) this.calcOptions.VeteranQuestionText = options.VeteranQuestionText; } jQuery(target).html(''); var script1 = document.createElement('script'); script1.src = this.calcRootUrl + 'static/js/main.chunk.js'; document.getElementsByTagName('head')[0].appendChild(script1); var script2 = document.createElement('script'); script2.src = this.calcRootUrl + 'static/js/runtime~main.js'; document.getElementsByTagName('head')[0].appendChild(script2); var script3 = document.createElement('script'); script3.src = this.calcRootUrl + 'static/js/0.chunk.js'; document.getElementsByTagName('head')[0].appendChild(script3); }, renderVertRates: function(target, rates) { if (!jQuery(target).length) { console.log('unable to render MAM vert table. `target` required but was not found'); return; } var vertApiEndpoint = this.apiRootUrl + 'rates/current/vertTable'; jQuery.ajax({ url: vertApiEndpoint, method: 'POST', type: 'POST', data: JSON.stringify({ siteId: this.siteId, rates: rates }), contentType: 'application/json', dataType: 'html', success: function (data) { jQuery(target).html(data); }, error: function (e) { console.error(e); jQuery(target).html(e.statusText); } }) }, renderHorizRates: function(target, rates) { if (!jQuery(target).length) { console.log('unable to render MAM horiz table. `target` required but was not found'); return; } var horizApiEndpoint = this.apiRootUrl + 'rates/current/horizTable'; jQuery.ajax({ url: horizApiEndpoint, method: 'POST', type: 'POST', data: JSON.stringify({ siteId: this.siteId, rates: rates }), contentType: 'application/json', dataType: 'html', success: function (data) { jQuery(target).html(data); }, error: function (e) { console.error(e); jQuery(target).html(e.statusText); } }) }, bindRates: function() { var ratesEndpoint = this.apiRootUrl + 'rates/current/json/' + this.siteId; jQuery.ajax({ url: ratesEndpoint, method: 'GET', dataType: 'json', success: function (data) { jQuery("[mam-rate-product]").each(function () { var productName = jQuery(this).attr('mam-rate-product'); var product = data.rates.find(function (rate) { return rate.product == productName; }) if (!product) { console.error('Product `' + productName + '` not found'); return; } var prop = jQuery(this).attr('mam-rate-property'); var val = prop == 'rate' ? product.rate : prop == 'apr' ? product.apr : prop == 'points' ? product.points : prop == 'payment' ? product.payment : 'mam-rate-product attribute required' ; if (jQuery(this).attr('mam-rate-formatter')) { var func = jQuery(this).attr('mam-rate-formatter'); val = eval(func)(val); } jQuery(this).html(val); }) }, error: function (e) { console.error(e); } }) }, paymentFormatter: function(input) { if (!isNaN(input)) { return '$' + val.toFixed(2) } return ''; }, rateFormatter: function (input) { if (!isNaN(input)) { return input.toFixed(3) + '%'; } return ''; }, aprFormatter: function(input) { if (!isNaN(input)) { return input.toFixed(3) + '%'; } return ''; }, leadCapture: function(params) { // holy hacks! (because formstack is 100 years old) Object.keys(params).forEach(function(key) { jQuery("#fsLightboxContent3441824 [fs-field-validation-name='" + key + "'] > input").val(params[key]); }) var leadCaptureForm = new FSLightbox({ form: 3441824, }); leadCaptureForm.fadeOverlay.onclick = null; leadCaptureForm.show(); setTimeout(function() { jQuery("#fsLightboxClose3441824").attr('href', 'javascript:;'); }, 500); if (jQuery("#fsForm3441824").attr('init') !== 'true') { jQuery("#fsForm3441824") .after('') .attr('target', 'leadCapturePostTarget') .attr('init', 'true'); } jQuery("#fsForm3441824").submit(function(e) { //javascript:; setTimeout(function() { var thankYouMessageHTML = '
' + ' ' + ' ' + '
'; jQuery("#fsForm3441824").html(thankYouMessageHTML); }, 1000) }) }, showAssumptions: function() { var file = 'https://www.borrowercenter.memberadvantagemortgage.com/Assumptions.asp?siteId=' + this.siteId; msgWindow = window.open(file,'assumptionswin','toolbar=no,scrollbars=yes,width=550,height=350'); setTimeout("msgWindow.document.location.href='" + file + "';", 1000); msgWindow.focus(); } } document.addEventListener("DOMContentLoaded", function() { jQuery(document).on('click', '[mam-c2a-Link]', function(e) { var product = jQuery(e.target).attr('mam-c2a-Product'); var link = jQuery(e.target).attr('mam-c2a-Link'); var siteId = jQuery(e.target).attr('mam-c2a-SiteId'); var widget = jQuery(e.target).attr('mam-c2a-Widget'); var todaysRatesLearnMoreClickUrl = MAM.apiRootUrl + 'rates/event/learnmore'; var data = JSON.stringify({ product: product, siteId: siteId, widget: widget }); if (link && link.toUpperCase() == 'LEADCAPTURE') { var product = jQuery(e.target).attr('mam-c2a-Product'); var widget = jQuery(e.target).attr('mam-c2a-Widget'); var institutionName = jQuery(e.target).attr('mam-c2a-InstitutionName'); var leadSource = jQuery(e.target).attr('mam-c2a-LeadSource'); var params = { Product: product, Widget: widget, InstitutionName: institutionName, LeadSource: leadSource, LoanAmount: '', PurchasePrice: '', DownPayment: '', }; MAM.leadCapture(params); } jQuery.ajax({ url: todaysRatesLearnMoreClickUrl, method: 'POST', type: 'POST', data: data, contentType: 'application/json', dataType: 'html', success: function (data) { if (link && link.toUpperCase() != 'LEADCAPTURE') { window.location.href = link; } }, error: function (e) { } }) }) });