	
	Ext.apply(Ext.form.VTypes, {
	    password : function(val, field) {
	        if (field.initialPassField) {    
	            var pwd = Ext.getCmp(field.initialPassField);
	            return (val == pwd.getValue());
	        }
	        return true;
	    },
	
	    passwordText : text_81
	});

    var height1 = (Ext.isIE ? 360 : 300);

   	var xmlBenutzer = new Ext.FormPanel({
	    title:text_82,
	    id:'xmlBenutzer',
		region: 'center',
	    labelAlign: 'right',
	    labelWidth: 140,
	    height:height1,
	    waitMsgTarget: true,
		trackResetOnLoad: true,
		
	    // configure how to read the XML Data
	    reader : new Ext.data.XmlReader({
	        record : 'Benutzer',
	        success: '@success'
	    }, [
	        'BenutzerID', 'Name', 'Passwort', 'Passwort_1', 'EMail', 'Admin', 'Beschreibung', 'GruppeID' 
	    ]),                                                                                                                      

		defaultType: 'textfield',
        items: [{
            	id: 'BenutzerID',
				hidden:true,
                height:0,
                width:0
            }, {
                fieldLabel: text_45,    
				id: 'U_Name',
                name: 'Name',
                tabindex:1,
				allowBlank: false,
                width:190
            }, {
                fieldLabel: text_83,
                name: 'Passwort',
                id: 'Passwort',
		        inputType:'password', 
                tabindex:2,
				allowBlank: false,
                width:190
            }, {
	                fieldLabel: text_84,
	                name: 'Passwort_1',
			        inputType:'password', 
	                width:190,               
	                tabindex:3,
			        vtype: 'password',
			        initialPassField: 'Passwort'
	            }, {                            
                fieldLabel: text_53,
                name: 'EMail',
                vtype:'email',
                tabindex:4,
				allowBlank: false,
                width:190
            }, {
				xtype: 'checkbox',
                fieldLabel: text_85,
                tabindex:5,
                name: 'Admin'
            }, {
				xtype: 'textarea',
				height:80,
                fieldLabel: text_46,
                name: 'Beschreibung',
                tabindex:6,
                width:300   

            }, new Ext.form.ComboBox({
                id: 'Gruppe',
                fieldLabel: text_44,
                hiddenName:'GruppeID',
				store: new Ext.data.Store({
	  				reader: new Ext.data.JsonReader({fields: ['GruppeID', 'GName']}),
				  	proxy: new Ext.data.HttpProxy({url:'groups.php'})
				}),
                valueField:'GruppeID',
                displayField:'GName',
                typeAhead: false,
                triggerAction: 'all',
                emptyText:text_88,
                selectOnFocus:true,
                width:190,   
                tabindex:7,
				listWidth:190,
				allowBlank: false,
				editable: false
            })
        ]
	});
    
    function storeBenutzer(selectNewNode) {
		xmlBenutzer.getForm().submit({
		    clientValidation: true,   
			url:'user_data.php?action=save', 
			waitMsg:text_39,             
		    success: function(form, action) {
				var ben_id = action.result.msg; 
    		  	if (Ext.getCmp('BenutzerID').getValue() == -1) {
	    		  	node = Ext.getCmp('treeEinstellungen').getNodeById('adminB').appendChild(new Ext.tree.TreeNode({
	                   	id:'adminB'+ben_id, text: Ext.getCmp('U_Name').getValue(), iconCls:'user', leaf:true 
					}));                   
	    		  	if (selectNewNode) {
						Ext.getCmp('treeEinstellungen').fireEvent('click', node);
	    		  		Ext.getCmp('treeEinstellungen').selectPath(node);
	    		  	}
				}
				else                                           
					treeEinstellungen.getLoader().load(treeEinstellungen.root);					
		    },
		    failure: function(form, action) {
		        switch (action.failureType) {
		            case Ext.form.Action.CLIENT_INVALID:
		                Ext.Msg.alert(text_29, text_30);
		                break;
		            case Ext.form.Action.CONNECT_FAILURE:
		                Ext.Msg.alert(text_29, text_31);
		                break;  
		            default:
		               Ext.Msg.alert(text_29, action.result.msg);
		       }
		    }
		});
    }    
	
	// explicit add
	var submitBenutzer = xmlBenutzer.addButton({
	    text: text_47,
	    disabled:true,
	    handler: function(){
			storeBenutzer(true);
	    }
	});

	var loeschenBenutzer = xmlBenutzer.addButton({
	    text: text_48,
	    disabled:true,
	    handler: function(){  
		
	     Ext.MessageBox.show({
	           title:text_49,
	           msg: text_87,
	           buttons: Ext.MessageBox.YESNO,
	           icon: Ext.MessageBox.QUESTION,
	           fn: function(btn) {
					if (btn == 'yes') {
						new Ext.data.Connection().request({
							    url: 'user_data.php',  
								params: {BenutzerID: Ext.getCmp('BenutzerID').getValue(), action:"delete"},
								failure: function(response, opts) {
								      Ext.MessageBox.alert(text_29, Ext.decode(response.responseText).msg);
								},
							    success: function(response, opts) {                                            
							      	var obj = Ext.decode(response.responseText);
									if (!obj.success) {
							     	 	Ext.MessageBox.alert(text_29, obj.msg);
							     	}
							    	else {
						    		  	Ext.getCmp('treeEinstellungen').getNodeById('adminB'+Ext.getCmp('BenutzerID').getValue()).remove();
						    		  	Ext.getCmp('BenutzerID').setValue(-1);  
						    		  	Ext.getCmp('treeEinstellungen').selectPath((Ext.getCmp('treeEinstellungen').getNodeById('adminBNeu').getPath()));
								    	xmlBenutzer.getForm().load({url:'user_data.php?action=read&BenutzerID=-1', 
								                                    waitMsg:text_41});
							        }
								}
							});					
					}
			    }
			});
	    }
	});   
	
	xmlBenutzer.on({
	    actioncomplete: function(form, action){
	        if(action.type == 'load'){
	            submitBenutzer.enable();
	        }
	    }
	});

	var editBenutzer = {
	    id: 'editBenutzer',
		region: 'center',
		frame:false,
		hideMode: 'offsets', 
	    layout: {
	        type: 'vbox',
	        pack: 'start',
	        align: 'stretch'
	    },
	    defaults: {
	        frame: true,
	        border:false
	    },
	    items: [xmlBenutzer, {
	        flex: 1,
	        html: ''
	    }]
	};


