
var _ASCR = "bananamoon";

function UpdateTotalPanier(devise,fdp,total,fdg,coupon,nblines){
	$("TotalSTOT").innerHTML = DecimalFormat(total - fdp) + " " + devise;
	$("TotalFDP").innerHTML = DecimalFormat(fdp) + " " + devise;
	$("TotalTTC").innerHTML = DecimalFormat(total) + " " + devise;
	if($("TotalCOUP")) $("TotalCOUP").innerHTML = DecimalFormat(coupon) + " " + devise;
	if($("TotalFDG")) $("TotalFDG").innerHTML = DecimalFormat(fdg) + " " + devise;
	var CartLabel = document.getElementById("cart_label");
	var Count = document.getElementsByTagName("img")[0];
	nblines = nblines + "";

	/*document.getElementById('cart_label').innerHTML = "";
	if(nblines.length>1) {
		document.getElementById('cart_label').innerHTML += "<img src='"+Count.src.substring(0, Count.src.lastIndexOf("/")+1)+nblines.charAt(0)+".png'>"
		document.getElementById('cart_label').innerHTML += "<img src='"+Count.src.substring(0, Count.src.lastIndexOf("/")+1)+nblines.charAt(1)+".png'>"
	} else {
		document.getElementById('cart_label').innerHTML += "<img class='spacer' src='"+pageURL+"ximg/shim.gif'>"
		document.getElementById('cart_label').innerHTML += "<img src='"+Count.src.substring(0, Count.src.lastIndexOf("/")+1)+nblines.charAt(0)+".png'>"
	}*/

	if(nblines == 0){
		document.getElementById('empty_cart_layer').style.display = "block";
		document.getElementById('full_cart_layer').style.display = "none";
	}else{
		document.getElementById('empty_cart_layer').style.display = "none";
		document.getElementById('full_cart_layer').style.display = "block";
	}
}

function PanierDelete_Response(del){
	var id=del.del.panier_id;
	var p=del.panier;
	
	while(document.getElementById("panier" + del.del.panier_id)){
		document.getElementById("panier" + del.del.panier_id).parentNode.removeChild(document.getElementById("panier" + del.del.panier_id));
	}
	
	var nids = "";
	var totalqte = 0;
	if(p.count > 0){
		for(var i=0; i<p.lines.length; i++){
			var l = p.lines[i];
			if(nids != "") nids += ","; nids += l.panier_id;
			totalqte += parseInt(p.lines[i].quantite);
		}
	}
	
	document.cart_form.list_panier_id.value = nids;
	
	if(p.count > 0){
		UpdateTotalPanier(p.devise,p.frais_port,p.total,p.frais_gestion,p.montant_coupon,totalqte);
	}else{
		UpdateTotalPanier(p.devise,0,0,0,0,0);
	}
}

function PanierUpdateSubmit(){
	/*var ids = document.cart_form.list_panier_id.value.split(',');
	var lq="",lp="";la="";lg="",d="document.cart_form.";
	for(var i=0; i<ids.length; i++){
		var pid = ids[i];
		if(eval(d+"quantite_"+pid).type == "hidden"){
			lq+=",0"+eval(d+"quantite_"+pid+".value");
		}else{
			lq+=",0"+eval(d+"quantite_"+pid+".options["+d+"quantite_"+pid+".selectedIndex].value");
		}
		lp+=",0"+eval(d+"produit_"+pid+".value");
		la+=",0"+eval(d+"attribut_"+pid+".value");
		var g=eval(d+"garantie_"+pid);
		if(g) lg+=","+g.options[g.selectedIndex].value;
		else lg+=",0";
	}
	PanierUpdate(ids,lq.substr(1),lp.substr(1),la.substr(1),lg.substr(1),document.cart_form.code_coupon.value);*/
	
	jQuery("#frmAction").val("update");
	jQuery("#cart_form").submit();
	
}

function PanierUpdate_Response(upd){
//dump(upd);
	var ids = ","+document.cart_form.list_panier_id.value+",";
	var nids = "";
	var d = "document.cart_form.";
	var p=upd.panier;
	var totalqte = 0;
	
	if(p.count > 0){
		for(var i=0; i<p.lines.length; i++){
			var l = p.lines[i];
			totalqte += parseInt(l.quantite);
			eval(d+"quantite_"+l.panier_id+".value="+l.quantite);
			document.getElementById("upd_panier"+l.panier_id).innerHTML = l.quantite;
			$("prix"+l.panier_id).innerHTML = DecimalFormat(l.prix_ligne_ht) + " " + p.devise;
			$("total"+l.panier_id).innerHTML = DecimalFormat(Number(l.prix_ligne_ht)*Number(l.quantite)) + " " + p.devise;
			if(l.quantite != 0){
				ids = ids.replace(","+l.panier_id+",", ",");
				if(nids != "") nids += ","; nids += l.panier_id;
			}
		}
	}
	if(ids != ","){
		ids = ids.split(",");
		for(var i=1; i<ids.length-1; i++){
			while(document.getElementById("panier" + ids[i])){
				document.getElementById("panier" + ids[i]).parentNode.removeChild(document.getElementById("panier" + ids[i]));
			}
		}
	}
	document.cart_form.list_panier_id.value = nids;

	UpdateTotalPanier(p.devise,p.frais_port,p.total,p.frais_gestion,p.montant_coupon,totalqte);
}

/* Get response from sendToAFriend() */
function getMailToAFriend_Response(httpRequest) {
		
		
		
		if (httpRequest.message.etat == '1') {
			alert(httpRequest.message.msg);
			desactiveZoom();
		}
		else
		{
			alert('Une erreur s\'est produite');
		}
}

/* Send to a friend */
function sendToAFriend(formulaire) {
	var the_form	= document.forms[formulaire];
	var prenom		= the_form.elements['prenom_expediteur'].value;
	var prenom_dest	= the_form.elements['prenom_destinataire'].value;
	var email_from	= the_form.elements['from'].value;
	var email_dest	= the_form.elements['email1'].value;
	var current_url	= window.location;
	
	//alert(current_url);
	
	if (the_form.elements['produit_id'].value != null)
	{
		makeRequest(pagesURL+'dreammail.cfm?cat_id='+the_form.elements['cat_id'].value+'&produit_id='+the_form.elements['produit_id'].value+'&from='+email_from+'&email1='+email_dest+'&prenom_expediteur='+prenom+'&prenom_destinataire='+prenom_dest+'&url_page='+current_url, 'getMailToAFriend');
	}
	else
	{
		makeRequest(pagesURL+'dreammail.cfm?from='+email_from+'&email1='+email_dest+'&prenom_expediteur='+prenom+'&prenom_destinataire='+prenom_dest+'&url_page='+current_url, 'getMailToAFriend');
	}
}
