// showItems() - displays shopping basket in a table
	function showItems() {
		index = document.cookie.indexOf("Korgen");

		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
		document.writeln('<TABLE BORDER=0 align=center>');
		document.writeln('<TR><TD width="200"><p><b>Vara</TD><TD width="60"><p><b>Antal</TD><TD width="60"><p><b>Pris/st</TD><td width="60"><p><b>Totalt</td><TD><p><b>Åtgärd&nbsp;</TD></TR>');
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		fulllist = document.cookie.substring(countbegin, countend);
		totprice = 0;
		porto = 0;
		if (fulllist.length <= 4 || index==-1) {
			document.writeln('<tr><td bgcolor=#E5ECF3><p></td><td align=right bgcolor=#E5ECF3><p>&nbsp;</td><td align=right bgcolor=#E5ECF3><p>&nbsp;</td><td align=right bgcolor=#E5ECF3><p>&nbsp;</td><td><p><a href="javascript:alert('+"'"+''+"När du laggt en eller flera varor i kundvangnen kan du enkelt ta bort dom genom att klicka här."+''+"'"+')">Ta bort</a></td></tr>');
		}

		else {
		weighttot = 0;
		porto = 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;
				commands = fulllist.substring(itemstart, itemend);
				fields = commands.split("#");
				itemlist = itemlist +1;
				theitem = fields[0];
				theprice = fields[1];
				thequantity = fields[2];
				theweight = fields[3];
				weighttot = weighttot + (parseInt(theweight)*thequantity);
				itemtotal = (eval(theprice*thequantity));
				totprice = totprice + itemtotal;
				document.writeln('<tr><td bgcolor=#E5ECF3><p>'+theitem+'</td><td align=right bgcolor=#E5ECF3><p>'+thequantity+'</td><td align=right bgcolor=#E5ECF3><p>'+theprice+'</td><td align=right bgcolor=#E5ECF3><p>'+alterError(itemtotal)+'</td><td align=right><p><a href="javascript:removeItem('+itemlist+')">Ta bort</a></p></td></tr>');
			
			}
		}
		
	  if (weighttot < 11){
			weighttot = weighttot + 9;
		}
		else {
			weighttot = weighttot + 80;
		}

		if (weighttot < 20){
			porto = 20;
		}
		else if (weighttot < 250){
			porto = 30;
		}
		else if (weighttot < 500){
			porto = 40;
		}
		else if (weighttot < 1000){
			porto = 60;
		}
		else {
			porto = 135;
		}
		
		document.writeln('<tr><td BGCOLOR=#E5ECF3><p>Frakt</td><td align=right BGCOLOR=#E5ECF3><p>1</td><td align=right BGCOLOR=#E5ECF3><p>'+porto+'</td><td align=right BGCOLOR=#E5ECF3><p>'+porto+'.00</td></tr>');
		
		}
		document.writeln('<tr><td colspan=3><p><b>Total summa</b></td><td align=right><p><b>'+alterError(totprice+porto)+'</td><td></td></tr></p>');
		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("Korgen");
		document.cookie="Korgen="+newItemList;
		location = "kundvagn.shtml";
	}

	// clearBasket() - removes all items from the basket
	function clearBasket() {
		if (confirm('Är du säker på att du vill tömma kundvagnen?')) {
			index = document.cookie.indexOf("Korgen");
			document.cookie="Korgen=.";
			location = "kundvagn.shtml";
		}
	}

// alterError - fixes a rounding bug in Netscape 2
        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);
        }
