Ext.onReady(function(){

	if (!Ext.get('queryDex')){
		return;
	}
    var ds = new Ext.data.Store({
        proxy: new Ext.data.ScriptTagProxy({
        	url: 'DexQS'
        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'fid'
        }, [
            {name: 'fflex', mapping: 'fflex'},
            {name: 'fword', mapping: 'fword'},
            {name: 'fhtml', mapping: 'fhtml'},
            {name: 'fdict', mapping: 'fdict'}
        ])
    });

    // Custom rendering Template
    var resultTpl = new Ext.XTemplate(
        '<tpl for=".">'+
	        '<div class="search-item">',
	            '{fhtml}<div>Sursă: <i>{fdict}</i></div>',
	        '</div>'+
        '</tpl>'
    );
    
    var search = new Ext.form.ComboBox({
        store: ds,
        displayField:'flex',
        selectOnFocus: true,
        typeAhead: true,
        typeAheadDelay: 100,
        hideTrigger: false,
        loadingText: 'Căutare...',
//        width: 530,
        minChars: 3,
        pageSize:10,
        hideTrigger:true,
        maxHeight: 500,
        tpl: resultTpl,
        applyTo: 'queryDex',
        itemSelector: 'div.search-item',
        onSelect: function(record){ 
            window.location =
                String.format('CautareDex?lang=ro&query={0}', record.data.fword);
        }
    });
});