
$(document).ready(function() {
	    
   $('#register_button').click(function(){
	    
   		$.post('/ajax/customer_register.php',$("#custmer_register").serialize(),function(data){
			if(data.result=='success'){					
				if($.getUrlVar('redirect_to')){
					location.href = $.getUrlVar('redirect_to');
				}else{
					location.href = '/account.html';
				}

			}else{
				alert("Please correct the following errors:\n\n" + data.errors);
			}
	    },"json");
   });
   
   $('#login_button').click(function(){
	    
   		$.post('/ajax/customer_login.php',$("#custmer_login").serialize(),function(data){
			if(data.result=='success'){					
				if($.getUrlVar('redirect_to')){
					location.href = $.getUrlVar('redirect_to');
				}else{
					location.href = '/account.html';
				}

			}else{
				alert(data.errors);
			}
	    },"json");
   });
   
   $('#customer_update_button').click(function(){
	    
   		$.post('/ajax/customer_update.php',$("#custmer_update").serialize(),function(data){
			if(data.result=='success'){					
				alert("Thank you. Your details have been updated");

			}else{
				alert("Please correct the following errors:\n\n" + data.errors);
			}
	    },"json");
   }); 

});


