// obtention d'un objet permettant d'emettre une requête ajax
function getXhr()
{
	var xhr;
	if(window.XMLHttpRequest)
	{
		// Firefox et autres
		xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		// Internet Explorer 
		try
		{
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else
	{
		xhr = false; 
	} 
	return xhr;
}

function URLEncode (texte)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = texte;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
		if (ch == " ") {
			encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
			encoded += ch;
		} else {
			var charCode = ch.charCodeAt(0);
			if (charCode <= 255) {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function trim(chaine) 
{
	var resultat = chaine;
	while (resultat.substring(0, 1) == ' ')
		resultat = resultat.substring(1, resultat.length);
	while (resultat.substring(resultat.length - 1, resultat.length) == ' ')
		resultat = resultat.substring(0, resultat.length - 1);
	return resultat;
}



function writeInConsole (text) {
    if (typeof console !== 'undefined') {
        console.log(text);    
    }
    else {
        alert(text);    
    }
}
