//<!--

/**************************************************************************************
 	 2001 Child tax credit
   usage: childCredit = calculateChildCredit(totalChildren, agi, incomeTax, married, printScreen); 
     
	 Copyright 2001 Mark E. Gunnison

 **************************************************************************************/
function calculateChildCredit(totalChildren, agi, incomeTax, married, printScreen)
{

var wstring;
var taXWindow;

var ctclimit = 0;
var childCredit = 0;
var excess = 0;
var result = 0;


	childCredit = totalChildren*600;  		// line 1


  if (!married)
	{
		ctclimit = 75000;           // Single
	}
	else
	{
		ctclimit = 110000;            // Married
	}


	excess = agi - ctclimit;		  	 // line 4
	if (excess < 0)
		 excess = 0;
	
	if (excess > 0)
	{
	 	 	result = Math.ceil(excess/1000);	//line 5
			childCredit = childCredit - (result * 50);	//line 7
			if (childCredit < 0)
			     childCredit = 0;
	}
		 
	
  if (childCredit > incomeTax)
	    childCredit = incomeTax;	 //Limited to income tax
	


  if (printScreen==1)
  {

    taXWindow = window.open('','sub','status,scrollbars=yes,resizable=yes,width=400,height=300');
		 if (!taXWindow.opener)
		 {
		  	taXWindow.opener = window
		 }


     wstring = "<HTML><TITLE>2001 Child Tax Credit</TITLE><BODY>"
     wstring += "<CENTER>"
     wstring += "<TABLE BORDER='0'>"
     wstring += "<TR><TD><B>2001 Child Tax Credit:</B>"
     wstring += "<TR><TD> Qualifying children ["+totalChildren+" x $600] = </TD><TD ALIGN=right>"+(totalChildren*500)+"</TD></TR>"
		 wstring += "<TR><TD> Adjusted gross income         </TD><TD ALIGN=right>"+agi+"</TD></TR>"
     wstring += "<TR><TD> Phase out amount              </TD><TD ALIGN=right>"+ctclimit+"</TD></TR>"
     wstring += "<TR><TD> Excess                        </TD><TD ALIGN=right>"+excess+"</TD></TR>"
  	 wstring += "<TR><TD> Excess devided by 1000        </TD><TD ALIGN=right>"+result+"</TD></TR>"
	   wstring += "<TR><TD> Credit lost (prior line x 50) </TD><TD ALIGN=right>"+(result*50)+"</TD></TR>"
		 wstring += "<TR><TD> Income tax before credits     </TD><TD ALIGN=right>"+incomeTax+"</TD></TR>"
	   wstring += "<TR><TD> Credit allowed                </TD><TD ALIGN=right>"+childCredit+"</TD></TR>"
		 wstring += "</TABLE>" 

     wstring += "<FORM><INPUT TYPE='button' NAME='closeBtn' VALUE='Close' onclick='window.close()'></FORM>" 
     wstring += "</CENTER>" 
     wstring += "</BODY></HTML>"

	   taXWindow.focus();
     taXWindow.document.write(wstring)
     //setTimeout("taXWindow.document.write(wstring)",500);	//stop strange error one second... window
     taXWindow.document.close(); 
  }

 return (childCredit);
}
//-->

