$(document).ready(function(){
						   

$("#submitbutton").click(function() { startcalc(); });



}); //end of document ready code


function startcalc()
{
	$("#errortxt").val("");
	
	var ty20112012 = $("input#ty20112012").val();
	var ty20102011 = $("input#ty20102011").val();
	var ty20092010 = $("input#ty20092010").val();
	var ty20082009 = $("input#ty20082009").val();
	var ty20072008 = $("input#ty20072008").val();
	var ty20062007 = $("input#ty20062007").val();
	var ty20052006 = $("input#ty20052006").val();
	var ty20042005 = $("input#ty20042005").val();
	var ty20032004 = $("input#ty20032004").val();

	var wholenumber = /^\d+(?:\.\d{0,2})?$/;  //regex to check for whole positive numbers with max 2 decimal points like 251.33

	
	if(ty20112012 != "")
	{
		if (wholenumber.test(ty20112012)== false) {  
       $("#errortxt").text("Enter your gross income without symbols i.e. 19999.99");
	   $("#errortxt").show();
       $("input#ty20112012").focus();  
       return false;  
     }
	
	}
	else
	{
		$("input#ty20112012").val("0.00");  
	}
	
/////////

	if(ty20102011 != "")
	{
		if (wholenumber.test(ty20102011)== false) {  
       $("#errortxt").text("Enter your gross income without symbols i.e. 19999.99");
	   $("#errortxt").show();
       $("input#ty20102011").focus();  
       return false;  
     }
	
	}
	else
	{
		$("input#ty20102011").val("0.00");  
	}
	
/////////	
	
		if(ty20092010 != "")
	{
		if (wholenumber.test(ty20092010)== false) {  
       $("#errortxt").text("Enter your gross income without symbols i.e. 19999.99");
	   $("#errortxt").show();
       $("input#ty20092010").focus();  
       return false;  
     }
	
	}
	else
	{
		$("input#ty20092010").val("0.00");  
	}
	
	
	
///////////	
		if(ty20082009 != "")
	{
		if (wholenumber.test(ty20082009)== false) {  
       $("#errortxt").text("Enter your gross income without symbols i.e. 19999.99");
	   $("#errortxt").show();
       $("input#ty20082009").focus();  
       return false;  
     }
	
	}
	else
	{
		$("input#ty20082009").val("0.00");  
	}
	
///////////
	
	
		if(ty20072008 != "")
	{
		if (wholenumber.test(ty20072008)== false) {  
       $("#errortxt").text("Enter your gross income without symbols i.e. 19999.99");
	   $("#errortxt").show();
       $("input#ty20072008").focus();  
       return false;  
     }
	
	}
	else
	{
		$("input#ty20072008").val("0.00");  
	}
	
	
////////////////	
	
	
		if(ty20062007 != "")
	{
		if (wholenumber.test(ty20062007)== false) {  
       $("#errortxt").text("Enter your gross income without symbols i.e. 19999.99");
	   $("#errortxt").show();
       $("input#ty20062007").focus();  
       return false;  
     }
	
	}
	else
	{
		$("input#ty20062007").val("0.00");  
	}
	
	
/////////////////	
	
		if(ty20052006 != "")
	{
		if (wholenumber.test(ty20052006)== false) {  
       $("#errortxt").text("Enter your gross income without symbols i.e. 19999.99");
	   $("#errortxt").show();
       $("input#ty20052006").focus();  
       return false;  
     }
	
	}
	else
	{
		$("input#ty20052006").val("0.00");  
	}
	
	
//////////////////	
	
	
		if(ty20042005 != "")
	{
		if (wholenumber.test(ty20042005)== false) {  
       $("#errortxt").text("Enter your gross income without symbols i.e. 19999.99");
	   $("#errortxt").show();
       $("input#ty20042005").focus();  
       return false;  
     }
	
	}
	else
	{
		$("input#ty20042005").val("0.00");  
	}
	
	
//////////////////////	
	
		if(ty20032004 != "")
	{
		if (wholenumber.test(ty20032004)== false) {  
       $("#errortxt").text("Enter your gross income without symbols i.e. 19999.99");
	   $("#errortxt").show();
       $("input#ty20032004").focus();  
       return false;  
     }
	
	}
	else
	{
		$("input#ty20032004").val("0.00");  
	}
	
	
	
	
	
	var sex = $("select#sex").val();
	var age = $("select#age").val();
	
	if(sex=="")
	{ 
       $("#errortxt").text("Please select your sex");
	   $("#errortxt").show();
       $("select#sex").focus();  
       return false;  	
	}
	
	
	if(age=="")
	{
		$("#errortxt").text("Please select your age");
	   $("#errortxt").show();
       $("select#age").focus();  
       return false;
	}
	
	
	
	$("#errortxt").hide();
	$("#loadingscreen").show();
	
	
	
	
	var dataString = 'ty20112012='+ ty20112012 + '&ty20102011=' + ty20102011 + '&ty20092010=' + ty20092010 + '&ty20082009=' + ty20082009 + '&ty20072008=' + ty20072008 + '&ty20062007=' + ty20062007 + '&ty20052006=' + ty20052006 + '&ty20042005=' + ty20042005 + '&ty20032004=' + ty20032004 + '&age=' + age + '&sex=' + sex; 
	

 $.ajax({  
   type: "POST",  
   url: "bin/maincalc.php",  
   data: dataString,  
   success: function(msg) {  //the msg container holds the xmlhttp response 
   
    
                             
	$("#loadingscreen").hide();      
	$("#entryform").slideUp("fast");
	
	/* Insert response HTML into the hidden results div */
	$("#results").html(msg);
	
	/* Show results div */
	$("#resultsholder").show();

	
	$.galog.pageView('calculation/wheredidmytaxgo'); //send trackinfo to analytics
			
			


   }
 });  


	
	
	
}





function entryscreen()
{

	$("#resultsholder").slideUp("fast");
	$("#entryform").slideDown("fast");

}





function checksend(){

$("#addmeerrorlabel").text("");
$("#addmeerrorlabel").hide("");


var emreg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;    //values to test email address 


var taxpayername = $("input#taxpayername").val();
var taxpayeremail = $("input#taxpayeremail").val();
var pensions = $("input#pensions").val();
var healthcare = $("input#healthcare").val();
var education = $("input#education").val();
var defence = $("input#defence").val();
var welfare = $("input#welfare").val();
var protection = $("input#protection").val();
var transport = $("input#transport").val();
var generalgovernment = $("input#generalgovernment").val();
var otherspending = $("input#otherspending").val();
var interestpaid = $("input#interestpaid").val();
var extraborrowed = $("input#extraborrowed").val();



if (emreg.test(taxpayeremail) == false) 
{    
      
	$("#addmeerrorlabel").text("Please Enter a Valid Email Address");
	$("#addmeerrorlabel").show("");
	$("input#taxpayeremail").focus();
	return false;  
} 

if(taxpayername == "")
{
	$("#addmeerrorlabel").text("Please Enter Your Name");
	$("#addmeerrorlabel").show("");
	$("input#taxpayername").focus();
	return false;
}

	var dataString2 = 'taxpayername=' + taxpayername + '&taxpayeremail=' + taxpayeremail + '&pensions=' + pensions + '&healthcare=' + healthcare + '&education=' + education + '&defence=' + defence + '&welfare=' + welfare + '&protection=' + protection + '&transport=' + transport + '&generalgovernment=' + generalgovernment + '&otherspending=' + otherspending + '&interestpaid=' + interestpaid + '&extraborrowed=' + extraborrowed; 
	
	

 $.ajax({  
   type: "POST",  
   url: "bin/addme.php",  
   data: dataString2,  
   success: function(msg) {  //the msg container holds the xmlhttp response 
   
    	$.galog.pageView('calculation/addtodb'); //send trackinfo to analytics
		$("#addmeformdiv").html('<h1>Thanks!</h1>');	
			

   }
 });  
 
 
 
return false;

}






function expanddetail(linker)
{
		
var category = linker.text();

var dataString3 = "category=" + category;

 $.ajax({  
   type: "POST",  
   url: "bin/catexplanation.php",  
   data: dataString3,  
   success: function(msg) {  //the msg container holds the xmlhttp response 
   
    	$("#explanation").html(msg);
		$("#explanation").fadeIn("fast");
	
			

   }
 });  


}





