$("#newsletterForm .field").focus(function() {
	if($(this).val()==$(this).attr("title") || $(this).val()==$(this).attr("rel")) $(this).val("").removeClass("error");
});

$("#newsletterForm .field").blur(function() {
	if($(this).val()==$(this).attr("title") || $(this).val()=="") $(this).val($(this).attr("title"));
});

$("#newsletterForm .field").blur();

$("#newsletterForm .submit").click(function() {
	var err=0;

	$("#newsletterForm input").each(function() {
		if($(this).val()=="" || $(this).val()==$(this).attr("title") || $(this).val()==$(this).attr("rel")) {
			$(this).val($(this).attr("rel")).addClass("error");
			err = 1;
		}
	});

	if(!err) {	
		// Submit the form with ajax
		$.ajax({
			type: "POST",
			url: "/",
			data: $("#newsletterForm").serialize(),
			success: function(response){
				if(response==1) {
					$("#newsletterForm .fields").fadeOut("fast",function() {
						$("#newsletterForm .success").fadeIn("slow");
						setTimeout("closeNewsletter()",1500);
					});
				}
			}
		});	
	}
	
	return false;
});

function closeNewsletter() {
	$("#closeUpper").click();
}
