jQuery.namespace('ibap.front.login');

ibap.front.login = {

    $: jQuery,
    
    run: function(){
        this.setFocus();
        this.addSubmitHandler();
    },

    setFocus: function(){
        this.$('#user_email').focus();
    },

    addSubmitHandler: function(){
        window.console && window.console.log('addErrorMessageEmail : message');
        var self = this;
        this.$('#form_login').bind('submit', function(event){
            // event.preventDefault();
            return self.onSubmit(this);
        });
    },

    onSubmit: function(form){
        var aErrors = [];
        var sEmail = form.email.value.trim();
        if ('' == sEmail){
            aErrors.push('- Email address is required.');
        } else if (!email_valid(sEmail)){
            aErrors.push('- Email address is invalid.');
        }
        var sPass = form.password.value.trim();
        if ('' == sPass){
            aErrors.push('- Password is required.');
        }
        if (aErrors.length > 0){
            var sErrors = '';
            sErrors += 'Please corect the following\n';
            sErrors += aErrors.join('\n');
            alert (sErrors);
            return false;
        } else {
            return true;
        }
    }

};

(function($){
    $(document).ready(function(){
        ibap.front.login.run();
    });
})(jQuery);

