licensedefender.addeditReseller = function(x,y,id)
{
    licensedefender.addResellerWindow = new Ext.Window({
            layout:       'form',
            width:        340,
            modal:        true,
            x: x + 40,
            y: y - 140,
            bodyStyle:    'padding:8px 15px 8px',
            autoHeight:   true,
            closeAction:  'close',
            shadow:       false,
            plain:        true,
            title:        'Add Reseller',
            closable:     true,
            labelAlign:  'left',
            buttonAlign:  'right',
            items:        [{
                xtype: 'textfield',
                id : 'ta_resellerusername',
                fieldLabel: 'Username',
                allowBlank: false,
                width: 195
            },{
                xtype: 'textfield',
                id : 'ta_resellerpassword',
                allowBlank: false,
                inputType: 'password',
                fieldLabel: 'Password',
                width: 195
            },new Ext.form.ComboBox({
               triggerAction: 'all',
               id : 'ta_resellertype',
               fieldLabel: 'Type',
               lazyRender:true,
               editable:false,
               value: '0',
               width: 195,
               store: [[0,'Reseller'],[3,'Distributor']],
               mode:  'local'
            }),{
                xtype: 'textfield',
                id : 'ta_resellernumoflicenses',
                fieldLabel: 'License Count',
                value: '5',
                allowBlank: false,
                width: 55
            },{
                xtype: 'checkbox',
                id : 'ta_limitip',
                fieldLabel: 'Limit by IP',
                width: 55,
                listeners: {
                    'check' : function (cb,checked) {
                        if (checked) {
                            Ext.getCmp('ta_ipranges').setVisible(true);
                        } else {
                            Ext.getCmp('ta_ipranges').setVisible(false);
                        }
                    }
                }
            },{
                xtype: 'textarea',
                id : 'ta_ipranges',
                height: 200,
                hidden :true,
                hideLabel: true,
                labelAlign: 'top',
                anchor: '100%',
                fieldLabel: 'IP Ranges',
                width: 195
            }
            ] ,
            buttons: [{
                text: 'Submit',
                handler: function(b) {

                    if (trim(Ext.getCmp('ta_resellerusername').getValue()) == "" ||
                         trim(Ext.getCmp('ta_resellerpassword').getValue()) == "" ||
                         trim(Ext.getCmp('ta_resellernumoflicenses').getValue()) == ""
                        ) {
                            Ext.MessageBox.alert("Error Validating","You must enter the username, password and licenses fields");
                            return false;
                        }

                    b.setDisabled(true);
                    Ext.Ajax.request({
                        url: 'index.php?fuse=home&action=DoSnapinPluginAction',
                        success: function(xhr) {
                            ce.parseAjaxResponse(xhr);
                            licensedefender.addResellerWindow.close();
                            licensedefender.gridstore.load({params:{start:0,limit:10}});
                        },
                        params: {
                            plugin: 'licensedefender',
                            pluginAction : 'addeditReseller',
                            username: Ext.getCmp('ta_resellerusername').getValue(),
                            password: Ext.getCmp('ta_resellerpassword').getValue(),
                            group: Ext.getCmp('ta_resellertype').getValue(),
                            license: Ext.getCmp('ta_resellernumoflicenses').getValue(),
                            checkip : Ext.getCmp('ta_limitip').getValue(),
                            iprange: Ext.getCmp('ta_ipranges').getValue(),
                            resellerid : (id) ? id : 0
                        }
                    });
                    
                }
            },{
                text: 'Cancel',
                handler : function() {
                    licensedefender.addResellerWindow.close();
                }
            }]

    });
    licensedefender.addResellerWindow.show();

    //we have an id so lets make the request of the data to populate this form
    if (id) {
         licensedefender.addResellerWindow.el.mask('Preparing Window', 'x-mask-loading');
         Ext.Ajax.request({
            url: 'index.php?fuse=home&action=DoSnapinPluginAction',
            success: function(xhr) {
                var json = ce.parseAjaxResponse(xhr);
                Ext.getCmp('ta_resellerusername').setValue(json.data.username);
                Ext.getCmp('ta_resellerusername').setDisabled(true);
                Ext.getCmp('ta_resellerpassword').setValue(json.data.password);
                Ext.getCmp('ta_resellertype').setValue(json.data.group);
                Ext.getCmp('ta_resellertype').setDisabled(true);
                Ext.getCmp('ta_resellernumoflicenses').setValue(json.data.license);
                Ext.getCmp('ta_ipranges').setValue(json.data.iprange);
                if (json.data.checkip==1) {
                    Ext.getCmp('ta_limitip').setValue(true);
                }
                licensedefender.addResellerWindow.el.unmask();
            },
            params: {
                plugin: 'licensedefender',
                pluginAction : 'getReseller',
                resellerid: id
            }
        });

        
        
    }


}