Ext.ns('Rebul.Login');

Rebul.Login = function(config){

	this.config = config || {};
	this.config.title = this.config.title ? '<span style="color:red">' + this.config.title + '</span>' : 'Please Login';
	
    Ext.QuickTips.init();
   	Ext.form.Field.prototype.msgTarget = 'side';
    
    Rebul.Login.superclass.constructor.call(this, {
    	id:'login-panel',
        labelWidth:80,
        url:'/processLogin.cfm', 
        frame:true, 
        title:this.config.title, 
        defaultType:'textfield',
		monitorValid:true,
		keys:[{
		   	key:Ext.EventObject.ENTER,
   			handler:function(){
   				Ext.getCmp('login-panel').submitForm();
   			},
   			stopEvent:true
		}],
	    items:[{ 
                fieldLabel:'Email', 
                width:170,
                name:'TXTEMAIL', 
                allowBlank:false,
                value:this.config.email || undefined 
            },{ 
                fieldLabel:'Password', 
                width:170,
                name:'TXTPASSWORD', 
                inputType:'password', 
                allowBlank:false 
            }],
 
	    buttons:[{ 
                text:'Login',
                formBind: true,	 
                handler:function(){
   					Ext.getCmp('login-panel').submitForm();
   				}
            }] 
    });
    
    this.submitForm = function(){ 
		this.getForm().submit({ 
	        method:'POST', 
	        waitTitle:'Connecting', 
	        waitMsg:'Sending data...',
	 
	        success:function(form, action){ 
	        	//Ext.Message.msgStay('Login Successful', action.result.info, 1000);
				window.location = action.result.redirect;	
			},
	 
	        failure:function(form, action){ 
				var el = Ext.getCmp('login-panel');
	        	Ext.Msg.alert('Login Failed', action.result.info); 
	        	el.getForm().reset(); 
	        } 
	    }); 
    }; 

};

Ext.extend(Rebul.Login, Ext.FormPanel, {});
