	$(function()
	{
		$("#newsletter").click(function() {	
			
			// First, disable the form from submitting
			$('form#subForm').submit(function() { return false; });
			
			// Grab form action
			formAction = $("form#subForm").attr("action");
			$("#error").hide();  // Hides "Error"
			
			// Hacking together id for email field
			// Replace the xxxxx below:
			// If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
			emailId = "tyjklu";
			emailId = emailId.replace("/", "");
			emailId = emailId + "-" + emailId;
			
			// Validate email address with regex
			var emailVal = $("#" + emailId).val();
			if (!checkEmail(emailVal)) 
			{
				//alert("Please enter a valid email address");
				$("#error").html("<h2>Foutmelding</h2><span>Je hebt niet een geldig eigen mailadres opgegeven.</span>"); 
				$("#error").fadeIn("slow");  // Shows "Error"
				return;
			}
			
			// Serialize form values to be submitted with POST
			var str = $("form#subForm").serialize();
			
			// Add form action to end of serialized data
			final = str + "&action=" + formAction;
			
			$("#theForm").hide();
			$("#confirmation").html("<h2>Even geduld a.u.b.</h2><span>De uitnodiging wordt momenteel verstuurd.</span>");
			$("#confirmation").fadeIn("slow");  // Shows "Thanks for subscribing" div

			// Submit the form via ajax
			$.ajax({
				url: "http://www.soundtrackcity.nl/amsterdam/wp-content/themes/soundtrackcity/scripts/proxy.php",
				type: "POST",
				data: final,
				success: function(html){
					$("#theForm").hide(); // If successfully submitted hides the form
					$("#error").hide(); // If successfully submitted hides the Error
					$("#confirmation").hide();
					$("#confirmation").html("<h2>Bedankt voor uw inschrijving.</h2><span>Controleer je mailbox voor de bevestigings E-mail<br /> en bevestig de inschrijving.</span>");
					$("#confirmation").fadeIn("slow");  // Shows "Thanks for subscribing" div
				}
			});
		});
	});
	
	$(function()
	{
		$("#sendafriend").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 contactname = $("#contactname").val();
			if (contactname == "" ) 
			{
				//alert("Geen naam opgegeven");
				$("#SF_error").html("<h2>Foutmelding</h2><span>Je bent vergeten je eigen naam in te vullen.</span>"); 
				$("#SF_error").fadeIn("slow");  // Shows "Error"
				return;
			
			}
			
			var friendname = $("#friendname").val();
			if (friendname == "" ) 
			{
				//alert("Geen naam opgegeven");
				$("#SF_error").html("<h2>Foutmelding</h2><span>Je bent vergeten de naam van de vriend in te vullen.</span>"); 
				$("#SF_error").fadeIn("slow");  // Shows "Error"
				return;
			
			}

			// Validate email address with regex
			var contactmail = $("#contactmail").val();
			if (!checkEmail(contactmail)) 
			{
				//alert("Fout eigen mailadres");
				$("#SF_error").html("<h2>Foutmelding</h2><span>Je hebt niet een geldig eigen mailadres opgegeven.</span>"); 
				$("#SF_error").fadeIn("slow");  // Shows "Error"
				return;
			}
			
			var friendmail = $("#friendmail").val();
			if (!checkEmail(friendmail)) 
			{
				//alert("Fout vriend mailadres");
				$("#SF_error").html("<h2>Foutmelding</h2><span>Je hebt niet een geldig mailadres opgegeven.</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_theForm").hide();
			$("#SF_confirmation").html("<h2>Even geduld a.u.b.</h2><span>De uitnodiging wordt momenteel verstuurd.</span>");
			$("#SF_confirmation").fadeIn("slow");  // Shows "Thanks for subscribing" div			

			// Submit the form via ajax
			$.ajax({
				url: "http://www.soundtrackcity.nl/amsterdam/wp-content/themes/soundtrackcity/scripts/proxy.php",
				type: "POST",
				data: final,
				dataType: "html",
				success: function(html,status){
					//alert(html);
					$("#SF_theForm").hide(); // If successfully submitted hides the form
					$("#SF_error").hide(); // If successfully submitted hides the Error
					$("#SF_confirmation").hide();
					$("#SF_confirmation").html("<h2>Succesvol verstuurd</h2><span>De uitnodiging aan " + friendname + " 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);
	}