Ext.onReady(function(){
	
Ext.QuickTips.init();

    var loginForm = new Ext.FormPanel({
        labelWidth: 75,
        frame:true,
        bodyStyle:'padding:5px 5px 0',
        defaults: {
    		width: 230,
    		enableKeyEvents:true,
    		listeners:{
	    		specialKey: function(field, el) {
	    			if(el.getKey() == Ext.EventObject.ENTER) {
	    				Ext.getCmp('loginButton').handler();
	    			}
	    	    }
    		}
    	},
        defaultType: 'textfield',
        buttonAlign:'center',
        formId: 'fmLoginForm',
        id:'loginForm',

        items: [{
                fieldLabel: 'Organization',
                name: 'company',
                id: 'company',
                value: _userCompany,
                validateOnBlur: false,
                allowBlank:true
                //allowBlank:false
            },{
                fieldLabel: 'Unit',
                validateOnBlur: false,
                value: _userUnit,
                allowBlank:true,
                id: 'unit',
                name: 'unit'
            },{
                fieldLabel: 'Login',
                value: _userLogin,
                validateOnBlur: false,
                allowBlank:true,
                //allowBlank:false,
                name: 'login',
                id: 'login'
            }, {
                fieldLabel: 'Password',
                //allowBlank:false,
                allowBlank:true,
                name: 'pass',
                id: 'pass',
                validateOnBlur: false,
                inputType: 'password'
            }
        ],

        buttons: [{
            text: 'Login',
            id: 'loginButton',
            handler: function(){
 		       	loginForm.getForm().submit(
    			{
    				url:'/processLogin',
    				waitMsg:'Veryfing User Info...',
    				params: { a: 'login'},
        			success: function(form, action) {
        						location.href=redirectUrl;
        			    },
    			    failure: function(form, action) {
        			       Ext.Msg.alert('Error', 'Login failed, please try again.');
        			    }
    			});
        }            	
        }
        ,{
            text: 'Reset',
            handler: function(){
        		loginForm.getForm().reset();
        	}            	
        }
        ]
    });

    var window = new Ext.Window({
    	title: 'Please login',
    	closable: false,
        width: 380,
        height:250,
        resizable: false,
        draggable: false,
        minWidth: 300,
        minHeight: 200,
        layout: 'fit',
        plain:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: loginForm

        
    });
    window.show();    
});