/*********************************************************
   2004 Individual Income Tax Calculation
   usage:  federalTax = calcSingle( taxableincome );
   usage:  federalTax = calcMarried( taxableincome );
	 usage:  federalTax = calcFederalTax( taxableIncome, married );
	 Copyright 2005 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<7150)
          fedTax = taxableIncomeR*.10;

     if (taxableIncomeR>=7150 && taxableIncomeR<29050)
          fedTax = ((taxableIncomeR-7150)*.15)+715;
			  
     if (taxableIncomeR>=29050 && taxableIncomeR<70350)
          fedTax = ((taxableIncomeR-29050)*.25)+4000;

     if (taxableIncomeR>=70350 && taxableIncomeR<146750)
          fedTax = ((taxableIncomeR-70350)*.28)+14325;

     if (taxableIncomeR>=146750 && taxableIncomeR<319100)
          fedTax = ((taxableIncomeR-146750)*.33)+35717;

     if (taxableIncomeR>=319100)
          fedTax = ((taxableIncomeR-319100)*.35)+92592.50;

     if (fedTax < 0)
          fedTax = 0;

     fedTax = Math.round(fedTax);
		 
		 return( fedTax );
}

function calcMarried( taxableIncomeR )
{

  var fedTax = 0;

     taxableIncomeR = roundIncome(taxableIncomeR);

     if (taxableIncomeR<14300)
          fedTax = taxableIncomeR*.10;

     if (taxableIncomeR>=14300 && taxableIncomeR<58100)
          fedTax = ((taxableIncomeR-14300)*.15)+1430;
			  
     if (taxableIncomeR>=58100 && taxableIncomeR<117250)
          fedTax = ((taxableIncomeR-58100)*.25)+8000;

     if (taxableIncomeR>=117250 && taxableIncomeR<178650)
          fedTax = ((taxableIncomeR-117250)*.28)+22787.50;

     if (taxableIncomeR>=178650 && taxableIncomeR<319100)
          fedTax = ((taxableIncomeR-178650)*.33)+39979.50;

     if (taxableIncomeR>=319100)
          fedTax = ((taxableIncomeR-319100)*.35)+86328;

     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 );
	
}
