// Fonction de creation de l'objet XMLHttpRequest qui resservira pour chaques fonctions AJAX 
function getXhr() 
{ 
	var xhr = null;
	
	if(window.XMLHttpRequest) 
		xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject) 
	{ 
		try 
		{ 
			xhr = new ActiveXObject("Msxml2.XMLHTTP"); 
		} 
		catch (e) 
		{ 
			xhr = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
	} 
	else 
	{ 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre à jour"); 
		xhr = false; 
	} 
	return xhr;
} 

function getEl(el)
{
	return document.getElementById(el);
}

function checkLogin()
{
	var xhr = getXhr(); 
	getEl("loginMessage").innerHTML = "Veuillez patienter.";
	getEl("loginMessage").className = "loginWait";
	xhr.onreadystatechange = function() 
	{ 
		if(xhr.readyState == 4 && xhr.status == 200) 
		{ 
			if(xhr.responseText != "")
			{
				getEl("loginMessage").style.display = "";
				getEl("loginMessage").innerHTML = xhr.responseText;
				getEl("loginMessage").className = "loginMessage"; 
			}
			else
			{
				getMembreInfos();
			}
		} 
	} 
	
	lelogin = getEl("login").value;
	pwd = getEl("pw").value;
	
	xhr.open("GET","/ajax/checkLogin.php?login="+lelogin+"&pw="+pwd+"&d="+ (new Date()).getTime(),true); 
	xhr.send(null); 
}

function getMembreInfos()
{
	var xhr = getXhr(); 

	xhr.onreadystatechange = function() 
	{ 
		if(xhr.readyState == 4 && xhr.status == 200) 
		{ 
			getEl("header_1").innerHTML = xhr.responseText; 
		} 
	} 

	
	xhr.open("GET","/ajax/membreInfos.php?d="+ (new Date()).getTime(),true); 
	xhr.send(null); 
}

function deconnect()
{
	var xhr = getXhr(); 

	xhr.onreadystatechange = function() 
	{ 
		if(xhr.readyState == 4 && xhr.status == 200) 
		{ 			
			getConnexionForm();
		} 
	} 

	
	xhr.open("GET",'/ajax/checkLogin.php?deconnect=1',true); 
	xhr.send(null); 
}

function getConnexionForm()
{
	var xhr = getXhr(); 

	xhr.onreadystatechange = function() 
	{ 
		if(xhr.readyState == 4 && xhr.status == 200) 
		{ 
			getEl("header_1").innerHTML = xhr.responseText; 
		} 
	} 

	
	xhr.open("GET","/ajax/connexionForm.php?d="+ (new Date()).getTime(),true); 
	xhr.send(null); 
}

function getCommentaires(artId, nump)
{
	var xhr = getXhr(); 

	xhr.onreadystatechange = function() 
	{ 
		if(xhr.readyState == 4 && xhr.status == 200) 
		{ 
			getEl("commentaires").innerHTML = xhr.responseText; 
		} 
	} 

	
	xhr.open("GET","/ajax/commentaires.php?art_id="+artId+"&nump="+nump+"&d="+ (new Date()).getTime(),true); 
	xhr.send(null); 
}




