// =============================================================================
// Créer un element fils a l'element spécifié
// =============================================================================
function CreateChild ( element , tag )
{
	var child;
	if ( element )
	{
		child = document.createElement ( tag );
		element.appendChild ( child );
	}
	return child;
}



// =============================================================================
// Renvoit un élement (même syntaxe que Prototype)
// =============================================================================
if ( typeof ( $ ) != 'function' )
{
	function $ ( elementid )
	{
		return document.getElementById ( elementid );
	}
}



// =============================================================================
// Vide un element
// =============================================================================
function ClearElement ( element )
{
	if ( element )
	{
		while( element.hasChildNodes() )
		{
			element.removeChild ( element.lastChild );
		}
	}

}



// =============================================================================
// Renvoit un objet XMLHttpRequest
// =============================================================================
function GetXHR ()
{
	if (window.XMLHttpRequest) 
	{
		//Firefox ou IE >= 7.0
		xhr = new XMLHttpRequest();
	}
	else if ( window.ActiveXObject ) 
	{
		try 
		{ // essaie de charger l'objet pour IE
			xhr = new ActiveXObject( "Msxml2.XMLHTTP" );
		} 
		catch (e) 
		{
		    try 
		    { // essaie de charger l'objet pour une autre version IE
				xhr = new ActiveXObject ( "Microsoft.XMLHTTP" );
		    } 
		    catch (e) 
		    {
				window.alert("Votre navigateur ne prend pas en charge l'objet XMLHTTPRequest.");
		    }
		} 
	}
	return xhr;
}



// =============================================================================
// Execute une requete AJAX
// =============================================================================
function AjaxRequest ( url , type , params , callback )
{
	var xhr = GetXHR();
	if ( xhr )
	{
	    xhr.onreadystatechange  = function ()
	    {
	        if ( xhr.readyState  == 4 )
	        {
	            
				if ( callback )
				{
					callback ( xhr.responseText );
				}
	                
	        }
	    }; 
		
		
		var send_params = null;
		if ( type == 'POST' || type == 'post' )
		{
			type = 'POST';
			send_params = params;
		}
		else
		{
			type = 'GET';
			url = url + '?' + params;
			send_params = null;
		}

		xhr.open ( type , url , true ); 
		
		if ( type == 'POST' )
			xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		
		xhr.send ( send_params ); 
	}
}