﻿/*TELEPHONE*/
function CheckTelephoneInDB(){
	var TELEPHONE = Remplace(trim(document.getElementById("TELEPHONE").value)," ","");
	if (TELEPHONE!=""){
		var xhr_object = null;
		
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else { // XMLHttpRequest non supporté par le navigateur
			alert("ERROR");
			return;
		}

		xhr_object.open("POST", "/Functions/CheckTelephoneInDB.php?TELEPHONE="+TELEPHONE, true);
		var data =encodeURI("TELEPHONE="+TELEPHONE);
		//alert(data);
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4) {
				document.getElementById("BtEnvoyerDisabled").style.display="block";
				document.getElementById("btEnvoyer").style.display="none";
				if(xhr_object.responseText=="0"){
					document.getElementById("ValiditeTel").value="1";
					FillInfosFromTelephoneNumber(TELEPHONE);
				}else{
					document.getElementById("ValiditeTel").value="0";
					alert("Le numéro de téléphone saisie correspond à un compte VIP.\nMerci d'utiliser le formulaire de renouvellement de mot de passe si vous l'avez oublié.");
				}
				if((document.getElementById("ValiditeTel").value=="1")&&(document.getElementById("ValiditeEmail").value!="0")){
					document.getElementById("BtEnvoyerDisabled").style.display="none";
					document.getElementById("btEnvoyer").style.display="block";
				}
			}
		}
		//Send the proper header information along with the request
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.setRequestHeader("Content-length", data.length);
		xhr_object.setRequestHeader("Connection", "close");
		xhr_object.send(data);
	}
}

function FillInfosFromTelephoneNumber(TELEPHONE){
	if (TELEPHONE!=""){
		var xhr_object = null;
		
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else { // XMLHttpRequest non supporté par le navigateur
			alert("ERROR");
			return;
		}

		xhr_object.open("POST", "/Functions/FillInfosFromTelephoneNumber.php", true);
		var data =encodeURI("TELEPHONE="+TELEPHONE);
		//alert(data);
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4) {
				eval(xhr_object.responseText);
			}
		}
		//Send the proper header information along with the request
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.setRequestHeader("Content-length", data.length);
		xhr_object.setRequestHeader("Connection", "close");
		xhr_object.send(data);
	}
}