/*********************************************************
   2005 Individual Income Tax Calculation
   usage:  federalTax = calcSingle( taxableincome );
   usage:  federalTax = calcMarried( taxableincome );
	 usage:  federalTax = calcFederalTax( taxableIncome, married );
	 Copyright 2006 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<7300)
          fedTax = taxableIncomeR*.10;

     if (taxableIncomeR>=7300 && taxableIncomeR<29700)
          fedTax = ((taxableIncomeR-7300)*.15)+730;
			  
     if (taxableIncomeR>=29700 && taxableIncomeR<71950)
          fedTax = ((taxableIncomeR-29700)*.25)+4090;

     if (taxableIncomeR>=71950 && taxableIncomeR<150150)
          fedTax = ((taxableIncomeR-71950)*.28)+14652.50;

     if (taxableIncomeR>=150150 && taxableIncomeR<326450)
          fedTax = ((taxableIncomeR-150150)*.33)+36548.50;

     if (taxableIncomeR>=326450)
          fedTax = ((taxableIncomeR-326450)*.35)+94727.50;

     if (fedTax < 0)
          fedTax = 0;

     fedTax = Math.round(fedTax);
		 
		 return( fedTax );
}

function calcMarried( taxableIncomeR )
{

  var fedTax = 0;

     taxableIncomeR = roundIncome(taxableIncomeR);

     if (taxableIncomeR<14600)
          fedTax = taxableIncomeR*.10;

     if (taxableIncomeR>=14600 && taxableIncomeR<59400)
          fedTax = ((taxableIncomeR-14600)*.15)+1460;
			  
     if (taxableIncomeR>=59400 && taxableIncomeR<119950)
          fedTax = ((taxableIncomeR-59400)*.25)+8180;

     if (taxableIncomeR>=119950 && taxableIncomeR<182800)
          fedTax = ((taxableIncomeR-119950)*.28)+23317.50;

     if (taxableIncomeR>=182800 && taxableIncomeR<326450)
          fedTax = ((taxableIncomeR-182800)*.33)+40915.50;

     if (taxableIncomeR>=326450)
          fedTax = ((taxableIncomeR-326450)*.35)+88320;

     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 );
	
}

