function getPrice(qty, q1, p1,q2,p2,q3,p3){
	myq = parseInt(qty);
		if(myq >= parseInt(q3)){
			return p3;
		}else if(myq >= parseInt(q2)){
			return p2;
		}else{
			return p1;
		}
	}
function showBasket() {
		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);
		subtotal = 0;
		document.writeln('<CENTER><FORM NAME="updateform"><font size="5" face="Verdana, Arial, Helvetica, sans-serif"><b>Shopping Cart</B></FONT><HR WIDTH=75% size=1 COLOR="#000000">');
		document.writeln('<table cellpadding="2" cellspacing="1" border="0">');

		document.writeln('<TR><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Quantity</b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Porduct Name</b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Item Number</b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Price</b></FONT></TD><td BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Sub Total</b></FONT><TD BGCOLOR="#B3B3B3"><b><FONT COLOR="#B3B3B3">.</FONT></b></TD></TR>');
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
				thisitem = 1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				theprice = getPrice(thequantity,qL1,pL1,qL2,pL2,qL3,pL3);
				itemtotal = (eval(theprice*thequantity));
				temptotal = itemtotal * 100;
				subtotal = subtotal + itemtotal;
				itemlist=itemlist+1;
				document.write('<tr><td align=middle BGCOLOR="#D9D9D9"><INPUT TYPE=TEXT NAME="quant'+itemlist+'" VALUE="'+thequantity+'" SIZE=3></td><td BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><a href=product.asp?id='+theitem+'>'+thename+'</A></FONT></td>');
				document.write('<td align=left BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><a href=product.asp?id='+theitem+'>'+theitem+'</A></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+theprice+'</FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+top.head.alterError(itemtotal)+'</FONT></td><td WIDTH="38" align=right BGCOLOR="#D9D9D9"><a href="javascript:amendItem('+itemlist+',document.updateform.quant'+itemlist+'.value)"><IMG SRC="../images/update.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="update"></a><IMG SRC="../images/space.gif" WIDTH="3" HEIGHT="2" ALT=""><a href="javascript:removeItem('+itemlist+')"><IMG SRC="../images/remove.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="remove"></a>&nbsp;</td></tr>');

			} else if (fulllist.substring(i,i+1) == '|') {
				if (thisitem==1) theitem = fulllist.substring(itemstart, i);
				if (thisitem==2) thename = fulllist.substring(itemstart, i);
				if (thisitem==3) qL1 = fulllist.substring(itemstart, i);
				if (thisitem==4) pL1 = fulllist.substring(itemstart, i);
				if (thisitem==5) qL2 = fulllist.substring(itemstart, i);
				if (thisitem==6) pL2 = fulllist.substring(itemstart, i);
				if (thisitem==7) qL3 = fulllist.substring(itemstart, i);
				if (thisitem==8) pL3 = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}

		document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Total</b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+top.head.alterError(subtotal)+'</FONT></td><td BGCOLOR="#B3B3B3"><FONT COLOR="#B3B3B3">.</FONT></td></tr>');
		document.writeln('</TABLE><CENTER><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><IMG SRC="../images/update.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="update"> = update  <IMG SRC="../images/remove.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="remove"> = remove<br> Minimal Order $100.00  </FONT></CENTER>');
		document.writeln('</FORM>');
	}


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);
		subtotal = 0;
		subweight = 0;
		document.writeln('<table cellpadding="2" cellspacing="1" border="0">');

		document.writeln('<TR><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_qty%></b></FONT></TD><TD  BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_art_no%></b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_item%></b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_price%></b></FONT></TD><td BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_sub_total%></b></FONT></td></TR>');
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				thisitem = 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;
				subtotal = subtotal + itemtotal;
				weighttotal = 0;
				weighttotal = (eval(theweight*thequantity));
				subweight = subweight + weighttotal;
				itemlist=itemlist+1;
				document.write('<tr><td align=middle BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+thequantity+'</FONT></td>');
				document.writeln('<td BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><a href=prod_show.asp?art_no='+thenumber+'>'+thenumber+'</A></FONT></td><td align=left BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><a href=prod_show.asp?art_no='+thenumber+'>'+theitem+'</A></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(theprice)+'</FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(itemtotal)+'</FONT></td></tr>');
		  
			} else if (fulllist.substring(i,i+1) == '|') {
				if (thisitem==1) theitem = fulllist.substring(itemstart, i);
				if (thisitem==2) theprice = fulllist.substring(itemstart, i);
				if (thisitem==3) thenumber = fulllist.substring(itemstart, i);
				if (thisitem==4) theweight = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}

		
		totprice = (Math.round(subtotal*100)/100);
	      shipping = (subweight*5)+6;
		totalcost = (totprice+shipping);
            tax = (Math.round(totalcost*6)/100);


		document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_sub_total%></b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(totprice)+'</FONT></td></tr>');
		document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Estimate Shipping</b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(shipping)+'</FONT></td></tr>');
		document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Tax</b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(tax)+'</FONT></td></tr>');
		document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_total%></b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(totalcost+tax)+'</FONT></td></tr>');
  		document.writeln('<INPUT TYPE="hidden" NAME="total" VALUE="'+alterError(totalcost+tax)+'" SIZE="40">');
		document.writeln('</TABLE>');

	}
	
function addItem(itemId,itemName,qL1,pL1,qL2,pL2,qL3,pL3,itemQuantity ) {
	
		if(qL1.length == 0){
			qL1 = 1;}
		if(qL2.length == 0){
			qL2 = qL1;
			pL2 = pL1;
			qL3 = qL1;
			pL3 = pL1;
		}
		if(qL3.length == 0){
			qL3 = qL2;
			pL3 = pL2;
			}
			
		if (parseInt(itemQuantity) < parseInt(qL1) ) {
			rc = alert('Less Than Minimal Order Quantity!');
		}else{
		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)+"["+itemId+"|"+itemName+"|"+qL1+"|"+pL1+"|"+qL2+"|"+pL2+"|"+qL3+"|"+pL3+"|"+itemQuantity+"]";
		 window.alert('The item has been added to your shopping cart!');     
		}
		
	}

function resetShoppingBasket() {
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket=.";
	}
	
	

function amendItem(itemno, newquant) {
		newItemList = null;
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				thisitem = 1;
				itemstart = i+1;
				fullstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				itemlist=itemlist+1;
				if (itemlist != itemno) {
					newItemList = newItemList+'['+fulllist.substring(fullstart, itemend)+']';
				} else {
					newItemList = newItemList + '['+theitem+'|'+theprice+'|'+thenumber+'|'+theweight+'|'+newquant+']';
				}
			} else if (fulllist.substring(i,i+1) == '|') {
				if (thisitem==1) theitem = fulllist.substring(itemstart, i);
				if (thisitem==2) theprice = fulllist.substring(itemstart, i);
				if (thisitem==3) thenumber = fulllist.substring(itemstart, i);
				if (thisitem==4) theweight = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket="+newItemList;
		self.location = "basket.asp";
	

	}

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;
		self.location = "basket.asp";
	
	}

function clearBasket() {
		if (confirm('<%=txt_reset_shopping_cart%>?')) {
			index = document.cookie.indexOf("TheBasket");
			document.cookie="TheBasket=.";
			self.location = "basket_empty.asp";
		}
	}
function showBasket() {
		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);
		subtotal = 0;
		document.writeln('<CENTER><FORM NAME="updateform"><font size="5" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_cart%></B></FONT><HR WIDTH=75% size=1 COLOR="#000000">');
		document.writeln('<table cellpadding="2" cellspacing="1" border="0">');
		document.writeln('<TR><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_qty%></b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_art_no%></b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_item%></b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_price%></b></FONT></TD><td BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_sub_total%></b></FONT><TD BGCOLOR="#B3B3B3"><b><FONT COLOR="#B3B3B3">.</FONT></b></TD></TR>');
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
				thisitem = 1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemtotal = (eval(theprice*thequantity));
				temptotal = itemtotal * 100;
				subtotal = subtotal + itemtotal;
				itemlist=itemlist+1;
				document.write('<tr><td align=middle BGCOLOR="#D9D9D9"><INPUT TYPE=TEXT NAME="quant'+itemlist+'" VALUE="'+thequantity+'" SIZE=3></td><td BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><a href=prod_show.asp?art_no='+thenumber+'>'+thenumber+'</A></FONT></td>');

				document.write('<td align=left BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><a href=prod_show.asp?art_no='+thenumber+'>'+theitem+'</A></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+theprice+'</FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+top.cart.alterError(itemtotal)+'</FONT></td><td WIDTH="38" align=right BGCOLOR="#D9D9D9"><a href="javascript:amendItem('+itemlist+',document.updateform.quant'+itemlist+'.value)"><IMG SRC="images/update.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="<%=txt_update%>"></a><IMG SRC="images/space.gif" WIDTH="3" HEIGHT="2" ALT=""><a href="javascript:removeItem('+itemlist+')"><IMG SRC="images/remove.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="<%=txt_remove%>"></a>&nbsp;</td></tr>');

			} else if (fulllist.substring(i,i+1) == '|') {
				if (thisitem==1) theitem = fulllist.substring(itemstart, i);
				if (thisitem==2) theprice = fulllist.substring(itemstart, i);
				if (thisitem==3) thenumber = fulllist.substring(itemstart, i);
				if (thisitem==4) theweight = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}

		document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_total%></b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+top.cart.alterError(subtotal)+'</FONT></td><td BGCOLOR="#B3B3B3"><FONT COLOR="#B3B3B3">.</FONT></td></tr>');
		document.writeln('</TABLE><CENTER><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><IMG SRC="images/update.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="<%=txt_update%>"> = <%=txt_update%>  <IMG SRC="images/remove.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="<%=txt_remove%>"> = <%=txt_remove%></FONT></CENTER>');
		document.writeln('</FORM>');
	}

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);
	}