/**
 * @author George Miller
 */
Ext.onReady(function(){
//initalize the quicktips
Ext.QuickTips.init();
	//extend the form
	Ext.override(Ext.form.FormPanel, {
	initComponent: function() {
		this.form = this.createForm();
		this.bodyCfg = {
			tag: 'form',
			action: 'admin/index.php',
			cls: this.baseCls + '-body',
			method: this.method || 'POST',
			id: this.formId || Ext.id()
		};
		if(this.fileUpload) {
			this.bodyCfg.enctype = 'multipart/form-data';
		}
		Ext.FormPanel.superclass.initComponent.call(this);
		this.addEvents(
			'clientvalidation'
		);
		this.relayEvents(this.form, ['beforeaction', 'actionfailed', 'actioncomplete']);
	},
	onRender: function(ct, position){
		this.initFields();
		Ext.FormPanel.superclass.onRender.call(this, ct, position);
		this.form.initEl(this.body);
	}
});

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

var form = new Ext.form.FormPanel({
	width: 300,
	height: 300,
	id: 'emailform',
    title: 'Enter Your Details To Login (Admin only)',
	labelAlign: 'top',
	labelWidth: 200,
	renderTo: 'form',
	frame: true,
	defaultType: 'textfield',
	url: 'admin/index.php',
	onSubmit: Ext.emptyFn,
        submit: function() {
			form.el.dom.action = form.url;
            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('emailform');
					
						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();
			}
        }]	
});
   
});