// JavaScript Document
var xhrCaddie ;

function ShowCaddie(id_prod){
		
	if (window.XMLHttpRequest) { //Navigateur FireFox
			xhrCaddie = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) //Navigateur IE 6 et plus
		{
			try {
			       xhrCaddie = new ActiveXObject("Msxml2.XMLHTTP");
			    } catch (e) {
					xhrCaddie = new ActiveXObject("Microsoft.XMLHTTP");
			   }
		}
	xhrCaddie.onreadystatechange = handleHttpResponseCaddie;
	var url = "/caddie_pc21.php?UC_AddId="+id_prod;
	xhrCaddie.open("GET", url, true);
	xhrCaddie.send(null);
}

function handleHttpResponseCaddie() {
    if(xhrCaddie.readyState == 4 && xhrCaddie.status == 200) {
		
		response = xhrCaddie.responseXML;
		var produit = response.getElementsByTagName("article");
		
		titre_prod = produit[0].getElementsByTagName("titre_prod")[0].firstChild.nodeValue;
		document.getElementById('titre_produit').innerHTML = titre_prod;
		mtt_total_ht = parseFloat(produit[0].getElementsByTagName("montant_ht")[0].firstChild.nodeValue);//Nb Montants total
		nb_articles =  parseInt(produit[0].getElementsByTagName("nb_articles")[0].firstChild.nodeValue);//Nb Article total
		id_prod =  parseInt(produit[0].getElementsByTagName("id_prod")[0].firstChild.nodeValue);//Référence du produit
		document.getElementById("caddie_popup").style.visibility='visible';
		//document.getElementById("caddie_popup").style.top=(((document.body.clientHeight - document.getElementById('caddie_popup').offsetHeight)/2) + document.body.scrollTop)+'px';
		///document.getElementById("caddie_popup").style.left=((document.body.clientWidth - document.getElementById('caddie_popup').offsetWidth)/2) + 'px';
		document.getElementById("caddie_popup").style.top=(((document.body.clientHeight - document.getElementById('caddie_popup').offsetHeight)/2) + document.body.scrollTop)+'px';
		document.getElementById("caddie_popup").style.left=((screen.width - document.getElementById('caddie_popup').offsetWidth)/2) + 'px';
		document.form_caddie_pc21.id_prod.value=id_prod;
		document.form_caddie_pc21.quantite.value=1;
		actualiseNbArticles(mtt_total_ht,nb_articles);
	}
}
function HideCaddie(){
	if(document.all){
		document.all["caddie_popup"].style.visibility='hidden';
	}else{
	
		if(document.getElementById){
			document.getElementById("caddie_popup").style.visibility='hidden';
		}
	}
	
	if(document.layers){
		document.layers["caddie_popup"].visibility='hidden';
	}
}


function InitCaddie(){
	document.write("<div id='caddie_popup' style='background-color:#FFFFFF; position:absolute; display:block; z-index: 999; visibility:hidden' ><table cellpadding='1' cellspacing='2'  style='border-color:#EFEFEF; border-style:solid; border-width:3px ' with='250px'  ><tr bgcolor='#FFFFFF'><td align='left'  width='1' ><img src='/img-graph/Puce_Titre.gif' border='0' ></td><td align='left' width='250' ><font class='soustitre'>Panier</font></td></tr><tr><td colspan=2>&nbsp;</td></tr>");
	document.write("<tr bgcolor='#FFFFFF'><td colspan='2'><span class='texte_noir' id='titre_produit' ></span></td></tr><tr bgcolor='#FFFFFF'><td colspan='2' ><span class='texte_noir'>Cet article a été ajouté à votre panier<br>Quantité ajouté :&nbsp;</span><span class='texte_noir_gras'>1</span></td></tr><tr><td colspan=2>&nbsp;</td></tr><tr><td colspan='2'><table width='100%' cellpadding='1' cellspacing='2'  style='border-color:#EFEFEF; border-style:solid; border-width:0px '>");
	document.write("<tr><td align='center' ><a href='javascript:HideCaddie();'><img src='/img-graph/Puce_Titre.gif' border='0'></a></td><td >&nbsp;</td><td align='center' ><a href='/1caddie.php' class='lien'><img src='/img-graph/ncaddie.jpg' border=0 ></a></td></tr><tr><td><a href='javascript:HideCaddie();' class='lien'>Continuer&nbsp;vos&nbsp;achats</a></td><td width='80%'>&nbsp;</td><td align='center'><a href='/1caddie.php' class='lien'>Visualiser&nbsp;votre&nbsp;panier</a></td></tr></table></td></tr></table></div>");
}

function actualiseNbArticles(mtt_total_ht,nb_articles_total){
	if(document.getElementById('montant_total_ht_caddie') != null){
		document.getElementById('montant_total_ht_caddie').innerHTML = mtt_total_ht ;
		document.getElementById('nb_articles_caddie').innerHTML = nb_articles_total;
	}
	if(document.getElementById('montant_entete') != null){
		document.getElementById('montant_entete').innerHTML = mtt_total_ht ;
		document.getElementById('nb_articles_entete').innerHTML = nb_articles_total;
	}
	
	setMontant(mtt_total_ht);
	setNbArticles(nb_articles_total);
}