/**
 * Si method = GET alors params=''
 * Si method = POST alors params='var1=valeur1&var2=valeur2'
 */
function file(page, method, params, asynchrone){
	var xhr_object = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	    xhr_object = new XMLHttpRequest();
	    if (xhr_object.overrideMimeType) {
	        xhr_object.overrideMimeType('text/xml');
	    }
	}
	else if (window.ActiveXObject) { // IE
	    try {
	        xhr_object = new ActiveXObject("Msxml2.XMLHTTP");
	    }
	    catch (e) {
	        try {
	            xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	        }
	        catch (e) {}
	    }
	}
	
	if (!xhr_object) {
	    //alert('Abandon :( Impossible de créer une instance XMLHTTP');
	    return false;
	}
     
	//onreadystatechange éxécuté en mode asynchrone seulement.
	xhr_object.onreadystatechange = function() { alertContents(xhr_object); };
	
	if(asynchrone==undefined){ asynchrone=false; }
	xhr_object.open(method, page, asynchrone);
	
	if(method=='POST'){
     	xhr_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr_object.send(params);
	}
	else{ xhr_object.send(null); }
	
	
	if(asynchrone==false){
		return(xhr_object.responseText);
	}
}


function alertContents(httpRequest) {
    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
            return(httpRequest.responseText);
        } else {
            return(false);
            //alert('Un problème est survenu avec la requête.');
        }
    }
}



/**
* tab_params_serialize est un tableau sérializé (fonction serialize de PHP)
**/
function exec_fonction(racine,include,fonction,tab_params_serialize){
	params='fonction='+fonction;
	if(include!=''){params+='&include='+include;}
	params+='&params='+tab_params_serialize;
	
	result=file(racine+'/ajax_exec_fonction.php','POST',params);
	return result;
}

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;
}
