function trimChaine(chaine)
{
	var j=chaine.length;
	var i=0;
	while(i<j)
	{
		i=i+1;
		chaine=chaine.replace(' ','');
	}
	return chaine;
}

function chiffres(event)
{
	// Compatibilit IE / Firefox
	if(!event&&window.event) {
		event=window.event;
	}
	// IE
	if(event.keyCode < 48 || event.keyCode > 57) {
		if (event.keyCode != 13)
		{
			event.returnValue = false;
			event.cancelBubble = true;
		}
	}
	// DOM
	if(event.which < 48 || event.which > 57) {
		if ((event.which != 8)&&(event.which != 13)&&(event.which != 0))
		{
			event.preventDefault();
			event.stopPropagation();
		}
	}
}
function checkEmail(email) 
{
	var arobase = email.indexOf("@");
	var point = email.lastIndexOf(".");
	if((arobase < 3) || (point + 3 > email.length) || (point < arobase+3)) {
		return false;
	}
	return true;
}
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..."); 
	   xhr = false; 
	} 
	return xhr;
}
function Authentification() 
{
	login = document.getElementById('login').value;
	mp = document.getElementById('mp').value;
	if (trimChaine(login)=='') 
	{ 	
		alert("Veuillez saisir votre login (email)"); 	return false; 
	}
	if (checkEmail(login)==false) 
	{ 	
		alert("Format login(email) incorrect"); 	return false; 
	}
	if (trimChaine(mp)=='') 
	{ 	
		alert("Veuillez saisir votre mot de passe"); 	return false; 
	}
	var xhr = getXhr();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			leselect = xhr.responseText;
			if(leselect=="true")
				location="reserver.php";
			else
			{
				alert("Login ou mot de passe incorrect!");
				document.getElementById('login').focus();
			}
		}
	}
	
	xhr.open("POST","Ajax/Authetification.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("login=" + login + "&mp=" + mp );
	return false;
}
function MPO() 
{
	loginMPO = document.getElementById('loginMPO').value;
	if (trimChaine(loginMPO)=='') 
	{ 	
		alert("Veuillez saisir votre login (email)"); 	return false; 
	}
	if (checkEmail(loginMPO)==false) 
	{ 	
		alert("Format login(email) incorrect"); 	return false; 
	}
	return false;
	var xhr = getXhr();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			leselect = xhr.responseText;
			if(leselect=="true")
				location="reserver.php";
			else
			{
				alert("Login ou mot de passe incorrect!");
				document.getElementById('login').focus();
			}
		}
	}
	
	xhr.open("POST","Ajax/Authetification.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("login=" + login + "&mp=" + mp );
	return false;
}
function affichierMPO()
{
	document.getElementById('RecupMotPasse').style.display="";
}
function changerDisplay(id)
{
	if(document.getElementById(id).style.display=="")
		document.getElementById(id).style.display="none";
	else
		document.getElementById(id).style.display="";
}
function validerEntrer(event)
{
	// Compatibilit IE / Firefox
	if(!event&&window.event) {
		event=window.event;
	}
	// IE
	if(event.keyCode == 13) {
		Authentification();
		return false;
	}
	// DOM
	if(event.which == 13) {
		Authentification();
		return false;
	}
}
function validerEntrerMPO(event)
{
	// Compatibilit IE / Firefox
	if(!event&&window.event) {
		event=window.event;
	}
	// IE
	if(event.keyCode == 13) {
		MPO();
		return false;
	}
	// DOM
	if(event.which == 13) {
		MPO();
		return false;
	}
}
function changerLangue(lg)
{
	var xhr = getXhr();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4){
			leselect = xhr.responseText;
			if(leselect=="ok")
			{
				location.reload();
			}
		}
	}
	xhr.open("POST","Ajax/changerlg.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("lg="+lg);
}
function cacherAnim()
{
	if(document.getElementById("headpub").style.visibility)
		document.getElementById("headpub").style.visibility="hidden";
}
function afficherAnim()
{
	if(document.getElementById("headpub").style.visibility)
		document.getElementById("headpub").style.visibility="visible";
}