/*!
 * Ext JS Library 3.2.0
 * Copyright(c) 2006-2010 Ext JS, Inc.
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
Ext.onReady(function(){

    var ds = new Ext.data.Store({
        proxy: new Ext.data.ScriptTagProxy({
            url: '../www.primappart.fr/php/livesearch.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'totalCount'
        }, [
            {name: 'affichage', mapping: 'affichage'},
            {name: 'ville', mapping: 'ville'},
            {name: 'cp', mapping: 'cp'}
        ])
    });

    // Custom rendering Template
    var resultTpl = new Ext.XTemplate(
        '<tpl for="."><div class="search-item">',
            '<h3><div style="float:left;">{cp}</div><span>&nbsp;{ville}</span></h3>',
        '</div></tpl>'
    );
    
    var search = new Ext.form.ComboBox({
        store: ds,
        minChars : 2,
        displayField:'affichage',
        typeAhead: false,
        loadingText: 'Recherche...',
        hideTrigger:true,
        tpl: resultTpl,
        applyTo: 'txt1',
        itemSelector: 'div.search-item'
    
    });
});
