/************************************************************************************/

function createObject(){
	
	var oXmlHttpReq=false;
	
    if(window.XMLHttpRequest){
		//Mozilla/Safari
        oXmlHttpReq = new XMLHttpRequest();
    }else if(window.ActiveXObject){
		//IE
		try{
            oXmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
               oXmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(e){}
		}
	}else{
		
		if (!oXmlHttpReq && typeof XMLHttpRequest!='undefined') {
			try {
				oXmlHttpReq = new XMLHttpRequest();
			} catch (e) {}
		}
		if (!oXmlHttpReq && window.createRequest) {
			try {
				oXmlHttpReq = window.createRequest();
			} catch (e) {}
		}
		
		// XMLHttpRequest non supporté par le navigateur 
		//alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest !");
	}
	return oXmlHttpReq;
}

/************************************************************************************/

function validerEmailMembre(courriel, id) {
	
	var valide=true;
	
	//Courriel
	if(valide && courriel != ''){
		valide = validerEmail(courriel,id);
	}
	
	return valide;
}

/************************************************************************************/

function validerEmail(courriel,id) {

	var valide=true;
	var strURL = pathBase+'php/email_check.php';
    var self = this;
	
	self.xmlHttpReq2 = createObject();
	if(self.xmlHttpReq2){
		
		self.xmlHttpReq2.open('POST', strURL, false); //synchrone
		self.xmlHttpReq2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		
		self.xmlHttpReq2.send(getemailstring(courriel,id));
		if(self.xmlHttpReq2.status == 200){

			if(self.xmlHttpReq2.responseText == 'no'){
				alert("The email address you entered is already in use by another member !");
				valide=false;
			}
			return valide;
		}
		
		/*
		self.xmlHttpReq2.open('POST', strURL, true); //asynchrone
		self.xmlHttpReq2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		self.xmlHttpReq2.onreadystatechange = function() {
			if (self.xmlHttpReq2.readyState == 4) {
				if (self.xmlHttpReq2.responseText == 'no'){
					alert("Le courriel que vous avez entré est déjà utilisé !");
					//document.getElementById("xpost0").setFocus();
				}
			}
		}
		self.xmlHttpReq2.send(getemailstring(courriel,id));
		*/
	}
}

function getemailstring(courriel,id) {
    var word = courriel;
    qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
	if(id != null){
		  qstr += '&id=' + escape(id);
	}
    return qstr;
}

/************************************************************************************/

function updatepage(str){
    document.getElementById("resultAJAX").innerHTML = str;
}

/************************************************************************************/


