//
// Class: LoginForm
// Description: Implements a simple login form control
// Date: 8/15/2008
//

BET.registerNamespace("BET.js.ui");

BET.js.ui.LoginForm = function(config) {
  
    var _private = {
        
        renderTo : config.renderTo,
        login : config.login,
        cancel : config.cancel,        
        register : config.register,
        
        titleText : function() {
           
            if(typeof(config.title) == 'undefined')
                return 'Enter your login information below';
            else
                return config.title;
            
        }()
        
    };
    
    return {
      
        getMarkup : function() {
            
            var markup = '<div id="loginForm" class="betui_form">' +
                            '<h3>' + config.title + '</h3>' +   
                            '<p>' +
                                '<label class="betui_label">E-mail: </label>' +
                                '<input type="text" name="username" id="username" class="betui_textbox" />' +
                            '</p>' +
                            '<p>' +
                                '<label class="betui_label">Password: </label>' +
                                '<input type="password" name="password" id="password" class="betui_textbox betui_password" />' +
                            '</p>' +
                            '<p>' +
                                '<input type="button" id="login" value="Login" class="betui_button" /> ' +
                                '<input type="button" id="cancel" value="Cancel" class="betui_button" />' +
                            '</p>' +
                            '<p>' +
                                'Not a member? Click here to <a href="#" id="register" class="betui_url">register</a>' +
                            '</p>' +
                        '</div>';
                        
            return markup;
            
        },
        
        bindEvents : function() {
            
            if(typeof(_private.login) == 'function') {
                
                jQuery('#loginForm #login').click(function() {
                    
                    _private.login(jQuery('#loginForm #username').val(), jQuery('#loginForm #password').val());
                    
                });
                
            }
            
            if(typeof(_private.cancel) == 'function') {
                
                jQuery('#loginForm #cancel').click(function() {
                    
                    _private.cancel();
                    
                });
                
            }
            
            if(typeof(_private.register) == 'function') {
                
                jQuery('#loginForm #register').click(function() {
                    
                    _private.register();
                    
                });
                
            }
            
        },
        
        render : function(target) {
            
            var t = _private.renderTo;
            
            if(target != null)
                t = target;
                
            if(t == null)
                t = 'body';                
            
            jQuery(t).append(this.getMarkup());
            this.bindEvents();
            
        },
        
        show : function(config) {
            
            var css = { width: '300px' };
            var overlayCSS = { backgroundColor: '#000', opacity: '0.6' };
            
            if(config != null) {
            
                if((typeof(config.css) == 'object') && (config.css != null)) {                    
                    css = config.css;                    
                }
                
                if((typeof(config.overlayCSS) == 'object') && (config.css != null)) {                    
                    overlayCSS = config.overlayCSS;
                }
                
            }
            
            jQuery.blockUI({ message : this.getMarkup(), css: css, overlayCSS: overlayCSS, baseZ: 39272 });
            this.bindEvents();
            
        },
        
        hide : function() {
            
            jQuery.unblockUI();
            
        }
        
    };    
    
};