var nomRepServeur = 'http://www.promoalert.com';
var myAjax = ajax();

function ajax() {
        var ajax = null;
        if (window.XMLHttpRequest) {
                try {
                        ajax = new XMLHttpRequest();
                }
                catch(e) {}
        }
        else if (window.ActiveXObject) {
                try {
                        ajax = new ActiveXObject("Msxm12.XMLHTTP");
                }
                catch (e){
                        try{
                                ajax = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e) {}
                }
        }
        return ajax;
}

function request(str) {
	var url = nomRepServeur + '/services/optionSaisieMagasin.php?debut='+document.getElementById('nomVille').value;
		
        myAjax.open("POST", url);
        myAjax.onreadystatechange = result;
        myAjax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        myAjax.send("search="+str);
}

function result() {
        if (myAjax.readyState == 4) {       	      
                var liste = myAjax.responseText;
                var cible = document.getElementById('divautocompletion').innerHTML = liste;                
                document.getElementById('divautocompletion').style.display = "block";              
        }
        myAjax.send(null);
}

function selected(choice, id_ville){
        var cible = document.getElementById('nomVille');
        var id_nomVille = document.getElementById('idVille');
        
        cible.value = choice;
        id_nomVille.value = id_ville;
        
        document.getElementById('divautocompletion').style.display = "none";
}