Cascade.panel.sonderteil = function() {
	var form;
	var wndAssistent;
	var _table;
	var mode = "test";
	var recordId = "test";

	
    
	var assistentSonderteil = function() {
            
        var onChangedCombo =  function(field, newValue, oldValue) {
			var values = formAssistent.getForm().getValues();
			values['__STORE_PATH__'] = 'DLGDATA.CA.FORMS.ASSISTENT_SONDERTEIL';
			
			Ext.Ajax.request({ 
				url: 'sonderteilassi/update-values',
				params : values, 
				success: function(response, options) {onChangedComboResponseHandler(response, options); field.collapse();}
			});            

        };

        var onChangedComboResponseHandler = function(response, options) {
            var result = Ext.util.JSON.decode(response.responseText);
            assistentSonderteilUpdate(result);
            
        };
        
        var assistentSonderteilUpdate = function(retObj) {

            var f = formAssistent.getForm();
            var tfBreite = f.findField( 'IDC_BREITE' );
            var tfLaenge = f.findField( 'IDC_LAENGE' );

            var vBreite = f.findField( 'visible_breite' );
            var vLaenge = f.findField( 'visible_laenge' );
            vBreite.setValue( retObj.data.visible_breite );
            vLaenge.setValue( retObj.data.visible_laenge );
            
            if (retObj.data.visible_breite == "1")
            {
                tfBreite.show();
                tfBreite.setLabel('$SONDERTEIL_BREITE$');
            }
            else
            {
                tfBreite.hide();
                tfBreite.setLabel('');
                tfBreite.setValue( '' );
            }
            if (retObj.data.visible_laenge == "1")
            {
                tfLaenge.show();
                tfLaenge.setLabel('$SONDERTEIL_LAENGE$');
            }
            else
            {
                tfLaenge.hide();
                tfLaenge.setLabel('');
                tfLaenge.setValue( '' );
            }
            // tfBreite.disable();
            
            var cbProd = f.findField( 'IDC_PRODUKTGRUPPE' );
            var cbArt = f.findField( 'IDC_ART' );
            var cbTyp = f.findField( 'IDC_TYP' );

            var cbAss1 = f.findField( 'IDC_ASS_SELECT_1' );
            var cbAss2 = f.findField( 'IDC_ASS_SELECT_2' );
            var cbAss3 = f.findField( 'IDC_ASS_SELECT_3' );
            var cbAss4 = f.findField( 'IDC_ASS_SELECT_4' );
            var cbAss5 = f.findField( 'IDC_ASS_SELECT_5' );
        
            cbProd.suspendEvents();
            cbArt.suspendEvents();
            cbTyp.suspendEvents();
            cbAss1.suspendEvents();
            cbAss2.suspendEvents();
            cbAss3.suspendEvents();
            cbAss4.suspendEvents();
            cbAss5.suspendEvents();
            
            // itemListen
            cbProd.store.loadData( retObj.data.itemLists.items_produktgruppe );
            cbArt.store.loadData( retObj.data.itemLists.items_art );
            cbTyp.store.loadData( retObj.data.itemLists.items_typ );
            cbAss1.store.loadData( retObj.data.itemLists.ASS_SELECT_ITEMS_1 );
            cbAss2.store.loadData( retObj.data.itemLists.ASS_SELECT_ITEMS_2 );
            cbAss3.store.loadData( retObj.data.itemLists.ASS_SELECT_ITEMS_3 );
            cbAss4.store.loadData( retObj.data.itemLists.ASS_SELECT_ITEMS_4 );
            cbAss5.store.loadData( retObj.data.itemLists.ASS_SELECT_ITEMS_5 );
            
            // Werden zwar auch aus der Form gesetzt, aber dies ist zuverlaessiger
            // bzgl. der IDs ... ansonsten gibts Probleme beim ersten Initialisieren
            
            cbProd.setValue( retObj.data.PRODUKTGRUPPE );
            cbArt.setValue( retObj.data.ART );
            cbTyp.setValue( retObj.data.TYP );
            cbAss1.setValue( retObj.data.ASS_SELECT_1 );
            cbAss2.setValue( retObj.data.ASS_SELECT_2 );
            cbAss3.setValue( retObj.data.ASS_SELECT_3 );
            cbAss4.setValue( retObj.data.ASS_SELECT_4 );
            cbAss5.setValue( retObj.data.ASS_SELECT_5 );
            
            cbAss1.setLabel(retObj.data.ASS_SELECT_NAME_1);
            cbAss2.setLabel(retObj.data.ASS_SELECT_NAME_2);
            cbAss3.setLabel(retObj.data.ASS_SELECT_NAME_3);
            cbAss4.setLabel(retObj.data.ASS_SELECT_NAME_4);
            cbAss5.setLabel(retObj.data.ASS_SELECT_NAME_5);
            
			Ext.getCmp ('SONDERTEIL_ASSI_IMG').getEl().update('<img src="'+retObj.data.NAME_BILD+'">');
			
			var gridHeight = 220;
			
            if (retObj.data.ASS_SELECT_NAME_1 == "")
                cbAss1.hide();
            else
                cbAss1.show();
            if (retObj.data.ASS_SELECT_NAME_2 == "")
            {
                cbAss2.hide();
                //gridHeight += 20;
            }
            else
                cbAss2.show();
            if (retObj.data.ASS_SELECT_NAME_3 == "")
            {
                cbAss3.hide();
                //gridHeight += 20;
            }
            else
                cbAss3.show();
            if (retObj.data.ASS_SELECT_NAME_4 == "")
            {
                cbAss4.hide();
                gridHeight += 20;
            }
            else
                cbAss4.show();
            if (retObj.data.ASS_SELECT_NAME_5 == "")
            {
                cbAss5.hide();
                gridHeight += 20;
            }
            else
                cbAss5.show();
                
            cbProd.resumeEvents();
            cbArt.resumeEvents();
            cbTyp.resumeEvents();
            cbAss1.resumeEvents();
            cbAss2.resumeEvents();
            cbAss3.resumeEvents();
            cbAss4.resumeEvents();
            cbAss5.resumeEvents();
            
            Ext.getCmp('assistent_tabelle').getStore().loadData(retObj.data);
            Ext.getCmp('assistent_tabelle').setHeight(gridHeight);
            if (! Ext.getCmp('assistent_tabelle').getSelectionModel().hasSelection())
                Ext.getCmp('assistent_tabelle').getSelectionModel().selectFirstRow();
        };
        
		if( !wndAssistent )
		{
			_table = new Ext.grid.GridPanel(
			{
				id: 'assistent_tabelle',
				store: new Ext.data.Store(
				{
					reader: new Ext.data.JsonReader(
					{
						root: 'aGrid',
						id: 'id'
					},
					[
						{ name: 'id' },
                        { name: 'mat_nr' },
						{ name: 'mat_kurz_txt' },
						{ name: 'gewicht' },
						{ name: 'preis' },
						{ name: 'max_laenge' },
						{ name: 'max_breite' }
					] )
				} ),

				columns: [
					{
						// MATNR
						header: '$ID_BESTELL_NR$',
						width: 100,
						sortable: true,
						dataIndex: 'mat_nr'
					},
					{
						// MATKURZTEXT
						header: '$TCH_BESCHREIBUNG$',
						width: 400,
						sortable: true,
						dataIndex: 'mat_kurz_txt'
					},
					{
						// Gewicht
						header: '$GEWICHT$',
						width: 100,
						sortable: true,
                        align: 'right',
						dataIndex: 'gewicht'
					}/*,
                    {
						// Preis
						header: '$TCH_PREIS$',
						width: 60,
						sortable: true,
                        align: 'right',
						dataIndex: 'preis'
					}*/
				],

				sm: new Ext.grid.RowSelectionModel( { singleSelect: true} ),

				width: 690,
				height: 220,
				frame: false,
				border: false,
				title: '',
				header: false
			} );

			wndAssistent = new Ext.Window(
			{
				id: 'sonderteilassi-window',
                layout: 'fit',
                width: 830,
                height: 570,
                closeAction: 'hide',
                title: '$ASSISTENT_SONDERTEIL$',
				modal: true,

				items: [
                    formAssistent = new Ext.FormPanel(
                    {
                        id: 'sonderteilassi-formpanel',
                        layout: 'form',
                        url: 'sonderteilassi/set-values',
                        baseParams: { __STORE_PATH__ : 'DLGDATA.CA.FORMS.ASSISTENT_SONDERTEIL' },
                        listeners: {
                            'actioncomplete': function(form, action) {
                                if (action.type == 'submit')
                                {
									// Hier haben wir die Form des Assi's ...
                                    var freePosField = document.getElementById('SCREEN_ID');
                                    if (freePosField && freePosField.value == 'IDD_FREIE_POSITION')
                                    {
                                        // alert("Hallo");
                                        // Werte in Basis-EasyGui-Form setzen ...
                                        var result = Ext.util.JSON.decode(action.response.responseText);
                                        var typField = document.getElementById('IDC_TYP_EDIT');
                                        var rhtypField = document.getElementById('IDC_RH_TYP_COMBOBOX');
                                        var matnrField = document.getElementById('IDC_NUMMER_EDIT');
                                        var preisField = document.getElementById('IDC_PREIS_EDIT');
                                        var gewichtField = document.getElementById('*.DLGDATA.FP.GEWICHT');
                                        var rohmassField = document.getElementById('*.DLGDATA.FP.IDC_ROHMASSPOS');
                                        if (typField)
                                            typField.value = result.data.FP_ARTIKELTEXT;
                                        if (matnrField)
                                            matnrField.value = result.data.FP_MATNR;
										if (preisField)
                                            preisField.value = result.data.FP_PREIS;
										if (gewichtField)
                                            gewichtField.value = result.data.FP_GEWICHT;
										if (rohmassField)
                                            rohmassField.value = result.data.IDC_ROHMASSPOS;
                                        if (rhtypField)
                                            rhtypField.value = result.data.RH_TYP;
										if (result.data.IDC_ROHMASSPOS == "1")
										{
											document.getElementById('IDC_OBFLSCHUTZ_LABEL').style.visibility = 'visible';
											document.getElementById('*.DLGDATA.FP.IDC_OBFLSCHUTZ_COMBO').style.visibility = 'visible';
											var selectedObfl = document.getElementById('*.DLGDATA.FP.IDC_OBFLSCHUTZ_COMBO').options[document.getElementById('*.DLGDATA.FP.IDC_OBFLSCHUTZ_COMBO').selectedIndex].value;
											if (selectedObfl == "OB_SONST")
												document.getElementById('*.DLGDATA.FP.IDC_OBFLSCHUTZ_EDIT').style.visibility = 'visible';
											else
												document.getElementById('*.DLGDATA.FP.IDC_OBFLSCHUTZ_EDIT').style.visibility = 'hidden';
											document.getElementById('IDC_OBFLSCHUTZ_HINWEIS').style.visibility = 'visible';
										}
										else
										{
											document.getElementById('IDC_OBFLSCHUTZ_LABEL').style.visibility = 'hidden';
											document.getElementById('*.DLGDATA.FP.IDC_OBFLSCHUTZ_COMBO').style.visibility = 'hidden';
											document.getElementById('*.DLGDATA.FP.IDC_OBFLSCHUTZ_EDIT').style.visibility = 'hidden';
											document.getElementById('IDC_OBFLSCHUTZ_HINWEIS').style.visibility = 'hidden';
										}
                                     }
                                    else
                                    // if (form.findField('CALLER_ID').getValue() == "RH")
                                    {
                                        var otherForm = Ext.getCmp('sonderteil-formpanel').getForm();
                                        otherForm.load({ url: 'sonderteil/reload-values',
                                            params : {  },
											success: function( form, action )
											{
												// Achtung: diese Form ist nicht dieselbe wie die oben bei der freien Pos!
												var cRohmass = form.findField('IDC_ROHMASSPOS');												
												var cCombo = form.findField('IDC_OBFLSCHUTZ');
												var cText  = Ext.getCmp('OB_MESSAGE');
												var cEdit  = form.findField('IDC_OBFLSCHUTZ_FREI');
												if (cRohmass.getValue() == "true")
												{
													if (cCombo.getValue() == 'OB_SONST')
														cEdit.setVisible(true);
													else
														cEdit.setVisible(false);										
													cCombo.setVisible(true);
													cText.getEl().update("<b>$ID_PREIS_SONDERTEIL_HINWEIS$</b>");
													cCombo.setLabel('$OBERFLAECHENSCHUTZ$');
												}
												else
												{
													cCombo.setVisible(false);
													cEdit.setVisible(false);
													cText.getEl().update("");
													cCombo.setLabel('');
												}
											}
										});
                                    }
                                }
                            }
						},
						//labelAlign: 'top',
						//labelStyle: 'font-size:11px',
						bodyStyle:'padding:0 20px 10px',
						frame: true,
						autoScroll: true,

						items: [
						{
							layout: 'column',
							width: 740,
							items: [
							{
								layout: 'form',
								items: [
								{
									xtype: 'fieldset',
									autoHeight: true,
									hideLabels: false,
									title: '$IDC_SONDERTEIL_SUCHKRITERIEN_LABEL$',
									items: [
									{
										xtype: 'combo',
										id:  'IDC_PRODUKTGRUPPE',
										hiddenName:  'PRODUKTGRUPPE',
										labelWidth: 170,
										listWidth: 300,
										labelSeparator: '',
										fieldLabel: '$PRODUKTGRUPPE$',
										store: new Ext.data.SimpleStore({
											fields: ['value', 'text'],
											data : [
											]
										}),
										displayField:'text',
										valueField:'value',
										typeAhead: true,
										mode: 'local',
										triggerAction: 'all',
										selectOnFocus:true,
                                        listeners: {
                                            'select': onChangedCombo
                                        },
										editable: false
									},{
										xtype: 'combo',
										id:  'IDC_ART',
										hiddenName:  'ART',
										labelWidth: 170,
										listWidth: 300,
										labelSeparator: '',
										fieldLabel: '$ART$',
										store: new Ext.data.SimpleStore({
											fields: ['value', 'text'],
											data : [
											]
										}),
										displayField:'text',
										valueField:'value',
										typeAhead: true,
										mode: 'local',
										triggerAction: 'all',
										selectOnFocus:true,
                                        listeners: {
                                            'select': onChangedCombo    // evtl. change benutzen?
                                        },
										editable: false
									},{
										xtype: 'combo',
										id:  'IDC_TYP',
										hiddenName:  'TYP',
										labelWidth: 170,
										listWidth: 300,
										labelSeparator: '',
										fieldLabel: '$TYP$',
										store: new Ext.data.SimpleStore({
											fields: ['value', 'text'],
											data : [
											]
										}),
										displayField:'text',
										valueField:'value',
										typeAhead: true,
										mode: 'local',
										triggerAction: 'all',
										selectOnFocus:true,
                                        listeners: {
                                            'select': onChangedCombo
                                        },
										editable: false
									},{
										xtype: 'combo',
										id:  'IDC_ASS_SELECT_1',
										hiddenName:  'ASS_SELECT_1',
										labelWidth: 170,
										listWidth: 300,
										labelSeparator: '',
										fieldLabel: 'ASS_SELECT_1',
										store: new Ext.data.SimpleStore({
											fields: ['value', 'text'],
											data : [
											]
										}),
										displayField:'text',
										valueField:'value',
										typeAhead: true,
										mode: 'local',
										triggerAction: 'all',
										selectOnFocus:true,
                                        listeners: {
                                            'select': onChangedCombo
                                        },
										editable: false
									},{
										xtype: 'combo',
										id:  'IDC_ASS_SELECT_2',
										hiddenName:  'ASS_SELECT_2',
										labelWidth: 170,
										listWidth: 300,
										labelSeparator: '',
										fieldLabel: 'ASS_SELECT_2',
										store: new Ext.data.SimpleStore({
											fields: ['value', 'text'],
											data : [
											]
										}),
										displayField:'text',
										valueField:'value',
										typeAhead: true,
										mode: 'local',
										triggerAction: 'all',
										selectOnFocus:true,
                                        listeners: {
                                            'select': onChangedCombo
                                        },
										editable: false
									},{
										xtype: 'combo',
										id:  'IDC_ASS_SELECT_3',
										hiddenName:  'ASS_SELECT_3',
										labelWidth: 170,
										listWidth: 300,
										labelSeparator: '',
										fieldLabel: 'ASS_SELECT_3',
										store: new Ext.data.SimpleStore({
											fields: ['value', 'text'],
											data : [
											]
										}),
										displayField:'text',
										valueField:'value',
										typeAhead: true,
										mode: 'local',
										triggerAction: 'all',
										selectOnFocus:true,
                                        listeners: {
                                            'select': onChangedCombo
                                        },
										editable: false
									},{
										xtype: 'combo',
										id:  'IDC_ASS_SELECT_4',
										hiddenName:  'ASS_SELECT_4',
										labelWidth: 170,
										listWidth: 300,
										labelSeparator: '',
										fieldLabel: 'ASS_SELECT_4',
										store: new Ext.data.SimpleStore({
											fields: ['value', 'text'],
											data : [
											]
										}),
										displayField:'text',
										valueField:'value',
										typeAhead: true,
										mode: 'local',
										triggerAction: 'all',
										selectOnFocus:true,
                                        listeners: {
                                            'select': onChangedCombo
                                        },
										editable: false
									},{
										xtype: 'combo',
										id:  'IDC_ASS_SELECT_5',
										hiddenName:  'ASS_SELECT_5',
										labelWidth: 170,
										listWidth: 300,
										labelSeparator: '',
										fieldLabel: 'ASS_SELECT_5',
										store: new Ext.data.SimpleStore({
											fields: ['value', 'text'],
											data : [
											]
										}),
										displayField:'text',
										valueField:'value',
										typeAhead: true,
										mode: 'local',
										triggerAction: 'all',
										selectOnFocus:true,
                                        listeners: {
                                            'select': onChangedCombo
                                        },
										editable: false
									}]
								}]
							},{
								layout: 'column',
								width: 250,
								bodyStyle:'padding:0 20px 10px',
								items: [
								{
									layout: 'form',
									items: [
									{
										xtype: 'fieldset',
										autoHeight: true,
										hideLabels: false,
										title: '$IDC_ARTIKELMERKMAL_LABEL$',
										items: [
										{
											xtype: 'numberfield',
											id:  'IDC_LAENGE',
											name:  'LAENGE',
											labelWidth: 170,
											labelSeparator: '',
											width: 100,
											fieldLabel: '$SONDERTEIL_LAENGE$',
											value: ''
										},{
											xtype: 'numberfield',
											id:  'IDC_BREITE',
											name:  'BREITE',
											labelWidth: 170,
											labelSeparator: '',
											width: 100,
											fieldLabel: '$SONDERTEIL_BREITE$',
											//disabled: true,
											value: ''
										},{
                                            xtype: 'hidden',
                                            id: 'CALLER_ID'
                                        },{
                                            xtype: 'hidden',
                                            id: 'TABLE_SELECTED_MAT'
                                        },{
                                            xtype: 'hidden',
                                            id: 'visible_laenge'
                                        },{
                                            xtype: 'hidden',
                                            id: 'visible_breite'
                                        }]
									}]
								}]
							},{
								width: 190,
								id: 'SONDERTEIL_ASSI_IMG'
							}]
						},{
							layout: 'fit',
							//width: 740,
							items: [
								_table,
								{
									//xtype: 'hidden',
									id: 'IDC_ASSISTENT_TABLE_INDEX'
								} ]
						}]
					})
				],

				buttons: [{
					id: 'sonderteilassi-uebernehmen',
					disabled: false,
					text:'$UEBERNEHMEN$',
					handler: function() {
                        var form = Ext.getCmp('sonderteilassi-formpanel').getForm();
                        var myField = form.findField('TABLE_SELECTED_MAT');
                        var vLaenge = form.findField('visible_laenge');
                        var vBreite = form.findField('visible_breite');
                        var cLaenge = form.findField('IDC_LAENGE');
                        var cBreite = form.findField('IDC_BREITE');
                        if (((vLaenge.getValue() == "1") && (cLaenge.getValue() == "")) ||
                            ((vBreite.getValue() == "1") && (cBreite.getValue() == "")))
                        {
                            alert('$IDC_WARNING_MISSING_SONDER$');
                            return;
                        }    
                        var fieldVal = "";
						var nMaxLaenge = 0, nMaxBreite = 0, nIstLaenge = 0, nIstBreite = 0;
                        if (Ext.getCmp('assistent_tabelle').getSelectionModel().hasSelection())
						{
                            fieldVal = Ext.getCmp('assistent_tabelle').getSelectionModel().getSelected().get('mat_nr');
                            nMaxLaenge = parseInt(Ext.getCmp('assistent_tabelle').getSelectionModel().getSelected().get('max_laenge'));
                            nMaxBreite = parseInt(Ext.getCmp('assistent_tabelle').getSelectionModel().getSelected().get('max_breite'));
							nIstLaenge = parseInt(cLaenge.getValue());
							nIstBreite = parseInt(cBreite.getValue());
							if (((vLaenge.getValue() == "1") && (nIstLaenge > nMaxLaenge)) ||
								((vBreite.getValue() == "1") && (nIstBreite > nMaxBreite)))
							{
								var strMass = "";
								if ((vLaenge.getValue() == "1") && (vBreite.getValue() == "1"))
									strMass = nMaxLaenge+"x"+nMaxBreite+" mm";
								else if (vLaenge.getValue() == "1")
									strMass = nMaxLaenge+" mm";
								else if (vBreite.getValue() == "1")
									strMass = nMaxBreite+" mm";
								alert('$IDC_WARNING_SONDER_MASSE$ '+strMass);
								return;
							}
						}
                        var ret = myField.setValue( fieldVal );
						form.submit();
						wndAssistent.hide();
					}
				},{
					text: '$ABBRECHEN$',
					handler: function(){
						wndAssistent.hide();
					}
				}]
			});
        }

		formAssistent.load( {
			url: 'sonderteilassi/get-values',
			success: function( form, action )
			{
                var retobj = Ext.util.JSON.decode( action.response.responseText );
                
                assistentSonderteilUpdate(retobj);
            }
		} );

		//Ext.getCmp('sonderteilassi-formpanel').getForm().load({ url: 'sonderteilassi/get-values'});
		wndAssistent.show(this);
	};
	
	return {
		init: function(idx) {
			if ( !form ) {
                form = new Ext.FormPanel(
				{
					id: 'sonderteil-formpanel',
					title: '$SONDERTEIL$',
					layout: 'form',
					frame: true,
					url: 'sonderteil/set-values',
					baseParams: { __STORE_PATH__ : 'DLGDATA.CA.FORMS.SONDERTEIL' },
					listeners: {
					},

					autoScroll: true,

					items: [{
						layout: 'column',
						items: [{
							layout: 'form',
							width: 350,
// -mw-							height: 40,
							items: [{
								xtype: 'textfield',
								id:  'IDC_STUECKZAHL',
								name:  'STUECKZAHL',
								labelWidth: 150,
								labelSeparator: '',
								width: 50,
								fieldLabel: '$IDS_ANZAHL$',
								value: ''
							}]
						},{
							layout: 'form',
							items: [{
								xtype: 'textfield',
								id:  'IDC_STKPOS',
								name:  'STKPOS',
								labelWidth: 150,
								labelSeparator: '',
								width: 30,
								fieldLabel: '$IDC_LABEL_STUECKLISTENPOS_SONDER$',
								value: ''
							}]
						}]
					},{
						layout: 'column',
						items: [{
							layout: 'form',
							width: 50
// -mw-							height: 40
						},{
							layout: 'form',
							width: 200,
							hideLabels: true,
							items: [{
								xtype: 'radio',
								id: 'IDC_FREIE_EINGABE',
								inputValue: 'FREIE_EINGABE',
								boxLabel:  '$IDC_LABEL_FREIE_EINGABE_SONDER$',
								name:'IDC_EINGABEART_STKL',
								checked: true,
								listeners: {
									'check' : this.onEingabeartStklCheck
								}
							}/*,{
								xtype: 'radio',
								id: 'IDC_AUSWAHLASSISTENT',
								inputValue: 'AUSWAHLASSI',
								boxLabel:  '$IDC_LABEL_AUSWAHLASSI_SONDER$',
								name:'IDC_EINGABEART_STKL',
								checked: false,
								listeners: {
									'check' : this.onEingabeartStklCheck
								}
							}*/]
						},{
							layout: 'form',
							hideLabels: true,
							items: [{
								xtype: 'radio',
								id: 'IDC_AUSWAHLASSISTENT',
								inputValue: 'AUSWAHLASSI',
								boxLabel:  '$IDC_LABEL_AUSWAHLASSI_SONDER$',
								name:'IDC_EINGABEART_STKL',
								checked: false,
								listeners: {
									'check' : this.onEingabeartStklCheck
								}
							}]
						},{
							layout: 'form',
							items: [{
								xtype: 'button',
								id: 'IDC_START_ASSISTENT',
								text: '$START_ASSISTENT$',
								minWidth: 130,
								style: 'margin-left:30px;',
								handler: assistentSonderteil.createDelegate(this)
							}]
						}]
					},{
						layout: 'column',
						items: [{
							layout: 'form',
							width: 350,
							labelWidth: 130,
// -mw-							height: 40,
							items: [{
								xtype: 'combo',
								id:  'IDC_RH_TYP',
								name:  'RH_TYP',
								listWidth: 150,
								width: 150,
								labelSeparator: '',
								fieldLabel: '$RH-Typ$',
								store: new Ext.data.SimpleStore({
									fields: ['value', 'text'],
									data : [
										['FP_LS', '$Lager/Schelle$'],
										['FP_HS', '$Haenger/Stuetze$'],
										['FP_ZU', '$Zubehoer$'],
										['FP_ST', '$Stahlbau$']
									]
								}),
							displayField:'text',
                            valueField:'value',
							typeAhead: true,
							mode: 'local',
							triggerAction: 'all',
							selectOnFocus:true,
							editable: false
							}]
						}]
					},{
						layout: 'column',
						height: 105,
						items: [{
							layout: 'form',
							labelWidth: 130,
							height: 100,
							items: [{
								xtype: 'textarea',
								id:  'IDC_ZEICHNR_BEMERKUNG',
								fieldLabel: '$IDC_LABEL_ARTIKELTEXT_SONDER$',
								labelSeparator: '',
								name:  'ZEICHNR_BEMERKUNG',
								width: 300,
								height: 100,
								value: ''
							}]
						}]
					},{
						layout: 'column',
						items: [{
							layout: 'form',
							width: 350,
							labelWidth: 130,
// -mw-							height: 40,
							items: [{
								xtype: 'textfield',
								id:  'IDC_EINBAUMASS',
								name:  'EINBAUMASS',
								labelSeparator: '',
								width: 150,
								fieldLabel: '$IDC_LABEL_EMASS_SONDER$',
								value: ''
							}]
						},{
							layout: 'form',
							//width: 300,
							labelWidth: 130,
							items: [{
								xtype: 'textfield',
								id:  'IDC_WI_MATNR',
								name:  'WI_MATNR',
								labelSeparator: '',
								width: 150,
								fieldLabel: '$ID_BESTELL_NR$',
								value: ''
							}]
						}]
					},{
						layout: 'column',
						items: [{
							layout: 'form',
							width: 350,
							labelWidth: 130,
// -mw-							height: 40,
							items: [{
								xtype: 'textfield',
								id:  'IDC_GEWICHT',
								name:  'GEWICHT',								
								labelSeparator: '',
								width: 150,
								fieldLabel: '$IDC_LABEL_FREIE_POSITION_GEW$',
								value: ''
							}]
						},{
							layout: 'form',
							labelWidth: 130,
							items: [{
								xtype: 'textfield',
								id:  'IDC_PREIS',
								name:  'PREIS',
								labelSeparator: '',
								width: 150,
								fieldLabel: '$IDC_LABEL_FREIE_POSITION_PREIS$ [$*.PROJECT.SETTINGS.WUR.CURRENCY_UNIT$]',
								value: ''
							}]
						}]
					},{
						layout: 'column',
						items: [{
							layout: 'form',
							width: 350,
							labelWidth: 130,
							items: [{
								xtype: 'combo',
								id:  'IDC_OBFLSCHUTZ',
								hiddenName:  'OBFLSCHUTZ',
								listWidth: 150,
								// width: 150,
								labelSeparator: '',
								fieldLabel: '$OBERFLAECHENSCHUTZ$',
								store: new Ext.data.SimpleStore({
									fields: ['value', 'text'],
									data : [
										['OB_ROH',   '$IDS_OBERFL_ROH$'],
										['OB_GALV',  '$IDS_OBERFL_GALVAN$'],
										['OB_FEUER', '$IDS_OBERFL_FEUER$'],
										['OB_GRUND', '$IDS_OBERFL_GRUND$'],
										['OB_SONST', '$IDS_OBERFL_SONST$']
									]
								}),
								displayField:'text',
								valueField:'value',
								typeAhead: true,
								mode: 'local',
								triggerAction: 'all',
								selectOnFocus:true,
								editable: false,
								listeners: {
									'select': function (combo, rec, index){
										var cEdit  = Ext.getCmp('IDC_OBFLSCHUTZ_FREI');
										if (rec.data.value=='OB_SONST')
											cEdit.setVisible(true);
										else
											cEdit.setVisible(false);										
									}
								}
							}]
						},{
							layout: 'form',
							labelWidth: 130,
							items: [{
								xtype: 'textfield',
								id:  'IDC_WERKSTOFF',
								name:  'WERKSTOFF',
								labelSeparator: '',
								width: 150,
								fieldLabel: '$WERKSTOFF$',
								value: ''
							},{
                                xtype: 'hidden',
                                id: 'CALCULATION_ENABLED'
                            },{
                                xtype: 'hidden',
                                id: 'IDC_ROHMASSPOS'
                            }]
						}]
					}, {
						layout: 'column',
						items: [{
							layout: 'form',
							width: 350,
							labelWidth: 130,
							items: [{
								xtype: 'textfield',
								id:  'IDC_OBFLSCHUTZ_FREI',
								name:  'OBFLSCHUTZ_FREI',
								labelSeparator: '',
								width: 150,
								fieldLabel: '$$',
								value: ''
							}]
						}, {
							id: 'OB_MESSAGE',
							html: '<b>$Vorgabepreis bezieht sich immer auf Oberflaechenschutz roh!$</b>'
						}]
					}],
					
					buttons: [
					{
						id: 'sonderteil-uebernehmen',
						disabled: false,
						text:'$UEBERNEHMEN$',
						handler: function() {
							var form = Ext.getCmp('sonderteil-formpanel').getForm();
							
							Ext.Ajax.request( {
								url: 'sonderteil/checkValues',
								success: function(response, options) {
									var result = Ext.util.JSON.decode(response.responseText);
									
									if ( result.ok ) {
										form.submit();
										Cascade.app.switchPanel('uebersicht_lastkette');
										//Kann man hier den grid Store neu laden.
										Cascade.panel.uebersicht_lastkette.mySubmitForm();
                                        // Cascade.app.updateDescription( 'uebersicht_lastkette' );
										var saveBut = Ext.getCmp('save');
										saveBut.enable();
									} else {
                                        Ext.Msg.alert('Warning', result.msg );
                                        
                                    }
								},
								
								params: form.getValues()
							});
						}
					},{
						text: '$ABBRECHEN$',
						handler: function(){
							Cascade.app.switchPanel('uebersicht_lastkette');
							var saveBut = Ext.getCmp('save');
							saveBut.enable();
						}
					}]
				});
				
				var cp = Ext.getCmp('center-panel');
				
				cp.insert(idx,form);
				cp.doLayout();
			}
			
			
			form.load({     url: 'sonderteil/get-values',
                            params : { mode: mode, recordId: recordId },
                            success: function( form, action )
                            {
                                var cRadio1 = form.findField('IDC_FREIE_EINGABE');
                                var cRadio2 = form.findField('IDC_AUSWAHLASSISTENT');
                                if (cRadio1.getValue() == true)
                                    cRadio1.setValue(true);
                                if (cRadio2.getValue() == true)
                                    cRadio2.setValue(true);
                                // Cascade.panel.sonderteil.onEingabeartStklCheck(cRadio1, cRadio1.getValue());

								var cRohmass = form.findField('IDC_ROHMASSPOS');
								var cCombo = form.findField('IDC_OBFLSCHUTZ');
								var cEdit  = form.findField('IDC_OBFLSCHUTZ_FREI');
								var cText  = Ext.getCmp('OB_MESSAGE');
								if (cRohmass.getValue() == "true")
								{
									if (cCombo.getValue() == 'OB_SONST')
										cEdit.setVisible(true);
									else
										cEdit.setVisible(false);										

									cCombo.setVisible(true);
									cText.getEl().update("<b>$ID_PREIS_SONDERTEIL_HINWEIS$</b>");
									cCombo.setLabel('$OBERFLAECHENSCHUTZ$');
								}
								else
								{
									cCombo.setVisible(false);
									cText.getEl().update("");
									cEdit.setVisible(false);
									cCombo.setLabel('');
								}

                                var cHidden1 = form.findField('CALCULATION_ENABLED');
                                if (cHidden1.getValue() != "true")
                                    form.findField('IDC_PREIS').disable();
                            }
            });
						   
			// Hier noch die Übernahme in den Warenkorb deaktivieren
			var saveBut = Ext.getCmp('save');
			saveBut.disable();
		},
		
		onEingabeartStklCheck : function(radio, checked)
		{
			var f = Ext.getCmp('sonderteil-formpanel').getForm();
            var but = Ext.getCmp('IDC_START_ASSISTENT');
            
            
			f.findField('IDC_STKPOS').disable();
            
			if((radio.id=='IDC_FREIE_EINGABE' && checked) ||
				(radio.id=='IDC_AUSWAHLASSISTENT' && !checked))
			{
				// f.findField('IDC_EINBAUMASS').enable();
				f.findField('IDC_ZEICHNR_BEMERKUNG').enable();
				f.findField('IDC_WI_MATNR').enable();
				// f.findField('IDC_STUECKZAHL').enable();
				f.findField('IDC_GEWICHT').enable();
				// f.findField('IDC_PREIS').enable();
				f.findField('IDC_WERKSTOFF').enable();
				
				f.findField('IDC_PREIS').setValue('');
				f.findField('IDC_WI_MATNR').setValue('');

				but.disable();

				// var cCombo = f.findField('IDC_OBFLSCHUTZ');
				// var cEdit  = f.findField('IDC_OBFLSCHUTZ_FREI');
				var cCombo = Ext.getCmp('IDC_OBFLSCHUTZ');
				var cEdit  = Ext.getCmp('IDC_OBFLSCHUTZ_FREI');
				var cText  = Ext.getCmp('OB_MESSAGE');
				cCombo.setVisible(false);
				cEdit.setVisible(false);
				if (cText.getEl())
					cText.getEl().update("");
				var x = f.findField('IDC_OBFLSCHUTZ');
				if (x && x.getEl())
					x.setLabel('');  // --> das hier verursachte JS-Fehler in unseren EEE ! grund: this.getEl() war undefined bei Eintritt (!) ins Fenster
			}
			if((radio.id=='IDC_AUSWAHLASSISTENT' && checked) ||
				(radio.id=='IDC_FREIE_EINGABE' && !checked))
			{
				but.enable();

				// f.findField('IDC_EINBAUMASS').disable();
				f.findField('IDC_ZEICHNR_BEMERKUNG').disable();
				f.findField('IDC_WI_MATNR').disable();
				// f.findField('IDC_STUECKZAHL').disable();
				f.findField('IDC_GEWICHT').disable();
				// f.findField('IDC_PREIS').disable();
				f.findField('IDC_WERKSTOFF').disable();
			}
		},
		
		setMode: function(conf) {
            mode = conf.mode || 'insert';
			recordId = conf.id; 
		},
		
		getMode: function() {
			return mode;
		},
		
		getRecordId: function() {
			return recordId;
		},
        
		callSonderteilAssi: function() {
            // assistentSonderteil.createDelegate
            assistentSonderteil.createDelegate(this)();
		}
	};
}();