|
<!-- Dynamic HTML code / JavaScript Personal income tax calculator (federal and provincial deductions). ( c. 2004 Igor Klepoch ) --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="robots" content="noindex, nofollow"> <TITLE>TAX calcucator</TITLE> <script language="JavaScript" type="text/javascript" src="src/tax.js"></script> <script language='javascript' type="text/javascript" > var LastElem1 = 0; var LastElem2 = 0; function AddHeader (oTHead, txt) { oTHead.appendChild(oRow); oCell = document.createElement("TH"); oCell.innerText = txt; oCell.className ='TblHeader'; oRow.appendChild(oCell); } function AddCell (oCell, oRow, Data, className) { oCell = document.createElement("TD"); oCell.innerText = Data; oCell.className = className; oRow.appendChild(oCell); } function AddCell1 (oRow, Data, className) { oCell = document.createElement("TD"); oCell.innerText = Data; oCell.className = className; oRow.appendChild(oCell); } function AddFederalInfo (oTBody, Title, Val, className) { oRow = document.createElement("TR"); AddCell1 (oRow, Title, className); AddCell1 (oRow, Val, className); oTBody.appendChild(oRow); } function FormatAmt (t) {return (Math.floor(t * 100)/100)}; function ShowTable (Amt) { Amt = Math.round (Amt); var oTable = document.createElement("TABLE"); var oTBody = document.createElement("TBODY"); oTable.appendChild(oTBody); oTable.className='TblFormatFed'; for (t=0;t<3;t++){ CDed = FormatAmt (CalcTax (ProvList[t][0], Amt)); AddFederalInfo (oTBody, ProvList[t][1], CDed, 'TblFederal'); } FEDAmt = CalcTax (FED, Amt); EIAmt = CalcTax (EI, Amt); CPPAmt = CalcTax (CPP, Amt); FedDED = ProvList[0][0][0][0] * (ProvList[0][2] + EIAmt + CPPAmt) / 100; TotDED = FormatAmt (FEDAmt + EIAmt + CPPAmt - FedDED); AddFederalInfo (oTBody, 'Basic personal amount for Federal Taxes (Credit)', FedDED, 'TblFederal'); AddFederalInfo (oTBody, 'Total deductions for EI, CPP and Federal Tax', TotDED, 'TblFederalTotal'); if (LastElem1 == 0) { oTableFederal.appendChild(oTable); } else { oTableFederal.replaceChild(oTable, LastElem1); } LastElem1 = oTable; var oTable = document.createElement("TABLE"); var oTHead = document.createElement("THEAD"); var oTBody = document.createElement("TBODY"); var oTFoot = document.createElement("TFOOT"); var oCaption = document.createElement("CAPTION"); oTable.appendChild(oTHead); oTable.appendChild(oTBody); oTable.appendChild(oTFoot); oTable.appendChild(oCaption); oTable.className='TblFormatProv'; oRow = document.createElement("TR"); AddHeader (oTHead, 'Province'); AddHeader (oTHead, 'Total Fed_tax+EI+CPP'); AddHeader (oTHead, 'Province tax'); AddHeader (oTHead, 'Pers Amt'); AddHeader (oTHead, 'Province Surtax'); AddHeader (oTHead, 'Health premium'); AddHeader (oTHead, 'Net Income'); AddHeader (oTHead, 'Marginal NET .gain from $1'); for (t=3; t<ProvList.length; t++) { CDed = FormatAmt (CalcTax (ProvList[t][0], Amt)); BasDED = FormatAmt (ProvList[t][0][0][0] * (ProvList[t][2] + EIAmt + CPPAmt) / 100); CDed = FormatAmt (CDed - BasDED); SurTax = FormatAmt (CalcSurTax (ProvList[t][3], CDed)); HealthPrem = FormatAmt (CalcHealthPrem (ProvList [t][4], Amt)); oRow = document.createElement("TR"); if (Math.round(t/2) * 2 == t) {oRow.className ='TblRowEven'} else {oRow.className ='TblRowOdd'}; oTBody.appendChild(oRow); AddCell (oCell, oRow, ProvList[t][1], oRow.className + 'Prov'); AddCell (oCell, oRow, TotDED, oRow.className); AddCell (oCell, oRow, FormatAmt (CDed + BasDED), oRow.className); AddCell (oCell, oRow, BasDED, oRow.className); AddCell (oCell, oRow, SurTax, oRow.className); AddCell (oCell, oRow, HealthPrem, oRow.className); AddCell (oCell, oRow, FormatAmt(Amt - (TotDED + CDed + SurTax + HealthPrem)), oRow.className); Amt2 = Amt + 1 FEDAmt2 = CalcTax (FED, Amt2); EIAmt2 = CalcTax (EI, Amt2); CPPAmt2 = CalcTax (CPP, Amt2); FedDED2 = ProvList[0][0][0][0] * (ProvList[0][2] + EIAmt2 + CPPAmt2) / 100; TotDED2 = FormatAmt (FEDAmt2 + EIAmt2 + CPPAmt2 - FedDED2); CDed2 = FormatAmt (CalcTax (ProvList[t][0], Amt2)); BasDED2 = FormatAmt (ProvList[t][0][0][0] * (ProvList[t][2] + EIAmt2 + CPPAmt2) / 100); CDed2 = FormatAmt (CDed2 - BasDED2); SurTax2 = FormatAmt (CalcSurTax (ProvList[t][3], CDed2)); HealthPrem2 = FormatAmt (CalcHealthPrem (ProvList [t][4], Amt2)); Diff = (Amt2 - (TotDED2 + CDed2 + SurTax2 + HealthPrem2)) - (Amt - (TotDED + CDed + SurTax + HealthPrem)); AddCell (oCell, oRow, FormatAmt(Diff), oRow.className); } if (LastElem2 == 0) { oTablePRovince.appendChild(oTable); } else { oTablePRovince.replaceChild(oTable, LastElem2); } LastElem2 = oTable; } function CalcTax (Prov, Amt) { res = 0; for (i=0; i<Prov.length; i++) { if (Prov [i][1] == 1000000) { c = Amt; Amt = 0; } else { c = Math.min (Amt, Prov [i][1]); Amt = Amt - c; } res = res + c * Prov [i][0]/100; } return (res); } function CalcSurTax (ProvTbl, TaxAmt) { res = 0; for (i=0; i<ProvTbl.length; i++) { if (TaxAmt >= ProvTbl[i][1]) { res = ((TaxAmt - ProvTbl[i][1]) * ProvTbl [i][0]) / 100; } } return (res); } function CalcHealthPrem (ProvTbl, TaxAmt) { res = 0; for (i=0; i<ProvTbl.length; i++) { if (TaxAmt >= ProvTbl[i][0]) { res = (TaxAmt - ProvTbl [i][0]) * ProvTbl [i][2] / 100 + ProvTbl [i][1]; // alert (TaxAmt); } } return Math.round (res); } function IncreaseIncome (Increase) { document.form.Income.value = FormatAmt (document.form.Income.value * (FormatAmt (Increase) + 100) / 100); ShowTable(document.form.Income.value); } </script> <link rel=stylesheet type="text/css" href="src/tax.css"> </HEAD> <BODY onload='javascript:ShowTable(document.form.Income.value);'> <form name="form" method="POST"> <table border="0"> <tr> <td class='IncEntry'>Enter your income:</td> <td> <input type="text" size="10" name="Income" value="50000" class='IncEntry'> </td> <td class='Space1'> </td> <td class='IncEntry2'>Increase income by [%] :</td> <td> <input type="text" size="5" name="Increase" value="3" class='IncEntry2'> </td> <td class='IncEntry'><input type="button" class='IncEntry2' name="B2" value="Increase" OnClick="IncreaseIncome (document.form.Increase.value);"></td> </tr> </table> <input type="button" class='IncEntry' name="B1" value="Calculate Deductions" OnClick="ShowTable(document.form.Income.value);"> </form> <br> <table> <tr><td> <DIV ID="oTableFederal"> </DIV> </td> <td class='Space1'> </td> <td> <table><tr> <td><a href="SWDeal.html" class='ImgLink'><img src="src/adv.gif" width="391"height="81" alt="" hspace="0" border="0"></a></td> </tr><tr> <td><a href="../CarAgenda/index.html" target="_car"><img src="src/car3.gif" width="370" height="90" alt="" border="0"></a></td> </tr></table> </td></tr></table> <br><br> <DIV ID="oTablePRovince"> </DIV> <!-- --------------------------------------------------------------------------------------- tax.js --------------------------------------------------------------------------------------- --> NullArr = new Array (0) var i = 0 function addRate (Arr, Perc, Max) { Arr[i] = new Array (2) Arr [i][0] = Perc Arr [i][1] = Max i++; } FED = new Array (4) i = 0; addRate (FED, 16, 35595); addRate (FED, 22, 35595); addRate (FED, 26, 44549); addRate (FED, 29, 1000000); NL = new Array (3) i = 0; addRate (NL, 10.57, 29590); addRate (NL, 16.16, 29590); addRate (NL, 18.02, 1000000); PE = new Array (3) i = 0; addRate (PE, 9.8, 30754); addRate (PE, 13.8, 30755); addRate (PE, 16.7, 1000000); NS = new Array (4) i = 0; addRate (NS, 8.79, 29590); addRate (NS, 14.95, 29590); addRate (NS, 16.67, 33820); addRate (NS, 17.5, 1000000); NB = new Array (4) i = 0; addRate (NB, 9.68, 32730); addRate (NB, 14.82, 32732); addRate (NB, 16.52, 40965); addRate (NB, 17.84, 1000000); ON = new Array (3) i = 0; addRate (ON, 6.05, 34010); addRate (ON, 9.15, 34010); addRate (ON, 11.16, 1000000); MB = new Array (3) i = 0; addRate (MB, 10.9, 30544); addRate (MB, 14, 34456); addRate (MB, 17.4, 1000000); SK = new Array (3) i = 0; addRate (SK, 11, 36770); addRate (SK, 13, 68286); addRate (SK, 15, 1000000); AB = new Array (1) i = 0; addRate (AB, 10, 1000000); BC = new Array (5) i = 0; addRate (BC, 6.05, 33061); addRate (BC, 9.15, 33062); addRate (BC, 11.7, 9764); addRate (BC, 13.7, 16268); addRate (BC, 14.7, 1000000); YT = new Array (4) i = 0; addRate (YT, 7.04, 35595); addRate (YT, 9.68, 35595); addRate (YT, 11.44, 44549); addRate (YT, 12.76, 1000000); NT = new Array (4) i = 0; addRate (NT, 5.9, 33811); addRate (NT, 8.6, 33811); addRate (NT, 12.2, 42317); addRate (NT, 14.05, 1000000); NU = new Array (4) i = 0; addRate (NU, 4, 35595); addRate (NU, 7, 35595); addRate (NU, 9, 44594); addRate (NU, 11.5, 1000000); EI = new Array (2) i = 0; addRate (EI, 1.95, 39000); addRate (EI, 0, 1000000); CPP = new Array (2) i = 0; addRate (CPP, 4.95, 41100 - 3500); addRate (CPP, 0, 1000000); ONST = new Array (2) i = 0; addRate (ONST, 20, 3929); addRate (ONST, 56, 4957); NLST = new Array (1) i = 0; addRate (NLST, 9, 7032); PEST = new Array (1) i = 0; addRate (PEST, 10, 5200); NSST = new Array (1) i = 0; addRate (NSST, 10, 10000); YTST = new Array (1) i = 0; addRate (YTST, 5, 6000); function addHealth (PrArr, Bracket, MinAmt, Perc) { PrArr [i] = new Array (3) PrArr [i][0] = Bracket PrArr [i][1] = MinAmt PrArr [i][2] = Perc i++; } ONHlt = new Array (10) i = 0; addHealth (ONHlt, 20000, 0, 6); addHealth (ONHlt, 25000, 300, 0); addHealth (ONHlt, 36000, 300, 6); addHealth (ONHlt, 38500, 450, 0); addHealth (ONHlt, 48000, 450, 25); addHealth (ONHlt, 48600, 600, 0); addHealth (ONHlt, 72000, 600, 25); addHealth (ONHlt, 72600, 750, 0); addHealth (ONHlt, 200000, 750, 25); addHealth (ONHlt, 200600, 900, 0); ABHlt = new Array (1) i = 0; addHealth (ABHlt, 0, 1056, 0); i = 0; function addProv (Prabbr, PrName, PersAmt, SurTax, Health) { ProvList [i] = new Array (5) ProvList [i][0] = Prabbr ProvList [i][1] = PrName ProvList [i][2] = PersAmt ProvList [i][3] = SurTax ProvList [i][4] = Health i++; } ProvList = new Array (15) addProv (FED, 'Federal Tax', 8148, '', ''); addProv (EI, 'Employment Insurance', 0, '', ''); addProv (CPP, 'CPP', 0, '', ''); addProv (NL, 'Newfoundland and Labrador', 7410, NLST, NullArr); addProv (PE, 'Prince Edward Island', 7412, PEST, NullArr); addProv (NS, 'Nova Scotia', 7231, NSST, NullArr); addProv (NB, 'New Brunswick', 7888, NullArr, NullArr); addProv (ON, 'Ontario', 8196, ONST, ONHlt); addProv (MB, 'Manitoba', 7634, NullArr, NullArr); addProv (SK, 'Saskatchewan', 8404, NullArr, NullArr); addProv (AB, 'Alberta', 14523, NullArr, ABHlt); addProv (BC, 'British Columbia', 8676, NullArr, NullArr); addProv (YT, 'Yukon', 8148, YTST, NullArr); addProv (NT, 'Northwest Territories', 11609, NullArr, NullArr); addProv (NU, 'Nunavut', 10674, NullArr, NullArr);