/*!
 * Ext JS Library 3.2.0
 * Copyright(c) 2006-2010 Ext JS, Inc.
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
 
Ext.onReady(function(){
if (document.getElementById('frm_residencebp')) {
    var dsbp = new Ext.data.Store({
        proxy: new Ext.data.ScriptTagProxy({
            url: '../www.avis-etudiant.fr/php/livesearchbp.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'totalCount'
        }, [
            {name: 'affichage', mapping: 'affichage'},
            {name: 'ville', mapping: 'ville'},
            {name: 'id', mapping: 'id'},
            {name: 'cp', mapping: 'cp'}
        ])
    });

    // Custom rendering Template
    var resultTplbp = new Ext.XTemplate(
        '<tpl for="."><div class="search-item">',
            '<h3><span>&nbsp;{affichage}</span></h3>',
        '</div></tpl>'
    );
    
    var search = new Ext.form.ComboBox({
        store: dsbp,
        minChars : 2,
        displayField:'affichage',
        typeAhead: false,
        loadingText: 'Recherche...',
         valueField:'id',
        hideTrigger:true,
        tpl: resultTplbp,
        applyTo: 'txtbp',
          listeners:{
         'select': function() {              
              document.getElementById('frm_residencebp').id_residence.value = search.getValue();
          }
        },

        
        itemSelector: 'div.search-item'
    
    });
}
    });   
 
Ext.onReady(function(){
if (document.getElementById('frm_residence')) {
	$('#frm_residence input[name=localisation]').val('');
	$('#frm_residence input[type=submit]').click(function(event) {
		event.preventDefault();
		alert('Veuillez sélectionner une entrée dans la liste');
	});
    var ds = new Ext.data.Store({
        proxy: new Ext.data.ScriptTagProxy({
            url: '../www.avis-etudiant.fr/php/livesearch.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'totalCount'
        }, [
            {name: 'affichage', mapping: 'affichage'},
            {name: 'ville', mapping: 'ville'},
            {name: 'id', mapping: 'id'},
            {name: 'cp', mapping: 'cp'}
        ])
    });

    // Custom rendering Template
    var resultTpl = new Ext.XTemplate(
        '<tpl for="."><div class="search-item">',
            '<h3><span>&nbsp;{affichage}</span></h3>',
        '</div></tpl>'
    );
    
    var search = new Ext.form.ComboBox({
        store: ds,
        minChars : 2,
        displayField:'affichage',
        typeAhead: false,
        loadingText: 'Recherche...',
         valueField:'id',
        hideTrigger:true,
        tpl: resultTpl,
        applyTo: 'txt1',
          listeners:{
         'select': function() {
			var id = search.getValue();
			document.getElementById('frm_residence').id_residence.value = id;
			if (id) {
				var l = search.store.data.map[ id ].data.affichage;
				window.location = 'http://www.avis-etudiant.fr/Residences/' + id + '_' + l.replace(/ /g, '-') + '.html';
			} else {
				document.getElementById('frm_residence').submit();
			}
          }
        },

        
        itemSelector: 'div.search-item'
    
    });
}
    });  
Ext.onReady(function(){
if (document.getElementById('form-avis')) {
    var dsres = new Ext.data.Store({
        proxy: new Ext.data.ScriptTagProxy({
            url: '../www.avis-etudiant.fr/php/livesearchresidence.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'totalCount'
        }, [
            {name: 'affichage', mapping: 'affichage'},
            {name: 'ville', mapping: 'ville'},
            
             {name: 'id', mapping: 'id'},
            {name: 'cp', mapping: 'cp'}
        ])
    });

    // Custom rendering Template
    var resultTplres = new Ext.XTemplate(
        '<tpl for="."><div class="search-itemres">',
            '<h3><span>&nbsp;{affichage}</span></h3>',
        '</div></tpl>'
    );
    
    var searchres = new Ext.form.ComboBox({
        store: dsres,
        minChars : 2,
        displayField:'affichage',
        valueField:'id',
        typeAhead: false,
        loadingText: 'Recherche...',
        hideTrigger:true,
        tpl: resultTplres,
        applyTo: 'txtresavis',
        listeners:{
         'select': function() {              
              document.getElementById('form-avis').id_residence.value = searchres.getValue();
          }
        },

        
        itemSelector: 'div.search-itemres'
    
    }); 
    
}
    
  
});

Ext.onReady(function(){  
if (document.getElementById('form-bon_plan')) {
    var dsres = new Ext.data.Store({
        proxy: new Ext.data.ScriptTagProxy({
            url: '../www.avis-etudiant.fr/php/livesearchresidence.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'rows',
            totalProperty: 'totalCount'
        }, [
            {name: 'affichage', mapping: 'affichage'},
            {name: 'ville', mapping: 'ville'},
            
             {name: 'id', mapping: 'id'},
            {name: 'cp', mapping: 'cp'}
        ])
    });

    // Custom rendering Template
    var resultTplres = new Ext.XTemplate(
        '<tpl for="."><div class="search-itemres">',
            '<h3><span>&nbsp;{affichage}</span></h3>',
        '</div></tpl>'
    );


    var searchres2 = new Ext.form.ComboBox({
        store: dsres,
        minChars : 2,
        displayField:'affichage',
        valueField:'id',
        typeAhead: false,
        loadingText: 'Recherche...',
        hideTrigger:true,
        tpl: resultTplres,
        applyTo: 'txtres',
        listeners:{
         'select': function() {              
              document.getElementById('form-bon_plan').id_residence.value = searchres2.getValue();
          }
        },

        
        itemSelector: 'div.search-itemres'
    
    }); 
}
});
