/*********************************************************
   2003 Individual Income Tax Calculation
   usage:  federalTax = calcSingle( taxableincome );
   usage:  federalTax = calcMarried( taxableincome );
	 usage:  federalTax = calcFederalTax( taxableIncome, married );
	 Copyright 2003 Mark E. Gunnison
  *********************************************************/

function calcFederalTax( taxableIncome, married )
{
var fedTax = 0;


 			if (married == 1)
			 	fedTax = calcMarried( taxableIncome );
			else
				fedTax = calcSingle( taxableIncome );

			return (fedTax);
}	
	
	
function calcSingle( taxableIncomeR )
{
   var fedTax = 0;

     taxableIncomeR = roundIncome(taxableIncomeR);

     if (taxableIncomeR<7000)
          fedTax = taxableIncomeR*.10;

     if (taxableIncomeR>=7000 && taxableIncomeR<28400)
          fedTax = ((taxableIncomeR-7000)*.15)+700;
			  
     if (taxableIncomeR>=28400 && taxableIncomeR<68800)
          fedTax = ((taxableIncomeR-28400)*.25)+3910.0;

     if (taxableIncomeR>=68800 && taxableIncomeR<143500)
          fedTax = ((taxableIncomeR-68800)*.28)+14010;

     if (taxableIncomeR>=143500 && taxableIncomeR<311950)
          fedTax = ((taxableIncomeR-143500)*.33)+34926;

     if (taxableIncomeR>=307050)
          fedTax = ((taxableIncomeR-311950)*.35)+90514.5;

     if (fedTax < 0)
          fedTax = 0;

     fedTax = Math.round(fedTax);
		 
		 return( fedTax );
}

function calcMarried( taxableIncomeR )
{

  var fedTax = 0;

     taxableIncomeR = roundIncome(taxableIncomeR);

     if (taxableIncomeR<14000)
          fedTax = taxableIncomeR*.10;

     if (taxableIncomeR>=14000 && taxableIncomeR<56800)
          fedTax = ((taxableIncomeR-14000)*.15)+1400;
			  
     if (taxableIncomeR>=56800 && taxableIncomeR<114650)
          fedTax = ((taxableIncomeR-56800)*.25)+7820;

     if (taxableIncomeR>=114650 && taxableIncomeR<174700)
          fedTax = ((taxableIncomeR-114650)*.28)+22282.50;

     if (taxableIncomeR>=174700 && taxableIncomeR<311950)
          fedTax = ((taxableIncomeR-174700)*.33)+39096.50;

     if (taxableIncomeR>=311950)
          fedTax = ((taxableIncomeR-311950)*.35)+84398.00;

     if (fedTax < 0)
          fedTax = 0;

     fedTax = Math.round(fedTax);
		 
		 
 		 return( fedTax );
}

/***************** Round to amount used by the IRS in their table ************************/
function roundIncome(taxableIncomeR)
{
var taxableIncome = 0;
taxableIncome = taxableIncomeR;


        if (taxableIncome<3000 && taxableIncome>0)       //use IRS rounding for table
	{

                taxableIncomeR = Math.floor(taxableIncome/100);  // round to 100
                taxableIncomeR = taxableIncomeR*100;

                if (taxableIncome - taxableIncomeR < 25)
                        taxableIncomeR += 13;
                if (taxableIncome - taxableIncomeR >= 25 && taxableIncome - taxableIncomeR < 50)
                        taxableIncomeR += 38;
                if (taxableIncome - taxableIncomeR >= 50 && taxableIncome - taxableIncomeR < 75)
                        taxableIncomeR += 63;
                if (taxableIncome - taxableIncomeR >= 75 && taxableIncome - taxableIncomeR < 100)
                        taxableIncomeR += 88;

	}


        if (taxableIncome<100000 && taxableIncome>=3000)       //use IRS rounding for table
	{

                taxableIncomeR = Math.floor(taxableIncome/100);  // round to 100
                taxableIncomeR = taxableIncomeR*100;

                if (taxableIncome - taxableIncomeR < 50)
			taxableIncomeR += 25;
		else	
			taxableIncomeR += 75;
	}

	return( taxableIncomeR );
	
}
