var mortgage = { init:function(){ $("#calculate").bind({ "click":function(){ mortgage.displayBasic(); } }); }, dataArr:[], displayDetail:function(){ var P = $.url().param('p'); var R = $.url().param('r')/100; var YR = $.url().param('yr'); var period = $.url().param('period'); if(P&&R&&period) { var NUM_OF_TERM = period; var R_PER_MONTH = R/12 var Installment = extraMath.round2D(mortgage.calInstallment(P,R_PER_MONTH,NUM_OF_TERM)); var PN_remain = P; for(i=0;i0)?(PN_remain - PrincipalRepayment):0; if(i==NUM_OF_TERM-1) { Installment = Installment + OutstandingBalance; PrincipalRepayment = PrincipalRepayment + OutstandingBalance; OutstandingBalance = 0; } mortgage.dataArr.push([ //extraMath.formatMoney(PN_remain,3,".",","), extraMath.formatMoney(Installment,2,".",","), extraMath.formatMoney(InterestPayment,2,".",","), extraMath.formatMoney(PrincipalRepayment,2,".",","), extraMath.formatMoney(OutstandingBalance,2,".",",") ]); PN_remain -= PrincipalRepayment; } $("#dataTable").html(mortgage.genTable(mortgage.dataArr)); $("#p").html(extraMath.formatMoney($.url().param('p'),2,".",",")); $("#period").html($.url().param('period')); $("#r").html(extraMath.formatMoney($.url().param('r'),2,".",",")+"%"); } }, displayBasic:function(){ if(mortgage.formCheck()) { var P = $("#p").val(); var R = $("#r").val()/100; var period = $("#period").val(); // Monthly var R_PER_MONTH = R/MONTH_PER_YEAR; var Installment = mortgage.calInstallment(P,R_PER_MONTH,period); Installment = extraMath.round2D(Installment); // Client Request Cal in %.2f var NUM_OF_TERM = mortgage.calInstallmentNum(P,R_PER_MONTH,Installment); NUM_OF_TERM = (NUM_OF_TERM'+mortgageDisplayText.RepaymentSchedule[lang]+''); } }, calInstallment:function(a, r, n) { return ( (r * a * Math.pow(1 + r, n)) / ( Math.pow(1 + r, n) - 1) ) }, calInstallmentNum:function(a, r, instal) { return Math.log10(instal / (instal - (r * a))) / Math.log10(1 + r); }, calAccInterest:function(a, r, instal, instalnum) { return (instal * (instalnum -1)) + ( Math.pow((1 + r), instalnum) * (a - (instal / r)) ) + ( (1 + r) * instal / r ) - a; }, genTable:function(arr){ var tempTable = ""; tempTable += ""; tempTable += ""; tempTable += ''; //tempTable += '"; tempTable += '"; tempTable += '"; tempTable += '"; tempTable += '"; tempTable += ""; for(i=0;i"+(i+1)+""; for(j=0;j"; tempTable += ""; } tempTable += "
'+mortgageDisplayText.Term[lang]+''+mortgageDisplayText.OpeningBalance[lang]+"'+mortgageDisplayText.Instalment[lang]+"'+mortgageDisplayText.InterestPayment[lang]+"'+mortgageDisplayText.PrincipalRepayment[lang]+"'+mortgageDisplayText.OutstandingBalance[lang]+"
"; return tempTable; }, formCheck:function(){ var check = true; var errorText = ""; if($("#p").val().trim()=="") errorText += "- "+mortgageDisplayText.InputLoanAmount[lang]+"\n"; else if(isNaN($("#p").val())) errorText += "- "+mortgageDisplayText.InvalidLoanAmount[lang]+"\n"; else if($("#p").val() < 1 || $("#p").val() > 999999999) errorText += "- "+mortgageDisplayText.InvalidLoanAmountRange[lang]+"\n"; if($("#period").val().trim()=="") errorText += "- "+mortgageDisplayText.InputRepaymentPeriod[lang]+"\n"; else if(isNaN($("#period").val())) errorText += "- "+mortgageDisplayText.InvalidRepaymentPeriod[lang]+"\n"; else if($("#period").val() < 1 || $("#period").val() > 999) errorText += "- "+mortgageDisplayText.InvalidRepaymentPeriodRange[lang]+"\n"; if($("#r").val().trim()=="") errorText += "- "+mortgageDisplayText.InputInterestRate[lang]+"\n"; else if(isNaN($("#r").val())) errorText += "- "+mortgageDisplayText.InvalidInterestRate[lang]+"\n"; else if($("#r").val() < 0.01 || $("#r").val() > 99.99) errorText += "- "+mortgageDisplayText.InvalidInterestRateRange[lang]+"\n"; if(errorText) { errorText = errorText; check = false; alert(errorText) } return check; } } var mortgageDisplayText = { index:function(){ if(lang=="tc") $("#header").html('
按揭計算機 - 計算最高可負擔貸款額
'); else if(lang=="sc") $("#header").html('
按揭计算机 - 计算最高可负担贷款额
'); else $("#header").html('
Mortgage calculator - calculate monthly repayment amounts
'); $(".PrincipleLoanAmount").text(mortgageDisplayText.PrincipleLoanAmount[lang]); $(".RateOfInterest").text(mortgageDisplayText.RateOfInterest[lang]); $(".RepaymentPeriod").text(mortgageDisplayText.RepaymentPeriod[lang]); $("#RateEnquiry").html(''+mortgageDisplayText.RateEnquiry[lang]+'') $("#calculate").val(mortgageDisplayText.Calculate[lang]); $("#clear").val(mortgageDisplayText.Clear[lang]); $(".CalculationResult").text(mortgageDisplayText.CalculationResult[lang]); $("#YourInput").text(mortgageDisplayText.YourInput[lang]); $("#MonthlyPaymentMethod").text(mortgageDisplayText.MonthlyPaymentMethod[lang]); $("#BiWeeklyPaymentMethod").text(mortgageDisplayText.BiWeeklyPaymentMethod[lang]); $("#InstallmentAmount").text(mortgageDisplayText.InstallmentAmount[lang]); $("#ActualNumberOfInstallments").text(mortgageDisplayText.ActualNumberOfInstallments[lang]); $("#EffectiveRepaymentPeriodMonths").text(mortgageDisplayText.EffectiveRepaymentPeriodMonths[lang]); $("#EffectiveRepaymentPeriodYears").text(mortgageDisplayText.EffectiveRepaymentPeriodYears[lang]); $("#TotalInterestPaid").text(mortgageDisplayText.TotalInterestPaid[lang]); if(lang=="en") $("#MakeAppointment").html(''+mortgageDisplayText.MakeAppointment[lang]+'') else $("#MakeAppointment").html(''+mortgageDisplayText.MakeAppointment[lang]+'') $("#InstantPropertyValuation").html(''+mortgageDisplayText.InstantPropertyValuation[lang]+'') $("#CloseBtn").html(''+mortgageDisplayText.CloseBtn[lang]+'') $("#note1").text(mortgageDisplayText.note1[lang]); $("#note2").text(mortgageDisplayText.note2[lang]); // For HKCBF if($.url().param('com')=="hkcbf") { $("#header").html(''); /* $("#RateEnquiry").html(''+mortgageDisplayText.RateEnquiry[lang]+'') if(lang=="en") $("#MakeAppointment").html(''+mortgageDisplayText.MakeAppointment[lang]+''); else $("#MakeAppointment").html(''+mortgageDisplayText.MakeAppointment[lang]+''); */ $("#RateEnquiry").html(''); $("#MakeAppointment").html('').remove(); $("#InstantPropertyValuation").html('').remove(); $("#CloseBtn").html('').remove(); $("#CloseBtn_hkcbf").html(''+mortgageDisplayText.CloseBtn[lang]+'') $("#note2").text(mortgageDisplayText.note2_HKCBF[lang]); $("#CalculationResultTable tr").each(function(index, element) { $(this).find("td:last[id!=RepaymentSchedule]").remove(); $(this).find("td").removeClass("textCenter"); }); $("#RepaymentSchedule").attr("colspan",2); } }, detail:function(){ $("#PrincipleLoanAmount").text(mortgageDisplayText.PrincipleLoanAmount[lang]); $("#RateOfInterest").text(mortgageDisplayText.RateOfInterest[lang]); $("#RepaymentPeriod").text(mortgageDisplayText.RepaymentPeriod[lang]); $("#calculate").val(mortgageDisplayText.Calculate[lang]); $("#clear").val(mortgageDisplayText.Clear[lang]); $("#note3").text(mortgageDisplayText.note3[lang]); }, RateEnquiry:{ "en":"Rate Enquiry", "tc":"查詢利率", "sc":"查询利率" }, RateEnquiryLink:{ "en":"https://www.cncbinternational.com/rate-table/init_rate_en.html", "tc":"https://www.cncbinternational.com/rate-table/init_rate_tc.html", "sc":"https://www.cncbinternational.com/rate-table/init_rate_sc.html" }, RateEnquiryLink_HKCBF:{ "en":"#", "tc":"#", "sc":"#" }, Calculate:{ "en":"Calculate", "tc":"計算", "sc":"计算" }, Clear:{ "en":"Clear", "tc":"重新輸入", "sc":"重新输入" }, CalculationResult:{ "en":"Calculation Result", "tc":"計算結果", "sc":"计算结果" }, YourInput:{ "en":"Your Input", "tc":"你的資料", "sc":"你的资料" }, PrincipleLoanAmount:{ "en":"Loan Amount (HKD)", "tc":"貸款額 (港幣)", "sc":"贷款额 (港币)" }, RateOfInterest:{ "en":"Expected Annual Interest Rate (%) ", "tc":"預期貸款年利率 (%)", "sc":"预期贷款年利率 (%)" }, Year:{ "en":"Year", "tc":"", "sc":"" }, RepaymentPeriod:{ "en":"Repayment Period (Months)", "tc":"還款期 (月)", "sc":"还款期 (月)" }, Term:{ "en":"No. of Installment", "tc":"期數", "sc":"期数" }, MonthlyPaymentMethod:{ "en":"Monthly Payment Method", "tc":"每月供款方法", "sc":"每月供款方法" }, BiWeeklyPaymentMethod:{ "en":"Bi Weekly Payment Method", "tc":"每兩星期供款方法", "sc":"每两星期供款方法" }, InstallmentAmount:{ "en":"Installment Amount (HKD)", "tc":"供款金額 (港幣)", "sc":"供款金额 (港币)" }, ActualNumberOfInstallments:{ "en":"Actual number of installments", "tc":"實際供款期數", "sc":"实际供款期数" }, EffectiveRepaymentPeriodMonths:{ "en":"Effective Repayment Period (months)", "tc":"實際供款年期 (月)", "sc":"实际供款年期 (月)" }, EffectiveRepaymentPeriodYears:{ "en":"Effective Repayment Period (years)", "tc":"實際供款年期 (年)", "sc":"实际供款年期 (年)" }, TotalInterestPaid:{ "en":"Total Interest Paid (HKD)", "tc":"總利息支出 (港幣)", "sc":"总利息支出 (港币)" }, OpeningBalance:{ "en":"Opening Balance
(HKD)", "tc":"", "sc":"" }, Instalment:{ "en":"Repayment Amount", "tc":"供款金額", "sc":"供款金额" }, InterestPayment:{ "en":"Interest", "tc":"利息", "sc":"利息" }, PrincipalRepayment:{ "en":"Principal", "tc":"本金", "sc":"本金" }, OutstandingBalance:{ "en":"Outstanding Balance", "tc":"本金餘額", "sc":"本金余额" }, RepaymentSchedule:{ "en":"Repayment Schedule", "tc":"還款表", "sc":"还款表" }, MakeAppointment:{ "en":"Make Appointment with Mortgage Specialist", "tc":"預約按揭顧問", "sc":"预约按揭顾问" }, MakeAppointmentLink:{ "en":"https://www.cncbinternational.com/mortgageloanapp/eng/3_1_mortgages_loan_application.jsp", "tc":"https://www.cncbinternational.com/mortgageloanapp/tchi/3_1_mortgages_loan_application.jsp", "sc":"https://www.cncbinternational.com/mortgageloanapp/schi/3_1_mortgages_loan_application.jsp" }, MakeAppointmentLink_HKCBF:{ "en":"#", "tc":"#", "sc":"#" }, InstantPropertyValuation:{ "en":"Instant Property Valuation", "tc":"即時物業估價", "sc":"即时物业估价" }, InstantPropertyValuationLink:{ "en":"https://www.cncbinternational.com/onlineapp/mortgagevalua.jsp?LANG=en_US", "tc":"https://www.cncbinternational.com/onlineapp/mortgagevalua.jsp?LANG=zh_CN", "sc":"https://www.cncbinternational.com/onlineapp/mortgagevalua.jsp?LANG=zh_HK" }, CloseBtn:{ "en":"Close", "tc":"關閉", "sc":"关闭" }, CloseBtnLink:{ "en":"https://ibanking.cncbinternational.com/CKWPortal/resources/personal/common/winclose.html", "tc":"https://ibanking.cncbinternational.com/CKWPortal/resources/personal/common/winclose.html", "sc":"https://ibanking.cncbinternational.com/CKWPortal/resources/personal/common/winclose.html" }, note1:{ "en":"*The above information is for reference only.", "tc":"* 以上資料只供參考", "sc":"* 以上资料只供参考。" }, note2:{ "en":"Should you have any enquiries, please call our Customer Service Hotline 2287 6788 for assistance.", "tc":"如有任何疑問,請致電本行客戶服務熱線 2287 6788 查詢。", "sc":"如有任何疑问,请致电本行客户服务热线 2287 6788 查询。" }, note2_HKCBF:{ "en":"Should you have any enquiries, please call our Customer Service Hotline 3603 3760 for assistance.", "tc":"如有任何疑問,請致電本行客戶服務熱線 3603 3760 查詢。", "sc":"如有任何疑问,请致电本行客户服务热线 3603 3760 查询。" }, note3:{ "en":"Note: The calculation is based on the information provided by customer and the calculator result is for reference only", "tc":"註: 以上的計算結果是根據客戶提供之資料計算及只供參考", "sc":"注: 以上的计算结果是根据客户提供之资料计算及只供参考" }, InputLoanAmount:{ "en":"Please input the Loan Amount.", "tc":"請輸入貸款額。", "sc":"请输入贷款额。" }, InputRepaymentPeriod:{ "en":"Please input the Repayment Period.", "tc":"請輸入還款期。", "sc":"请输入还款期。" }, InputInterestRate:{ "en":"Please input the Interest Rate.", "tc":"請輸入年利率。", "sc":"请输入年利率。" }, InvalidLoanAmount:{ "en":"The amount you inputted is invalid. Please re-enter.", "tc":"你所輸入的貸款額不正確,請重新輸入。", "sc":"你所输入的贷款额不正确,请重新输入。" }, InvalidRepaymentPeriod:{ "en":"The period you inputted is invalid. Please re-enter.", "tc":"你所輸入的還款期不正確,請重新輸入。", "sc":"你所输入的还款期不正确,请重新输入。" }, InvalidInterestRate:{ "en":"The rate you inputted is invalid. Please re-enter.", "tc":"你所輸入的年利率不正確,請重新輸入。", "sc":"你所输入的年利率不正确,请重新输入。" }, InvalidLoanAmountRange:{ "en":"Loan Amount must be between 1 to 999,999,999.", "tc":"貸款額須在1至999,999,999內。", "sc":"贷款额须在1至999,999,999内。" }, InvalidRepaymentPeriodRange:{ "en":"Repayment Period must be between 1 to 999.", "tc":"還款期數值須在1至999內。", "sc":"还款期数值须在1至999内。" }, InvalidInterestRateRange:{ "en":"Interest Rate must be between 0.01 to 99.99% .", "tc":"年利率數值須在0.01至99.99%內。", "sc":"年利率数值须在0.01至99.99%内。" } } // Batch 2 START $(document).ready(function () { let lang = window.location.search; if (lang.indexOf('lang=en') != -1) { $('html').attr({"xml:lang": "en","lang": "en"}) $('#CalculationResultTable .srHeading').text("Calculation Result") } else if (lang.indexOf('lang=sc') != -1) { $('html').attr({"xml:lang": "sc","lang": "sc"}) $('#CalculationResultTable .srHeading').text("计算结果") } else if (lang.indexOf('lang=tc') != -1) { $('html').attr({"xml:lang": "tc","lang": "tc"}) $('#CalculationResultTable .srHeading').text("計算結果") } }) // Batch 2 END