/*********************************************************
   2007 Individual Income Tax Calculation
   usage:  federalTax = calcSingle( taxableincome );
   usage:  federalTax = calcMarried( taxableincome );
	 usage:  federalTax = calcFederalTax( taxableIncome, married );
	 Copyright 2008 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<7825)
          fedTax = taxableIncomeR*.10;

     if (taxableIncomeR>=7825 && taxableIncomeR<31850)
          fedTax = ((taxableIncomeR-7825)*.15)+782.50;
			  
     if (taxableIncomeR>=31850 && taxableIncomeR<77100)
          fedTax = ((taxableIncomeR-31850)*.25)+4386.25;

     if (taxableIncomeR>=77100 && taxableIncomeR<160850)
          fedTax = ((taxableIncomeR-77100)*.28)+15698.75;

     if (taxableIncomeR>=160850 && taxableIncomeR<349700)
          fedTax = ((taxableIncomeR-160850)*.33)+39148.75;

     if (taxableIncomeR>=349700)
          fedTax = ((taxableIncomeR-349700)*.35)+101469.25;

     if (fedTax < 0)
          fedTax = 0;

     fedTax = Math.round(fedTax);
		 
		 return( fedTax );
}

function calcMarried( taxableIncomeR )
{

  var fedTax = 0;

     taxableIncomeR = roundIncome(taxableIncomeR);

     if (taxableIncomeR<15650)
          fedTax = taxableIncomeR*.10;

     if (taxableIncomeR>=15650 && taxableIncomeR<63700)
          fedTax = ((taxableIncomeR-15650)*.15)+1565;
			  
     if (taxableIncomeR>=63700 && taxableIncomeR<128500)
          fedTax = ((taxableIncomeR-63700)*.25)+8772.5;

     if (taxableIncomeR>=128500 && taxableIncomeR<195850)
          fedTax = ((taxableIncomeR-128500)*.28)+24972.50;

     if (taxableIncomeR>=195850 && taxableIncomeR<349700)
          fedTax = ((taxableIncomeR-195850)*.33)+43830.50;

     if (taxableIncomeR>=349700)
          fedTax = ((taxableIncomeR-349700)*.35)+94601;

     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 );
	
}

