//Estado del Carrito
	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; 
	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; 
	totprice = totprice + itemtotal; 
	itemlist=itemlist+1; 
	} else if (fulllist.substring(i,i+1) == ',') { 
	theitem = fulllist.substring(itemstart, i); 
	itemstart = i+1; 
	} else if (fulllist.substring(i,i+1) == '#') { 
	theprice = fulllist.substring(itemstart, i); 
	itemstart = i+1; 
	} 
	} 
	
	function buyItem(newItem, newPrice, newQuantity) { 
	if (newQuantity <= 0) { 
	rc = alert('La cantidad ingresada es incorrecta'); 
	return false; 
	} 
	if (confirm('¿Agregar '+newQuantity+' '+newItem+' al carrito?')) { 
	index = document.cookie.indexOf("TheBasket"); 
	countbegin = (document.cookie.indexOf("=", index) + 1); 
	countend = document.cookie.indexOf(";", index); 
	if (countend == -1) { 
	countend = document.cookie.length; 
	} 
	document.cookie="TheBasket="+document.cookie.substring(countbegin, countend)+"["+newItem+","+newPrice+"#"+newQuantity+"]"; 
	window.location.reload(); 
	
	} 
	return true; 
	} 
	
	function resetShoppingBasket() { 
	index = document.cookie.indexOf("TheBasket"); 
	document.cookie="TheBasket=."; 
	} 









//Formulario de Carrito

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_form() {
		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;

		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('<INPUT TYPE="hidden" NAME="Producto'+itemlist+'" VALUE="'+theitem+'" SIZE="40">');
				document.writeln('<INPUT TYPE="hidden" NAME="Cantidad'+itemlist+'" VALUE="'+thequantity+'" SIZE="40">')
				document.writeln('<INPUT TYPE="hidden" NAME="ProductoTotal'+itemlist+'" VALUE="'+alterError(itemtotal)+'" SIZE="40">');
			} else if (fulllist.substring(i,i+1) == ',') {
				theitem = fulllist.substring(itemstart, i);
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == '#') {
				theprice = fulllist.substring(itemstart, i);
				itemstart = i+1;
			}
		}

		document.writeln('<INPUT TYPE="hidden" NAME="Total" VALUE="'+alterError(totprice)+'" SIZE="40">');

	}
	function Total() {
		document.writeln(alterError(totprice));
	}







//Insertar Producto al Carrito
	function buyItem(newItem, newPrice, newQuantity) {
		if (newQuantity <= 0) {
			rc = alert('La cantidad ingresada es incorrecta');
			return false;
		}
		//if (confirm('¿Agregar '+newQuantity+' '+newItem+' al carrito?')) 
		{
			index = document.cookie.indexOf("TheBasket");
			countbegin = (document.cookie.indexOf("=", index) + 1);
        		countend = document.cookie.indexOf(";", index);
	        	if (countend == -1) {
        	    		countend = document.cookie.length;
        		}
	                document.cookie="TheBasket="+document.cookie.substring(countbegin, countend)+"["+newItem+","+newPrice+"#"+newQuantity+"]";
		}
		return true;
		}


	function resetShoppingBasket() {
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket=.";
	}
	




//Ver Estado del Carrito
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() {
		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><img src=images/img_ctrpedidos.jpg><br><table border="1" cellspacing="1" width="100%" bgcolor="#E0E0E0" bordercolor="#FFFFFF">');

document.writeln('<TR><TD><b>Producto</b></TD><TD align="right"><b>Cantidad</b></TD><TD align="right"><b>Costo x unidad</b></TD><td align="right"><b>Costo total</b><TD>&nbsp;</TD></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 bgcolor=#EEEEEE align=left> '+theitem+'</td><td align=right bgcolor=#EEEEEE>'+thequantity+'</td><td align=right bgcolor=#EEEEEE>'+theprice+'</td><td align=right bgcolor=#EEEEEE>'+alterError(itemtotal)+'</td><td align=center bgcolor=#EEEEEE><input TYPE="button" NAME="remove" VALUE="Quitar" 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 = fulllist.substring(itemstart, i);
				itemstart = i+1;
			}
		}

		

		document.writeln('<tr><td colspan=3 align=right><b>Total</b></td><td align=right>'+alterError(totprice)+'</td><td>&nbsp;</td></tr>');
		document.writeln('</TABLE>');
	}

	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 = "carrito.php";
	}

	function clearBasket() {
		if (confirm('¿Confirma que desea eliminar el listado de su Pedido?')) {
			index = document.cookie.indexOf("TheBasket");
			document.cookie="TheBasket=.";
			top.location = "carrito.php";
		}
	}
	
	
	
	
	//Mostrar Carrito en Formulario de Confirmación
	
		function showItems_confirm() {
		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="1" cellspacing="1" width="100%" bgcolor="#E0E0E0" bordercolor="#FFFFFF">');

document.writeln('<TR><TD><b>Producto</b></TD><TD align="right"><b>Cantidad</b></TD><TD align="right"><b>Costo x unidad</b></TD><td align="right"><b>Costo total</b></TD></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 bgcolor=#EEEEEE align=left> '+theitem+'</td><td align=right bgcolor=#EEEEEE>'+thequantity+'</td><td align=right bgcolor=#EEEEEE>'+theprice+'</td><td align=right bgcolor=#EEEEEE>'+alterError(itemtotal)+'</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 = fulllist.substring(itemstart, i);
				itemstart = i+1;
			}
		}

		

		document.writeln('<tr><td colspan=3 align=right><b>Total</b></td><td align=right>'+alterError(totprice)+'</td></tr>');
		document.writeln('</TABLE>');
	}