$(document).ready(function(){
   
   $('#signup-form').ajaxForm({
       dataType: 'json',
       success: function(resp, status, xhr, $form){
           if (resp.duplicateUser) {
               alert('I am sorry, this email address has already been registered');
               return;
           }
           
           if (!resp.success) {
               alert('I am sorry, one or more of the fields you entered was incorrect. Please try again.');
               return;
           }
           
           alert('Your account has been created! Signin to the left.');
           
           $('#login_email').val($('#email').val()).focus();
           $('#password').focus();
           
           $form.find('input').val('');
       }
   });
   
   
   $('#login-form').ajaxForm({
       dataType: 'json',
       success: function(resp, status, xhr, $form){
           if (!resp.success) {
               alert('Your login credentials were invalid. Please try again');
               return;
           }
           
           window.location = BASE_URL + "/builder";
       }
   });
   
});
