function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		xmlhttp = false;
		}
	  }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	try {
	  xmlhttp = new XMLHttpRequest();
	  } catch (e) {
	  xmlhttp = false;
	  }
	}
  return xmlhttp;
}


function aff_puce(id){
	document.getElementById("reponse_demande").innerHTML = "";
	document.getElementById('mdp_oublie').style.display = "none";
	document.getElementById('demande_mdp').style.display = "none";
	document.getElementById(id).style.display = "inline";
}

function verif_mail(mail){
	if ((mail.indexOf("@",1)>1)&&(mail.indexOf(".",1)>0)){return true;}else{return false;}
}

function submit_prati(){
	if(verif_mail(document.getElementById('mail_quest').value)==true){
		document.form_quest.submit();
	}else{
		alert('Votre E-Mail est incorrect...');
	}
}

function valider_entree(e){
	if(window.event) // IE
		keynum = e.keyCode;
	else if(e.which) // Netscape/Firefox/Opera
		keynum = e.which;
	if(keynum == 13){
		document.form_quest.submit();
	}
}

var http_submit_rech = new getHTTPObject();

function submit_rech(){
		alert("Cette espace est désactivé pour le moment.");
		return false;
		
	var login = document.getElementById("recherche1").value;
	var pass = document.getElementById("recherche2").value;
	if(pass == "" || login == ""){
		alert("Tous les champs doivent être renseignés");
		return false;
	}
	
	var envoi = "recherche1="+login+"&";
		envoi += "recherche2="+pass;
	
	http_submit_rech.open("POST","./transition_recherche.php", true);
	http_submit_rech.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http_submit_rech.send(envoi);
	http_submit_rech.onreadystatechange = retour_submit_rech;
}

function retour_submit_rech(){
	if(http_submit_rech.readyState == 4){
		var reponse = http_submit_rech.responseText;
		if(reponse == "OK"){
			document.location.href="index.php";
		}else{
			alert("Informations éronnées.");
			return false;
		}		
	}
}

var http_demande_mdp = new getHTTPObject();

function demande_mdp(obj){
	var tableau = document.getElementById("demande_mdp").getElementsByTagName("input");
	var envoi = "";
	for(var i=0;i<=parseInt(tableau.length)-1;i++){
		if(tableau[i].type == "text"){
			if(tableau[i].value == ""){
				alert("Tous les champs doivent être remplis");
				return false;
				break;
			}
			envoi += tableau[i].id+"="+tableau[i].value+"&";
		}
	}
	
	var mail = document.getElementById("mail").value;
	if(verif_mail(document.getElementById('mail').value) != true){
		alert("Votre adresse e-mail est invalide");
		return false;
	}
	
	http_demande_mdp.open("POST","./traitement_dMdp.php", true);
	http_demande_mdp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http_demande_mdp.send(envoi);
	http_demande_mdp.onreadystatechange = retour_demande_mdp;
}

function retour_demande_mdp(){
	if(http_demande_mdp.readyState == 4){
		document.getElementById('mdp_oublie').style.display = "none";
		document.getElementById('demande_mdp').style.display = "none";
		document.getElementById("reponse_demande").innerHTML = http_demande_mdp.responseText;
	}
}

function plan(){
	window.open("./plan_accueil.php","Plan","width=550,height=350,scrollbars=yes");
}