function showElem(elem){
	var idHtml = '#'+elem;
	$(idHtml).css('display','block');
}

function hideElem(elem){
	var idHtml = '#'+elem;
	$(idHtml).css('display','none');
}

function afficherPanier(){
	var quantite = 0;
	var montant = 0;
	var monpanier = getCookieInfo('panier');
	articles=monpanier.split('||');
	longueur=articles.length;
	for(i=0;i<longueur;i++) {
		nbarticles=articles[i].split('<>');
		quantite = parseInt(quantite)+parseInt(nbarticles[3]);
		montant = parseFloat(montant) + (parseFloat(nbarticles[2])*parseInt(nbarticles[3]));
	}
	
	document.write('<div id="resumePanier">');
	if (!isNaN(quantite) && parseInt(quantite)!=0){
		document.write('<table border="0" cellspacing="0" cellpadding="0"><tr><td><b><a class="titrePanier" href="javascript:panier_Voir();">' + quantite + ' article(s)</b></td>');
		document.write('<td style="padding:0 0 0 15px;"><b>' + Math.round(montant*100) / 100 + '€</a></b></td></tr></table>');
	}else{
		document.write('<b>Votre panier est vide</b>');
	}
	document.write('</div>');
}

function panier_changeDiv50(){
	var browser = checkNavigateur();
	var quantite = 0;
	var montant = 0;
	var monpanier = getCookieInfo('panier');
	articles=monpanier.split('||');
	longueur=articles.length;
	for(i=0;i<longueur;i++) {
		nbarticles=articles[i].split('<>');
		quantite = parseInt(quantite)+parseInt(nbarticles[3]);
		montant = parseFloat(montant) + (parseFloat(nbarticles[2])*parseInt(nbarticles[3]));
	}
	
	if(window.opener){
		if(window.opener.document.getElementById('resumePanier')){
			if (!isNaN(quantite) && parseInt(quantite)!=0){
				window.opener.document.getElementById('resumePanier').innerHTML ='<table border="0" cellspacing="0" cellpadding="0"><tr><td><b><a class="titrePanier" href="javascript:panier_Voir();">' + quantite + ' article(s)</b></td><td style="padding:0 0 0 15px;">' + Math.round(montant*100) / 100 + '€</a></b></td></tr></table>';
			}else{
				window.opener.document.getElementById('resumePanier').innerHTML ='<b>Votre panier est vide</b>';
			}
		}
	}else{
		
		if(document.getElementById('resumePanier')){
			if (!isNaN(quantite) && parseInt(quantite)!=0){
				document.getElementById('resumePanier').innerHTML ='<table border="0" cellspacing="0" cellpadding="0"><tr><td><b><a class="titrePanier" href="javascript:panier_Voir();">' + quantite + ' article(s)</b></td><td style="padding:0 0 0 15px;">' + Math.round(montant*100) / 100 + '€</a></b></td></tr></table>';
			}else{
				document.getElementById('resumePanier').innerHTML ='<b>Votre panier est vide</b>';
			}
		}
	}
}

function panier_changeDiv51(){
	var browser = checkNavigateur();
	var quantite = 0;
	var montant = 0;
	var monpanier = getCookieInfo('panier');
	articles=monpanier.split('||');
	longueur=articles.length;
	for(i=0;i<longueur;i++) {
		nbarticles=articles[i].split('<>');
		quantite = parseInt(quantite)+parseInt(nbarticles[3]);
		montant = parseFloat(montant) + (parseFloat(nbarticles[2])*parseInt(nbarticles[3]));
	}
	if(document.getElementById('resumePanier')){
		if (!isNaN(quantite) && parseInt(quantite)!=0){
			document.getElementById('resumePanier').innerHTML ='<table border="0" cellspacing="0" cellpadding="0"><tr><td><b><a class="titrePanier" href="javascript:panier_Voir();">' + quantite + ' article(s)</b></td><td style="padding:0 0 0 15px;">' + Math.round(montant*100) / 100 + '€</a></b></td></tr></table>';
		}else{
			document.getElementById('resumePanier').innerHTML ='<b>Votre panier est vide</b>';
		}
	}
}

function ajouterPanier(ref,libelle,prix,quantite){
	var chaine = ref+'<>'+libelle+'<>'+prix+'<>'+quantite;
	poserDsCookie("panier",chaine,"",'/',"");
}

function poserDsCookie( nomPanier, valeurPanier, expiration, chemin, domaine) 
{
	var strTmp = String(document.location);
	var strTmp2 = strTmp.substring(7,strTmp.length);
	var strTmp3 = strTmp2.split("/");
	if(strTmp3[0] == 'central'){
		var root = 'http://'+strTmp3[0]+'/'+strTmp3[1];
	}else{
		var root = '';
	}
	
	var ligneArt = valeurPanier.split('<>');
	var form = document.getElementById('ajouter_panier');
	
	//On recupere la reference du produit à insérer
	var refAjout = ligneArt[0] + ligneArt[1];
	var refart = '';
	var donnecookiePanier = getCookieInfo('panier');
	if(donnecookiePanier!='false'){
	
	//On verifie que le produit n'existe pas deja...
		var string = donnecookiePanier;
		if(string!='false'){
			var lignearticle = string.split('||');
			var i = 0;
			while(i<lignearticle.length && refart != refAjout){
				article = lignearticle[i];
				article = article.split('<>');
				refart = article[0]+article[1];
				i++;
			}
			if (refart == refAjout){
				valeurPanier = string;
					alert('Ce produit est dejà présent dans le panier');
					document.cookie = "refererurl=" +document.location.href+";path=/";
					url=root + '/service/panier.php';
					nom = 'fencentarticle';
					largeur = 770;
					hauteur = 450;
					options = 'toolbar=no,resizable=no,status=no,scrollbars=yes'
					var haut=(screen.height-hauteur)/2;
					var Gauche=(screen.width-largeur)/2;
					fencentarticle=window.open(url,nom,"top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+options);
			}else{
				valeurPanier += '||' + string;
				document.cookie = nomPanier + "=" +valeurPanier+";path=/";
				//window.location.reload();
				alert('Ce produit a été ajouté au panier');
				document.cookie = "refererurl=" +document.location.href+";path=/";
				panier_changeDiv50();
				panier_changeDiv51();
				url=root + '/service/panier.php';
					nom = 'fencentarticle';
					largeur = 770;
					hauteur = 450;
					options = 'toolbar=no,resizable=no,status=no,scrollbars=yes'
					var haut=(screen.height-hauteur)/2;
					var Gauche=(screen.width-largeur)/2;
					fencentarticle=window.open(url,nom,"top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+options);
			}	
		}else{
			document.cookie = nomPanier + "=" +valeurPanier+";path=/";
			//window.location.reload();
			alert('Ce produit a été ajouté au panier');
			document.cookie = "refererurl=" +document.location.href+";path=/";
			panier_changeDiv50();
			panier_changeDiv51();
			url=root + '/service/panier.php';
					nom = 'fencentarticle';
					largeur = 770;
					hauteur = 450;
					options = 'toolbar=no,resizable=no,status=no,scrollbars=yes'
					var haut=(screen.height-hauteur)/2;
					var Gauche=(screen.width-largeur)/2;
					fencentarticle=window.open(url,nom,"top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+options);
		}
	}else{
		document.cookie = nomPanier + "=" +valeurPanier+";path=/";
			//window.location.reload();
			alert('Ce produit a été ajouté au panier');
			document.cookie = "refererurl=" +document.location.href+";path=/";
			panier_changeDiv50();
			panier_changeDiv51();
			url=root + '/service/panier.php';
					nom = 'fencentarticle';
					largeur = 770;
					hauteur = 450;
					options = 'toolbar=no,resizable=no,status=no,scrollbars=yes'
					var haut=(screen.height-hauteur)/2;
					var Gauche=(screen.width-largeur)/2;
					fencentarticle=window.open(url,nom,"top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+options);
	}
}

