
var winUpload; 
var uploadSheet;

var uploadFormPanel = new Ext.FormPanel({
    fileUpload: true,
    width: 500,
    frame: true,
    autoHeight: true,
    bodyStyle: 'padding: 10px 10px 0 10px;',
    labelWidth: 75,
    defaults: {
        allowBlank: false,
        msgTarget: 'side',
        anchor: '95%'
    },
    items: [{
		height:90,   
        fieldLabel: text_78,
        xtype: 'textarea',
        readOnly: true,
        value: text_73
    },{
		id: 'Sheet',
        name: 'Sheet',
		xtype: 'textarea',
        height:0,
        allowBlank:true,
		hidden:true
    },{
		id: 'Upload-Name',
        xtype: 'textfield',
        fieldLabel: text_45,
        name: 'Name'
    }, {
		xtype: 'checkbox',
        fieldLabel: text_74,
        name: 'OhneDaten'
    },{
        xtype: 'fileuploadfield',
        id: 'form-excel-file',
        emptyText: text_86,
        fieldLabel: text_75, 
        name: 'excel-file',
        msgTarget: 'qtip',
        buttonText: '',
        buttonCfg: {
            iconCls: 'upload-icon'
        },                   
		listeners:{
	        'fileselected': function() {
	         	Ext.getCmp('Sheet').setValue("");				
			}
	    }
    }],
    buttons: [{
        text: text_76,
        handler: function(){
            if(uploadFormPanel.getForm().isValid()){
            	
                uploadFormPanel.getForm().submit({
                    url: 'file-upload.php',
                    waitMsg: text_77,
			    	success: function(form, action) {                                        
			         	if (Ext.getCmp('Sheet').getValue() == "" && action.result.sheets) {
			    			uploadBlattwahl(action.result.sheets);
			         	} 
	                    else {
                        	Ext.MessageBox.alert(text_78, text_79 + action.result.file + text_80);

					       	var tabelle_id = action.result.tab_id; 
			    		  	Ext.getCmp('treeEinstellungen').getNodeById('adminT').appendChild(new Ext.tree.TreeNode({
			                   	id:'adminT'+tabelle_id, text: Ext.getCmp('Upload-Name').getValue(), iconCls:'table', leaf:true 
							}));                   
							treeTabellen.getLoader().load(treeTabellen.root);					
	
			    		  	Ext.getCmp('TabelleID').setValue(-1);
							Ext.getCmp('treeEinstellungen').selectPath((Ext.getCmp('treeEinstellungen').
								getNodeById('adminTNeu').getPath()));
			    			xmlTabelle.getForm().load({url:'table_data.php?action=read&TabelleID=-1', 
			   	            	waitMsg:text_41});   
	
							winUpload.hide();						
						}
                    },
				    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(){
			winUpload.hide();						
        }
    },{
		text: text_169,
	    handler: function(){
	    	uploadFormPanel.getForm().reset();
	    }
	}] 
});

function uploadWindow() {

	if (!winUpload) {
               
	     winUpload = new Ext.Window({
	         layout:'fit',
	         width:500,     
			 autoHeight:true,
	         closeAction:'hide',
	         plain: true,  
			 modal: true,
			 title: text_65,                      
		     items: uploadFormPanel 
			});
	}
	else{
		Ext.getCmp('Sheet').setValue("");
	}
 	winUpload.show();
 	winUpload.center();
}	
	


