$(document).ready(function() {					  
	$("#email").keyup(function(){
	var email = $("#email").val();
	if(validate_email(email)){
		$('#submit').attr('disabled', false);
		$(".valid").fadeIn('slow').html('<img src="yes_valid.png" alt="Válido" align="middle" style="border:0">');
	}else{
		$('#submit').attr('disabled', 'disabled');
		$(".valid").fadeIn('slow').html('<img src="no_valid.png" alt="No Válido" align="middle" style="border:0">');
	}
	});
	function validate_email(emailAddress) {
 		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
 		return pattern.test(emailAddress);
	}					   
    $('#subscribe').submit(function() {
	  $('.msg').fadeIn('slow').html('<img src="loading.gif" width="16px" height="16px" alt="Loading">')
	  $.ajax({
      type: "POST",
      url: "notify.php",
      data: $(this).serialize(),
      success: function(data) {
        $('.msg').fadeIn('slow').html(data);
      },
		error: function (response) {
        $('.msg').fadeIn('slow').html('<span style="color:#900;">Detectamos un error, intenta nuevamente</span>');
		}
     });
    return false;
    }); 
})