function getCookie(nomparam) {
	var strCookie = new String(document.cookie);
	//strCookie = strCookie.toLowerCase();
	var debut = strCookie.indexOf(nomparam+'=');
	if (debut>=0) {
		debut += (nomparam+'=').length;
		var fin = strCookie.indexOf(';', debut);
		if (fin>=0)	return unescape(strCookie.substring(debut, fin));
		else		return unescape(strCookie.substr(debut));
	}
	return '';
}

function ajout_panier(id_article) {
	contenu_panier = getCookie("panier");
	if (contenu_panier=='')
		contenu_panier = id_article;
	else
		contenu_panier = contenu_panier + '¤' + id_article
	document.cookie="panier=" + contenu_panier + "; path=/";
	initPanier();
	alert("Article ajouté au panier.");
}

function initPanier() {
	contenu = getCookie("panier");
	nb_articles = 0;
	if (contenu!='') {
		contenu_array = contenu.split("¤");
		nb_articles = contenu_array.length;
	}
	affichage = 'Mon panier : ' + nb_articles + ' article';
	if (nb_articles > 1)
		affichage = affichage + 's';
	affichage = affichage + '';
	document.getElementById('panier').innerHTML= affichage;
}

function calcule_panier() {
	panier_string="";
	for (i=0;i<document.panier.elements.length;i++) {
		for (j=1;j<=document.panier.elements[i].value;j++)
			if (document.panier.elements[i].id!=""){
				panier_string = panier_string + document.panier.elements[i].id + '¤'
			}
	}
	if (panier_string.length!=0)
		panier_string=panier_string.substr(0, panier_string.length-1)
	document.cookie="panier=" + panier_string + "; path=/";
	window.location.reload();
}
