var insurableMortgageRate = 4.44 var uninsuredMortgageRate = 4.8 if (window.location.href.match(/c21\.ca\/fr-ca\/listing/)) { var languageCode = 'FR' } else { var languageCode = 'EN' } if (languageCode == "FR") { document.getElementById('langAffordability').innerHTML = "Accessibilité" document.getElementById('langHomePrice').innerHTML = "Prix de la maison" document.getElementById('langMortgagePayment').innerHTML = "Paiement hypothécaire" document.getElementById('langDownPaymentPercent').innerHTML = "Paiement initial" document.getElementById('langLoanDetails').innerHTML = "Détails du prêt" document.getElementById('langDownPayment').innerHTML = "Paiement initial" document.getElementById('langPrincipleandInterest').innerHTML = "Capital et intérêts" document.getElementById('langPropertyTax').innerHTML = "Impôt foncier" document.getElementById('langHomeInsurance').innerHTML = "Assurance habitation" document.getElementById('langMonthlyTotal').innerHTML = "Total mensuel" document.getElementById('langGetPrequalified').innerHTML = "Obtenez une préqualification en 3 minutes" document.getElementById('lang25Year').innerHTML = "25 ans" document.getElementById('langDisclaimer').innerHTML = "Veuillez noter que les estimations ci-dessus, telles que le capital et les intérêts, l'impôt foncier, l'assurance habitation et les totaux mensuels, sont des estimations et sont sujettes à changement selon les prêteurs et les conditions de courtage spécifiques." } else { document.getElementById('langAffordability').innerHTML = "Affordability" document.getElementById('langHomePrice').innerHTML = "Home Price" document.getElementById('langMortgagePayment').innerHTML = "Mortgage Payment" document.getElementById('langDownPaymentPercent').innerHTML = "Down Payment" document.getElementById('langLoanDetails').innerHTML = "Loan Details" document.getElementById('langDownPayment').innerHTML = "Down Payment" document.getElementById('langPrincipleandInterest').innerHTML = "Principle and Interest" document.getElementById('langPropertyTax').innerHTML = "Property Tax" document.getElementById('langHomeInsurance').innerHTML = "Home Insurance" document.getElementById('langMonthlyTotal').innerHTML = "Monthly Total" document.getElementById('langGetPrequalified').innerHTML = "Get Pre-Qualified in 3 Minutes" document.getElementById('lang25Year').innerHTML = "25-year" document.getElementById('langDisclaimer').innerHTML = "Please note the estimates above such as principal and interest, property tax, home insurance and monthly totals are estimates and subject to change as per specific lenders and brokerage terms." } function calculateMonthlyPayment(homePrice, downPayment, mortgageTermYears, mortgageRate) { const monthlyRate = mortgageRate / 100 / 12 const mortgageTermMonths = mortgageTermYears * 12 const loanAmount = homePrice - downPayment const monthlyPayment = loanAmount * (monthlyRate * Math.pow(1 + monthlyRate, mortgageTermMonths)) / (Math.pow(1 + monthlyRate, mortgageTermMonths) - 1) return Math.round(monthlyPayment, 2) } if (Wx.data.listing_detail.price) { var homePrice = Wx.data.listing_detail.price } else if (Wx.data.listing_detail.list_price) { var homePrice = Wx.data.listing_detail.list_price } var mortgageRate = 0 if (homePrice > 1000000 && uninsuredMortgageRate) { mortgageRate = uninsuredMortgageRate } else if (insurableMortgageRate) { mortgageRate = insurableMortgageRate } document.getElementById('mortgageRate').innerHTML = mortgageRate if (Wx.data.listing_detail.property_tax) { var propertyTax = Math.round(Wx.data.listing_detail.property_tax / 12) document.getElementById('propertyTax').innerHTML = "$" + propertyTax.toLocaleString() } else { document.getElementById('propertyTaxDiv').style.display = "none" } if (homePrice) { var downPayment = Math.round(homePrice / 5) document.getElementById('displayPrice').innerHTML = "$" + homePrice.toLocaleString() document.getElementById('downPayment').innerHTML = "$" + downPayment.toLocaleString() var monthlyPayment = calculateMonthlyPayment(homePrice, downPayment, 25, mortgageRate) if (monthlyPayment) { document.getElementById('monthlyPayment').innerHTML = "$" + Math.round(monthlyPayment).toLocaleString() document.getElementById('monthlyPaymentExact').innerHTML = "$" + monthlyPayment.toLocaleString() } var homeInsurance = Math.round(homePrice / 4800) document.getElementById('homeInsurance').innerHTML = "$" + homeInsurance.toLocaleString() if (monthlyPayment && homeInsurance) { var monthlyTotal = monthlyPayment + homeInsurance if (propertyTax) { monthlyTotal = monthlyTotal + propertyTax } document.getElementById('monthlyTotal').innerHTML = "$" + monthlyTotal.toLocaleString() } var percentMortgage = 80 percentMortgage = Math.round((monthlyPayment / monthlyTotal) * 100) var percentInsurance = 20 percentInsurance = Math.round((homeInsurance / monthlyTotal) * 100) var percentPropertyTax = 0 if (propertyTax) { var percentPropertyTax = Math.round((propertyTax / monthlyTotal) * 100) } if (percentMortgage + percentInsurance + percentPropertyTax > 100) { percentMortgage = percentMortgage - 1 } document.getElementById('barMortgage').style.flex = '1 1 ' + percentMortgage + '%' document.getElementById('barInsurance').style.flex = '1 1 ' + percentInsurance + '%' document.getElementById('barPropertyTax').style.flex = '1 1 ' + percentPropertyTax + '%' } if (monthlyPayment && monthlyTotal) { document.getElementById('mortgageTile').style.display = "block" }