$(function() {
	$('.error').hide();
	$('input.loginboxstyle').css({backgroundColor:"#FDFBCA"});
	$('input.loginboxstyle').focus(function(){
		$(this).css({backgroundColor:"#FFDDAA"});
	});
	$('input.loginboxstyle').blur(function(){
		$(this).css({backgroundColor:"#FDFBCA"});
	});
	
	$(".login_button").click(function() {
		// validate and process form
		// first hide any error messages
		$('.error').hide();
		
		var name = $("input#newsletter_name").val();
		if (name == "") {
			$("span#newsletter_name_error").show();
			$("input#newsletter_name").focus();
			return false;
		}
		var email = $("input#newsletter_email").val();
		if (email == "") {
			$("span#newsletter_email_error").show();
			$("input#newsletter_email").focus();
			return false;
		}
		
		//var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;
		var dataString = $("#newsletter").serialize()
		//alert (dataString);return false;
		
		$.ajax({
			type: "POST",
			url: "/process.php",
			data: dataString,
			success: function() {
				$('#newsletter').html("<div id='message'></div>");
				$('#message').html("<h2>Thank you</h2>")
				.append("<p>You have successfully registered for the Yooseful Newsletter</p>")
				.hide()
				.fadeIn(1500, function() {
					$('#message').prepend("<img id='checkmark' src='/i/check.png' />");
				});
			}
		});
		return false;
	});
});

