// création de l'objet XMLHttpRequest
function XmlHttp( )
{
	this.CreateXmlHttpObject = CreateXmlHttpObject;
	this.GetUrlContent= GetUrlContent;
	this.GetResponseText= GetResponseText;
	this.GetReadyState= GetReadyState;
	this.HttpMethod = 'GET';
	// default 
	this.objXmlHttp = this.CreateXmlHttpObject();
}

// Initialisation de l'objet XMLHttpObject
function CreateXmlHttpObject()
{
	var xmlhttp=false;
	// on regarde sur quel navigateur l'on se trouve
	if (window.XMLHttpRequest)
	{
		// Mozilla, Safari,... 
		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType)
		{
			// on change le type de contenu pour que l'on transmette de l'HMTL
			xmlhttp.overrideMimeType('text/html');
		}
	}
	else
	{
		// on est sur IE
		try
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (E)
			{
				xmlhttp = false;
			}
		}
	}

	// on regarde si l'on a réussi à créer l'objet XMLHttpRequest
	if (!xmlhttp)
	{
		alert('Impossible de créer l\'objet XMLHTTP. Le site ne peut pas fonctionner!');
		return false;
	}
	return xmlhttp;
}

function GetReadyState( )
{
	return this.objXmlHttp.readyState;
}

function GetResponseText( )
{
	return this.objXmlHttp.responseText;
}

function GetResponseXML( )
{
	return this.objXmlHttp.responseXML;
}

// Function qui appel le fichier défini dans strUrl, grâce à l'objet XMLHttpRequest// la requête est asynchrone// Quand l'état de l'objet XMLHttpRequest change, on appel la fonction définie // par objOnReadyStateChangeFunction

function GetUrlContent( strUrl, objOnReadyStateChangeFunction )
{
	this.objXmlHttp.open(this.HttpMethod, strUrl, true);
	this.objXmlHttp.setRequestHeader('Content-Type', 'text/xml; charset=iso-8859-1');
	
	if(objOnReadyStateChangeFunction)
	{
		this.objXmlHttp.onreadystatechange=function(){objOnReadyStateChangeFunction();}
	}
	
	this.objXmlHttp.send(null);
}

// on crée l'objet XMLHttpRequestvar
objXMLHttp =new XmlHttp();

// fonction pour remplacer un caractère par un autre// sera utile si il y a un problème avec des \n, on les remplacera par des <br>

function replace(string,text,by)
{

var strLength = string.length, txtLength = text.length;

if ((strLength == 0) || (txtLength == 0)) return string;

var i = string.indexOf(text);

if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;

var newstr = string.substring(0,i) + by;

if (i+txtLength < strLength) newstr += replace(string.substring(i+txtLength,strLength),text,by);

return newstr;

}