var lancerExpiration ;
function makeRequestCommande(url) 
{
	if (ajaxinuse==false)
	{
		if (url=="CreerCommande.asp")
			lancerExpiration = true;
		else
			lancerExpiration = false;

		lockAjax();	
		sendRequestCommande(url);
	}
}

function sendRequestCommande(url)
{
	ajaxrequest.onreadystatechange = onResponseCommande;
	ajaxrequest.open("GET", url, true);
	ajaxrequest.send(null);
}

function checkReadyStateCommande(obj)
{
	if(obj.readyState == 0) { document.all['tdCommande'].innerHTML = ChargementEnCours(); }
	if(obj.readyState == 1) { document.all['tdCommande'].innerHTML = ChargementEnCours(); }
	if(obj.readyState == 2) { document.all['tdCommande'].innerHTML = ChargementEnCours(); }
	if(obj.readyState == 3) { document.all['tdCommande'].innerHTML = ChargementEnCours(); }
	if(obj.readyState == 4)
	{
		if(obj.status == 200)
		{
			unlockAjax();
			return true;
		}
		else if(obj.status == 404)
		{
			// Add a custom message or redirect the user to another page
			unlockAjax();
			document.all['tdCommande'].innerHTML = MsgErreur();
		}
		else
		{
			unlockAjax();
			document.all['tdCommande'].innerHTML = MsgErreur();
		}
	}
}

function onResponseCommande() 
{
	if(checkReadyStateCommande(ajaxrequest))
	{
		if (ajaxrequest.responseText == "-1")
			document.location = "/deconnexion.asp";
		else
		{
			document.all['tdCommande'].innerHTML = ajaxrequest.responseText;
			if(document.all['alertevovendus'])
			{
				alert(AlerteVOVendus());
			}
			if(isCommandeOuverte())
			{
				FermeFicheEncart();
				if (lancerExpiration == true)
				{
					cdeexpiration20 = setTimeout("CommandeExpire20();",6000000);
					cdeexpiration5 = setTimeout("CommandeExpire5();",6900000);
					cdeexpiration = setTimeout("CommandeExpire();",7200000);
					//cdeexpiration20 = setTimeout("CommandeExpire20();",30000);
					//cdeexpiration5 = setTimeout("CommandeExpire5();",60000);
					//cdeexpiration = setTimeout("CommandeExpire();",90000);
				}
				FermeFicheVo();
				if(document.all['cdemessage'])
					if (document.all['cdemessage'].value != '')
						alert(document.all['cdemessage'].value);
			}
			else
			{
				OuvreFicheEncart();
				trCommande.style.display = "none" ;
				FermeFicheVo();
				if (typeAffichage=='Liste') makeRequestRechercheVo("ListeVO.asp");
				else makeRequestComparerVo(urlComparaison) ;
				clearTimeout(cdeexpiration);
			}
			if(document.all['reload'])
			{
				if (typeAffichage=='Liste') makeRequestRechercheVo("ListeVO.asp");
				else makeRequestComparerVo(urlComparaison) ;
			}

			if((document.all['coderetour']) && (document.all['coderetour'].value == "-1"))
			{
				MsgCommandeFull();
			}
			GestionToolbar();
		}
	}
}