// JavaScript Document
function getHTTPObject(data_cut)
{
  var xmlhttp = false;

  /* Compilation conditionnelle d'IE */
  /*@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 @*/

  /* on essaie de créer l'objet si ce n'est pas déjà fait */
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
  {
     try
     {
        xmlhttp = new XMLHttpRequest();
     }
     catch (e)
     {
        xmlhttp = false;
     }
  }

  if (xmlhttp)
  {
     xmlhttp.onreadystatechange=function()
     {
     
        if (xmlhttp.readyState == 4) /* 4 : état "complete" */
        {
           if (xmlhttp.status == 200) /* 200 : code HTTP pour OK */
           {
              
              //alert(xmlhttp.responseText + " miam");
              if(xmlhttp.responseText != "OK[REJECT/FAILED]" && xmlhttp.responseText != "erreur ici"){
              //window.location='connect.php';
              //alert("Oui");
              /*
              document.getElementById("form_recherche").style.display = "none";
              document.getElementById("resultat_log").style.display = "block";
              document.getElementById('mon_login').innerHTML = xmlhttp.responseText;
              */
              var sURL = unescape(window.location.pathname);
              window.location.href = sURL;
              } else {
              alert("Login et/ou Mot de passe incorrect");
              }
           }
        }
     }
  }
  return xmlhttp;
}

function getHTTPObject2(data_cut)
{
  var xmlhttp = false;

  /* Compilation conditionnelle d'IE */
  /*@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 @*/

  /* on essaie de créer l'objet si ce n'est pas déjà fait */
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
  {
     try
     {
        xmlhttp = new XMLHttpRequest();
     }
     catch (e)
     {
        xmlhttp = false;
     }
  }

  if (xmlhttp)
  {
     xmlhttp.onreadystatechange=function()
     {
     
        if (xmlhttp.readyState == 4) /* 4 : état "complete" */
        {
           if (xmlhttp.status == 200) /* 200 : code HTTP pour OK */
           {
              
              //alert(xmlhttp.responseText + " miam");
              if(xmlhttp.responseText != "Non" && xmlhttp.responseText != "Moyen"){
                  alert("Inscription validée");
              } else {
                  if(xmlhttp.responseText == "Moyen"){
                      alert("Veuillez recommencer");
                  } else {
                      alert("Email incorrect");
                  }
                  
              }
           }
        }
     }
  }
  return xmlhttp;
}

function verifId(objet,objet2){
		//alert(objet+" "+objet2);
		//envoi des données
		sendData(
		'POST',
		'/tpl/identification-xml.php',
		'xmlhttp=1&login='+objet+'&password='+objet2);
}

function verifNews(objet){
		//alert(objet+" "+objet2);
		//envoi des données
		sendData2(
		'POST',
		'/tpl/identification-news-xml.php',
		'xmlhttp=1&email='+objet);
}

function sendData(method, url, data){	
	data_cut = data.substring(10, data.length);
	//alert(data);
	//alert(data_cut);
	var xmlhttp = getHTTPObject(data_cut);
	
	if (!xmlhttp)
	{
	return false;
	}
	
	if(method == "GET")
	{
	if(data == 'null')
	{
	xmlhttp.open("GET", url, true); //ouverture asynchrone
	}
	else
	{
	xmlhttp.open("GET", url+"?"+data, true);
	}
	xmlhttp.send(null);
	}
	else if(method == "POST")
	{
	xmlhttp.open("POST", url, true); //ouverture asynchrone
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttp.send(data);
	}
	return true;
}

function sendData2(method, url, data){	
	data_cut = data.substring(10, data.length);
	//alert(data);
	//alert(data_cut);
	var xmlhttp = getHTTPObject2(data_cut);
	
	if (!xmlhttp)
	{
	return false;
	}
	
	if(method == "GET")
	{
	if(data == 'null')
	{
	xmlhttp.open("GET", url, true); //ouverture asynchrone
	}
	else
	{
	xmlhttp.open("GET", url+"?"+data, true);
	}
	xmlhttp.send(null);
	}
	else if(method == "POST")
	{
	xmlhttp.open("POST", url, true); //ouverture asynchrone
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttp.send(data);
	}
	return true;
}
