function number_format_price(price) {
var pricelength=price.length;
	if(price.charAt(pricelength-3)!='.') if(price.charAt(pricelength-2)=='.') {
	price=price+"0";
	} else {
	price=price+".00";
	}
pricelength=price.length;
if(pricelength>6) price=price.substring(0, (pricelength-6))+','+price.substring((pricelength-6), pricelength);
return price;
}

function updateSubtotal() {
var subtotal=0;
var spantags=document.body.getElementsByTagName('span');
var spantagslength=spantags.length;
 	for(var x=0; x<spantagslength; x++) if(spantags[x].className=='cartprice') {
 		var valeur = spantags[x].innerHTML.replace(',', '.')
 		valeur = valeur.replace(' ', '');
 		subtotal+=parseInt(valeur*100);
 		//subtotal+=parseInt(spantags[x].innerHTML.replace(',', '.')*100);
 	}
 	subtotalFR = number_format_price((subtotal/100).toString());
 	subtotalFR = subtotalFR.replace(',', '');
 	subtotalFR = subtotalFR.replace('.', ',');

document.getElementById('cartsubtotal').innerHTML=subtotalFR;

return subtotal;

}


function updateQuantity(productid) {
	if(typeof document.getElementById!='undefined') {
	var thiselement=document.getElementById('cartquantity_'+productid);
	var userinput=thiselement.value;
	thiselement.value=thiselement.value.replace(/\D/g, '');
	var quantity=parseInt(thiselement.value);
		if(isNaN(quantity)||quantity<1) {
		if(userinput==''||userinput.match(/\s+/)) userinput='[empty]';
		alert(userinput+' is not a valid number');
		quantity=1;
		document.getElementById('cartquantity_'+productid).value=1;
		}
	document.location='assets/snippets/cartX/ajustcart.php?productid='+productid+'&quantity='+quantity+'&quitemode=1';
	var price=parseFloat(document.getElementById('cartpriceperunit_'+productid).innerHTML.replace(',', '.'));
	var newprice=number_format_price((Math.round(price*quantity*100)/100).toString());
	
	newprice = newprice.replace(',', ' ');
	newprice = newprice.replace('.', ',');
	
	document.getElementById('cartprice_'+productid).innerHTML=newprice;
	updateSubtotal();
	} else {
	document.forms['cart'].submit();
	}
}


function removeProduct(productid) {
var adjusturl='assets/snippets/cartX/ajustcart.php?productid='+productid;
	if(typeof document.getElementById!='undefined') {
	document.getElementById('cartrow_'+productid).innerHTML='';
	document.getElementById('cartrow_'+productid).style.display='none';
	if(updateSubtotal()) adjusturl+='&quitemode=1';
	}
document.location=adjusturl+'&void='+random();
}