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

Ext.onReady(function(){

    var ds = new Ext.data.Store({
        proxy: new Ext.data.ScriptTagProxy({
            url: 'topics-remote.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'articles',
            totalProperty: 'totalCount',
            id: 'n'
        }, [
            {name: 'title', mapping: 'designation'},
            {name: 'pointeur', mapping: 'pf'},
            {name: 'excerpt', mapping: 'epoque'}
        ])
    });

    // Custom rendering Template
    var resultTpl = new Ext.XTemplate(
        '<tpl for="."><div class="search-item">',
            '<h3>{title}<span>{excerpt}</span></h3>',
        '</div></tpl>'
    );
    
    var search = new Ext.form.ComboBox({
        store: ds,
		minLength: 3,
		minChars: 3,
		emptyText: ' MOTEUR DE RECHERCHE',
        displayField:'title',
        typeAhead: false,
        width: 258,
        hideTrigger:true,
        tpl: resultTpl,
        applyTo: 'search',
        itemSelector: 'div.search-item',
        onSelect: function(record){ // override default onSelect to do redirect
            window.location =
                String.format('liste.php?keyword={1}&direct={0}&Pf={2}', record.id, this.getValue(), record.data.pointeur);
        }
    });
});

