jQuery(document).ready(function() {	

jQuery('.loading').hide();
jQuery('#ooolright').hide();

jQuery('.news-submit').click(function () {
	var email = jQuery('input[name=newsletter]');	
 if (email.val()=='') {  
            email.addClass('error');
			email.focus();  
            return false;  
        } else email.removeClass('error');
		
//organize the data properly
		var data = jQuery('#acnewsletter').serialize();
		/*alert(data);*/
		
	jQuery('.loading').fadeIn('fast');
		
 //start the ajax  
        jQuery.ajax({  
            //this is the php file that processes the data and send mail  
            url: "newslettervalidation.php",   
              
            //GET method is used  
            type: "GET",  
  
            //pass the data           
            data: data,       
              
            //Do not cache the page  
            cache: false,  
              
            //success  
            success: function (html) {                
                //if process.php returned 1/true (send mail success)  
                if (html==1) {                    
                    //hide the form  
                    jQuery('#acnewsletter').fadeOut('fast');                   
                      
                    //show the success message  
                    jQuery('#ooolright').fadeIn('slow');  
                      
                //if process.php returned 0/false (send mail failed)  
                } else { 
				alert('Désolé, il y a une erreur dans la saisie de votre adresse email.'+data);
				jQuery('.loading').hide();
				}
            }         
        });  
          
        //cancel the submit button default behaviours  
        return false;  
    });
	
});
