      
var winEtiketten;    
var winEtiketten;    
var etikettenRecords;    

var tabellenFelderStore =  new Ext.data.Store({
	reader: new Ext.data.JsonReader({fields: ['FeldID', 'Name']}),
  	proxy: new Ext.data.HttpProxy({url:'tabellenfelder.php?TabelleID=-1'})
});

function getFeldname(id) {                   
	var id1 = Ext.getCmp(id).getValue();
	for (var i = 0; i < tabellenFelderStore.getCount(); i++) {
		var record = tabellenFelderStore.getAt(i);
		if (record.get("FeldID") == id1)
			return record.get("Name");   	
	}                                 
	return "";
}
                                       
function vorschau(){      
	Ext.getCmp('vorschau').setValue(  
		getFeldname('FeldID11') + ' ' + getFeldname('FeldID12') + ' ' + getFeldname('FeldID13') + "\n" +
		getFeldname('FeldID21') + ' ' + getFeldname('FeldID22') + ' ' + getFeldname('FeldID23') + "\n" +
		getFeldname('FeldID31') + ' ' + getFeldname('FeldID32') + ' ' + getFeldname('FeldID33') + "\n" +
		getFeldname('FeldID41') + ' ' + getFeldname('FeldID42') + ' ' + getFeldname('FeldID43'));
}
     
var etikettenFeldWidth = 150;
                    
var etikettenFormPanel = new Ext.FormPanel({
    id:'etikettenFormPanel',
    frame:true,
    autoHeight:true,
    bodyStyle:'padding:5px 5px 0',
    reader : new Ext.data.XmlReader({
        record : 'Tabelle',
        success: '@success'
    }, [
        'TabelleID', 
		'FeldID11', 'FeldID12', 'FeldID13', 
		'FeldID21', 'FeldID22', 'FeldID23', 
		'FeldID31', 'FeldID32', 'FeldID33', 
		'FeldID41', 'FeldID42', 'FeldID43', 
		'FormatID'
    ]),
    defaults: {
	    labelAlign: 'left',
	    labelWidth: 1,
        anchor: '95%'
    },
    items: [{
        xtype:'fieldset',
        title: text_32,
        autoHeight:true,
        items :[{
	        xtype: 'textarea',
	        height: 55,
			hideLabel : true, 
			readOnly: true,
	        anchor: '99%',
	        value: text_33
	    }]
	 },{
        xtype:'fieldset',
        title: text_34,
        autoHeight:true,
        items :[{
            layout:'column',
            items:[{
                columnWidth:.33,
                layout: 'form',
			    defaults: {
				    labelAlign: 'left',
				    labelWidth: 1,
					hideLabel : true, 
			        anchor: '95%'
			    },
                items: [new Ext.form.ComboBox({
					hideLabel : true, 
					id: 'FeldID11',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					forceSelection: true,
					listeners:{
				         'select': function() {
							vorschau(TabelleID);
						}
				    }
                }), new Ext.form.ComboBox({
					id: 'FeldID21',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					forceSelection: true,
					listeners:{
				         'select': function(TabelleID) {
							vorschau();
						}
				    }
				}), new Ext.form.ComboBox({
					id: 'FeldID31',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					forceSelection: true,
					listeners:{
				         'select': function(TabelleID) {
							vorschau();
						}
				    }
				}), new Ext.form.ComboBox({
					id: 'FeldID41',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					forceSelection: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					listeners:{
				         'select': function(TabelleID) {
							vorschau();
						}
				    }
				})]
            },{
                columnWidth:.33,
                layout: 'form',
			    defaults: {
				    labelAlign: 'left',
				    labelWidth: 1,
					hideLabel : true, 
			        anchor: '95%'
			    },
                items: [new Ext.form.ComboBox({
					hideLabel : true, 
					id: 'FeldID12',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					forceSelection: true,
					listeners:{
				         'select': function() {
							vorschau(TabelleID);
						}
				    }
                }), new Ext.form.ComboBox({
					id: 'FeldID22',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					forceSelection: true,
					listeners:{
				         'select': function(TabelleID) {
							vorschau();
						}
				    }
				}), new Ext.form.ComboBox({
					id: 'FeldID32',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					forceSelection: true,
					listeners:{
				         'select': function(TabelleID) {
							vorschau();
						}
				    }
				}), new Ext.form.ComboBox({
					id: 'FeldID42',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					forceSelection: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					listeners:{
				         'select': function(TabelleID) {
							vorschau();
						}
				    }
				})]
            },{
                columnWidth:.33,
                layout: 'form',
			    defaults: {
				    labelAlign: 'left',
				    labelWidth: 1,
					hideLabel : true, 
			        anchor: '95%'
			    },
                items: [new Ext.form.ComboBox({
					hideLabel : true, 
					id: 'FeldID13',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					forceSelection: true,
					listeners:{
				         'select': function() {
							vorschau(TabelleID);
						}
				    }
                }), new Ext.form.ComboBox({
					id: 'FeldID23',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					forceSelection: true,
					listeners:{
				         'select': function(TabelleID) {
							vorschau();
						}
				    }
				}), new Ext.form.ComboBox({
					id: 'FeldID33',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					forceSelection: true,
					listeners:{
				         'select': function(TabelleID) {
							vorschau();
						}
				    }
				}), new Ext.form.ComboBox({
					id: 'FeldID43',
		            hiddenName:'FeldID',
		            displayField:'Name',
		            valueField:'FeldID',
					store: tabellenFelderStore,
		            typeAhead: false,
		            triggerAction: 'all',
		            emptyText:text_9,
		            selectOnFocus:true,
					editable: true,
					forceSelection: true,
					listWidth: etikettenFeldWidth,
					width: etikettenFeldWidth,
					listeners:{
				         'select': function(TabelleID) {
							vorschau();
						}
				    }
				})]
            }]
        }]
    },{
        xtype:'fieldset',
        title: text_35,
        autoHeight:true,
        items :[{
	        xtype: 'textarea',
	        id: 'vorschau',
	        height: 70,
			hideLabel : true, 
			readOnly: true,
	        anchor: '99%',
			allowBlank: false,
	        value: ''
	    }]
	}, new Ext.form.ComboBox({
		id: 'EtikettenFormat',
		fieldLabel: text_36,
		labelWidth: 150,
        hiddenName:'FormatID',
        displayField:'Name',
        valueField:'FormatID',
		store: new Ext.data.Store({
			reader: new Ext.data.JsonReader({fields: ['FormatID', 'Name']}),
		  	proxy: new Ext.data.HttpProxy({url:'etikettenformat.php'})
		}),
        typeAhead: true,
        triggerAction: 'all',
        emptyText:text_10,
        selectOnFocus:true,
		editable: false,
		forceSelection: true,
		allowBlank: false,
        anchor: '95%'
    }),{       
		xtype: 'textfield',
        fieldLabel: text_37,    
		id: 'AnzahlLeere',
        name: 'AnzahlLeere',
		allowBlank: true,
		labelWidth: 150,
        anchor: '95%'
	}],
    buttons: [{
        text: text_38,
     	handler: function() {                  
			Ext.getCmp('etikettenFormPanel').getForm().submit({
			    clientValidation: true,   
				url:'etikettenfelder.php?action=save&TabelleID='+currentColumnDefinitions.data.tab_id+
												  '&FeldID11='+Ext.getCmp('FeldID11').getValue()+
												  '&FeldID12='+Ext.getCmp('FeldID12').getValue()+
												  '&FeldID13='+Ext.getCmp('FeldID13').getValue()+
												  '&FeldID21='+Ext.getCmp('FeldID21').getValue()+
												  '&FeldID22='+Ext.getCmp('FeldID22').getValue()+
												  '&FeldID23='+Ext.getCmp('FeldID23').getValue()+
												  '&FeldID31='+Ext.getCmp('FeldID31').getValue()+
												  '&FeldID32='+Ext.getCmp('FeldID32').getValue()+
												  '&FeldID33='+Ext.getCmp('FeldID33').getValue()+
												  '&FeldID41='+Ext.getCmp('FeldID41').getValue()+
												  '&FeldID42='+Ext.getCmp('FeldID42').getValue()+
												  '&FeldID43='+Ext.getCmp('FeldID43').getValue()+
												  '&FormatID='+Ext.getCmp('EtikettenFormat').getValue(),
				waitMsg:text_39,             
			    success: function(form, action) {
			       	var redirect = 'etiketten.php?TabelleID='+currentColumnDefinitions.data.tab_id+
											    '&FeldID11='+Ext.getCmp('FeldID11').getValue()+
											    '&FeldID12='+Ext.getCmp('FeldID12').getValue()+
											    '&FeldID13='+Ext.getCmp('FeldID13').getValue()+
											    '&FeldID21='+Ext.getCmp('FeldID21').getValue()+
											    '&FeldID22='+Ext.getCmp('FeldID22').getValue()+
											    '&FeldID23='+Ext.getCmp('FeldID23').getValue()+
											    '&FeldID31='+Ext.getCmp('FeldID31').getValue()+
											    '&FeldID32='+Ext.getCmp('FeldID32').getValue()+
											    '&FeldID33='+Ext.getCmp('FeldID33').getValue()+
											    '&FeldID41='+Ext.getCmp('FeldID41').getValue()+
											    '&FeldID42='+Ext.getCmp('FeldID42').getValue()+
											    '&FeldID43='+Ext.getCmp('FeldID43').getValue()+
											    '&Filter='+currentFilter+
											    '&AnzahlLeere='+Ext.getCmp('AnzahlLeere').getValue()+											    
											    '&FormatID='+Ext.getCmp('EtikettenFormat').getValue()+
											    '&records='+etikettenRecords;											    
				    winEtiketten.hide();
					if (Ext.isChrome)
			       		window.location = redirect;  
					else
						window.open(redirect);
			    },        
			    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);
			       }
			    }
			});
		}
    },{
        text: text_15, 
     	handler: function() {
         	winEtiketten.hide();
     	}
    }]
});


function etikettenWindow(TabelleID, records) {
	
	if (version == BASIC_VERSION) {
		Ext.MessageBox.alert(text_28, text_122);
		return;
	}

	tabellenFelderStore.proxy = new Ext.data.HttpProxy({url:'tabellenfelder.php?TabelleID='+TabelleID});
    tabellenFelderStore.reload();
	etikettenRecords = records;

	if (!winEtiketten) {
	    winEtiketten = new Ext.Window({
	        layout:'fit',
	        closeAction:'hide',
	        plain: true,
			modal: true,
		    width: 550,
	        autoHeight:true,
			title:text_40,                      
			items: etikettenFormPanel
	    });   
	}
	etikettenFormPanel.get("EtikettenFormat").store.load();

 	winEtiketten.show();   
	winEtiketten.center();
    etikettenFormPanel.getForm().load({url:'etikettenfelder.php?action=read&TabelleID='+TabelleID, 
    	waitMsg:text_41}); 
	
}
        
etikettenFormPanel.on({
    actioncomplete: function(form, action){
        if(action.type == 'load'){            
			vorschau();
        }
    }
});





