function RoundNumbers(TheNum) { //return Math.round(TheNum); return TheNum; }
function addComma(TheNum) { numVar = String(TheNum); var commaNumber = ""; var thenumber = "" var thefraction = ""; var j = numVar.indexOf("."); var l = numVar.length;
if (j > 0) { //found a period. tvar = numVar + "00"; numVar = numVar.substr(0, j); for (i = j; i < j + 3; i++) { thefraction = thefraction + tvar.charAt(i); } } else { //no period found thefraction = ".00"; } j = numVar.length; for (i = j; i > 0; i--) { if ((i != j) && ((j - i) % 3 == 0)) thenumber = thenumber + " "; thenumber = thenumber + numVar.charAt(i - 1); } j = thenumber.length; for (i = j; i >= 0; i--) commaNumber = commaNumber + thenumber.charAt(i);
commaNumber = commaNumber + thefraction; return commaNumber; }
function addCommaEx(TheNum) { numVar = String(TheNum); var commaNumber = ""; var thenumber = "" var thefraction = ""; var j = numVar.length;
for (i = j; i > 0; i--) { if ((i != j) && ((j - i) % 3 == 0)) thenumber = thenumber + " "; thenumber = thenumber + numVar.charAt(i - 1); } j = thenumber.length; for (i = j; i >= 0; i--) commaNumber = commaNumber + thenumber.charAt(i);
return commaNumber; }
function remComma(TheNum) { numVar = String(TheNum); var thenumber = "" var l = numVar.length;
for (i = l; i > 0; i--) { if (numVar.charAt(i - 1) != " ") thenumber = thenumber + numVar.charAt(i - 1); }
numVar = "" j = thenumber.length; for (i = j; i >= 0; i--) numVar = numVar + thenumber.charAt(i);
if ((numVar == ".00")) { numVar = "0" } return numVar; }
function CalculateTransfer() { var tot1 = 0; var tot2 = 0; document.frmCalc.calcOption.value = 1; if (remComma(document.frmCalc.txtPurch.value) == 0) { alert("Please enter a purchase price.") document.frmCalc.txtPurch.focus() } else {
tot1 = CalculateTransferFees(1); tot2 = CalculateBondFees(0); tot3 = CalculateRepayments(0);
document.frmCalc.txtTtotal2.value = document.frmCalc.txtTtotal.value; //transfer cost breakdown total document.frmCalc.txtPurch2.value = addComma(remComma(document.frmCalc.txtPurch.value));//TRANSFER COSTS purchase price } }
function CalculateBond() { var tot1 = 0; var tot2 = 0; document.frmCalc.calcOption.value = 2; if (remComma(document.frmCalc.txtAmt.value) == 0) { alert("Please enter a bond amount.") document.frmCalc.txtAmt.focus() } else { document.frmCalc.txtAmt2.value = document.frmCalc.txtAmt.value;//bond amount
tot1 = CalculateTransferFees(0); tot2 = CalculateBondFees(1); tot3 = CalculateRepayments(1);
document.frmCalc.txtBtotal2.value = document.frmCalc.txtBtotal.value; //bond cost breakdown total document.frmCalc.txtAmt3.value = addComma(remComma(document.frmCalc.txtAmt.value));//BOND COSTS bond amount } }
function CalculateAll() { var tot1 = 0; var tot2 = 0; document.frmCalc.calcOption.value = 3; if (remComma(document.frmCalc.txtPurch.value) == 0) { alert("Please enter a purchase price.") document.frmCalc.txtPurch.focus() } else { if (remComma(document.frmCalc.txtAmt.value) == 0) { alert("Please enter a bond amount.") document.frmCalc.txtAmt.focus() } else { document.frmCalc.txtAmt2.value = document.frmCalc.txtAmt.value; //bond amount
tot1 = CalculateTransferFees(1); tot2 = CalculateBondFees(1); tot3 = CalculateRepayments(1);
document.frmCalc.txtTotal.value = addComma(RoundNumbers(tot1 + tot2)); //total cost document.frmCalc.txtTtotal2.value = document.frmCalc.txtTtotal.value;//transfer cost breakdown total document.frmCalc.txtBtotal2.value = document.frmCalc.txtBtotal.value;//bond cost breakdown total document.frmCalc.txtPurch2.value = addComma(remComma(document.frmCalc.txtPurch.value));//TRANSFER COSTS purchase price document.frmCalc.txtAmt3.value = addComma(remComma(document.frmCalc.txtAmt.value));//BOND COSTS bond amount } } }
function ValidateNumberOnlyInput(allowdot) { if (!((event.keyCode >= 48) && (event.keyCode <= 57))) { event.returnValue = false; } if ((allowdot > 0) && (event.keyCode == 46)) { event.returnValue = true; } }
function UpdateInfo(MustUpdate) { var amt = 0; //add commas to the top values document.frmCalc.txtPurch.value = addCommaEx(remComma(document.frmCalc.txtPurch.value)); document.frmCalc.txtDep.value = addCommaEx(remComma(document.frmCalc.txtDep.value)); document.frmCalc.txtAmt.value = addCommaEx(remComma(document.frmCalc.txtAmt.value));
if ((MustUpdate == 1) && (remComma(document.frmCalc.txtPurch.value) > 0) && (remComma(document.frmCalc.txtDep.value) > 0)) { amt = remComma(document.frmCalc.txtPurch.value) - remComma(document.frmCalc.txtDep.value); document.frmCalc.txtAmt.value = addCommaEx(amt); } }
function UpdateRepayment() { CalculateRepayments(); }
/********* Transfer Conveyancing Tariff Fee ***********/
function GetTxferCost(Amt) { var AmtTXfer1 = 650; var AmtTXfer2 = 1300; var AmtTXfer3 = 650; var AmtTXfer4 = 325;
txfer = 0; if (Amt <= 100000) { txfer = 4300; } x = 0 if (txfer == 0) { if ((Amt > 100000) && (Amt <= 500000)) { txfer = txfer + 4300; x = Math.ceil((Amt - 100000) / 50000); txfer = txfer + (x * AmtTXfer1); } if ((Amt > 500000) && (Amt <= 1000000)) { txfer = txfer + 9500; x = Math.ceil((Amt - 500000) / 100000); txfer = txfer + (x * AmtTXfer2); } if ((Amt > 1000000) && (Amt <= 5000000)) { txfer = txfer + 16000; x = Math.ceil((Amt - 1000000) / 100000); txfer = txfer + (x * AmtTXfer3); } if (Amt > 5000000) { txfer = txfer + 42000; x = Math.ceil((Amt - 5000000) / 100000); txfer = txfer + (x * AmtTXfer4); } } return txfer; }
/********* Bond Conveyancing Tariff Fee */
function GetBondCost(Amt) { var AmtBondC1 = 650; var AmtBondC2 = 1300; var AmtBondC3 = 650; var AmtBondC4 = 325;
bond = 0; if (Amt <= 100000) { bond = 4300; } x = 0 if (bond == 0) { if ((Amt > 100000) && (Amt <= 500000)) { bond = bond + 4300; x = Math.ceil((Amt - 100000) / 50000); bond = bond + (x * AmtBondC1); } if ((Amt > 500000) && (Amt <= 1000000)) { bond = bond + 9500; x = Math.ceil((Amt - 500000) / 100000); bond = bond + (x * AmtBondC2); } if ((Amt > 1000000) && (Amt <= 5000000)) { bond = bond + 16000; x = Math.ceil((Amt - 1000000) / 100000); bond = bond + (x * AmtBondC3); } if (Amt > 5000000) { bond = bond + 42000; x = Math.ceil((Amt - 5000000) / 100000); bond = bond + (x * AmtBondC4); } } return bond; }
/********* Transfer duty ***********/
function GetTxferDuty(Amt) { txfd = 0; if (document.frmCalc.rdg[0].checked) { //seller is a vat vendor return (0); } else { //seller is a natural person if (document.frmCalc.rdg[1].checked) { x = 0; if (Amt <= 900000) { txfd = 0; } //looks good if ((Amt > 900000) && (Amt <= 1250000)) { x = (Amt - 900000) * (3 / 100); txfd = x; } if ((Amt > 1250000) && (Amt <= 1750000)) { x = 10500; x = x + ((Amt - 1250000) * (6 / 100)); txfd = x; } if ((Amt > 1750000) && (Amt <= 2250000)) { x = 40500; x = x + (Amt - 1750000) * (8 / 100); txfd = x; } if ((Amt > 2250000) && (Amt <= 10000000)) { x = 80500; x = x + (Amt - 2250000) * (11 / 100); txfd = x; } if (Amt > 10000000) { x = 933000; x = x + (Amt - 10000000) * (13 / 100); txfd = x; } } return (txfd); } }
/********* Define VAT Values ***********/
function GetVat(Amt) { var VAT_rate = 14 return RoundNumbers(Amt * (VAT_rate / 100)); }
function CalculateTransferFees(MustUpdate) { var Petties = 850; var SearchFee = 200; var Tdocfee = 200; var Evaultfee = 390; var tvat = 0; var runTotal = 0;
v = remComma(document.frmCalc.txtPurch.value); //purchase price tc = GetTxferCost(v); td = GetTxferDuty(v); tvat = GetVat(tc + Petties + SearchFee + Tdocfee + Evaultfee);
/********* Deeds Office Fees Apr 2017 ***********/
exam = 0; if (v <= 100000) { exam = 35; } if ((v > 100000) && (v <= 200000)) { exam = 75; } if ((v > 200000) && (v <= 300000)) { exam = 465; } if ((v > 300000) && (v <= 600000)) { exam = 580; } if ((v > 600000) && (v <= 800000)) { exam = 815; } if ((v > 800000) && (v <= 1000000)) { exam = 930; } if ((v > 1000000) && (v <= 2000000)) { exam = 1050; } if ((v > 2000000) && (v <= 4000000)) { exam = 1275; } if ((v > 4000000) && (v <= 6000000)) { exam = 1750; } if ((v > 6000000) && (v <= 8000000)) { exam = 2100; } if ((v > 8000000) && (v <= 10000000)) { exam = 2455; } if ((v > 10000000) && (v <= 15000000)) { exam = 2920; } if ((v > 15000000) && (v <= 20000000)) { exam = 3505; } if (v > 20000000) { exam = 4675; }
if (MustUpdate == 1) { document.frmCalc.txtTduty.value = addComma(td); document.frmCalc.txtTtariff.value = addComma(tc); document.frmCalc.txtTpost.value = addComma(Petties); document.frmCalc.txtTsearch.value = addComma(SearchFee); document.frmCalc.txtTvat.value = addComma(tvat); document.frmCalc.txtTexam.value = addComma(exam); document.frmCalc.txtTdocfee.value = addComma(Tdocfee); document.frmCalc.txtTevaultfee.value = addComma(Evaultfee); }
with (document.frmCalc) { runTotal = td + exam + tc + Petties + SearchFee + tvat + Tdocfee + Evaultfee; if (MustUpdate == 1) { document.frmCalc.txtTtotal.value = addComma(RoundNumbers(runTotal)); } } return runTotal; }
function CalculateBondFees(MustUpdate) { var runTotal = 0; var Petties = 950; var Aktex = 140; var Bdocfee = 175; ; var Bevaultfee = 390; var bvat = 0; var x = 0;
v = remComma(document.frmCalc.txtAmt.value); bc = GetBondCost(v); bvat = GetVat(bc + Petties + Aktex + Bdocfee + Bevaultfee);
/********* Deeds Office Fees Apr 2017 ***********/
deeds = 0; if (v <= 150000) { deeds = 360; } if ((v > 150000) && (v <= 300000)) { deeds = 400; } if ((v > 300000) && (v <= 600000)) { deeds = 580; } if ((v > 600000) && (v <= 800000)) { deeds = 810; } if ((v > 800000) && (v <= 1000000)) { deeds = 935; } if ((v > 1000000) && (v <= 2000000)) { deeds = 1050; } if ((v > 2000000) && (v <= 4000000)) { deeds = 1456; } if ((v > 4000000) && (v <= 6000000)) { deeds = 1765; } if ((v > 6000000) && (v <= 8000000)) { deeds = 2100; } if ((v > 8000000) && (v <= 10000000)) { deeds = 2455; } if ((v > 10000000) && (v <= 15000000)) { deeds = 2923; } if ((v > 15000000) && (v <= 20000000)) { deeds = 3510; } if ((v > 20000000) && (v <= 30000000)) { deeds = 4090; } if (v > 30000000) { deeds = 5845; }
if (MustUpdate == 1) { document.frmCalc.txtBtariff.value = addComma(bc); document.frmCalc.txtBpost.value = addComma(Petties); document.frmCalc.txtBdeeds.value = addComma(deeds); document.frmCalc.txtBaktex.value = addComma(Aktex); document.frmCalc.txtBdocfee.value = addComma(Bdocfee); document.frmCalc.txtBevaultfee.value = addComma(Bevaultfee); document.frmCalc.txtBvat.value = addComma(bvat); }
with (document.frmCalc) { runTotal = deeds + bc + Petties + Aktex + bvat + Bdocfee + Bevaultfee; if (MustUpdate == 1) { document.frmCalc.txtBtotal.value = addComma(RoundNumbers(runTotal)); } } return runTotal; }
function CalculateRepayments(MustUpdate) { var int_perc = 0; var monthly_int_rate = 0; var month_term = 0;
v = remComma(document.frmCalc.txtAmt2.value);//bond amount i = document.frmCalc.txtInt.value; //interest rate y = document.frmCalc.txtTerm.value; //years
int_perc = i / 100; monthly_int_rate = int_perc / 12; month_term = 12 * y;
p = Math.pow((1 + monthly_int_rate), (-1 * month_term)); r = v * (monthly_int_rate / (1 - p));
if (MustUpdate == 1) { document.frmCalc.txtRepay.value = addComma(RoundNumbers(r)); } }
function CalculateMonthlyInstallment() { var tot1 = 0; var tot2 = 0; var int_perc = 0; var monthly_int_rate = 0; var month_term = 0;
document.frmCalc.calcOption.value = 2; if (remComma(document.frmCalc.txtAmt2.value) == 0) { alert("Please enter a bond amount.") document.frmCalc.txtAmt2.focus() } else {
v = remComma(document.frmCalc.txtAmt2.value); //bond amount i = document.frmCalc.txtInt.value; //interest rate y = document.frmCalc.txtTerm.value;//years
int_perc = i / 100; monthly_int_rate = int_perc / 12; month_term = 12 * y;
p = Math.pow((1 + monthly_int_rate), (-1 * month_term)); r = v * (monthly_int_rate / (1 - p));
document.frmCalc.txtRepay.value = addComma(RoundNumbers(r)); document.frmCalc.txtAmt2.value = addComma(remComma(document.frmCalc.txtAmt2.value)); document.frmCalc.txtBtotal2.value = document.frmCalc.txtBtotal.value; //bond cost breakdown total } }
function UpdateBondCalcOnly(MustUpdate) { var amt = 0; document.frmCalc.txtAmt2.value = addCommaEx(remComma(document.frmCalc.txtAmt2.value)); }