(function() { 'use strict'; const API_BASE = 'https://mortgagemax.co.za/wp-json/mortgagemax/v1'; const fmt = (n) => 'R ' + parseFloat(n || 0).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); const getField = (name) => document.querySelector(`[name="${name}"]`); let currentPdfUrl = null; let currentCalcType = null; // ============================================ // CALCULATOR CONFIGURATIONS // ============================================ const CALCULATORS = { // 1. AFFORDABILITY affordability: { paths: ['/calculators/affordability', '/embedded-calculator/embedded-affordability', '/template/affordability-calculator'], fields: { 'form-field-qphbmm': 'gross_income', 'form-field-aqrmwu': 'net_income', 'form-field-cjxrwb': 'expenses', 'form-field-gklclo': 'interest_rate', 'form-field-kodmze': 'term' }, results: { 'result-loan-amount': (d) => fmt(d.results.affordableLoanAmount), 'result-monthly-repayment': (d) => fmt(d.results.monthlyRepayment), 'result-gross-income': (d, i) => fmt(i.gross_income), 'result-net-income': (d, i) => fmt(i.net_income), 'result-expenses': (d, i) => fmt(i.expenses), 'result-interest-rate': (d, i) => i.interest_rate + '%', 'result-repayment-term': (d, i) => i.term + ' years' }, resetDefaults: { 'result-loan-amount': 'R0.00', 'result-monthly-repayment': 'R0.00', 'result-gross-income': 'R0.00', 'result-net-income': 'R0.00', 'result-expenses': 'R0.00', 'result-interest-rate': '%', 'result-repayment-term': 'years' }, downloadBtn: 'afford-download-btn', resetBtn: 'brxe-dpglun' }, // 2. BOND REPAYMENT bond_repayment: { paths: ['/calculators/repayment', '/embedded-calculator/embedded-repayment', '/template/repayment-calculator'], fields: { 'form-field-fsnrvp': 'purchase_price', 'form-field-zdvvfw': 'loan_amount', 'form-field-xpziwk': 'interest_rate', 'form-field-tkzwxj': 'term' }, results: { 'bond_result_monthly_repayment': (d) => fmt(d.results.monthlyRepayment), 'bond_result_total_loan_amount': (d) => fmt(d.results.totalRepayment), 'bond_result_total_costs': (d) => fmt(d.results.totalInterest), 'bond_result_purchase_price': (d, i) => fmt(i.purchase_price), 'bond_result_bond_amount': (d, i) => fmt(i.loan_amount), 'bond_result_interest_rate': (d, i) => i.interest_rate + '%', 'bond_result_repayment_term': (d, i) => i.term + ' years' }, resetDefaults: { 'bond_result_monthly_repayment': 'R0.00', 'bond_result_total_loan_amount': 'R0.00', 'bond_result_total_costs': 'R0.00', 'bond_result_purchase_price': 'R0.00', 'bond_result_bond_amount': 'R0.00', 'bond_result_interest_rate': '%', 'bond_result_repayment_term': 'years' }, downloadBtn: 'bond-download-btn', resetBtn: 'brxe-jungrb' }, // 3. BOND & TRANSFER COSTS bond_transfer: { paths: ['/calculators/bond-transfer', '/embedded-calculator/embedded-bond-and-transfer-cost', '/template/bond-transfer-calculator'], fields: { 'form-field-73d1b8': 'purchase_price', 'form-field-uszfyo': 'loan_amount', 'form-field-cafozy': 'interest_rate', 'form-field-vxzexl': 'term' }, results: { 'bt_result_grand_total': (d) => fmt(d.results.grandTotal), 'bt_result_total_bond_costs': (d) => fmt(d.results.totalBondCosts), 'bt_result_bond_attorney': (d) => fmt(d.results.bondAttorney), 'bt_result_bond_deeds': (d) => fmt(d.results.bondDeeds), 'bt_result_bond_petties': (d) => fmt(d.results.bondPetties), 'bt_result_total_transfer_costs': (d) => fmt(d.results.totalTransferCosts), 'bt_result_transfer_duty': (d) => fmt(d.results.transferDuty), 'bt_result_transfer_attorney': (d) => fmt(d.results.transferAttorney), 'bt_result_transfer_deeds': (d) => fmt(d.results.transferDeeds), 'bt_result_transfer_petties': (d) => fmt(d.results.transferPetties) }, resetDefaults: { 'bt_result_grand_total': 'R0.00', 'bt_result_total_bond_costs': 'R0.00', 'bt_result_bond_attorney': 'R0.00', 'bt_result_bond_deeds': 'R0.00', 'bt_result_bond_petties': 'R0.00', 'bt_result_total_transfer_costs': 'R0.00', 'bt_result_transfer_duty': 'R0.00', 'bt_result_transfer_attorney': 'R0.00', 'bt_result_transfer_deeds': 'R0.00', 'bt_result_transfer_petties': 'R0.00' }, downloadBtn: 'bt-download-btn', resetBtn: 'brxe-wswwdu' }, // 4. ADDITIONAL PAYMENT additional_payment: { paths: ['/calculators/additional', '/embedded-calculator/embedded-bond-additional-payment', '/template/additional-payment'], fields: { 'form-field-32432e': 'loan_amount', 'form-field-pprwyu': 'additional_payment', 'form-field-kqdrex': 'interest_rate', 'form-field-qakowg': 'term' }, results: { 'ap_result_new_duration': (d) => d.results.newDuration + ' months', 'ap_result_total_savings': (d) => fmt(d.results.totalSavings), 'ap_result_total_loan_amount': (d) => fmt(d.results.totalLoanAmount), 'ap_result_total_interest': (d) => fmt(d.results.totalInterest), 'ap_result_monthly_repayment': (d) => fmt(d.results.monthlyRepayment), 'ap_result_old_monthly_repayment': (d) => fmt(d.results.oldMonthlyRepayment), 'ap_result_loan_amount': (d, i) => fmt(i.loan_amount), 'ap_result_additional_payment': (d, i) => fmt(i.additional_payment), 'ap_result_interest_rate': (d, i) => i.interest_rate + '%', 'ap_result_term': (d, i) => i.term + ' years' }, resetDefaults: { 'ap_result_new_duration': 'months', 'ap_result_total_savings': 'R0.00', 'ap_result_total_loan_amount': 'R0.00', 'ap_result_total_interest': 'R0.00', 'ap_result_monthly_repayment': 'R0.00', 'ap_result_old_monthly_repayment': 'R0.00', 'ap_result_loan_amount': 'R0.00', 'ap_result_additional_payment': 'R0.00', 'ap_result_interest_rate': '%', 'ap_result_term': 'years' }, downloadBtn: 'ap-download-btn', resetBtn: 'brxe-dqsbqu' }, // 5. DEPOSIT SAVINGS deposit_savings: { paths: ['/calculators/savings', '/embedded-calculator/embedded-deposit-savings', '/template/deposit-savings'], fields: { 'form-field-32432e': 'purchase_price', 'form-field-pprwyu': 'deposit_percent', 'form-field-kqdrex': 'existing_savings', 'form-field-qakowg': 'deposit_interest', 'form-field-zcgwsw': 'required_date' }, results: { 'ds_result_deposit_goal': (d) => fmt(d.results.depositGoal), 'ds_result_monthly_saving': (d) => fmt(d.results.monthlySavings), 'ds_result_savings_required': (d) => fmt(d.results.savingsRequired), 'ds_result_loan_amount': (d, i) => fmt(i.purchase_price), 'ds_result_deposit_percent': (d, i) => i.deposit_percent + '%', 'ds_result_existing_savings': (d, i) => fmt(i.existing_savings), 'ds_result_required_date': (d, i) => i.required_date, 'ds_result_deposit_interest': (d, i) => i.deposit_interest + '%' }, resetDefaults: { 'ds_result_deposit_goal': 'R0.00', 'ds_result_monthly_saving': 'R 0.00', 'ds_result_savings_required': 'R0.00', 'ds_result_loan_amount': 'R0.00', 'ds_result_deposit_percent': '0%', 'ds_result_existing_savings': 'R0.00', 'ds_result_required_date': '2025/01/01', 'ds_result_deposit_interest': '0%' }, downloadBtn: 'ds-download-btn', resetBtn: 'brxe-wdbpoj' }, // 6. AMORTISATION amortisation: { paths: ['/calculators/amortisation', '/embedded-calculator/embedded-amortisation', '/template/amortisation'], fields: { 'form-field-32432e': 'loan_amount', 'form-field-pprwyu': 'loan_months', 'form-field-kqdrex': 'interest_rate', 'form-field-qakowg': 'fixed_term_months', 'form-field-zcgwsw': 'fixed_interest_rate' }, results: { 'amort_result_total_interest': (d) => fmt(d.results.totalInterest), 'amort_result_loan_amount': (d, i) => fmt(i.loan_amount), 'amort_result_loan_months': (d, i) => i.loan_months + ' months', 'amort_result_interest_rate': (d, i) => i.interest_rate + '%', 'amort_result_fixed_term_months': (d, i) => i.fixed_term_months + ' months', 'amort_result_fixed_interest_rate': (d, i) => i.fixed_interest_rate + '%' }, resetDefaults: { 'amort_result_total_interest': 'R0.00', 'amort_result_loan_amount': 'R0.00', 'amort_result_loan_months': 'months', 'amort_result_interest_rate': '%', 'amort_result_fixed_term_months': 'months', 'amort_result_fixed_interest_rate': '%' }, downloadBtn: 'amort-download-btn', resetBtn: 'brxe-asaspj' }, // 7. 3-IN-1 three_in_one: { paths: ['/calculators/3-in-1', '/embedded-calculator/embedded-3in1', '/template/3-in-1'], fields: { 'form-field-73d1b8': 'purchase_price', 'form-field-uszfyo': 'loan_amount', 'form-field-enaore': 'additional_payment', 'form-field-cafozy': 'interest_rate', 'form-field-vxzexl': 'term' }, results: { 't3_result_monthly_repayment': (d) => fmt(d.results.monthlyRepayment), 't3_result_total_loan': (d) => fmt(d.results.totalLoanAmount), 't3_result_total_interest': (d) => fmt(d.results.totalInterest), 't3_result_purchase_price': (d, i) => fmt(i.purchase_price), //'t3_result_interest_rate': (d, i) => i.interest_rate + '%', 't3_result_interest_rate': (d, i) => (d.inputs?.interest_rate || i.interest_rate || 0) + '%', 't3_result_bond_amount': (d, i) => fmt(i.loan_amount), //'t3_result_term': (d, i) => i.term + ' years', 't3_result_term': (d, i) => (d.inputs?.term || i.term || 0) + ' years', 't3_result_total_savings': (d) => fmt(d.results.totalSavings), 't3_result_new_duration': (d) => d.results.newDuration + ' months', 't3_result_transfer_fee': (d) => fmt(d.results.transferAttorney), 't3_result_transfer_deeds': (d) => fmt(d.results.transferDeeds), 't3_result_transfer_petties': (d) => fmt(d.results.transferPetties), 't3_result_transfer_duty': (d) => fmt(d.results.transferDuty), 't3_result_transfer_costs': (d) => fmt(d.results.totalTransferCosts), 't3_result_bond_registration': (d) => fmt(d.results.bondRegistration), 't3_result_bond_petties': (d) => fmt(d.results.bondPetties), 't3_result_bond_costs': (d) => fmt(d.results.totalBondCosts), 't3_result_total_bond_and_transfer_fee': (d) => fmt(d.results.grandTotal) }, resetDefaults: { 't3_result_monthly_repayment': 'R0.00', 't3_result_total_loan': 'R0.00', 't3_result_total_interest': 'R0.00', 't3_result_purchase_price': 'R0.00', 't3_result_interest_rate': '', 't3_result_bond_amount': 'R0.00', 't3_result_term': '0', 't3_result_total_savings': 'R0.00', 't3_result_new_duration': 'months', 't3_result_transfer_fee': 'R0.00', 't3_result_transfer_deeds': 'R0.00', 't3_result_transfer_petties': 'R0.00', 't3_result_transfer_duty': 'R0.00', 't3_result_transfer_costs': 'R0.00', 't3_result_bond_registration': 'R0.00', 't3_result_bond_petties': 'R0.00', 't3_result_bond_costs': 'R0.00', 't3_result_total_bond_and_transfer_fee': 'R0.00' }, downloadBtn: 't3-download-btn', resetBtn: 'brxe-suxypl' } }; // ============================================ // DETECT CURRENT CALCULATOR // ============================================ function detectCalculator() { const path = window.location.pathname; for (const [type, config] of Object.entries(CALCULATORS)) { if (config.paths.some(p => path.includes(p))) { return { type, config }; } } return null; } const calculator = detectCalculator(); if (!calculator) { return; } currentCalcType = calculator.type; const config = calculator.config; console.log('MortgageMAX: Detected calculator:', currentCalcType); // ============================================ // MAIN INITIALIZATION // ============================================ document.addEventListener('DOMContentLoaded', function() { const calcBtn = document.querySelector('button[type="submit"].bricks-button'); if (!calcBtn) { console.log('MortgageMAX: Submit button not found'); return; } const form = calcBtn.closest('form'); if (form) { form.addEventListener('submit', function(e) { e.preventDefault(); e.stopPropagation(); return false; }); } // ============================================ // CALCULATE BUTTON HANDLER // ============================================ calcBtn.addEventListener('click', async function(e) { e.preventDefault(); e.stopPropagation(); const inputs = {}; for (const [fieldName, paramName] of Object.entries(config.fields)) { const field = getField(fieldName); if (field) { const val = field.value; if (paramName.includes('date')) { inputs[paramName] = val; } else if (paramName.includes('term') || paramName.includes('months')) { inputs[paramName] = parseInt(val) || 0; } else { inputs[paramName] = parseFloat(val) || 0; } } } console.log('MortgageMAX: Inputs', inputs); const originalText = calcBtn.querySelector('.text')?.innerText || 'Calculate'; if (calcBtn.querySelector('.text')) { calcBtn.querySelector('.text').innerText = 'Calculating...'; } calcBtn.disabled = true; try { const response = await fetch(API_BASE + '/calculate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ calculator_type: currentCalcType, ...inputs }) }); const data = await response.json(); console.log('MortgageMAX: Response', data); if (data.success) { currentPdfUrl = data.pdf_url; for (const [elementId, formatter] of Object.entries(config.results)) { const el = document.getElementById(elementId); if (el) { try { el.innerText = formatter(data, inputs); } catch (err) { console.warn('MortgageMAX: Error formatting', elementId, err); } } } console.log('MortgageMAX: Results updated'); console.log('MortgageMAX: PDF URL', currentPdfUrl); } else { console.error('MortgageMAX: API Error', data.error); alert('Error: ' + data.error); } } catch (err) { console.error('MortgageMAX: Fetch Error', err); alert('Calculation failed: ' + err.message); } if (calcBtn.querySelector('.text')) { calcBtn.querySelector('.text').innerText = originalText; } calcBtn.disabled = false; return false; }); // ============================================ // DOWNLOAD BUTTON HANDLER // ============================================ const downloadBtn = document.getElementById(config.downloadBtn); if (downloadBtn) { downloadBtn.addEventListener('click', function(e) { e.preventDefault(); if (currentPdfUrl) { window.open(currentPdfUrl, '_blank'); } else { alert('Please calculate first'); } }); } // ============================================ // RESET BUTTON HANDLER // ============================================ const resetBtn = config.resetBtn ? document.getElementById(config.resetBtn) : null; if (resetBtn) { resetBtn.addEventListener('click', function(e) { e.preventDefault(); if (form) { form.reset(); form.querySelectorAll('input').forEach(input => { if (input.type !== 'hidden') { input.value = ''; } }); } for (const [elementId, defaultVal] of Object.entries(config.resetDefaults)) { const el = document.getElementById(elementId); if (el) { el.innerText = defaultVal; } } currentPdfUrl = null; console.log('MortgageMAX: Form reset'); }); } // ============================================ // SHARE FORM HANDLER // ============================================ document.addEventListener('click', async function(e) { const btn = e.target.closest('button[type="submit"]'); if (!btn) return; const shareForm = btn.closest('form'); if (!shareForm) return; const emailField = shareForm.querySelector('[name="share_email"]'); const nameField = shareForm.querySelector('[name="share_name"]'); if (!emailField) return; shareForm.removeAttribute('data-script-id'); shareForm.removeAttribute('data-interactions'); shareForm.setAttribute('data-bricks-disabled', 'true'); btn.removeAttribute('data-interactions'); const newBtn = btn.cloneNode(true); btn.parentNode.replaceChild(newBtn, btn); e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); const recipientEmail = emailField.value; const senderName = nameField?.value || 'Someone'; console.log('MortgageMAX: Sharing to', recipientEmail); if (!recipientEmail) { alert('Please enter an email address'); return false; } if (!currentPdfUrl) { alert('Please calculate first before sharing'); return false; } const textSpan = newBtn.querySelector('.text'); const originalBtnText = textSpan?.innerText || 'Send'; if (textSpan) { textSpan.innerText = 'Sending...'; } newBtn.disabled = true; try { const response = await fetch(API_BASE + '/share-email', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ recipient_email: recipientEmail, sender_name: senderName, pdf_url: currentPdfUrl, calculator_type: currentCalcType }) }); const data = await response.json(); console.log('MortgageMAX: Share response', data); if (data.success) { const closeBtn = document.querySelector('.brx-popup-close, .brxe-popup-close, [data-popup-close]'); if (closeBtn) closeBtn.click(); const popupOverlays = document.querySelectorAll('.brx-popup-overlay, .brx-popup-backdrop, .brxe-popup-overlay, [class*="popup-overlay"]'); popupOverlays.forEach(overlay => overlay.remove()); const popupContainers = document.querySelectorAll('.brx-popup-content, .brxe-popup, #bricks-popup-container, [class*="brx-popup"]'); popupContainers.forEach(container => { container.style.display = 'none'; container.style.visibility = 'hidden'; }); document.body.style.overflow = ''; document.body.classList.remove('brx-popup-open', 'bricks-popup-open'); setTimeout(() => { const openPopups = document.querySelectorAll('.brx-popup-content, .brxe-popup'); openPopups.forEach(p => p.style.display = 'none'); const modal = document.createElement('div'); modal.id = 'mmx-success-modal'; modal.innerHTML = `
Success

Results sent successfully!

Your results have been sent to the email provided. If you don't see them soon, please check your spam or promotions folder.

`; document.body.appendChild(modal); modal.querySelector('div').addEventListener('click', function(ev) { if (ev.target === this) { modal.remove(); } }); }, 300); } else { alert('Failed to send: ' + data.error); } } catch (err) { console.error('MortgageMAX: Share error', err); alert('Failed to send email: ' + err.message); } if (textSpan) { textSpan.innerText = originalBtnText; } newBtn.disabled = false; return false; }, true); }); })(); MortgageMAX
bell

MortgageMAX UK is launching soon. Stay tuned.

bell

MortgageMAX UK is launching soon. Stay tuned.

header lady on tablet
header shards bottom right

Helping you deliver the best homeloans for your clients

MortgageMAX empowers ambitious entrepreneurs to run their own mortgage origination businesses.

Become a partner
absa icon

Absa

New offer

fnb icon

FNB

New offer

investec icon

Investec

New offer

nedbank icon

Nedbank

New offer

rmb icon

RMB

New offer

standard bank icon

Standard Bank

New offer

african bank icon

African Bank

New offer

What we do

Your growth partner in mortgage origination

MortgageMAX empowers ambitious entrepreneurs to run their own small to medium-sized mortgage origination businesses. We provide the platform, expertise and support so you can focus on what you do best: helping clients achieve homeownership.

Bond origination

We have contracts with leading banks to ensure credibility and access.

services bank icons 1

Marketing tools

We provide a range of marketing tools and campaigns to help you grow your business.

services marketing

Advanced technology

Enjoy access to our suite of digital tools for customer onboarding and deal processing.

mm offer img

World-class support

Our central Support Hub and Regional Managers provide invaluable business insights.

Full processing team available

Designated bank consultants

Designated software training

Regional managers across South Africa

Help-desk

services support 1

Value Adds

Extra advantages that grow your business

From insurance to finance to commission tracking, we offer a range of value-add services designed to support your business and your clients.

house check

Home & Life Insurance

Offer clients additional cover with insurance solutions designed to protect their homes and their families.

Bridging Finance

Help clients access funds to cover transfer duties and other transaction costs, so their home purchase keeps moving without delays.

Commission Tracking

Stay on top of your earnings with easy-to-use tools that track, manage and forecast commission payments.

Join us

Build your mortgage origination business.

We serve independent mortgage originators and entrepreneurs in South Africa and the UK, helping you harness your expertise to grow a successful business.

check

Gain independence and grow your own business.

check

Continuously develop your skills to deliver real value to clients.

check

Be part of a credible, bank-accredited network with proven systems.

check

Help your clients secure the best possible mortgage rate

mm brand element

Trusted partner

Why partner with MortgageMAX?

We serve independent mortgage originators and entrepreneurs in South Africa and the UK, helping you harness your expertise to grow a successful business.

pie chart money

Competitive commission

Benefit from transparent, market-leading commission structures that reward performance.

users

Dedicated relationship managers

Get personal support from experts who understand your business and your clients.

briefcase bank

Contracts with major banks

Give your clients access to all the leading banks, ensuring choice and better deals.

check

Package options

Choose flexible packages that match the size and needs of your business.

Are you ready to pioneer your mortgage business?

Let us help you protect your home with comprehensive contents insurance.

Getting started
header shards bottom right