EMA.Alert.form.Alarm = Ext.extend(Ext.FormPanel, {
	labelWidth: 75,
    frame:true,
    bodyStyle:'padding:5px 5px 0',
    width: 350,
    defaults: {width: 230},
    defaultType: 'textfield',
    waitMsgTarget: true,
	constructor: function(config) {
		this.url = config.url;
		this.populate = config.populate;
		this.parentWindow = config.parentWindow;
		 /*
    	 * Fill form with value of our Account
    	 */
		this.data = config.data;
		this.callback = config.callback;
		this.items = [
		    {
	            name: 'data[Account][id]',
	            value: this.populate ? this.data['Account.id'] : '',
        		xtype: 'hidden'
	        }, {
	            fieldLabel: 'First Name',
	            id: 'data[Account][firstname]',
	            name: 'data[Account][firstname]',
	            value: this.populate ? this.data['Account.firstname'] : '',
	            allowBlank: false,
        		xtype: 'textfield'
	        }, {
	            fieldLabel: 'Last Name',
	            name: 'data[Account][lastname]',
	            value: this.populate ? this.data['Account.lastname'] : '',
	            allowBlank: false,
        		xtype: 'textfield'
	        }, {
	            fieldLabel: 'Alias',
	            name: 'data[Account][alias]',
	            value: this.populate ? this.data['Account.alias'] : '',
	            allowBlank: true,
        		xtype: 'textfield'
	        }, {
	            fieldLabel: 'Credit Limit',
	            name: 'data[Account][credit_limit]',
	            allowNegative: false,
	            allowDecimals: false,
	            xtype: 'numberfield',
	            minValue: 0,
	            allowBlank: false,
	            value: this.populate ? this.data['Account.credit_limit'] : 0,
	            width: 150
	        }
        ];
		
		this.buttons = [
			{
		        text: 'Save',
		        listeners: {
		        	scope: this,
		        	click: function() {
		        		this.onSubmit();
		        	}
		        }
		    }, {
		        text: 'Cancel',
		        listeners: {
		        	scope: this.parentWindow,
		        	click: function(e) {
		        		this.hide();
		        	}
		        }
			}
		];
	    
		EMA.Alert.form.Alarm.superclass.constructor.apply(this, arguments);
	},
	onSubmit: function () {
		var parentWindow = this.parentWindow;
		var transactionForm = this.getForm();
		var callback = this.callback;
		
		if (this.getForm().isValid()) {
			this.getForm().submit({
				success: function(form, action) {
					callback(action.result.id);
	    	    },
	    	    failure: function(form, action) {
	    	    	parentWindow.hide();
	    	    	Ext.Msg.alert('Failed', action.result.errorMessage);
	    	    },
				waitMsg: 'Processing'
			});
		}
	}
});
