$(function()
	{
		
		$("#formulier").click(function() {
		
		// First, disable the form from submitting
		$('form#contactForm').submit(function() { return false; });
			
		// Grab form action
		formAction = $("form#contactForm").attr("action");
		$("#SF_error").hide();  // Hides "Error"
		
  		var naam = $("#naam").val();
  		var adres = $("#adres").val();
  		var postcode = $("#postcode").val();
  		var woonplaats = $("#woonplaats").val();
  		var telefoonnummer = $("#telefoonnummer").val();
  		var email = $("#email").val();
  		var geboortedatum = $("#geboortedatum").val();
  		var geslacht = $("#geslacht").val();
  		var informatie = $("#informatie").val();
  		var depressiviteit = $("#depressiviteit").val();
  		var angstklachten = $("#angstklachten").val();
  		var concentratieproblemen = $("#concentratieproblemen").val();
  		var lichamelijkeklachten = $("#lichamelijkeklachten").val();
  		var dwangklachten = $("#dwangklachten").val();
  		var ticstoornis = $("#ticstoornis").val();
  		var autismespectrum = $("#autismespectrum").val();
  		var slaapstoornis = $("#slaapstoornis").val();
  		var anders = $("#anders").val();
			
		if (naam == "" ) {
			$("#SF_error").html("<span>Je bent vergeten je naam in te vullen.</span>"); 
			$("#SF_error").fadeIn("slow");  // Shows "Error"
			return;
		}
		
		if (adres == "" ) {
			$("#SF_error").html("<span>Je bent vergeten je adres in te vullen.</span>"); 
			$("#SF_error").fadeIn("slow");  // Shows "Error"
			return;
		}
		
		if (postcode == "" ) {
			$("#SF_error").html("<span>Je bent vergeten je postcode in te vullen.</span>"); 
			$("#SF_error").fadeIn("slow");  // Shows "Error"
			return;
		}
		
		if (woonplaats == "" ) {
			$("#SF_error").html("<span>Je bent vergeten je woonplaats in te vullen.</span>"); 
			$("#SF_error").fadeIn("slow");  // Shows "Error"
			return;
		}
		
		if (telefoonnummer == "" ) {
			$("#SF_error").html("<span>Je bent vergeten je telefoonnummer in te vullen.</span>"); 
			$("#SF_error").fadeIn("slow");  // Shows "Error"
			return;
		}
		
		if (email == "" ) {
			$("#SF_error").html("<span>Je bent vergeten je email in te vullen.</span>"); 
			$("#SF_error").fadeIn("slow");  // Shows "Error"
			return;
		}
		
		if (geboortedatum == "" ) {
			$("#SF_error").html("<span>Je bent vergeten je geboortedatum in te vullen.</span>"); 
			$("#SF_error").fadeIn("slow");  // Shows "Error"
			return;
		}
		if (!isChecked()) 
        { 
            $("#SF_error").html("<span>Je bent vergeten je geslacht in te vullen.</span>"); 
			$("#SF_error").fadeIn("slow");  // Shows "Error"
			return;
        }
        
			// Serialize form values to be submitted with POST
			var str = $("form#contactForm").serialize();
			
			// Add form action to end of serialized data
			final = str + "&action=" + formAction;
			
			$("#SF_form").hide();
			$("#SF_confirmation").html("<span>Het formulier wordt momenteel verstuurd.</span>");
			$("#SF_confirmation").fadeIn("slow");  // Shows "Thanks for subscribing" div			

			// Submit the form via ajax
			$.ajax({
				url: "http://www.braindynamicsgroningen.nl/wp-content/themes/braindynamic/scripts/proxy.php",
				type: "POST",
				data: final,
				dataType: "html",
				success: function(html,status){
					//alert(html);
					$("#SF_form").hide(); // If successfully submitted hides the form
					$("#SF_error").hide(); // If successfully submitted hides the Error
					$("#SF_confirmation").hide();
					$("#SF_confirmation").html("<span>Het formulier is succesvol verzonden.");
					$("#SF_confirmation").fadeIn("slow");  // Shows "Thanks for subscribing" div
				}
			});
		});
	});
	
	function checkEmail(email)
	{	
		var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		//var emailVal = $("#" + email).val();
		return pattern.test(email);
	}
	
	function isChecked() 
    { 
        var checked = $("input[name=geslacht]:checked").length; 
        if (checked == 0) 
        { 
            return false; 
        } 
        else 
        { 
            return true; 
        } 
    } 