
	$(document).ready(function(){

		$('#submit').click(function(e)
		{
			e.preventDefault();
			
				// Email 
				var email = $("input#email").val();
				if (!email.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
					$("#result").html("&iexcl; Verifique o e-mail n&atilde;o est&oacute; correto !");
					$("#result").fadeIn("normal");
					$("input#email").focus();
					return false;
				};

				/* Consulta */
				var mensaje = $("textarea#mensaje").val();	
				if (mensaje.length<5) {
					if (mensaje.length<1) {
						$("#result").html("&iexcl;N&atilde;o h&aacute; nada escrito !");
					}else{
						$("#result").html("&iexcl; Esta n&atilde;o &eacute; um coment&aacute;rio !");
					}
					
					$("#result").fadeIn("normal");
					$("textarea#mensaje").focus();
					return false;
				};
		
				var dataString = {'email': email, 'comentario':mensaje };
			
				$("#submit").hide();
				$("#result").html("Envio...");
			
				/* Envia! t*/	
				$.ajax({
					type: "POST",
					url: "http://www.chupachups.pt/mail.php",
					data: dataString,
					contentType: "application/x-www-form-urlencoded;charset=UTF-8",
					cache:false,
					success: function(html) {
						alert(html);
						
						if(html=="OK"){ 
							var htmltxt="Mensagem enviada.";
							$('#result').html(htmltxt);
							$("#result").fadeIn("slow");
							
						}else{
							var htmltxt="H&aacute; um problema com o transporte.<br/>Por favor, tente novamente mais tarde";
							$('#result').html(htmltxt);
							$("#result").fadeIn("slow");
							$("#submit").show();
						};

					},
					error : function(err){ console.log(err); }
				});
			
			
		
			return false;
			
		});


	});

