
$(document).ready(function()
{
	$("#news_form").submit(function()
	{
		//removemos todas las clases y aņadimos la claxe de messagebox para comenzar el fading
		$("#msg2box").removeClass().addClass('messagebox').html('<img src="img/load.gif" alt="validando ..." class="load" />').fadeIn(2000);
		// Aņadido otro campo mas de tipo :checked para poder dar de baja a alguien del newsletter
		$.post("boletin/",{ e_mail:$('#email').val(),b_orrado:$('#borrado:checked').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='yes') //en el caso de que sea correcto el email
		  {
		  	$("#msg2box").fadeTo(200,0.1,function()  // fade
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('<span class="load-info">alta correcta!</span>').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirecion // en el caso de altas no hace falta
				 //document.location='index.php';
			  });
			  
			});
		  }
		  else if(data=='baja') // acciones y texto para cuando te das de baja
		  {
			$("#msg2box").fadeTo(200,0.1,function()  // fade
			{
				$(this).html('<span class="load-info">baja correcta!</span>').addClass('messageboxerror').fadeTo(900,1);
		  });
		  }
		  else 
		  {
		  	$("#msg2box").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('<span class="load-info">Error! </span>').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
});
