function webServ_telform(tel)
{
		value_session_telform = document.form_adduser.session_telform.value;
        // The full path to the proxy
		
		//PROD
        //var url = 'http://www.vetaffaires.fr/speedform/accesServiceSpeedForm.php?Tel='+tel+'&session_telform='+value_session_telform;
		
		//DEV
		var url = 'http://vetaffaires/speedform/accesServiceSpeedForm.php?Tel='+tel+'&session_telform='+value_session_telform;
		
		//echo url;

        // Create xmlhttprequest object
        var xmlhttp = null;
        if (window.XMLHttpRequest) {
                xmlhttp = new XMLHttpRequest();
                //make sure that Browser supports overrideMimeType
                if ( typeof xmlhttp.overrideMimeType != 'undefined') { xmlhttp.overrideMimeType('text/xml'); }
        } else if (window.ActiveXObject) {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }  else {
                alert('Perhaps your browser does not support xmlhttprequests?');
        }
        // Create an HTTP GET request
        xmlhttp.open('GET', url, true);


        // Set the callback function
        xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4) {
              var valSplit = xmlhttp.responseText.split('#');
			  
			  //Aucune adresse n'a été trouvé
			  if (valSplit[0] == '-2') 
			  {
					document.getElementById("msg_telform2").style.display = "block";
					document.getElementById("msg_telform").style.display = "none";
				  
			  }
			  //Une adresse est remonté par le webservice
              else if (valSplit[0] == '1') 
			  {
                  document.getElementById("msg_telform2").style.display = "none";
				  document.getElementById("msg_telform").style.display = "block";
				  
				  // script suppression des espaces devant et dérrière
				  String.prototype.trim = function () {
					   return this.replace(/^\s*|\s*$/,"");
						}
				  // script suppression des doubles espaces dans la chaine
				  String.prototype.simplify= function () {
					   return this.replace(/\s+/g," ");
						}
				  //civilité:Radio
				 if (valSplit[22]=='Mle'){
				  document.form_adduser.gender[0].checked=1;}
				 else{document.form_adduser.gender[0].checked=0;}
				 if (valSplit[22]=='Mme'){
				  document.form_adduser.gender[1].checked=1;}
				 else{document.form_adduser.gender[1].checked=0;}
				 if (valSplit[22]=='M.'){
				 document.form_adduser.gender[2].checked=1;}
				 else{document.form_adduser.gender[2].checked=0;}
				  
				  
				  //Nom : simple textbox
				  document.form_adduser.lastname.value = valSplit[2].simplify();
						  
				  //PrÃ©nom : simple textbox
				  document.form_adduser.firstname.value = valSplit[3].simplify();
				  
				  //Raison Sociale
				  //document.form_adduser.societeFacturation.value = valSplit[4].simplify();
				  
            	  function noaccent(chaine) {
                                temp = chaine.replace(/[\300\301\302\303\304\305\306\340\341\342\343\344\345ÀÁÂÃÄÅÆàâä]/gi,"a")
                                temp = temp.replace(/[\350\351\352\353\340\310\311\312\313éèêë]/gi,"e")
                                temp = temp.replace(/[\314\315\316\317\354\355\356\357îï]/gi,"i")
                                temp = temp.replace(/[\322\323\324\325\326ôö]/gi,"o")
                                temp = temp.replace(/[\331\332\333\334ùûü]/gi,"u")

                                temp = temp.replace(/[\307\347]/gi,"c")
                                return temp
                                }
				  
				  //Nom : simple textbox
            	  //document.form_adduser.lastname.value = valSplit[2];
            	  //Prénom : simple textbox
            	  //document.form_adduser.firstname.value = valSplit[3];
            	  //Raison Sociale
            	  //document.form_adduser.company.value = valSplit[4];
            	  //Type voie court
            	  //document.form_adduser.TypeVoieLong.value = valSplit[5];
            	  //Type voie long
            	  //document.form_adduser.TypeVoieCourt.value = valSplit[6];
            	  //numero
            	  //document.form_adduser.CUSTOMER_STREET_NUMBER.value = valSplit[7]+ '' + valSplit[8];
            	  //numero cplt
            	  //document.form_adduser.CplNumero.value = valSplit[8];
            	  // L'adresse
            	  //document.form_adduser.Adresse.value = valSplit[9];
				  Adresse =valSplit[7] + '' + valSplit[8] + ' ' + valSplit[6] + ' ' +valSplit[9];
				  AdressePropre = Adresse.trim();
            	  document.form_adduser.voie.value = Adresse.trim().simplify();
            	  //document.form_adduser.suburb.value = valSplit[10] + ' ' + valSplit[11] + ' ' + valSplit[12];

            	  // complement adresse
				  AdresseCplt = valSplit[10] + ' ' + valSplit[11] + ' ' + valSplit[12];
				  AdresseCpltPropre = AdresseCplt.trim();
            	  document.form_adduser.etage.value = AdresseCpltPropre.simplify();
            	  


            	  // Boite postal
            	  //document.form_adduser.BoitePostal.value = valSplit[11];
            	  // Cedex
            	  //document.form_adduser.Cedex.value = valSplit[12];
            	  // Le code postal
            	  document.form_adduser.postcode.value = valSplit[13];
            	  
				  villa = noaccent(valSplit[14]);
				  var VilleMaj= villa.toUpperCase();
				  // La ville
            	  document.form_adduser.city.value = VilleMaj.simplify();
            	  // Le Pays
            	  if (valSplit[15] == 'France') 
				  {					  
					  selObj = document.form_adduser.country;					  
					  selObj.selectedIndex = 1; //Le 1er de la liste des pays est la France !!ATTENTION!! Bien vérifier la cohérence avec le fichier 'fra_pays.csv'
				  }
            	  // Le telephone
            	  //document.form_adduser.telephone.value = tel;
            	   // Type utilisateur
            	  //document.form_adduser.TypeUtilisateur.value = valSplit[17];
            	  // Siret
            	  //document.form_adduser.Siret.value = valSplit[18];
            	  // NAF
            	  //document.form_adduser.CodeNaf.value = valSplit[19];
            	  //Sécurité
            	  //document.form_adduser.Referer.value = valSplit[20];
              }
                }
            };
            // Make the actual request
            xmlhttp.send(null);
}

function validatePhone(phone)
{
	return phone.replace(/\D/g,"");
}

function isTel() 
{
	document.getElementById("msg_telform2").style.display = "none";
	document.getElementById("msg_telform").style.display = "none";

	value_tel = document.form_adduser.telephone.value;
	tel = validatePhone(value_tel);
	length_tel = tel.length;
	if ( length_tel >= 10 )
	{
		webServ_telform(tel);
	}
}
