$("#signup").live('submit', function(){
	$(".error").hide();
	var hasError = false;
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	var emailVal = $("#email2").val();
	if(emailVal == '') {
		$("#email2").after('<span class="error">You forgot to enter your email!</span>');
		hasError = true;
	} else if(!emailReg.test(emailVal)) {	
		$("#email2").after('<span class="error">This email address is not valid!.</span>');
		hasError = true;
	}
	var email3Val = $("#email3").val();
	if(emailVal != email3Val) {
		$("#email3").after('<span class="error">Your email addresses do not match.</span>');
		hasError = true;
	}
	
	var yournameVal = $("#yourname2").val() + " wants to sign up for the Abbaland Newsletter";
	if(hasError == false) {
		//$(this).hide();
		//$("#sendEmail li.buttons").append('<img src="/wp-content/themes/default/images/template/loading.gif" alt="Loading" id="loading" />');
		$.post("/sendemail.php",
			{ email: emailVal, yourname: yournameVal},
			function(data){
				$("#signup").slideUp("normal", function() {
					$("#signup").before('<h1>Success!</h1><p>Your email was sent.</p>');									
				});
			}
		);
	}
	return false;
});


$(document).ready(function() {
	$("#sendEmail").submit(function(){		
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var emailVal = $("#email").val();
		if(emailVal == '') {
			$("#email").after('<span class="error">You forgot to enter your email!</span>');
			hasError = true;
		} else if(!emailReg.test(emailVal)) {	
			$("#email").after('<span class="error">This email address is not valid!.</span>');
			hasError = true;
		}
		var natureVal = $("#nature").val();
		if(natureVal == '') {
			$("#nature").after('<span class="error">You forgot to enter the enquiry.</span>');
			hasError = true;
		}
		var yournameVal = $("#yourname").val() + " has sent you a message from AbbaLand.co.uk";
		var telephoneVal = $("#telephone").val();
		
		var codeVal = $("#code").val();
			
		if (ry == '0') {
			if(codeVal !="nattily" ){
				$("#code").after('<span class="error">You forgot to enter the enquiry.</span>');
				hasError = true;
			}
		} else if (ry == '1') {
			if(codeVal !="joyant" ){
				$("#code").after('<span class="error">You forgot to enter the enquiry.</span>');
				hasError = true;
			}
		} else if (ry == '2') {
			if(codeVal !="emissary" ){
				$("#code").after('<span class="error">You forgot to enter the enquiry.</span>');
				hasError = true;
			}
		} else if (ry == '3') {
			if(codeVal !="gramme" ){
				$("#code").after('<span class="error">You forgot to enter the enquiry.</span>');
				hasError = true;
			}
		} else if (ry == '4') {
			if(codeVal !="emperor" ){
				$("#code").after('<span class="error">You forgot to enter the enquiry.</span>');
				hasError = true;
			}
		} else if (ry == '5') {
			if(codeVal !="scramble" ){
				$("#code").after('<span class="error">You forgot to enter the enquiry.</span>');
				hasError = true;
			}
		}
		
		if(hasError == false) {
			//$(this).hide();
			//$("#sendEmail li.buttons").append('<img src="/wp-content/themes/default/images/template/loading.gif" alt="Loading" id="loading" />');
			$.post("/sendemail.php",
				{ email: emailVal, nature: natureVal, yourname: yournameVal, telephone: telephoneVal},
				function(data){
					$("#sendEmail").slideUp("normal", function() {
						$("#sendEmail").before('<h1>Success!</h1><p>Your email was sent.</p>');									
					});
				}
			);
		}
		return false;
	});
});
