Ext.onReady(function(){
    //
    var loginForm = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        id: 'loginForm',
        frame:true,
        bodyStyle:'padding:5px 5px 0',
        width: 350,
        defaults: {width: 230},
        defaultType: 'textfield',
		keys : [{
            //when the enter key is pressed
            key: Ext.EventObject.ENTER,
            fn: function() { loginForm.authenticate() }
        }],
        items: [{
            fieldLabel: 'E-mailadres',
            name: 'data[User][email]',
            allowBlank:false
        },{
            fieldLabel: 'Wachtwoord',
            name: 'data[User][password]',
            allowBlank:false,
            inputType:'password'
        }],

        buttons: [{
            text: 'Inloggen',
            handler: function() {
                loginForm.authenticate();
            }
        }]
    });
	
	loginForm.authenticate = function() {
		loginForm.getForm().submit({
            waitMsg: 'Controleren..',
            url:'/users/login.json',
            success:function(form,action) {
                if(action.result.success) {
                    window.location.href = '/?' + new Date().getTime();
                }
            },
            failure:function(form,action) {
                Ext.Msg.alert('Status', 'Onjuiste gebruikersnaam of wachtwoord, probeert u het nogmaals.');
            }
		});
	}
	
	var loginWindow = new Ext.Window({
		title: 'Inloggen op 1voud CMS',
		width: 400,
    	height: 150,
    	autoScroll: false,
    	layout: 'fit',
    	buttonAlign:'center',
    	modal : false,
    	closable: false,
    	draggable: false,
    	resizable : false,
    	items: [loginForm]
	});

 	loginWindow.show();

});
