// Fonction de creation de l'objet XMLHttpRequest qui resservira pour chaques fonctions AJAX
function getXhr()
 {
  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;
   }
 }
var xhr = null;

function ajax_selection()
 {
 var mbqf= getCookieInfo('mbqf');

if (mbqf==undefined){ajax_mbr('2');return false;}

  var num=document.getElementById('num').value;
  var supv=document.getElementById('sup').value;
  getXhr();
  xhr.open("POST",'/ajax_cookies.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send("num="+num+"&sup="+supv);
  if (supv==0){document.getElementById('text_sel').innerHTML='<img src="/assets/min.png"> Retirer de votre sélection';
  document.getElementById('part2').innerHTML='Cet évènement est ajouté à votre sélection.<br>Vous pouvez y accéder à tout moment en cliquant sur \'sélection\' dans le menu tout en bas à gauche.<div align=right><a href="#" onclick = "ajaxiris_close();return false;" ><font class=url>Fermer</font></a></div>';
  document.getElementById('sup').value='1';}
  if (supv==1){document.getElementById('text_sel').innerHTML='<img src="/assets/add.png"> Ajouter votre sélection';
  document.getElementById('part2').innerHTML='';
  document.getElementById('sup').value='0';}
 }

 function ajax_mbr(out)
 {
 var mbqf= getCookieInfo('mbqf');
if (mbqf==undefined){
 getXhr();
 xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) {
	
	 var reponse = xhr.responseText;
	var tableau='part'+out;
	
	  if (reponse){document.getElementById(tableau).innerHTML=reponse;}
		 
	  }
  }
  xhr.open("POST",'/ajax_formu_mbr.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send("out="+out);
 return false;
 }
 }  
 
 function ajax_check_mbr(out)
 {
var mail=document.getElementById("c1").value;
var mdp=document.getElementById("c2").value;
 getXhr();
 xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) {
	
	 var reponse = xhr.responseText;
	var tableau='part'+out;
	
	  if (reponse){document.getElementById('prof_int').innerHTML=reponse;}
	
	  else{
	  	document.getElementById(tableau).innerHTML='';
	  	document.getElementById(tableau).style.borderWidth = '0px';
	  	if (out==1){ajax_parti();}
	  	if (out==2){ajax_selection();}
	  	if (out==3){Behaviour.register(ratingAction);}	
	  	if (out==6){var num=document.getElementById("num").value; window.document.location.href='pic.php?num='+num;return true;}		  	
	  }
	  }
  }
  xhr.open("POST",'/ajax_mbr.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send("mail="+mail+"&mdp="+mdp);
 }
 
 function ajax_parti(er)
 {
var mbqf= getCookieInfo('mbqf');
if (mbqf==undefined && er==1){ajax_mbr('1');return false;}
if (mbqf==undefined && er==6){ajax_mbr('6');return false;}
var num=document.getElementById("num").value;
var tableau='part'+er;
getXhr();
 xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200)  {
     document.getElementById(tableau).innerHTML = xhr.responseText;
     }
	  }
if (er==1){xhr.open("POST",'/ajax_list_form_2.php',true);}
if (er==4){xhr.open("POST",'/ajax_ami.php',true);}
if (er==5){xhr.open("POST",'/ajax_map.php',true);}
if (er==6){window.document.location.href='pic.php?num='+num;return true;}
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.send("num="+num);
 }
  
 function ajax_check_mail(out)
 {
var mbqf= getCookieInfo('mbqf');
if (mbqf==undefined){var mail1=document.getElementById("mail1").value;var nom=document.getElementById("nom").value;}
var mail2=document.getElementById("mail2").value;
var com=document.getElementById("com").value;
var num=document.getElementById("num").value;
 getXhr();
 xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) {
	
	 var reponse = xhr.responseText;
	
	
	  if (reponse){document.getElementById('mes2').innerHTML=reponse;}
	
	  else{document.getElementById('part4').innerHTML='<table bgcolor=CEDCF4 width=200><tr><tr>Votre mail est envoy&eacute;.<div align=right><a href="#" onclick = "ajaxiris_close();return false;" ><font class=url>Fermer</font></a></div></td></tr></table>';
	  	  		  	
	  }
	  }
  }
  xhr.open("POST",'/ajax_ami2.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send("mail1="+mail1+"&mail2="+mail2+"&nom="+nom+"&com="+com+"&num="+num);
 }
 
 function ajax_check_parti()
 {
var c1=document.getElementById("c1").value;
var c2=document.getElementById("c2").value;
var c3=document.getElementById("c3").value;
var num=document.getElementById("num").value;
 getXhr();
 xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) {
	
	 var reponse = xhr.responseText;
	
	  if (reponse){document.getElementById('part1').innerHTML=reponse;ajax_lp();}
		
	  }
  }
  xhr.open("POST",'/ajax_list_form_3.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send("c1="+c1+"&c2="+c2+"&c3="+c3+"&num="+num);
 }
 
 // liste des participants
 function ajax_lp()
 {
var num=document.getElementById("num").value;
 getXhr();
 xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) {
	
	 var reponse = xhr.responseText;
	
	 if (reponse){document.getElementById('part_liste').innerHTML=reponse;}
		 
	  }
  }
  xhr.open("POST",'/ajax_liste_mb.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
 xhr.send("num="+num);
 }

 function ajax_tec(fam)
 {
var archive=document.getElementById('iris').style;
var date1=document.getElementById('date1').value;
var heure1=document.getElementById('heure1').value;

	if(archive.display=='block'){

		archive.display='none';

	} else {

		archive.display='block';

	}

  getXhr();
  xhr.onreadystatechange = function()
   {
    if(xhr.readyState == 4 && xhr.status == 200)
     {
      // Nous remplacons le contenu du div iris par le retour de "ajax/ajaxiris.php"
      document.getElementById('iris').innerHTML = xhr.responseText;
     }
   }
  xhr.open("POST",'/tec.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send("ajax=o&num="+fam+"&d="+date1+"&h="+heure1);
 }
function ch()
{
var mi=document.getElementById('heure').value;
var mod = new RegExp("^[0-2]{0,1}[0-9]{1}[:]{1}[0-6]{0,1}[0-9]{1}$","g");
var hr=mi.substring(0,2);
var mn=mi.substring(3,5);
if(!mod.test(mi) || hr>23 || mn>59){document.getElementById('em').innerHTML='<font color=red><b>L\'heure indiqu&eacute;e n\'est pas correcte.<br>Le format doit etre du type 00:00</b></font>'; return false; }
document.getElementById('em').innerHTML='';
}

function ajaxiris_close(out)
{
document.getElementById('part1').innerHTML='';
document.getElementById('part2').innerHTML='';
document.getElementById('part3').innerHTML='';
document.getElementById('part4').innerHTML='';
document.getElementById('part6').innerHTML='';
}

