/************************************************************/
/*********************** Constructeur ***********************/
/************************************************************/

function newXHR()
{
	var xhr;
	try
	{
		xhr = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch(e1) 
	{
		try 
		{
			xhr = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch(e2)
		{
			try
			{
				xhr = new XMLHttpRequest();
			}
			catch(e3)
			{
				xhr = false;
			}
		}
	}
	return xhr;
}

/*************************************************************/
/************************** Fonctions ************************/
/*************************************************************/

function AfficherInfosEnvoyerFiche(urlhash)
{
	var xhr = newXHR();
	if(xhr)
	{
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4)
			{
				if(xhr.status == 200)
				{
					document.getElementById("infosenvoifiche").innerHTML = xhr.responseText;
					document.getElementById("expe").focus();
				}
				else
					alert("Error code : "+xhr.status);
			}
		};
		xhr.open("GET", urlhash, true);
		xhr.send(null);
	}
}

function EnvoyerFicheProduit(urlhash, hash)
{
	var xhr = newXHR();
	if(xhr)
	{
		// Construction du POST : on récupère les données
		var params = "action=envoyerfiche&hash="+encodeURIComponent(hash)+"&expe="+encodeURIComponent(document.getElementById("expe").value)+"&desti="+encodeURIComponent(document.getElementById("desti").value)
		// Ouverture de la connexion avec le serveur
		xhr.open("POST", urlhash, true);
		// Envoi des header
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr.setRequestHeader("Content-length", params.length);
		xhr.setRequestHeader("Connection", "close");
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4)
			{
				if(xhr.status == 200)
				{
					document.getElementById("infosenvoifiche").innerHTML = xhr.responseText;
				}
				else
					alert("Error code : "+xhr.status);
			}
		};
		xhr.send(params); // Envoi des données POST au serveur
	}
}