var winCuenta;
var frmCuenta = new Ext.FormPanel({ 
        labelWidth:80,
        url:'php/loginCuenta.php', 
        frame:true, 
		autoHeight: true,
        defaultType:'textfield',
		monitorValid:true,
        items:[{ 
                fieldLabel:'No de Socio', 
                name:'loginUsernameCuenta', 
				id: 'txtCuenta',
				selectOnFocus: true,
                enableKeyEvents: true,
				listeners: {
                	keydown: function(t, e){
						if (e.getKey() == 13) {							
                        		Ext.getCmp('txtNip').focus();
                    	}
                	}
            	}//listeners
            },{ 
                fieldLabel:'NIP', 
                name:'loginPasswordCuenta',
				id: 'txtNip', 
                inputType:'password', 
				selectOnFocus: true,
                enableKeyEvents: true,
				listeners: {
                	keydown: function(t, e){
						if (e.getKey() == 13) {
							if(!Ext.getCmp('accesar').disabled){
                        		Ext.getCmp('accesar').focus();
							}
                    	}
                	}
            	}//listeners
            }], 	   
        buttons:[{ 
                text:'Accesar',
				id: 'accesar',
                formBind: true,	                
                handler:function(){ 
				
					if(!validaCamposLoginCuenta())return;
				
                    frmCuenta.getForm().submit({ 
                        method:'POST', 
                        waitTitle:'Conectando', 
                        waitMsg:'Enviando datos...',
                        success:function(form, action){ 
								obj = Ext.util.JSON.decode(action.response.responseText); 
								nombre= action.result.nombre;	
								id_asociado = action.result.id_asociado;
								winCuenta.hide();
								frmCuenta.getForm().reset();
								var h = (window.screen.availHeight) - 30;
								var w = (window.screen.availWidth) - 10;
								window.open('reportes/repTicketEdoCuentaAsociado.php?id_asociado='+id_asociado, "", "width= " + w + ", height=" + h + ",Resizable=yes, scrollbars,top=0, left=0");
							 },
                        failure:function(form, action){ 
                            if(action.failureType == 'server'){ 
                                obj = Ext.util.JSON.decode(action.response.responseText); 
                                Ext.Msg.alert('Conexion Fallida', obj.errors.reason); 
                            }else{ 
                                Ext.Msg.alert('Error!', 'El servidor de autenticación es inalcanzable : ' + action.response.responseText); 
                            } 
                            frmCuenta.getForm().reset(); 
                        } 
                    }); 
                } 
            }] 
    });
	
function validaCamposLoginCuenta(){
	var objeto = '';
	var band = true;
	
	if(Ext.getCmp('txtCuenta').getValue() == ''){ Ext.getCmp('txtCuenta').markInvalid('Introduzca Usuario previamente.');		band=false;   objeto == '' ? objeto = Ext.getCmp('txtCuenta') : objeto = objeto }
	if(Ext.getCmp('txtNip').getValue() == ''){	  Ext.getCmp('txtNip').markInvalid('Introduzca Contraseña previamente.');		band=false;   objeto == '' ? objeto = Ext.getCmp('txtNip')	: objeto = objeto }
	if(band == false){objeto.focus(true,100); return band;}
	return band;
}	
	
	
	
function cuenta(){
	if (!winCuenta) {
		winCuenta = new Ext.Window({
			layout: 'fit',
			width: 300,
			autoHeight: true,
			title: 'Acceso a Sistema',
			resizable: false,
			closeAction: 'hide',
			plain: true,
			border: false,
			modal: true,
			items: [frmCuenta],
			listeners: {
				show: function(){
					frmCuenta.getForm().reset();
					Ext.getCmp('txtCuenta').focus(true,400);
				}
			}
		});
	}
	winCuenta.show();
}
