function createAJAX() {
	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;
}


	var xhr=createAJAX();
	var xhra=createAJAX();

function ajaxAjouterProduit(id){
	var nom = document.getElementById("ajouterProduit").value;
	var url = baseUrl+'/index/afficher/id/'+id;
	
	xhr.open("GET", url, true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(null);
	
	xhr.onreadystatechange = function() { ajouterProduit(); };
	
	function ajouterProduit(){
		if (xhr.readyState == 4) {
			window.location=baseUrl+'/index/afficher';
		}
	}
}
	
function afficherProduit(){
	if (xhra.readyState == 4) {
		if (xhra.status == 200) {
			document.getElementById('afficherProduit').innerHTML = xhra.responseText;
		}
	}
}	
		

	
function ajaxSupprimerProduit(id){
	var noma = document.getElementById('supProduit');
	var urla = baseUrl+'/index/delpanier/id/'+id;
	
	xhra.open("GET", urla, true);
	xhra.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhra.send(null);
	xhra.onreadystatechange = function() { ajaxAfficherProduit(); };
	
	function ajaxAfficherProduit(){
		if (xhra.readyState == 4){
			ajaxTotalPrix(id);
		}
	}
}
	
function ajaxTotalPrix(id){
	
	var urla = baseUrl+'/index/ajaxtotal';
	
	xhr.open("GET", urla, true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(null);
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4){
			document.getElementById('afficherTotal').innerHTML = xhr.responseText;
		}
	};
}


function inputQuantiteBlur(idq, qt){
	q = parseFloat(document.getElementById('quantite'+idq).value);
	var Qt = qt;
	if( q >= Qt ){
		document.getElementById('quantite'+idq).value = q;
	}else{
		document.getElementById('quantite'+idq).value = Qt; 
	}	
}

function ajaxRequete(idq) {
			q = parseFloat(document.getElementById('quantite'+idq).value);
			
			if(!q)return false;
			
			 url = baseUrl+'/index/ajaxprix/idq/'+idq+'/quantite/'+q;
			
			var httpRequest = false;
	
			if (window.XMLHttpRequest) { // Mozilla, Safari,...
				httpRequest = new XMLHttpRequest();
				if (httpRequest.overrideMimeType) {
					httpRequest.overrideMimeType('text/xml');
					// Voir la note ci-dessous Ã  propos de cette ligne
				}
			}
			else if (window.ActiveXObject) { // IE
				try {
					httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e) {
					try {
						httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch (e) {}
				}
			}
	
			if (!httpRequest) {
				alert('Abandon :( Impossible de cr&eacute;er une instance XMLHTTP');
				return false;
			}
			httpRequest.onreadystatechange = function() { alertContents(httpRequest, idq); };
			httpRequest.open('GET', url, true);
			httpRequest.send(null);
			
		
		function alertContents(httpRequest, idq) {
			if (httpRequest.readyState == 4) {
				if (httpRequest.status == 200) {
					ajaxTotalPrix(idq);
					document.getElementById('prix'+idq).innerHTML = httpRequest.responseText;
				} else {
					//alert('Un problème est survenu avec la requête.');
				}
			}
		}
	
}