/*********************************************************
   1999 exemption phase out Calculation
   usage: exemptions = calcExemptPhaseOut( agi, totalExemptions, married, print ); 
     
	 Copyright 2000 Mark E. Gunnison
  *********************************************************/

function calcExemptPhaseOut( agi, totalExemptions, married, print )
{

var taxWindow;
var wstring;

var SINGLE = 126600;
var MARRIED = 189950;
var exempt=0;
var income = 0;
var limit1 = 0;
var remainder = 0;
var lostExemptions = 0;


if (!married)
	{
		limit1 = SINGLE;           // Single
	}
	else
	{
		limit1 = MARRIED;            // Married
	}



excess = agi-limit1;
	if (excess < 0)
		excess = 0;

	remainder = Math.ceil(excess/2500);

 
	exemptions = totalExemptions-(remainder*.02*totalExemptions);
	if (exemptions < 0)
		exemptions = 0;

		
		


 	 if (print)
   {

     taxWindow = window.open('','Note','toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=330,height=330');

		 if (!taxWindow.opener)
		 {
		  	taxWindow.opener = window
		 }


     wstring = "<HTML><TITLE>Exemption Phase out Calculator</TITLE><BODY>"
     wstring += "<CENTER>"
     wstring += "<TABLE BORDER='0'>"
     wstring += "<TR><TD colspan=3><B>Exemption Phase Out:</B></TD></TR>"
     wstring += "<TR><TD> 1 </TD><TD> Total exemptions  </TD><TD>   </TD><TD ALIGN=right>"+totalExemptions+"</TD></TR>"
     wstring += "<TR><TD> 2 </TD><TD> AGI               </TD><TD ALIGN=right>"+agi+"</TD></TR>"
		 wstring += "<TR><TD> 3 </TD><TD> First tear        </TD><TD ALIGN=right>"+limit1+"</TD></TR>"
  	 wstring += "<TR><TD> 4 </TD><TD> Excess            </TD><TD ALIGN=right>"+excess+"</TD></TR>"
		 wstring += "<TR><TD> 5 </TD><TD> Excess/2500       </TD><TD ALIGN=right>"+remainder+"</TD></TR>"
		 wstring += "<TR><TD> 6 </TD><TD> Line 5 x 2%       </TD><TD ALIGN=right>"+(remainder*.02)+"</TD></TR>"
		 wstring += "<TR><TD> 7 </TD><TD> Exemptions lost   </TD><TD>  </TD><TD ALIGN=right>"+(remainder*.02*totalExemptions)+"</TD></TR>"
		 wstring += "<TR><TD> 8 </TD><TD> Deduction for Exemptions </TD><TD>  </TD><TD ALIGN=right>"+exemptions+"</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()
     
     taxWindow.document.write(wstring);
     taxWindow.document.close() 

   }

 		 return( exemptions );
}

