/*
 * Ext JS Library 2.1
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 *
 * http://extjs.com/license
 */

function makeurl(store,options)
{
  var tf = Ext.get('tf')
  phrase=tf.getValue(false);
  store.proxy.url+="?phrase="+phrase
}

Ext.onReady(function(){

    var ds = new Ext.data.Store({
         proxy: new Ext.data.ScriptTagProxy({
            url: 'http://www.ontrenet.net/expand-proxy.php'
            //url: 'http://extjs.com/forum/topics-remote.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'concepts',
            totalProperty: 'totalCount',
            id: 'id'
        }, [
            {name: 'id'},
            {name: 'word'},
            {name: 'concept'}
        ])
    });
    //ds.on("beforeload",makeurl);
    // Custom rendering Template
    var resultTpl = new Ext.XTemplate(
        '<tpl for="."><div class="search-item">',
            '<h3>{id}. {word} -{concept}</h3>',
        '</div></tpl>'
    );

    var search = new Ext.form.ComboBox({
        store: ds,
        displayField:'word',
        typeAhead: false,
        loadingText: 'Searching...',
        width: 350,
        autoShow: false,
        selectOnFocus: false,
        pageSize:0,
        hideTrigger:true,
        tpl: resultTpl,
        applyTo: 'tf',
        itemSelector: 'div.search-item',
        onSelect: function(record){ // override default onSelect to do redirect
                var concept = record.data.concept.replace(/[^A-Za-z0-9 ]+/g,'');
                window.forms.action.submit();
            //window.location =
            //    String.format('http://localhost:8080/concept?id={0}', concept);
        }
    });
});
