/*********************************************************
   1999 Individual Income Tax Itemized Deductions Calculator
   usage:  totalDeductions = calcItemized( agi, married, printSchedule )
	 Copyright 2000 Mark E. Gunnison
  *********************************************************/




function calcItemized( agi, married, printSchedule )
{
var taxWindow
var  wstring

var temp = 0;
var medical = 0;
var medicalAllowed = 0;
var stateTaxes = 0;
var realTaxes = 0;
var persTaxes = 0;
var otherTaxes = 0;
var mortgageInt = 0;
var mortgageIntNot = 0;
var pointsInt = 0;
var investInt = 0;
var cashGifts = 0;
var cashGiftsLimited = 0;
var noncashGifts = 0;
var noncashGiftsLimited = 0;
var casualtyLoss = 0;
var unreimbursed = 0;
var taxPrep = 0;
var otherMisc = 0;
var otherMiscNot = 0;
var miscelleneousAllowed = 0;
var totalItimized = 0;





 
   cashGiftsLimited = 0;

   noncashGiftsLimited = 0;

 
 	   medical = Math.round(document.tax.Medical.value);
	   stateTaxes= Math.round(document.tax.StateTaxes.value); 
		 realTaxes = Math.round(document.tax.RealTaxes.value);
		 persTaxes = Math.round(document.tax.PersTaxes.value);
		 otherTaxes= Math.round(document.tax.OtherTaxes.value);
 		 mortgageInt= Math.round(document.tax.MortgageInt.value);
 		 mortgageIntNot= Math.round(document.tax.MortgageIntNot.value);
 		 pointsInt= Math.round(document.tax.PointsInt.value);
 		 investInt= Math.round(document.tax.InvestInt.value);
 		 cashGifts= Math.round(document.tax.CashGifts.value);
 		 noncashGifts= Math.round(document.tax.NonCashGifts.value);
 		 casualtyLoss= Math.round(document.tax.CasualtyLoss.value);
 		 unreimbursed = Math.round(document.tax.Unreimbursed.value);
 		 taxPrep= Math.round(document.tax.TaxPrep.value);
 		 otherMisc= Math.round(document.tax.OtherMisc.value);		
 		 otherMiscNot= Math.round(document.tax.OtherMiscNot.value);
 		 //agi= Math.round(document.tax.AGI.value);

 		 medicalAllowed = (medical - Math.round(agi * .075));				  //Take haircut for medical at 7.5%
 		 if (medicalAllowed < 0)
  	 	medicalAllowed = 0;
		 
 		 if (cashGifts > Math.round(agi*.5)) 	 	  //Limit Cash donations
 		 {
 		  	cashGifts = Math.round(agi*.5);
			cashGiftsLimited = 1;
 		 }
 		 if (noncashGifts > Math.round(agi*.3))	  // Limit noncash donations
 		 {
 		  	noncashGifts = Math.round(agi*.3)
			noncashGiftsLimited = 1;
 		 }
		
 		 miscellaneousAllowed = ((unreimbursed+taxPrep+otherMisc) - Math.round(agi*.02))	 //take haircut for misc deductions
     if (miscellaneousAllowed < 0)
		   	miscellaneousAllowed = 0;
 
		
		totalItimized = medicalAllowed+stateTaxes+realTaxes+persTaxes+otherTaxes+mortgageInt+mortgageIntNot+pointsInt+investInt+cashGifts+noncashGifts+casualtyLoss+miscellaneousAllowed+otherMiscNot; 
 
 


	

	if (printSchedule == 1)
	{

     taxWindow = window.open('','sub','status,scrollbars=yes,resizable=yes,width=400,height=400');

		 if (!taxWindow.opener)
		 {
		  	taxWindow.opener = window
		 }


     wstring = "<HTML><TITLE>Schedule A Tax Calculator</TITLE><BODY>"
     wstring += "<CENTER>"
     wstring += "<TABLE BORDER='0'>"
     wstring += "<TR><TD colspan=4><B>Form 1040 Schedule A</B>"
		 wstring += "<TR><TD colspan=4><HR><B>Medical and Dental Expense:</B></TD></TR>"
     wstring += "<TR><TD><B> 1 </B></TD><TD> Medical and dental expense  </TD><TD ALIGN=right>"+medical+"</TD></TR>"
     wstring += "<TR><TD><B> 3 </B></TD><TD>                             </TD><TD ALIGN=right>"+Math.round(agi*.075)+"</TD></TR>"
		 wstring += "<TR><TD><B> 4 </B></TD><TD>                             </TD><TD> </TD><TD ALIGN=right>"+medicalAllowed+"</TD></TR>"
	
		 wstring += "<TR><TD colspan=4><HR><B>Taxes You Paid:</B></TD></TR>"
     wstring += "<TR><TD><B> 5 </B></TD><TD> State and local income tax  </TD><TD ALIGN=right>"+stateTaxes+"</TD></TR>"
     wstring += "<TR><TD><B> 6 </B></TD><TD> Read Estate Taxes  </TD><TD ALIGN=right>"+realTaxes+"</TD></TR>"
     wstring += "<TR><TD><B> 7 </B></TD><TD> Personal Property Taxes  </TD><TD ALIGN=right>"+persTaxes+"</TD></TR>"
     wstring += "<TR><TD><B> 8 </B></TD><TD> Other Taxes  </TD><TD ALIGN=right>"+otherTaxes+"</TD></TR>"
     wstring += "<TR><TD><B> 9 </B></TD><TD>   </TD><TD> </TD><TD ALIGN=right>"+(stateTaxes+realTaxes+persTaxes+otherTaxes)+"</TD></TR>"
		
		 wstring += "<TR><TD colspan=4><HR><B>Interest You Paid:</B></TD></TR>"
     wstring += "<TR><TD><B> 10 </B></TD><TD> Home mortgage interest and points </TD><TD ALIGN=right>"+mortgageInt+"</TD></TR>"
     wstring += "<TR><TD><B> 11 </B></TD><TD> Mortgage not on from Form 1099  </TD><TD ALIGN=right>"+mortgageIntNot+"</TD></TR>"
     wstring += "<TR><TD><B> 12 </B></TD><TD> Points not reported on Form 1099  </TD><TD ALIGN=right>"+pointsInt+"</TD></TR>"
     wstring += "<TR><TD><B> 13 </B></TD><TD> Investment interest  </TD><TD ALIGN=right>"+investInt+"</TD></TR>"
		 wstring += "<TR><TD><B> 14 </B></TD><TD>  </TD><TD>  </TD><TD ALIGN=right>"+(mortgageInt+mortgageIntNot+pointsInt+investInt)+"</TD></TR>"
		 
		 wstring += "<TR><TD colspan=4><HR><B>Gifts to Charity:</B></TD></TR>"
     wstring += "<TR><TD><B> 15 </B></TD><TD>  Gifts by cash or check"
		 if (cashGiftsLimited==1)
		 	wstring += " (limited)"
		 wstring += "</TD><TD ALIGN=right>"+cashGifts+"</TD></TR>"
		 wstring += "<TR><TD><B> 16 </B></TD><TD>  Gifts other than by cash or check"
		 if (noncashGiftsLimited==1)
		 	wstring += " (limited)"
		 wstring += "</TD><TD ALIGN=right>"+noncashGifts+"</TD></TR>"
		 wstring += "<TR><TD><B> 18 </B></TD><TD>   <TD></TD></TD><TD ALIGN=right>"+(cashGifts+noncashGifts)+"</TD></TR>"
		
		 wstring += "<TR><TD colspan=4><HR><B>Casualty and Theft Losses:</B></TD></TR>"
		 wstring += "<TR><TD><B> 19 </B></TD><TD> Casualty and Theft Losses </TD><TD> </TD><TD ALIGN=right>"+casualtyLoss+"</TD></TR>"
		
		 wstring += "<TR><TD colspan=4><HR><B>Job Expenses and Miscellaneous Deductions:</B></TD></TR>"
     wstring += "<TR><TD><B> 20 </B></TD><TD> Unreimbursed employee expenses </TD><TD ALIGN=right>"+unreimbursed+"</TD></TR>"
     wstring += "<TR><TD><B> 21 </B></TD><TD> Tax preparation fee </TD><TD ALIGN=right>"+taxPrep+"</TD></TR>"
     wstring += "<TR><TD><B> 22 </B></TD><TD> Other expenses </TD><TD ALIGN=right>"+otherMisc+"</TD></TR>"
  	 wstring += "<TR><TD><B> 25 </B></TD><TD> 2% of AGI </TD><TD ALIGN=right>"+Math.round(agi*.02)+"</TD></TR>"
	   wstring += "<TR><TD><B> 26 </B></TD><TD>  </TD><TD> </TD><TD ALIGN=right>"+miscellaneousAllowed+"</TD></TR>"
	  
		 wstring += "<TR><TD colspan=4><HR><B>Other Miscellaneous Deductions:</B></TD></TR>"
		 wstring += "<TR><TD><B> 27 </B></TD><TD> Other Miscellaneous Deductions </TD><TD> </TD><TD ALIGN=right>"+otherMiscNot+"</TD></TR>"
		 
		 wstring += "<TR><TD colspan=4><HR><B>Total Itimized Deductions:</B></TD></TR>"
		 wstring += "<TR><TD><B> 28 </B></TD><TD> Other Miscellaneous Deductions </TD><TD> </TD><TD ALIGN=right>"+totalItimized+"</TD></TR>"
	   if (agi > 126600)
		 		wstring += "<TR><TD colspan=4><HR><B>Warning! Your deduction is limited.  See IRS instructions.</B></TD></TR>"		  
     wstring += "</TABLE>" 

     wstring += "<FORM><INPUT TYPE='button' NAME='closeBtn' VALUE='Close' onclick='window.close()'></FORM>" 
     wstring += "</CENTER>" 
     wstring += "</BODY></HTML>"
		 
		 location.href="#Top";
     taxWindow.focus()
     
     
     //setTimeout("taxWindow.document.write(wstring)",500)	//stop strange error one second... window
		 taxWindow.document.write(wstring);
		 taxWindow.document.close();

		 
  }
  return( Math.round(totalItimized));

}


