/*
Pour utiliser cette fonction ajax, suivre cet exemple:
_________________________________________________
<html>
<head>
<script type="text/javascript" src="../../scripts/ajax.js"></script>
<script type="text/javascript">
function send_ajax(){
	get = '?get_text=' + document.getElementById("get_text").value;
	get = get +'&get_text2=' + document.getElementById("get_text2").value;
	post = "post_text="+document.getElementById("post_text").value;
	post = post + "&post_text2="+document.getElementById("post_text2").value;
	path = 'prosses.php'; // path to server side prossessing page.
	element = 'resultats'; // placeholder for the html returned from the server side prossessing page.
	ajax(path,get,post,element);
	}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
GET1: <input type="text" id="get_text" onkeyup="send_ajax()" /><br />
GET2:<input type="text" id="get_text2" onkeyup="send_ajax()" />
  
  <br /><br />

<form action="" method="post">
POST1:<input id="post_text" type="text" /><br />
POST2:<input id="post_text2" type="text" /><br />
<input type="button" value="Button" onclick="send_ajax()" /><br />
</form>
<span id="resultats">Le r&eacute;sultat va apparaitre ici</span>
</body>
</html>
_________________________________________________
*/

var xmlhttp;
function ajax(path,get,post,element){
	ajax_suite(path,get,post);
		
function ajax_suite(path,get,post){
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null){
  alert ("Your browser does not support http requests");
  return;
  }
  if(get == ""){
	rand = "?sid="+Math.random();
  }else{
	rand = "&sid="+Math.random();
  }
var url=path + get + rand;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("POST", url, true); 
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", post.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(post); 
}

function stateChanged(){
	
if ((xmlhttp.readyState==1)||(xmlhttp.readyState==2)||(xmlhttp.readyState==3)){
//document.getElementById(element).innerHTML="<br/><br/>Loading...";
  if(element !== ""){
	document.getElementById('ajax_loading').className = 'visible';
  }
}
if (xmlhttp.readyState==4){
document.getElementById(element).innerHTML=xmlhttp.responseText;
reponse = xmlhttp.responseText;
document.getElementById('ajax_loading').className = 'hidden';
}
}

function GetXmlHttpObject(){
if (window.XMLHttpRequest){
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject){
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
}