/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$(document).ready(function(){

    //Wyczyść pole po klieknięciu w niego
    $("#newsletter_recipient_email").click(function(){
    $("#newsletter_recipient_email").val("")
     });

    //Wyślij adres
    $("#newsletterForm").submit(function(){
       if(validate($('#newsletter_recipient_email').val())){
            var form = $(this);
            
            $.post(form.attr('action')+'?ajax=1', form.serialize(), function(data){
                $(form).css('background','none');
                $("#newsletter_recipient_email").val(data);
            });
       }
       return false;
    });



});

//sprawdź e-mail
function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false)
   {
      $("#newsletter_recipient_email").val("Niepoprawny adres");
      return false;

   }
   else
   	return true;
}

