/**
 * @author George Miller
 */
Ext.onReady(function(){
//initalize the quicktips
Ext.QuickTips.init();


//reference the default image
Ext.BLANK_IMAGE_URL = 'ext-3.0/resources/images/default/s.gif';

var form = new Ext.form.FormPanel({
	baseCls: 'x-plain',
	labelAlign: 'top',
	labelWidth: 200,
	id: 'loginform',
	defaultType: 'textfield',
	url: 'users/index.php',
	onSubmit: Ext.emptyFn,
        submit: function() {
			form.el.dom.action = form.url;
			form.form.findField('userPass').setValue(Ext.util.MD5(form.form.findField('userPass').getValue()));
            form.getForm().getEl().dom.submit();
        },
	keys: {
        key: [10,13],
        fn: function(){ form.submit(); }
    },
	items: [{
		name: 'userName',
		anchor: '80%',
		allowBlank: false,
		fieldLabel: 'Username'
	},{
		name: 'userPass',
		anchor: '80%',
		allowBlank: false,
		fieldLabel: 'Password',
		inputType: 'password'
	},{
		xtype: 'checkbox',
		name: 'userRemember',
		hideLabel: true,
		boxLabel: 'Remember Me'
	},{
		xtype: 'hidden',
		name: 'action',
		value: 'login'
	}]
       ,buttons: [{
            text: 'Login',
			handler: function(){
						var form = Ext.getCmp('loginform');
					
						if (form.form.isValid()) {
			form.submit();
						}
						else {
							Ext.MessageBox.show({
							title: 'Error',
							width: 250,
							height: 150,
							msg: 'Please correct indicated errors',
							buttons: Ext.MessageBox.OK,
							icon: Ext.MessageBox.WARNING
						})
						}
					}
        },{
            text: 'Cancel',
			handler: function(){
				Ext.getCmp('emailform').getForm().reset();
			}
        }]	
});

Ext.get('loginbtn').on('click', function(){
var check = Ext.getCmp('loginwin');

if(!check){
	var win = new Ext.Window({
	bodyStyle: 'padding: 5px;',
	title: 'Enter your details',
	width: 350,
	height: 200,
	id: 'loginwin',
	constrain: true,
	items: form
});
}

win.show();	
});


   
});

