function CurrencyFormatted(amount) { var i = parseFloat(amount); if (isNaN(i)) { i = 0.00; } var minus = ''; if (i < 0) { minus = '-'; } i = Math.abs(i); i = parseInt((i + .005) * 100); i = i / 100; s = new String(i); if (s.indexOf('.') < 0) { s += '.00'; } if (s.indexOf('.') == (s.length - 2)) { s += '0'; } s = minus + s; return s; } function CommaFormatted(amount) { var delimiter = ","; // replace comma if desired var a = amount.split('.', 2) var d = a[1]; var i = parseInt(a[0]); if (isNaN(i)) { return ''; } var minus = ''; if (i < 0) { minus = '-'; } i = Math.abs(i); var n = new String(i); var a = []; while (n.length > 3) { var nn = n.substr(n.length - 3); a.unshift(nn); n = n.substr(0, n.length - 3); } if (n.length > 0) { a.unshift(n); } n = a.join(delimiter); if (d.length < 1) { amount = n; } else { amount = n + '.' + d; } amount = minus + amount; return amount; } var i = "1"; function calculate() { var property = parseFloat(document.querySelector("#calculator1 [name=pvalue]").value.replace(/,/g, '')); var fee = "RM "; //currencyFormat(this,',','.',event)) if (document.querySelector("#calculator1 [name=pvalue]").value == "") { alert("Please enter the property value."); document.querySelector("#calculator1 [name=pvalue]").focus(); } else if (!parseFloat(document.querySelector("#calculator1 [name=pvalue]").value)) { alert("Please enter only number."); document.querySelector("#calculator1 [name=pvalue]").focus(); } // } else if (property <= "150000") { // pcount = property * 0.01; // pcount = CurrencyFormatted(pcount); // pcount = CommaFormatted(pcount); // document.querySelector("#calculator1 [name=totalfees]").value = fee + pcount; // } else if (property <= "1000000") { // pcount = (1500 + (property - 150000) * 0.007); // pcount = CurrencyFormatted(pcount); // pcount = CommaFormatted(pcount); // document.querySelector("#calculator1 [name=totalfees]").value = fee + pcount; // } else if (property <= "3000000") { // pcount = (7450 + (property - 1000000) * 0.006); // pcount = CurrencyFormatted(pcount); // pcount = CommaFormatted(pcount); // document.querySelector("#calculator1 [name=totalfees]").value = fee + pcount; // } else if (property <= "5000000") { // pcount = (19450 + (property - 3000000) * 0.005); // pcount = CurrencyFormatted(pcount); // pcount = CommaFormatted(pcount); // document.querySelector("#calculator1 [name=totalfees]").value = fee + pcount; // } else if (property <= "7500000") { // pcount = (29450 + (property - 5000000) * 0.004); // pcount = CurrencyFormatted(pcount); // pcount = CommaFormatted(pcount); // document.querySelector("#calculator1 [name=totalfees]").value = fee + pcount; // } // else if (property > "7500000") { // var rateval = prompt("Please key in the negotiated rate for property more than RM7.5 million.Example: 0.4"); // if (!parseFloat(rateval)) { // alert("Please enter only number."); // } // else { // var prate = parseFloat(rateval); // pcount = (39450 + (property - 7500000) * (prate / 100)); // pcount = CurrencyFormatted(pcount); // pcount = CommaFormatted(pcount); // document.querySelector("#calculator1 [name=totalfees]").value = fee + pcount; // } // } pcount = calculateNew(property); pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator1 [name=totalfees]").value = fee + pcount; } function calculateNew(value) { var newP; var remainder = value - 500000; if (remainder >= 500000) { newP = 500000 * 0.01; } else { newP = value * 0.01; } if (newP < 500){ newP = 500; } if (remainder > 0) { if (remainder >= 500000) { newP = newP + (500000 * 0.008); } else { newP = newP + (remainder * 0.008); } remainder = remainder - 500000; } if (remainder > 0) { if (remainder >= 2000000) { newP = newP + (2000000 * 0.007); } else { newP = newP + (remainder * 0.007); } remainder = remainder - 2000000; } if (remainder > 0) { if (remainder >= 2000000) { newP = newP + (2000000 * 0.006); } else { newP = newP + (remainder * 0.006); } remainder = remainder - 2000000; } if (remainder > 0) { if (remainder >= 2000000) { newP = newP + (2000000 * 0.005); } else { newP = newP + (remainder * 0.005); } remainder = remainder - 2000000; } if (remainder > 0) { newP = newP + (remainder * 0.005); remainder = 0; } return newP; } /* function more_rate() { if (parseFloat(document.calculator.pvalue.value)>="7500000" && i=="1") { alert("If property value is more than RM 7.5 million, please key in the excess rate. Example 0.2%"); i = "2"; //unhide('irate'); } else if (document.calculator.pvalue.value=="" && i=="2") { i = "1"; //unhide('irate'); } } function unhide(divID) { var item = document.getElementById(divID); if (item) { item.className=(item.className=='hidden')?'unhidden':'hidden'; } } function go_stamp() { myrev="legal_calculator_stamp.php?solo=y"; window.open (myrev, '','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizeable=0,width=300,height=150,left=51%,top=51%'); } */ function calculate_stamp() { var property = parseFloat(document.querySelector("#calculator2 [name=pvalue2]").value.replace(/,/g, '')); var fee = "RM "; //currencyFormat(this,',','.',event)) if (document.querySelector("#calculator2 [name=pvalue2]").value == "") { alert("Please enter the property value."); document.querySelector("#calculator2 [name=pvalue2]").focus(); } else if (!parseFloat(document.querySelector("#calculator2 [name=pvalue2]").value)) { alert("Please enter only number."); document.querySelector("#calculator2 [name=pvalue2]").focus(); } else if (property <= "100000") { pcount = property * 0.01; pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator2 [name=totalfees2]").value = fee + pcount; } else if (property <= "500000") { pcount = (1000 + (property - 100000) * 0.02); pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator2 [name=totalfees2]").value = fee + pcount; } else if (property <= "1000000") { pcount = (9000 + (property - 500000) * 0.03); pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator2 [name=totalfees2]").value = fee + pcount; } else if (property > "1000000") { pcount = (15000+9000 + (property - 1000000) * 0.04); pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator2 [name=totalfees2]").value = fee + pcount; } } function calculate_stamp2() { var property = parseFloat(document.querySelector("#calculator3 [name=pvalue3]").value.replace(/,/g, '')); var fee = "RM "; //currencyFormat(this,',','.',event)) if (document.querySelector("#calculator3 [name=pvalue3]").value == "") { alert("Please enter the property value."); document.querySelector("#calculator3 [name=pvalue3]").focus(); } else if (!parseFloat(document.querySelector("#calculator3 [name=pvalue3]").value)) { alert("Please enter only number."); document.querySelector("#calculator3 [name=pvalue3]").focus(); } else { var ans, ans2 ans = Math.ceil(property / 1000) ans2 = Math.ceil(ans * 1000) pcount = ans2 * 0.005 pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator3 [name=totalfees3]").value = fee + pcount; } } function computeLoan() { var s = validation(); if (s != true) { return; } lar = deFormatCurrency(document.getElementById("txtTotalPrice").value); if (lar > 0) { ir = document.getElementById("txtIR").value lt = document.getElementById("txtLT").value mof = document.getElementById("txtMOF").value lat = lar * 1 * mof / 100 // Calculate Monthly Repayment if (lt > 0) { mr = -pmt((ir / 100) / 12, (lt * 12), (lat), 0, 0); } else { mr = 0; } // Calculate Min. Monthly Income Required mmir = mr / (33 / 100); document.getElementById("txtTotalPrice").value = formatCurrency(lar); //document.getElementById("txtLoanAmount").value = formatCurrency(lat); document.getElementById("txtMR").value = formatCurrency(mr); //document.getElementById("txtMMIR").value = formatCurrency(mmir); //document.getElementById("txtTotalPrice").value = document.getElementById("txtLAR").value; document.getElementById("txtTotalLoan").value = formatCurrency(lat); } } function pmt(rate, nper, pv, fv, p_type) { var pvif = Math.pow(1 + rate, nper); var fvifa = (Math.pow(1 + rate, nper) - 1) / rate; var type1 = (p_type != 0) ? 1 : 0; var lvamt = ((-pv * pvif - fv) / ((1 + rate * type1) * fvifa)); if (isNaN((-pv * pvif - fv) / ((1 + rate * type1) * fvifa))) { return 0.00; } else { return ((-pv * pvif - fv) / ((1 + rate * type1) * fvifa)); } } function deFormatCurrency(num) { num = num.toString().replace(/\$|\,/g, ''); return num; } function formatCurrency(num) { num = num.toString().replace(/\$|\,/g, ''); if (isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num * 100 + 0.50000000001); cents = num % 100; num = Math.floor(num / 100).toString(); for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3)); return (((sign) ? '' : '-') + num); } function IsNumeric(sText) { var ValidChars = "0123456789.,"; var IsNum = true; var Char; for (i = 0; i < sText.length && IsNum == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNum = false; } } return IsNum; } function validation() { // Margin Of Finance if (!IsNumeric(document.getElementById("txtTotalPrice").value)) { alert("Please Enter Number Only."); docRef.txtMOF.focus(); return false; } // Margin Of Finance if (!IsNumeric(document.getElementById("txtMOF").value)) { alert("Please Enter Number Only."); docRef.txtMOF.focus(); return false; } // Interest Rate if (!IsNumeric(document.getElementById("txtIR").value)) { alert("Please Enter Number Only."); docRef.txtIR.focus(); return false; } // Loan Tenure if (!IsNumeric(document.getElementById("txtLT").value)) { alert("Please Enter Number Only."); docRef.txtLT.focus(); return false; } return true; } function calculate_quotation() { var property = parseFloat(document.querySelector("#calculator_quotation [name=pvalue]").value); var fee = "RM "; //currencyFormat(this,',','.',event)) if (document.querySelector("#calculator_quotation [name=pvalue]").value == "") { alert("Please enter the property value."); document.querySelector("#calculator_quotation [name=pvalue]").focus(); } else if (!parseFloat(document.querySelector("#calculator_quotation [name=pvalue]").value)) { alert("Please enter only number."); document.querySelector("#calculator_quotation [name=pvalue]").focus(); } else if (property <= "30000") { pcount = 300; pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator_quotation [name=totalfees]").value = fee + pcount; } else if (property <= "150000") { pcount = (property) * 0.01; pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator_quotation [name=totalfees]").value = fee + pcount; } else if (property <= "300000") { pcount = ((property - 150000) * 0.007 + 1500); pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator_quotation [name=totalfees]").value = fee + pcount; } else if (property <= "500000") { pcount = (property - 300000) * 0.005 + 2550; pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator_quotation [name=totalfees]").value = fee + pcount; } else if (property <= "1000000") { pcount = (property - 500000) * 0.004 + 3550; pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator_quotation [name=totalfees]").value = fee + pcount; } else if (property <= "2000000") { pcount = (property - 1000000) * 0.003 + 5550; pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator_quotation [name=totalfees]").value = fee + pcount; } else if (property <= "3000000") { pcount = (property - 2000000) * 0.002 + 8550; pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator_quotation [name=totalfees]").value = fee + pcount; } else if (property <= "5000000") { pcount = (property - 3000000) * 0.001 + 10550; pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator_quotation [name=totalfees]").value = fee + pcount; } else { pcount = 12550; pcount = CurrencyFormatted(pcount); pcount = CommaFormatted(pcount); document.querySelector("#calculator_quotation [name=totalfees]").value = fee + pcount; } } jQuery(document).ready(function () { jQuery("#cal1").click(function () { calculate(); }); jQuery("#cal2").click(function () { calculate_stamp(); }); jQuery("#cal3").click(function () { calculate_stamp2(); }); jQuery("#cal_quot").click(function () { calculate_quotation(); }); jQuery("#txtTotalPrice, #txtMOF, #txtIR, #txtLT, #txtTotalLoan").keyup(function () { computeLoan(); }); jQuery("#pvalue").keyup(function () { document.getElementById("pvalue").value = formatCurrency($("#pvalue").val()); }); jQuery("#pvalue2").keyup(function () { document.getElementById("pvalue2").value = formatCurrency($("#pvalue2").val()); }); jQuery("#pvalue3").keyup(function () { document.getElementById("pvalue3").value = formatCurrency($("#pvalue3").val()); }); });