Ext.onReady(function(){	
	
	Ext.create('Ext.tip.ToolTip', {
	    target: 'aideSuggestBoxVilles',
	    html: "Saisir les premières lettres d'une ville",
	    anchor: 'top'
	});
	
	Ext.define("Modele", {
        extend: 'Ext.data.Model',
        proxy: {
            type: 'ajax',
            url: PARAM_URL + 'index.php?module=ajax&action=listerVillesSuggestBox&idUnivers=11', 
            reader: {                
                root: 'results',
                totalProperty: 'total'
            }
        },
        fields: [
            {name: 'ville', mapping: 'ville'},
            {name: 'departement', mapping: 'departement'},
            {name: 'pays', mapping: 'pays'},
            {name: 'nb', mapping: 'nb'},
            {name: 'localisation', mapping: 'localisation'}                        
        ]
    });
		
	Ext.create('Ext.form.field.ComboBox', {
		id: "suggestBoxVilles",
       	renderTo: "bloc_recherche",
        store: Ext.create('Ext.data.Store', {
            pageSize: 10,
            model: 'Modele'
        }),
        displayField: 'ville',
        typeAhead: false,
        hideLabel: true,
        hideTrigger:true,
        anchor: '100%',
        minChars: 1,
        pageSize: 10,
        width: 174,   
        enableKeyEvents: true,
        matchFieldWidth: false,
        listConfig: {
        	loadingText: 'Recherche...',
            autoHeight: true,
            emptyText: 'Aucun résultat',
            getInnerTpl: function() {
            	var tpl = "{ville} <i>({nb}</i>)";
                return tpl;
            }
        },
        listeners: {
        	expand: function(combo){
        		var picker = combo.getPicker();
                picker.setSize(220, 250);
            },
            /*keyup: function(textfield, event, options) {            	
            	//remmplacement des tous les caractères non alpha-numériques par des tirets 
        		//var regExpression=/[^A-Za-z0-9-]+/;
            	ville = textfield.rawValue;
        		ville = ville.replace(" ", "-");
        		//var regex=/^[^0-9a-zA-Z]+g/;
        		//ville = ville.replace(regex, "-");
        		this.setValue(ville);
            },*/
            select: function(combo, record, e) {            	   
            	var villeRecherche = record[0].get('ville');
	   			lancerRecherche(0);
	   		}
        }
    });
});
