function createXHR() 
{
    var request = false;
        try {
            request = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (err2) {
            try {
                request = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (err3) {
		try {
			request = new XMLHttpRequest();
		}
		catch (err1) 
		{
			request = false;
		}
            }
        }
    return request;
}


/**
	responseHTML
	(c) 2007 xul.fr		
	Licence Mozilla 1.1
*/	


/**
	Searches for body, extracts and return the content
	New version contributed by users
*/


function getBody(content) 
{
   //content = content.toLowerCase();    // to eliminate case sensitivity
   var x = content.indexOf("<body");
   if(x == -1) return "";

   x = content.indexOf(">", x);
   if(x == -1) return "";

   var y = content.lastIndexOf("</body>");
   if(y == -1) y = content.lastIndexOf("</html>");
   if(y == -1) y = content.length;    // If no html then just grab everything till end

   var z = content.slice(x + 1, y);   //make sure we grab the original content
   return z;
} 

/**
	Loads a HTML page
	Put the content of the body tag into the current page.
	Arguments:
		url of the other HTML page to load
		id of the tag that has to hold the content
*/		

function loadHTML(url, fun, storage, param)
{
	var xhr = createXHR();
	xhr.onreadystatechange=function()
	{ 
		if(xhr.readyState == 4)
		{
			//if(xhr.status == 200)
			{
				storage.innerHTML = getBody(xhr.responseText);
				fun(storage, param);
			}
		} 
	}; 

	xhr.open("GET", url , true);
	xhr.send(null); 

} 

	/**
		Callback
		Assign directly a tag
	*/		


	function processHTML(temp, target)
	{
		//target.innerHTML = temp.innerHTML;
	}

	function loadWholePage(url)
	{
		var y = document.getElementById("storage");
		var x = document.getElementById("panier_petit");
		loadHTML(url, processHTML, x, y);
	}	

	function loadWholePhoto(url)
	{
		var y = document.getElementById("storage");
		var x = document.getElementById("iframe_photo");
		loadHTML(url, processHTML, x, y);
	}	

	/**
		Create responseHTML
		for acces by DOM's methods
	*/	
	
	function processByDOM(responseHTML, target)
	{
		target.innerHTML = "Extracted by id:<br />";

		var message = responseHTML.getElementsByTagName("div").namedItem("two").innerHTML;
		target.innerHTML += message;

		target.innerHTML += "<br />Extracted by name:<br />";
		
		message = responseHTML.getElementsByTagName("form").namedItem("ajax");
		target.innerHTML += message.dyn.value;
	}
	
	function accessByDOM(url)
	{
		//var responseHTML = document.createElement("body");	// Bad for opera
		var responseHTML = document.getElementById("storage");
		var y = document.getElementById("panier_petit");
		loadHTML(url, processByDOM, responseHTML, y);
	}	

/*loadWholePage('/boutique/panier-petit.php');*/
loadWholePage('/boutique/tetiere_droite_panier.php');
