jQuery(document).ready(function()
{
		
	jQuery("#form").validate({
 		submitHandler: function(form) {
		
			jQuery("#form").ajaxSubmit({ 
       		 dataType:  'json', 
        		success:   processJson 
    		});

 		}
	});
	
});

function processJson(data) { 
    // 'data' is the json object returned from the server 
    if(data.message == 1){
    	 jQuery('.form').css('opacity','.2').delay(500,function(){
		jQuery('.messaggi').show().delay(10,function(){    	 
		jQuery('.loader').fadeIn().delay(3000,function(){
			jQuery('.loader').fadeOut().delay(500,function(){
				jQuery('.success').fadeIn().delay(2000,function(){
					if(data.cancellazionenewsletter != 1){
					jQuery('.success').fadeOut().delay(300,function(){
						
							location.href = "";
							return false;
						
					});
					}
				})
			})
			
		})
		})	
		}) 
    }else{
   	 jQuery('.errore').fadeIn().delay(2000,function(){
   	 	jQuery('.errore').fadeOut();
   	 });
    }
    
    
}



