Ext.onReady(function(){			
    Ext.QuickTips.init();
 
	// Create a variable to hold our EXT Form Panel. 
	// Assign various config options as seen.	 
    var login = new Ext.FormPanel({ 
        labelWidth:80,
		url:BASE_URL+INDEX+'cliente/login',
        frame:true, 
        title:'Clientes', 
        defaultType:'textfield',
		monitorValid:true,
	// Specific attributes for the text fields for username / password. 
	// The "name" attribute defines the name of variables sent to the server.
        items:[{ 
			   	width:220,
                fieldLabel:'E-mail', 
                name:'email',
				id:'email', 
                allowBlank:false,
				value:'Seu E-mail'
            },{ 
				width:220,
                fieldLabel:'Senha', 
                name:'senha', 
                id:'senha', 
                inputType:'password',
                allowBlank:false
            }],
 
	// All the magic happens after the user clicks the button     
        buttons:[{ 
                text:'Entrar no sistema',
                formBind: true,	 
				buttonAlign: 'center',
                // Function that fires when user clicks the button 
                handler:function(){ 
                    login.getForm().submit({ 
                        method:'POST', 
                        waitTitle:'Connectando', 
                        waitMsg:'Enviando dados...', 
                        success:function(){   
							var redirect = BASE_URL+INDEX+'clientes/inicio'; 
							window.location = redirect;              
                   		},
                        failure:function(form, action){ 
                            if(action.failureType == 'server'){ 
                                obj = Ext.util.JSON.decode(action.response.responseText); 
                                Ext.Msg.alert('Login Falhou!', obj.errors.reason); 
                            }else{ 
                                Ext.Msg.alert('Aten&ccedil;&atilde;oo!', 'Autentica&ccedil;&atilde;o falhou : ' + action.response.responseText); 
                            } 
                            login.getForm().reset(); 
                        } 
                    }); 
                } 
            },{
				text:'Cadastre-se',
 				handler:function(){   
							var redirect = BASE_URL+INDEX+'cadastro'; 
							window.location = redirect;              
                   		}
			},{
				text:'Esqueceu sua senha',
				handler:function(){   
							var redirect = BASE_URL+INDEX+'lembrar'; 
							window.location = redirect;              
                   		}
			}] 
    }); 
	// This just creates a window to wrap the login form. 
	// The login object is passed to the items collection.       
    var win = new Ext.Window({
        layout:'fit',
        width:360,
        height:150,
        closable: false,
        resizable: false,
        plain: false,
        border: false,
        items: [login]
	});
	win.show();
	
	$('#email').focus(function(){
		$('#email').val('');
	});
	
	$('#senha').focus(function(){
		$('#senha').val('');
	});
	
});


