// SJ Purdy for Hafixs Industrial Products
// (c) 2001-2004
//

// This script can handle a max of this number of items - if you change this you must add
//   subroutines in function refresh to handle the rows.
var MaxItems=15;
//
//
// Nothing should need changing after here.
//
//
if ( ProdList.length > MaxItems ) {
	NoItems = MaxItems;
} else {
	NoItems = ProdList.length;
}
//
//
var totprice=0;
//
today=new Date();
today.setTime(today.getTime() + (3600000));
today=today.toGMTString();
currentdate=new Date();
currentdate=currentdate.toLocaleString();
//
index = document.cookie.indexOf('BasketName');
if (index > -1) {
   countbegin=(document.cookie.indexOf('=',index)+1);
   countend=document.cookie.indexOf(';',index);
   if(countend==-1) {
      fulllist='';
   } else {
      fulllist=document.cookie.substring(countbegin,countend);
   }
} else {
   fulllist='';
}
//
if(fulllist.length < 1) {
   document.cookie='BasketCode=.; expires='+today;
   document.cookie='BasketName=.; expires='+today;
   document.cookie='BasketPrice=.; expires='+today;
   document.cookie='BasketQuantity=.; expires='+today;
   document.cookie='Mailto=UK; expires='+today;
   document.cookie='Referrer=.; expires='+today;
}
//
theCurrency=1;
currencyCode='GBP'; 
currencyName='GBP'; 
currencyPre='£'; 
currencyDecimals='2'; 
currencyMiddle='.'; 
currencyPost=''; 
//
function refresh()
{
	for (var i=0;i<NoItems;i++) {
		sjp = i + 10;
		Bits = ProdList[i].split("|");
//    Code|Description|Price|Desc page|Image|Thumb
		PriceStr = Bits[2] + "~";
		ItemQty = Retrieve_Qty(Bits[0],Bits[1]);
		ItemLineTotal = Retrieve_LineTotal(Bits[0],Bits[1]);
//
		if ( i == 0 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o10Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o10Item.value = "";
			}
			document.basketform._x10lineqty.value = ItemQty;
			document.basketform._x10linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 1 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o11Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o11Item.value = "";
			}
			document.basketform._x11lineqty.value = ItemQty;
			document.basketform._x11linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 2 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o12Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o12Item.value = "";
			}
			document.basketform._x12lineqty.value = ItemQty;
			document.basketform._x12linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 3 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o13Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o13Item.value = "";
			}
			document.basketform._x13lineqty.value = ItemQty;
			document.basketform._x13linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 4 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o14Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o14Item.value = "";
			}
			document.basketform._x14lineqty.value = ItemQty;
			document.basketform._x14linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 5 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o15Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o15Item.value = "";
			}
			document.basketform._x15lineqty.value = ItemQty;
			document.basketform._x15linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 6 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o16Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o16Item.value = "";
			}
			document.basketform._x16lineqty.value = ItemQty;
			document.basketform._x16linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 7 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o17Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o17Item.value = "";
			}
			document.basketform._x17lineqty.value = ItemQty;
			document.basketform._x17linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 8 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o18Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o18Item.value = "";
			}
			document.basketform._x18lineqty.value = ItemQty;
			document.basketform._x18linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 9 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o19Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o19Item.value = "";
			}
			document.basketform._x19lineqty.value = ItemQty;
			document.basketform._x19linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 10 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o20Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o20Item.value = "";
			}
			document.basketform._x20lineqty.value = ItemQty;
			document.basketform._x20linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 11 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o21Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o21Item.value = "";
			}
			document.basketform._x21lineqty.value = ItemQty;
			document.basketform._x21linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 12 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o22Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o22Item.value = "";
			}
			document.basketform._x22lineqty.value = ItemQty;
			document.basketform._x22linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 13 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o23Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o23Item.value = "";
			}
			document.basketform._x23lineqty.value = ItemQty;
			document.basketform._x23linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 14 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o24Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o24Item.value = "";
			}
			document.basketform._x24lineqty.value = ItemQty;
			document.basketform._x24linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
		if ( i == 15 ) {
			if ( ItemQty != 0 ) {
				document.basketform.o25Item.value = ""+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(PriceStr)+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal);
			} else {
				document.basketform.o25Item.value = "";
			}
			document.basketform._x25lineqty.value = ItemQty;
			document.basketform._x25linetot.value = ""+showPriceSingle(ItemLineTotal);
		}
	}
	refresh_2();
}
//
function refresh_2()
{
	CalcBasket();
	document.basketform._pm1.value=""+Postques+" for "+Postfrom+" postage";
	document.basketform._pm2.value=""+Postto+" Postage";
	document.basketform.n01Mailto.value=Postto;
	document.basketform._gcost.value=showPriceSingle(GoodsTotal);
	document.basketform.p01PostandPack.value=showPriceSingle(postcost);
	document.basketform.s01TotalCost.value=showPriceSingle(totprice);
}
//
function reload()
{
	window.location.reload();
}
//
function goBuy() {
        ilist='';
        ilist=ilist+retrieveCookie('BasketCode',0,0)+'^';
        ilist=ilist+retrieveCookie('BasketName',0,0)+'^';
        ilist=ilist+retrieveCookie('BasketPrice',0,0)+'^';
        ilist=ilist+retrieveCookie('BasketQuantity',0,0)+'^';
        ilist=ilist+retrieveCookie('Mailto',0,0)+'^';
        ilist=ilist+retrieveCookie('Referrer',0,0)+'^';
        ilist=changeUnwanted(ilist);
        ilist=escape(ilist);
        ilist=changePercent(ilist);
        if (top.name != '') {
             window.open( ChkOutURL, ilist);
        } else {
             top.name = ilist;
             top.location = ChkOutURL;
        }
}
//
function changeUnwanted(tstring) {
    nstring='';
    for (var i=0; i <= tstring.length; i++) {
        nchar=tstring.charAt(i);
        if (nchar=='*') { nchar='!&1'; }
        if (nchar=='+') { nchar='!&2'; }
        if (nchar=='@') { nchar='!&3'; }
        if (nchar=='.') { nchar='!&4'; }
        if (nchar=='/') { nchar='!&5'; }
        if (nchar=='-') { nchar='!&6'; }
        nstring=nstring+nchar;
    }
    return nstring;
}
//
function changePercent(tstring) {
    nstring='';
    for (var i=0; i <= tstring.length; i++) {
        nchar=tstring.charAt(i);
        if (nchar=='%') { nchar='_'; }
        nstring=nstring+nchar;
    }
    return nstring;
}
//
function showPrice(pricestring) {
    thisitem=0;
    itemstart=0;
    theprice=0;
    for (var i=0; i<pricestring.length; i++) {
       if (pricestring.substring(i,i+1)=='~') {
          thisitem++;
          if (thisitem==eval(theCurrency)) {
             theprice=pricestring.substring(itemstart,i);
          }
          itemstart=i+1;
       }
    }
    return presentValue(theprice,currencyDecimals,currencyPre,currencyMiddle,currencyPost);
}
//
function showPriceSingle(pricestring) {
    return presentValue(pricestring,currencyDecimals,currencyPre,currencyMiddle,currencyPost);
}
//
function showPricePlain(pricestring) {
    return presentValue(pricestring,currencyDecimals,'',currencyMiddle,'');
}
//
function getPrice(pricestring) {
    thisitem=0;
    itemstart=0;
    theprice=0;
    for (var i=0; i<pricestring.length; i++) {
       if (pricestring.substring(i,i+1)=='~') {
          thisitem++;
          if (thisitem==eval(theCurrency)) {
             theprice=pricestring.substring(itemstart,i);
          }
          itemstart=i+1;
       }
    }
    return theprice;
}
//
function presentValue(value,dp,pt,mt,at) {
        if(value<=0.9999) {
            newPounds='0';
        } else {
            newPounds=parseInt(value);
        }
        dec='1';
        for (var i=1; i<=dp;i++) {
            dec=dec+'0';
        }
        if (value>0) {
            newPence=Math.round((eval(value)+.000008 - newPounds)*(eval(dec)));
        } else {
            newPence=0;
        }
        compstring='9';
        for (var i=1; i <=dp-1;i++) {
            if (eval(newPence) <= eval(compstring)) newPence='0'+newPence;
            compstring=compstring+'9';
        }
        if (dp>0) {
            if (newPence==eval(dec)) { newPounds++; newPence=0; }
            newString=pt+newPounds+mt+newPence+at;
        } else {
            newString=pt+newPounds+at;
        }
        return (newString);
}
//
function retrieveCookie(thecookie,thenumber,theadditional) {
    index = document.cookie.indexOf(thecookie);
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    fulllist=document.cookie.substring(countbegin,countend);
    if (thenumber==0) { return fulllist; }
    thisitem=0;
    newcookie='';
    itemstart=0;
    for(var i=0; i<fulllist.length;i++) {
        if (fulllist.substring(i,i+1)=='|') {
            thisitem++;
           itemvalue=fulllist.substring(itemstart,i);
           if (thisitem==thenumber) {
                if (theadditional==0) {
                    return itemvalue;
                } else {
                    itemstarttwo=0;
                    thisitemtwo=0;
                    for (var j=0; j<itemvalue.length; j++) {
                        if (itemvalue.substring(j,j+1)=='~') {
                            thisitemtwo++;
                            itemvaluetwo=itemvalue.substring(itemstarttwo,j);
                            if (thisitemtwo==theadditional) {
                                return itemvaluetwo;
                            }
                            itemstarttwo=j+1;
                        }
                    }
                }
            }
            itemstart=i+1;
        }
    }
    return '';
}
//
function addToCookie(thecookie,thevalue) {
    fulllist=retrieveCookie(thecookie,0,0);
    if (fulllist=='.') { fulllist=''; }
    fulllist=fulllist+thevalue+'|';
    document.cookie=thecookie+'='+fulllist+'; expires='+today;
}
//
function removeFromCookie(thecookie,thenumber) {
    fulllist=retrieveCookie(thecookie,0,0);
    thisitem=0;
    newcookie='';
    itemstart=0;
    for(var i=0; i<fulllist.length;i++) {
        if (fulllist.substring(i,i+1)=='|') {
            thisitem++;
            itemvalue=fulllist.substring(itemstart,i);
            if (thisitem!=thenumber) {
                newcookie=newcookie+itemvalue+'|';
            }
            itemstart=i+1;
        }
    }
    if (newcookie=='') { newcookie='.'; }
    document.cookie=thecookie+'='+newcookie+'; expires='+today;
}
//
function changeCookieValue(thecookie,thenumber,thevalue) {
    fulllist=retrieveCookie(thecookie,0,0);
    thisitem=0;
    newcookie='';
    itemstart=0;
    for(var i=0; i<fulllist.length;i++) {
        if (fulllist.substring(i,i+1)=='|') {
            thisitem++;
            itemvalue=fulllist.substring(itemstart,i);
            if (thisitem==thenumber) {
                itemvalue=thevalue;
            }
            newcookie=newcookie+itemvalue+'|';
            itemstart=i+1;
        }
    }
    document.cookie=thecookie+'='+newcookie+'; expires='+today;
}
//
function retrieveCookieCount(thecookie) {
   fulllist=retrieveCookie(thecookie,0,0);
   thisitem=0; newcookie=''; itemstart=0;
   for(var i=0; i<fulllist.length;i++) {
    if (fulllist.substring(i,i+1)=='|') {
        thisitem++;
        itemstart=i+1;
    }
   }
   return thisitem;
}
//
function MailOs() {
	document.cookie='Mailto=OS; expires='+today;
	refresh_2();
}
//
function MailUk() {
	document.cookie='Mailto=UK; expires='+today;
	refresh_2();
}
//
function showBasket() {
   sepchar='"';
   totItem=0;
   if ( retrieveCookie('Mailto',0,0) == "UK" ) {
      This1Item=UK1Item;
      This2Item=UK2Item;
      Checked="";
      Postto="UK";
      Postfrom="Overseas";
      Postques="Selector";
   } else {
      This1Item=OS1Item;
      This2Item=OS2Item;
      Checked="CHECKED";
      Postto="Overseas";
      Postfrom="UK";
      Postques="Deselector";
   }
   postcost=0;
   totprice=0;
   document.writeln("<tr bgcolor='#000000' align='center'>");
   document.writeln("<td colspan='8'><font face='Verdana, Arial, Helvetica, sans-serif' size='2' color='#ffffff'>");
   document.writeln("<b>The prices above include VAT.<br>The cost of postage is calculated automatically</b>");
   document.writeln("</font></td></tr>");
//
   for (var i=1;i<=retrieveCookieCount('BasketCode');i++) {
       theCode=retrieveCookie('BasketCode',i,0);
       theName=retrieveCookie('BasketName',i,0);
       thePrice=retrieveCookie('BasketPrice',i,0);
       theQuantity=retrieveCookie('BasketQuantity',i,0);
       totItem=totItem+eval(theQuantity);
       itemtotal=eval(theQuantity)*eval(getPrice(thePrice));
       totprice=totprice+itemtotal;

   }
   GoodsTotal=totprice;
//
   if (totItem <= FirstFor) {
	postcost=This1Item;
   } else {
	postcost=This1Item+(This2Item*(totItem - FirstFor));
   }
   if (totItem > CapItem) {
	postcost=This1Item+(This2Item*(CapItem - FirstFor));
   }
   if (totItem<=0) {
	postcost=0;
   }
   totprice=totprice+postcost;
//
   document.writeln("<tr bgcolor=FFFFFF align=right>");
   document.writeln("<td colspan='2'><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000>&nbsp;</font></td>");
   document.writeln("<td align=left colspan='5'><font face='Verdana, Arial, Helvetica, sans-serif' size=3 color=000000>Goods Total</font></td>");
   document.writeln("<td><input style='BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; TEXT-ALIGN: right;  font-family:Verdana,Arial,Helvetica,sans-serif; font-size:12pt' size=8 name=_gcost value=0.00 onchange=refresh_2()></td>");
   document.writeln("</tr>");
//
   document.writeln("<tr bgcolor=FFFFFF align=right>");
   document.writeln("<td align=left colspan='2'>");
   document.writeln("<input type=checkbox onClick='if(this.checked){MailOs()}else{MailUk()}' "+Checked+" >");
   document.writeln("<input style='BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; TEXT-ALIGN: left;  font-family:Verdana,Arial,Helvetica,sans-serif; font-size:12pt' size=35 name=_pm1 value=''></td>");
   document.writeln("</td>");
   document.writeln("<td align=left colspan='5'><input style='BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; TEXT-ALIGN: left;  font-family:Verdana,Arial,Helvetica,sans-serif; font-size:12pt' size=20 name=_pm2 value=''></td>");
   document.writeln("<td><input style='BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; TEXT-ALIGN: right;  font-family:Verdana,Arial,Helvetica,sans-serif; font-size:12pt' size=8 name=p01PostandPack value=0.00 onchange=refresh_2()></td>");
   document.writeln("</tr>");
//
   document.writeln("<tr bgcolor=FFFFFF align=right>");
   document.writeln("<td colspan='2'><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000>&nbsp;</font></td>");
   document.writeln("<td align=left colspan='5'><font face='Verdana, Arial, Helvetica, sans-serif' size=3 color=000000>Order Total</font></td>");
   document.writeln("<td><input style='BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; TEXT-ALIGN: right;  font-family:Verdana,Arial,Helvetica,sans-serif; font-size:12pt' size=8 name=s01TotalCost value=0.00 onchange=refresh_2()></td>");
   document.writeln("</tr>");
//
   document.writeln("<tr align=center bgcolor=#ffffff><td colspan=8>");
   document.writeln("<table>");
   document.writeln("<tr align=center>");
   document.writeln("<td>");
   document.writeln("<a href='JavaScript:clearBasket()'><img src=\""+ImageDir+"EmptyBasketButton.gif\" alt='Empty Basket Button' border=0></a>");
   document.writeln("</td>");
   document.writeln("<td>");
   document.writeln("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
   document.writeln("</td>");
   document.writeln("<td>");
   document.writeln("<input type=hidden name='n01Mailto' value='"+Postto+"'>");
   document.writeln("<input type='image' src='"+ImageDir+"CheckoutButton.gif' alt='Checkout Button' name='buygoods' value='Checkout'>");
   document.writeln("</td>");
   document.writeln("</tr></table>");
   document.writeln("</td></tr></table>");
   document.writeln("<p>");
   document.writeln("<font size=\"+1\" color=\"#ffff99\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
   document.writeln("For larger orders the cost of postage ");
   document.writeln(" may be different.<br>Please see our <a href=\""+TandCPage+"\" onclick=\"this.target='tandc'\">terms&nbsp;and&nbsp;conditions</a> for full details.");
   document.writeln("</font>");
}
//
// Add one item to line / Remove one item from line
function IncDec_Item(newCode,newItem,newPrice,newQuantity) {
// newQuantity should be +1(inc) or -1(dec)
	amended = false;
	newItemList=''; itemlist=0;
	for (var i=1;i<=retrieveCookieCount('BasketCode');i++) {
		theCode=retrieveCookie('BasketCode',i,0);
		theItem=retrieveCookie('BasketName',i,0);
		theQuantity=retrieveCookie('BasketQuantity',i,0);
		if (theCode==newCode && theItem==newItem ) {
			tempquantity=eval(theQuantity)+eval(newQuantity);
			amended=true;
			if ( tempquantity < 0 ) {
				tempquantity = 0;
			}
			if ( tempquantity > 99 ) {
				tempquantity = 99;
			}
			changeCookieValue('BasketQuantity',i,tempquantity);
		}
	}
	if (amended==false && eval(newQuantity) > 0) {
		addToCookie('BasketCode',newCode);
		addToCookie('BasketName',newItem);
		addToCookie('BasketPrice',newPrice);
		addToCookie('BasketQuantity',newQuantity);
	}
	refresh();
}
//
// retrieve quantity from a cookie
//    Code|Description|Price|Desc page|Image|Thumb
function Retrieve_Qty(xCode,xDesc) {
	quantity=0;
	for (var i=1;i<=retrieveCookieCount('BasketCode');i++) {
		theCode=retrieveCookie('BasketCode',i,0);
		theDesc=retrieveCookie('BasketName',i,0);
		theQuantity=retrieveCookie('BasketQuantity',i,0);
		if (theCode==xCode && theDesc==xDesc ) {
			quantity=theQuantity;
		}
	}
	return quantity;
}
//
// retrieve quantity from a cookie
//    Code|Description|Price|Desc page|Image|Thumb
function Retrieve_LineTotal(xCode,xDesc) {
	itemtotal=0;
	for (var i=1;i<=retrieveCookieCount('BasketCode');i++) {
		theCode=retrieveCookie('BasketCode',i,0);
		theDesc=retrieveCookie('BasketName',i,0);
		theQuantity=retrieveCookie('BasketQuantity',i,0);
		thePrice=retrieveCookie('BasketPrice',i,0);
		if (theCode==xCode && theDesc==xDesc ) {
			itemtotal=eval(theQuantity)*eval(getPrice(thePrice));
		}
	}
	return itemtotal;
}
//
function flipImage(imgname,imgsrc) {
	document.images[imgname].src=imgsrc;
}
//
function removeItem(itemno) {
        removeFromCookie('BasketCode',itemno);
        removeFromCookie('BasketName',itemno);
        removeFromCookie('BasketPrice',itemno);
        removeFromCookie('BasketQuantity',itemno);
        refresh();
}
//
function clearBasket() {
        if (confirm('Are you sure you wish to clear the basket?')) {
            index=document.cookie.indexOf('Basket');
            document.cookie='BasketCode=.; expires='+today;
            document.cookie='BasketName=.; expires='+today;
            document.cookie='BasketPrice=.; expires='+today;
            document.cookie='BasketQuantity=.; expires='+today;
            refresh();
        }
}
//
function showProdList() {
	document.writeln('<table border=1 cellpadding=2 cellspacing=0>');
	document.writeln('<tr bgcolor=000000 align=center>');
	document.writeln("<th><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=ffffff>Code</font></th>");
	document.writeln("<th><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=ffffff>Description</font></th>");
	document.writeln("<th><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=ffffff>More<br>Info</font></th>");
	document.writeln("<th><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=ffffff>Price<br>Each</font></th>");
	document.writeln("<th colspan=3><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=ffffff>Current<br>Order</font></th>");
	document.writeln("<th><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=ffffff>Line<br>Total</font></th>");
	document.writeln("</tr>");
	for (var i=0;i<NoItems;i++) {
		sjp = i + 10;
		Bits = ProdList[i].split("|");
//    Code|Description|Price|Desc page|Image|Thumb
		InfoLink = "&nbsp;";
		if ( Bits[3] != "" ) {
			InfoLink = "<a href=\""+DataDir+Bits[3]+"\"><img src=\""+ImageDir+"i.gif\" alt='Info Button' border=\"0\"></a>";
		}
		PriceStr = Bits[2] + "~";
		document.writeln("<td bgcolor=FFFFFF><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000>"+Bits[0]+"</font></td>");
		document.writeln("<td bgcolor=FFFFFF><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000>"+Bits[1]+"</font></td>");
		document.writeln("<td bgcolor=FFFF99 align=center><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000><b>"+InfoLink+"</b></font></td>");
		document.writeln("<td bgcolor=FFFFFF align=right><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000>"+showPrice(PriceStr)+"</font></td>");
//
		document.writeln("<td bgcolor=FFFFFF align=center>");
		document.writeln("&nbsp;<a href='JavaScript:IncDec_Item(\""+Bits[0]+"\",\""+Bits[1]+"\",\""+PriceStr+"\", -1)'><img src=\""+ImageDir+"btnminus.gif\" alt='Minus Button' border=0></a>");
		document.writeln("</td>");
//
// Number of this item
		document.writeln("<td bgcolor=FFFFFF align=right><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000>");
		ItemQty = Retrieve_Qty(Bits[0],Bits[1]);
		document.writeln("<input style='BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; TEXT-ALIGN: right; font-family:Verdana,Arial,Helvetica,sans-serif; font-size:12pt' size=3 name='_x"+sjp+"lineqty' value=0 onchange=refresh()>");
		document.writeln("</font></td>");
//
		document.writeln("<td bgcolor=FFFFFF align=center>");
		document.writeln("<a href='JavaScript:IncDec_Item(\""+Bits[0]+"\",\""+Bits[1]+"\",\""+PriceStr+"\", 1)'><img src=\""+ImageDir+"btnplus.gif\" alt='Plus Button' border=0></a>&nbsp;");
		document.writeln("</td>");
//
// Line total
		document.writeln("<td bgcolor=FFFFFF align=right><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000>");
		ItemLineTotal = Retrieve_LineTotal(Bits[0],Bits[1]);
//		document.writeln(" "+showPriceSingle(ItemLineTotal)+" ");
		document.writeln("<input style='BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; TEXT-ALIGN: right; font-family:Verdana,Arial,Helvetica,sans-serif; font-size:12pt' size=8 name='_x"+sjp+"linetot' value=0.00 onchange=refresh()>");

//    Code|Description|Price|Desc page|Image|Thumb
// SJP
	       document.writeln("<input type=hidden name='o"+sjp+"Item' value='"+Bits[0]+"²"+Bits[1]+"²r;"+showPrice(Bits[2])+"²c;"+ItemQty+"²r;"+showPriceSingle(ItemLineTotal)+"'>");
//SJP End
		document.writeln("</font></td>");
		document.writeln("</tr>");
	}
}
//
function ShowPage() {
	document.writeln('<p>');
	document.writeln("<font size=\"2\" color=\"#ffff99\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
	document.writeln("<b>Change quantities for each item by pressing the + or - buttons.<br>");
	document.writeln("Use the <b>Selector</b> for UK or Overseas postage.");
	document.writeln("<br>When the order is ready click on 'Checkout'.");
	document.writeln("</b>");
	document.writeln("</font> ");
	document.writeln("<FORM name='basketform' method='post' action='"+ChkOutURL+"' >");
	showProdList();
	showBasket();
	refresh();
	document.writeln("</FORM>");
}
//
function ShowHome() {
      document.writeln("<a href='"+HomePage+"'>Home Page</a>");
}
//
function ShowTandC() {
      document.writeln("| <a href='"+TandCPage+"' onclick=\"this.target='tandc'\">Terms and Conditions</a>");
}
//
function CalcBasket() {
   totItem=0;
   if ( retrieveCookie('Mailto',0,0) == "UK" ) {
      This1Item=UK1Item;
      This2Item=UK2Item;
      Checked="";
      Postto="UK";
      Postfrom="Overseas";
      Postques="Selector";
   } else {
      This1Item=OS1Item;
      This2Item=OS2Item;
      Checked="CHECKED";
      Postto="Overseas";
      Postfrom="UK";
      Postques="Deselector";
   }
   postcost=0;
   totprice=0;
   for (var i=1;i<=retrieveCookieCount('BasketCode');i++) {
       theCode=retrieveCookie('BasketCode',i,0);
       theName=retrieveCookie('BasketName',i,0);
       thePrice=retrieveCookie('BasketPrice',i,0);
       theQuantity=retrieveCookie('BasketQuantity',i,0);
       totItem=totItem+eval(theQuantity);
       itemtotal=eval(theQuantity)*eval(getPrice(thePrice));
       totprice=totprice+itemtotal;
   }
   GoodsTotal=totprice;
   if (totItem <= FirstFor) {
	postcost=This1Item;
   } else {
	postcost=This1Item+(This2Item*(totItem - FirstFor));
   }
   if (totItem > CapItem) {
	postcost=This1Item+(This2Item*(CapItem - FirstFor));
   }
   if (totItem<=0) {
	postcost=0;
   }
   totprice=totprice+postcost;
}


