
function getHTTPObject(ID, statusID)
{
  var xmlhttp = false;
	// Internet Explorer
	try {
		// 	alert("Msxml2.XMLHTTP");
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}catch (e){
		try{
			//	alert("Microsoft.XMLHTTP");
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e) {
			try{
				//alert("Firefox");
				// Firefox, Opera 8.0+, Safari
				 xmlhttp=new XMLHttpRequest();
			}catch (e){
				alert("Your browser does not support AJAX!");
				xmlhttp = false;
			}
		}
	 }
	

  if (xmlhttp)
  {
     /* on définit ce qui doit se passer quand la page répondra */
     xmlhttp.onreadystatechange=function()
     {
        if (xmlhttp.readyState == 4) /* 4 : état "complete" */
        {
           if (xmlhttp.status == 200) /* 200 : code HTTP pour OK */
           {
              /*
              Traitement de la réponse.
              */
	      	  if (document.getElementById(statusID) != null)  document.getElementById(statusID).innerHTML = "";
		  if (document.getElementById(ID) != null)  document.getElementById(ID).innerHTML = xmlhttp.responseText;
		  
           } else {
           	  if (document.getElementById(statusID) != null)  document.getElementById(statusID).innerHTML = "<i>Vi&#7879;c t&#7843;i n&#7897;i dung n&#224;y b&#7883; l&#7895;i. B&#7841;n c&#243; th&#7875; refresh l&#7841;i b&#7857;ng c&#225;ch nh&#7845;n <b>F5</b>. </i>";
           }
        }
     }
  } else {
  		alert("Trinh duyet nay khong ho tro AJAX!");
  }
  return xmlhttp;
}

function verifId()
 {
    //envoi des données
    return !sendData(
       'POST',
       'identification-xml.php',
       'xmlhttp=1&'+
       'login='+document.getElementById('txtLogin').value+
       '&'+
       'password='+document.getElementById('txtPassword').value);
 }


/**
  * Envoie des données à l'aide d'XmlHttpRequest?
  * @param string methode d'envoi ['GET'|'POST']
  * @param string url
  * @param string données à envoyer sous la forme var1=value1&var2=value2...
  */
 function sendData(ID, url, data, method, statusID)
 {
    if (document.getElementById(statusID) != null)  document.getElementById(statusID).innerHTML = "<img src='images/loading.gif'>";
    var xmlhttp = getHTTPObject(ID, statusID);

    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 ajaxPostFile(ID, filename, data){
	sendData(ID, filename, data, "POST", ID);
}

function ajaxPostFile2(ID, filename, data, statusID){
	sendData(ID, filename, data, "POST", statusID);
}

function ajaxGetFile(ID, filename){
	sendData(ID, filename, "null", "GET", ID);
}

function ajaxGetFile2(ID, filename, statusID){
	sendData(ID, filename, "null", "GET", statusID);
}
