function webServ_telform(tel)
{
		value_session_telform = document.getElementById('session_telform').value;
        // The full path to the proxy
        var url = 'http://www.waterair.fr/TelForm/accesServiceTelForm.php?Tel='+tel+'&session_telform='+value_session_telform;

        // 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('#');
              //alert(valSplit[0]);
              if (valSplit[0] == '1') {
                  document.getElementById("msg_telform").style.display = "block";
            	  //Nom : simple textbox
            	  document.getElementById("reponse_104").value = valSplit[2];
            	  //Pr?nom : simple textbox
            	  document.getElementById("reponse_105").value = valSplit[3];
				  
				  
				  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
								}
				  
            	  //Raison Sociale
				  if (document.getElementById("reponse_104").value == '')
				  {
            	  	document.getElementById("reponse_104").value = valSplit[4];
				  }
            	  //Type voie long
            	  //document.create_account.TypeVoieLong.value = valSplit[5];
            	  //Type voie court
            	  //document.create_account.TypeVoieCourt.value = valSplit[6];
            	  //numero
            	  //document.create_account.Numero.value = valSplit[7];
            	  //numero
            	  //document.create_account.CplNumero.value = valSplit[8];
            	  // L'adresse
            	  //document.create_account.Adresse.value = valSplit[9];
            	  document.getElementById("reponse_106").value = valSplit[7] + ' ' + valSplit[8]+ ' ' +valSplit[6] + ' ' + noaccent(valSplit[9]);
            	  //document.create_account.suburb.value = noaccent(valSplit[10])+ ' ' + valSplit[11] + ' ' + valSplit[12];

            	  // complement adresse
            	  document.getElementById("reponse_107").value = valSplit[10] + ' ' + valSplit[11] + ' ' + valSplit[12];
            	  
				  /*
        	  for(i=0; i<document.create_account.country.length; i++)
        		{
        			if(document.create_account.country.options[i].value == 73)
        			{
        				document.create_account.country.options[i].selected=true;
        			}
        		}
				*/

            	  // Boite postal
            	  //document.create_account.BoitePostal.value = valSplit[11];
            	  // Cedex
            	  //document.create_account.Cedex.value = valSplit[12];
            	  // Le code postal
            	  document.getElementById("reponse_108").value = valSplit[13];
				  document.getElementById("reponse_114").value = valSplit[13];
            	  // La ville
            	 // document.getElementById("reponse_109").value = valSplit[14];
				  
				  villa = noaccent(valSplit[14]);
				var VilleMaj= villa.toUpperCase();
            	  document.getElementById("reponse_109").value = VilleMaj;
            	  // Le Pays
            	  //document.create_account.Pays.value = valSplit[15];
            	  // Le telephone
            	  document.getElementById("reponse_111").value = valSplit[16];
            	   // Type utilisateur
            	  //document.create_account.TypeUtilisateur.value = valSplit[17];
            	  // Siret
            	  //document.create_account.Siret.value = valSplit[18];
            	  // NAF
            	  //document.create_account.CodeNaf.value = valSplit[19];
            	  //S?curit?
            	  //document.create_account.Referer.value = valSplit[20];
              }
                }
            };
            // Make the actual request
            xmlhttp.send(null);
}
function webServ_telformAnnu(MotDir)
{
	RecupCodePostal = document.getElementById("reponse_108").value;
	RecupNom = document.getElementById("reponse_104").value;
	value_session_telform = document.getElementById('session_telform').value;
	
        // The full path to the proxy
        var url = 'http://www.waterair.fr/TelForm/accesServiceTelFormAnnu.php?MotDirecteur='+MotDir+'&CP='+RecupCodePostal+'&Nom='+RecupNom+'&session_telform='+value_session_telform;

        // 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('#');
              //alert(valSplit[0]);
              if (valSplit[0] == '1') {
                  
            	  // Le telephone
            	  //document.create_account.phoneFixe.value = valSplit[16];
				  document.getElementById("reponse_Telform").value = valSplit[16];
				  document.getElementById("reponse_112").value = valSplit[16];
				  
              }
                } 
            }
            // Make the actual request
            xmlhttp.send(null);
}

function validatePhone(phone)
    {
        return phone.replace(/\D/g,"");
    }

function isTel(obj) {
  //value_tel = document.create_account.telephone_telform.value;
  value_tel = obj.value;
  tel = validatePhone(value_tel);
  length_tel = tel.length;
  
  if ( length_tel >= 10 )
  {
	 //console.log('TelForm : '+ tel);
     webServ_telform(tel);
  }
}

function Extract_LgMotdir(AdresseComplete)
    {
		//return AdresseComplete.charAt(5);
        return AdresseComplete.lastIndexOf(' ');
    }

function Extract_Motdir(AdresseComplete)
    {	
	return AdresseComplete.substring(LgMotDir+1);
	}
	
function MotDirecteur () {
	AdresseComplete = document.getElementById("reponse_106").value;
	//LongueurAdr = AdresseComplete.length;
	LgMotDir = Extract_LgMotdir(AdresseComplete);
	//DebMotDir = LongueurAdr-LgMotDir;
	MotDir = Extract_Motdir(AdresseComplete);
	RecupCodePostal = document.getElementById("reponse_108").value;
	RecupNom = document.getElementById("reponse_104").value;
	//document.getElementById("reponse_114").value = MotDir;
	//document.getElementById("reponse_114").value = AdresseComplete;
	//document.create_account.champ_cache_Adr.value = AdresseComplete;

	if ( MotDir != '' && RecupCodePostal != '' && RecupCodePostal.length == 5 && RecupNom != '')
	{
		webServ_telformAnnu(MotDir);
	}
	
}

function utf8_encode ( argString ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
 
    var string = (argString+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");
 
    var utftext = "";
    var start, end;
    var stringl = 0;
 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }
 
    if (end > start) {
        utftext += string.substring(start, string.length);
    }
 
    return utftext;
}

function utf8_decode ( str_data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Norman "zEh" Fuchs
    // +   bugfixed by: hitwork
    // +   bugfixed by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
 
    var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
    
    str_data += '';
    
    while ( i < str_data.length ) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
 
    return tmp_arr.join('');
}