/*********************************************************
   2004 Self-Employment Tax calculator
   usage:  seTax = calcSETax( seIncome, socSecWages, print );
   Copyright 2007 Mark E. Gunnison
  *********************************************************/


function calcSETax( seIncome, socSecWages, printSchedule)
{


var taxWindow;
var wstring;

var seTax = 0;
var seTax2 = 0;

var line6 = 0;
var line7 = 94200; //SocSec wage limit
var line8 = 0;
var line9 = 0;
var line9a = 0;
var line10 = 0;
var line11 = 0;
var line12 = 0;

		line6 = Math.round(seIncome * .9235);

		line8 = socSecWages;
		line9 = line7 - line8;
		if (line9 < 0)
		{
		   line9 = 0;
		   line10 = 0;
		}
		else
		{
		 	if (line6 < line9)
			{
			    line10 = Math.round(line6 * .124);
				line9a = line6;
			}
			else
			{
				line10 = Math.round(line9 * .124);
				line9a = line9;
			}
		}
		
		line11 = Math.round(line6 * .029);
		seTax = line10 + line11; 

		if (line6 < 400)
		   seTax = 0;		   
		
		seTax2 = Math.round(seTax*.5);
		
  if (printSchedule == 1)
  {

     taxWindow = window.open('','Note','toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=390');

		 if (!taxWindow.opener)
		 {
		  	taxWindow.opener = window;
		 }

     wstring = "<HTML><TITLE>Self-Employment Tax Calculator</TITLE><BODY>";
     wstring += "<CENTER>";
     wstring += "<TABLE BORDER='0'>";
     wstring += "<TR><TD><B>Tax Computation:</B>";
     wstring += "<TR><TD> Self-employment earnings       </TD><TD ALIGN=right>"+seIncome+"</TD></TR>";
     wstring += "<TR><TD> 92.35% of SE earnings          </TD><TD></TD><TD ALIGN=right>"+line6+"</TD></TR>";
     wstring += "<TR><TD>   </TD><TD ALIGN=right> </TD></TR>";
     wstring += "<TR><TD> Maximum subject to Soc Sec     </TD><TD ALIGN=right>"+line7+"</TD></TR>";
  	 wstring += "<TR><TD> Total Soc Sec wages            </TD><TD ALIGN=right>("+line8+")</TD></TR>";
		 wstring += "<TR><TD> </TD><TD><HR></TD></TR>";
	   wstring += "<TR><TD> Untaxed earnings               </TD><TD ALIGN=right>"+line9+"</TD></TR>";
	   wstring += "<TR><TD> Smaller of untaxed or 92.35% of SE</TD><TD></TD><TD ALIGN=right>"+line9a+"</TD></TR>";
		 wstring += "<TR><TD> Soc Tax at 12.4%               </TD><TD></TD><TD ALIGN=right>"+line10+"</TD></TR>";
	   wstring += "<TR><TD> Medicare tax at 2.9% of total  </TD><TD></TD><TD ALIGN=right>"+line11+"</TD></TR>";
 		 wstring += "<TR><TD> </TD><TD></TD><TD><HR></TD></TR>";
 	   wstring += "<TR><TD> Total SE tax                   </TD><TD></TD><TD ALIGN=right>"+seTax+"</TD></TR>";
		 wstring += "<TR><TD> </TD><TD> </TD></TR>";
     wstring += "<TR><TD> Remember to deduct 50% from AGI   </TD><TD></TD><TD ALIGN=right>"+seTax2+"</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);	//stop strange error one second... window
     taxWindow.document.close() ;

  }
	
				
		return( seTax );		
}


