<!---------- JavaScript
// ***********************************************************
// Función para convertir el precio a cadena con punto de miles, coma decimales y añadir "€"
// ***********************************************************
function cadena(num)
{
var c, e, d, lon, lone, cad;
	if (num == 0){
	cad = "0 €";
	return (cad)}
c = Math.round(num * 100);
c = c+" ";
lon = c.length;
e = c.substr(0, lon - 3);
d = c.substr(lon - 3, 2 );
lone = e.length;
	if (lone < 4) {
  	cad = e+","+d+" €";
	}
	if (lone > 3 && lone < 5) {
  	cad = e.substr(0,1)+"."+e.substr(1,3)+","+d+" €";
  	}
	if (lone > 4 && lone < 6) {
  	cad = e.substr(0,2)+"."+e.substr(2,3)+","+d+" €";
	}
	if (lone > 5) {
  	cad = e.substr(0,3)+"."+e.substr(3,3)+","+d+" €";
	}
return (cad)
}

function alterError(value) {	
	if (value<=0.99) {
		newPounds = '0';
	} else {
	newPounds = parseInt(value);
	}
		newPence = parseInt((value+.0008 - newPounds)* 100);
		if (eval(newPence) <= 9) newPence='0'+newPence;
		newString = newPounds + '.' + newPence;
		return (newString);
	}

//function showItems() {
function showItems(textProduc,textCantid,textPrix,textImport,textSubtot,textValue) {

index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
   	if (countend == -1) {
  		countend = document.cookie.length;
   	}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
document.writeln('<form><table border="0" cellspacing="0" width="590" bordercolor="#EAEAEA" class="peq_resalt">');
document.writeln('<tr><td align="left" class="menu_tex_s" bgcolor="#E1FFE1" width="335">'+textProduc+'</td><td  class="menu_tex_s" bgcolor="#E1FFE1" width="30" align="right">'+textCantid.substr(0,4)+'</td><td class="menu_tex_s" bgcolor="#E1FFE1" width="60" align="right">'+textPrix+'</td><td class="menu_tex_s" bgcolor="#E1FFE1" width="80" align="right">'+textImport+'</tr>');

itemlist = 0;
	for (var i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			itemstart = i+1;
		} else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			thequantity = fulllist.substring(itemstart, itemend);
			itemtotal = 0;
			itemtotal = (eval(theprice*thequantity));
			temptotal = itemtotal * 100;
			var tax = itemtotal / 100 * (0 - 0);
   			tax = Math.floor(tax * 100)/100
			totprice = totprice + itemtotal + tax;
			itemlist=itemlist+1;
			document.writeln('<tr><td align="left" class="descrip_8">'+theitem+'</td><td align="center" class="descrip_8">'+thequantity+'</td><td align="right" class="descrip_8">'+cadena(theprice)+'</td><td align="right" class="descrip_8">'+cadena(alterError(itemtotal))+'</td><td align="center" class="descrip_8"><input type="button" name="remove" value="'+textValue+'" onclick="javascript:removeItem('+itemlist+')"></td></tr>');
		} else if (fulllist.substring(i,i+1) == ',') {
			theitem = fulllist.substring(itemstart, i);
			itemstart = i+1;
		} else if (fulllist.substring(i,i+1) == '#') {
			theprice = alterError(fulllist.substring(itemstart, i)*1);
			itemstart = i+1;
		}
	}
document.writeln('<tr><td align="right" colspan=3><b>'+textSubtot+'</b></td><td align=right>'+cadena(alterError(totprice))+'</td></tr>');
document.writeln('</table></form>');
}
function removeItem(itemno) {
newItemList = null;
itemlist = 0;
	for (var i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			itemstart = i+1;
		} else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			theitem = fulllist.substring(itemstart, itemend);
			itemlist=itemlist+1;
			if (itemlist != itemno) {
				newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
			}
		}
	}
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket="+newItemList;
top.location = "cesta.php";
}
function clearBasket() {
	if (confirm('¿Desea restablecer la cesta de compra?')) {
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket=.";
		top.location = "cesta.php";
	}
}

function ImportComp() {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
   	if (countend == -1) {
  		countend = document.cookie.length;
   	}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
	for (var i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			itemstart = i+1;
		} else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			thequantity = fulllist.substring(itemstart, itemend);
			itemtotal = 0;
			itemtotal = (eval(theprice*thequantity));
			temptotal = itemtotal * 100;
			var tax = itemtotal / 100 * (0 - 0);
 			tax = Math.floor(tax * 100)/100
			totprice = totprice + itemtotal + tax;
		} else if (fulllist.substring(i,i+1) == ',') {
			theitem = fulllist.substring(itemstart, i);
			itemstart = i+1;
		} else if (fulllist.substring(i,i+1) == '#') {
			theprice = alterError(fulllist.substring(itemstart, i)*1);
			itemstart = i+1;
		}
	}
return (alterError(totprice))
}
// JavaScript fin ---------->