Ext.TreeCombo = Ext.extend(Ext.form.ComboBox, {
	initList: function() {
		// Dummy store - wird nicht benutzt
		this.store = new Ext.data.SimpleStore({
				        fields: ['adummy', 'bdummy'],
				        data : []
				    });
		this.list = new Ext.tree.TreePanel({
			id: 'branchesselection_treepanel',
			root: new Ext.tree.AsyncTreeNode({
				text: 'root',
				children: this.children
			}),
			rootVisible: false,
			loader: new Ext.tree.TreeLoader(),
			floating: true,
			autoScroll: this.autoScroll,
			height: this.height,
			width: this.width-25,
			listeners: {
				click: this.onNodeClick,
				scope: this
			},
			alignTo: function(el, pos) {
				this.setPagePosition(this.el.getAlignToXY(el, pos));
			}
		});
	},

	expand: function() {
		if(typeof(this.list) == 'undefined') {
			this.initList();
		}
		
		if (!this.list.rendered) {
			this.list.render(document.body);
			this.list.setWidth(this.el.getWidth()+25);
			this.innerList = this.list.body;
			this.list.hide();
		}
		//this.el.focus();
		Ext.TreeCombo.superclass.expand.apply(this, arguments);
	},

	doQuery: function(q, forceAll) {
		this.expand();
	},

    collapseIf : function(e){
        if(!e.within(this.wrap) && !e.within(this.list.el)){
            this.collapse();
        }
    },

	onNodeClick: function(node, e) {
		this.setRawValue(node.attributes.text);
		if (this.hiddenField) {
			this.hiddenField.value = node.id;
		}
		this.collapse();
		var idArr = node.id.split('_');
		submitBranchesSelection(idArr[idArr.length - 1], node.getPath());
	}
});
Ext.reg('treecombo', Ext.TreeCombo);
