function getXhr(){
	var xhr = null;
	try {
 		xhr = new XMLHttpRequest();
 	}
	catch(e) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP" );
	}
	return xhr;
}

function call(url, callback, asynch, method, param) {
	if (method == null){
   		method = "GET";
 	}
	var xhr = getXhr();
	xhr.onreadystatechange  = function() {
		switch (xhr.readyState) {
			case 4 :
				if ((xhr.status  == 200) && (callback != undefined) && (typeof callback == 'function'))
					callback(xhr.responseText);
				break;
		}
	};
	xhr.open(method, url, asynch);
	if (method == "POST")
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send(param);
}

function addToCart(item) {
	var fincCart = function (str) {
		var cardBox = document.getElementById('bdcart');
		var val = cardBox.innerText;
		val = val.substring(val.indexOf('(') + 1, val.indexOf(')'));
		cardBox.innerText = 'panier ('+(parseInt(val)+1)+')';
	}

	call('cart.php?item='+item, fincCart, true);
	return false;
}

function deleteEmpty(prefix)
{
	var cpt = 0;
	while (section = document.getElementById(prefix+"grp_"+ cpt)) {
		if (!section.firstChild) {
			section.style.display = "none";
			document.getElementById(prefix+"a_"+ cpt).style.display = "none";
		}
		cpt++;
	}
}

function closeAllBut(prefix, param)
{
	var cpt = 0;
	while (group = document.getElementById(prefix+"grp_"+ cpt)) {
		if ((cpt != param) || (document.getElementById(prefix+"grp_"+ param).style.display == "block")) {
			group.style.display = "none";
			document.getElementById(prefix+"a_"+ cpt).style.backgroundImage = 'url(./images/reduced.png)';
		}
		else { 
			group.style.display = "block";
			document.getElementById(prefix+"a_"+ cpt).style.backgroundImage = 'url(./images/expended.png)';
		}
		cpt++;
	}
}
