/********************************************************************

 usage: deductableStudentInterest = calcStudentInterest( studentInterest, incomeB4Adj, adjustments, married, print );

 **********************************************************************/

function  calcStudentInterest( studentInterest, incomeB4Adj, adjustments, married, printreport )
{
var taxWindow;
var wstring;

var deductableStudentInterest = 0;
var limit = 0;
var adjustedIncome = 0;
var line7 = 0;
var line8 = 0;
var line9 = 0;

		studentInterest = Math.min( studentInterest, 1500 );
		adjustedIncome = incomeB4Adj - adjustments;


		if (married == 1)
		   limit = 60000;
		else
		   limit = 40000;

		line9 = 0;
		if (adjustedIncome > limit)
		{
		    line7 = adjustedIncome - limit;
			line8 = Math.min( line7/15000, 1 );
			line9 = Math.round(line8 * studentInterest);	
		}
    		   
	  deductableStudentInterest = studentInterest - line9;


		if (printreport == 1)
		{
		
		taxWindow = window.open('','sub','status,scrollbars=yes,resizable=yes,width=400,height=300');

		 if (!taxWindow.opener)
		 {
		  	taxWindow.opener = window
		 }


     wstring = "<HTML><TITLE>Student Loan Interest Computation</TITLE><BODY>"
     wstring += "<CENTER>"
     wstring += "<TABLE BORDER='0'>"
     wstring += "<TR><TD colspan=2><B>Student Loan Interest Computation:</B>"
	 	 wstring += "<TR><TD>Student loan interest ($1500 max)</TD><TD></TD><TD align=right>"+studentInterest+"</TD></TR>"
		 wstring += "<TR><TD>Income less adjustments          </TD><TD align=right>"+adjustedIncome+"</TD></TR>"
		 wstring += "<TR><TD>Limit                            </TD><TD align=right>"+limit+"</TD></TR>"
		 wstring += "<TR><TD>Excess                           </TD><TD align=right>"+line7+"</TD></TR>"
		 wstring += "<TR><TD>Excess / 15000                   </TD><TD></TD><TD align=right>"+line8+"</TD></TR>"
		 wstring += "<TR><TD>Prior line x student interest    </TD><TD></TD><TD align=right>"+line9+"</TD></TR>"
		 wstring += "<TR><TD>                                 </TD><TD></TD><TD><HR></TD></TR>"	
		 wstring += "<TR><TD>Student loan interest deduction  </TD><TD></TD><TD align=right>"+deductableStudentInterest+"</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 (deductableStudentInterest);
} 
 
