Ext.onReady(function(){

    // Custom rendering Template
    var resultTpl = new Ext.XTemplate(
        '<tpl for=".">'+
	        '<div class="search-item" style="font-color: black;">',
	            '<b>{fflex}</b> / {fword}<br/>&nbsp;&nbsp;{fhtml}</div>',
	        '</div>'+
        '</tpl>'
    );

    if (Ext.get('query_lemma_ro')){
    	 var dsLemmaRo = new Ext.data.Store({
 	        proxy: new Ext.data.ScriptTagProxy({
 	        	url: 'GramaticaQS?lang=ro'
 	        }),
 	        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'}
 	        ])
 	    });
    	 var searchLemmaRo = new Ext.form.ComboBox({
    	        store: dsLemmaRo,
    	        displayField:'flex',
    	        selectOnFocus: true,
    	        typeAhead: true,
    	        typeAheadDelay: 100,
    	        hideTrigger: false,
    	        loadingText: 'Căutare...',
    	        minChars: 3,
    	        pageSize:10,
    	        hideTrigger:true,
    	        maxHeight: 500,
    	        tpl: resultTpl,
    	        applyTo: 'query_lemma_ro',
    	        itemSelector: 'div.search-item',
    	        onSelect: function(record){
    	            window.location =
    	                String.format('Gramatica?lang=ro&query={0}', record.data.fflex);
    	        }
    	    });
	}
	if (Ext.get('query_lemma_en')){
	    var dsLemmaEn = new Ext.data.Store({
	        proxy: new Ext.data.ScriptTagProxy({
	        	url: 'GramaticaQS?lang=en'
	        }),
	        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'}
	        ])
	    });
	    var searchLemmaEn = new Ext.form.ComboBox({
	        store: dsLemmaEn,
	        displayField:'flex',
	        selectOnFocus: true,
	        typeAhead: true,
	        typeAheadDelay: 100,
	        hideTrigger: false,
	        loadingText: 'Căutare...',
	        minChars: 3,
	        pageSize:10,
	        hideTrigger:true,
	        maxHeight: 500,
	        tpl: resultTpl,
	        applyTo: 'query_lemma_en',
	        itemSelector: 'div.search-item',
	        onSelect: function(record){
	            window.location =
	                String.format('Gramatica?lang=en&query={0}', record.data.fflex);
	        }
	    });
	}
   
});