    function goBuy() {
        ilist='';
        index=document.cookie.indexOf('TheShop');
        countbegin=(document.cookie.indexOf('=', index)+1);
        countend=document.cookie.indexOf(';',index);
        if(countend==-1) { countend=document.cookie.length; }
        fulllist=document.cookie.substring(countbegin,countend);
        for(var i=0; i<= fulllist.length;i++) {
            if(fulllist.substring(i,i+1)=='[') {
                itemstart=i;
            } else if (fulllist.substring(i,i+1)==']') {
                itemend=i+1;
                ilist=ilist+fulllist.substring(itemstart,itemend);
            }
        }
        ilist=changeSpaces(ilist);
        top.location='shopbuy.htm?items='+ilist;
    }
	
	 function offline() {
        ilist='';
        index=document.cookie.indexOf('TheShop');
        countbegin=(document.cookie.indexOf('=', index)+1);
        countend=document.cookie.indexOf(';',index);
        if(countend==-1) { countend=document.cookie.length; }
        fulllist=document.cookie.substring(countbegin,countend);
        for(var i=0; i<= fulllist.length;i++) {
            if(fulllist.substring(i,i+1)=='[') {
                itemstart=i;
            } else if (fulllist.substring(i,i+1)==']') {
                itemend=i+1;
                ilist=ilist+fulllist.substring(itemstart,itemend);
            }
        }
        ilist=changeSpaces(ilist);
        top.location='offlinebuy.asp?items='+ilist;
    }

    function changeSpaces(tstring) {
        nstring='';
        for (var i=0; i <= tstring.length; i++) {
            if (tstring.charAt(i)==' ') { nstring=nstring+'^';
            } else { nstring=nstring+tstring.charAt(i); }
        }
        return nstring;
    }

function checkAdvanced(adv) {
     newAdv='';advlist=0;
    for (var j=0;j<=adv.length;j++) {
            if (adv.substring(j,j+1) == '{') {
            thisadv=1;
            advstart=j+1;
        } else if (adv.substring(j,j+1) == '}') {
            advend=j;
            advPrice2=adv.substring(advstart,advend);
            advlist++; applicable=true;
            if (applicable==true) {
                newAdv = newAdv+ '{'+advFrom+'~'+advTo+'~'+advPrice+'~'+advPrice2+'}'
            }
        } else if (adv.substring(j,j+1)=='~') {
            if (thisadv== 1) advFrom=adv.substring(advstart,j);
            if (thisadv== 2) advTo=adv.substring(advstart,j);
            if (thisadv== 3) advPrice=adv.substring(advstart,j);
            if (thisadv== 4) advPrice2=adv.substring(advstart,j);
            thisadv++;advstart=j+1;
        }
    }
    if (newAdv=='') newAdv='none';
    return newAdv;
}
    function buyItem(newItem,newPrice,newTaxable,newWeight,newAP,newQuantity) {
        if(newQuantity<=0) {
            rc = alert('The quantity entered is incorrect');
		} else if (newPrice < 50) {
			rc = alert('The minimum price of a voucher is £50');
        } else {
            if (confirm('Add '+newQuantity+' x '+newItem+' to basket? ')) {
                 if (newAP!='none') {
                     newAP=checkAdvanced(newAP);
                 }
                index=document.cookie.indexOf('TheShop');
                countbegin=(document.cookie.indexOf('=',index)+1);
                countend=document.cookie.indexOf(';',index);
                if(countend==-1) { countend=document.cookie.length; }
                 fulllist = document.cookie.substring(countbegin,countend);
                 amended = false;
                 newItemList=''; 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;
                         thequantity=fulllist.substring(itemstart,itemend);
                         itemlist++;
                         if (theItem==newItem ) {
                             amended=true;
                             tempquantity=eval(thequantity)+eval(newQuantity);
                             newItemList=newItemList+'['+theItem+'|'+thePrice+'|'+theTaxable+'|'+theWeight+'|'+newAP+'|'+tempquantity+']';
                         } else {
                             newItemList=newItemList+'['+theItem+'|'+thePrice+'|'+theTaxable+'|'+theWeight+'|'+theAP+'|'+thequantity+']';
                         }
                     } 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) theTaxable=fulllist.substring(itemstart,i);
                         if (thisitem== 4) theWeight=fulllist.substring(itemstart,i);
                         if (thisitem== 5) theAP=fulllist.substring(itemstart,i);
                         thisitem++;itemstart=i+1;
                     }
                 }
                 if (amended==false) {
                     newItemList=newItemList+'['+newItem+'|'+newPrice+'|'+newTaxable+'|'+newWeight+'|'+newAP+'|'+newQuantity+']'; }
                 index = document.cookie.indexOf('TheShop');
                 document.cookie='TheShop='+newItemList+'; expires=Friday, 31-Dec-2010 08:00:00 GMT';
            }
        }
		document.location=document.location
    }
	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) {
    index = document.cookie.indexOf('TheCurrency');
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    theCurrency=document.cookie.substring(countbegin,countend);
    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[theCurrency],currencyPre[theCurrency],currencyMiddle[theCurrency],currencyPost[theCurrency]);
}
function showPriceSingle(pricestring) {
    index = document.cookie.indexOf('TheCurrency');
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    theCurrency=document.cookie.substring(countbegin,countend);
    return presentValue(pricestring,currencyDecimals[theCurrency],currencyPre[theCurrency],currencyMiddle[theCurrency],currencyPost[theCurrency]);
}
function showPricePlain(pricestring) {
    index = document.cookie.indexOf('TheCurrency');
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    theCurrency=document.cookie.substring(countbegin,countend);
    return presentValue(pricestring,currencyDecimals[theCurrency],'',currencyMiddle[theCurrency],'');
}
function getPrice(pricestring) {
    index = document.cookie.indexOf('TheCurrency');
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    theCurrency=document.cookie.substring(countbegin,countend);
    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 presentValue(value) {
        if(value<=0.9999) {
            newPounds='0';
        } else {
            newPounds=parseInt(value);
        }
        dec='1';
        for (var i=1; i<=2;i++) {
            dec=dec+'0';
        }
        if (value>0) {
            newPence=Math.round((value+.000008 - newPounds)*(eval(dec)));
        } else {
            newPence=0;
        }
        compstring='9';
        for (var i=1; i <=2-1;i++) {
            if (eval(newPence) <= eval(compstring)) newPence='0'+newPence;
            compstring=compstring+'9';
        }
        if (2>0) {
            newString='£' + newPounds + '.' + newPence + '';
        } else {
            newString='£' + newPounds + '';
        }
        return (newString);
    }

function getAdvanced(adv,curr,qty,advField1) {
     newAdv='';advlist=0;applicable=true;advnewprice=0;
    for (var j=0;j<=adv.length;j++) {
            if (adv.substring(j,j+1) == '{') {
            thisadv=1;
            advstart=j+1;
        } else if (adv.substring(j,j+1) == '}') {
            advend=j;
            advPrice2=adv.substring(advstart,advend);
            advlist++; applicable=true;
            if (applicable==true) {
             if (eval(advFrom) > 0 && eval(advFrom) > eval(qty)) applicable=false;
             if (eval(advTo) > 0 && eval(advTo) < eval(qty)) applicable=false;
             if (curr==1 && applicable==true) advnewprice=advPrice;
             if (curr==2 && applicable==true) advnewprice=advPrice2;
            }
        } else if (adv.substring(j,j+1)=='~') {
            if (thisadv==1) nfield1 = adv.substring(advstart, j);
            if (thisadv== 2) advFrom=adv.substring(advstart,j);
            if (thisadv== 3) advTo=adv.substring(advstart,j);
            if (thisadv== 4) advPrice=adv.substring(advstart,j);
            if (thisadv== 5) advPrice2=adv.substring(advstart,j);
            thisadv++;advstart=j+1;
        }
    }
     return advnewprice;
}

    function goBuy() {
        ilist='';
        index=document.cookie.indexOf('TheTeapotteryBasket');
        countbegin=(document.cookie.indexOf('=', index)+1);
        countend=document.cookie.indexOf(';',index);
        if(countend==-1) { countend=document.cookie.length; }
        fulllist=document.cookie.substring(countbegin,countend);
        for(var i=0; i<= fulllist.length;i++) {
            if(fulllist.substring(i,i+1)=='[') {
                itemstart=i;
            } else if (fulllist.substring(i,i+1)==']') {
                itemend=i+1;
                ilist=ilist+fulllist.substring(itemstart,itemend);
            }
        }
        ilist=changeSpaces(ilist);
        top.location='https://secure.yorks.net/teapottery/buy.htm?items='+ilist;
    }

    function changeSpaces(tstring) {
        nstring='';
        for (var i=0; i <= tstring.length; i++) {
            if (tstring.charAt(i)==' ') { nstring=nstring+'^';
            } else { nstring=nstring+tstring.charAt(i); }
        }
        return nstring;
    }

 taxfield='United Kingdom';
 function showBasket() {
     currency=1;
     index=document.cookie.indexOf('TheTeapotteryBasket');
     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;totprice2=0;shippingtotal=0;shippingtotal2=0;taxtotalone=0;taxtotalone2=0;taxtotaltwo=0;taxtotaltwo2=0;ordertotal=0;ordertotal2=0;
     taxablestandard=0;taxablesecond=0;taxable=0;
     document.writeln('<table border=0 cellpadding=2 cellspacing=0>');
     document.writeln('<tr>');
     document.writeln('<td><b>Name</b></td>');
     document.writeln('<td align=right><b>Price</b></td>');
     document.writeln('<td align=right><b>Quantity</b></td><td align=right><b>Total Cost</b></td><td align=right><b>Action</b></td>');
     document.writeln('</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;itemtotal2=0;
             
             itemtotal=(eval(theprice*thequantity));
             temptotal=itemtotal*100;
             totprice=totprice+itemtotal;
             itemlist=itemlist+1;
         document.writeln('<tr><td><input type=hidden name=Item_'+itemlist+' value="'+theitem+'">'+theitem+'</td>');
     document.writeln('<td align=right><input type=hidden name=Item_Price_'+itemlist+' value='+presentValue(eval(theprice))+'>'+presentValue(eval(theprice))+'</td>');
     document.writeln('<td align=right><input type=hidden name="Quantity_'+itemlist+'" value='+thequantity+' size=3>'+thequantity+'</td>');
     document.writeln('<td align=right><input type=hidden name=Item_Total_'+itemlist+' value='+presentValue(itemtotal)+'>'+presentValue(itemtotal)+'</td>');
     document.writeln('<td align=right><input type=button name="remove'+itemlist+'" value="Remove" onClick="removeItem('+itemlist+');"></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) thetaxable=fulllist.substring(itemstart,i);
                 if (thisitem== 4) theweight=fulllist.substring(itemstart,i);
                 if (thisitem== 5) field1=fulllist.substring(itemstart,i);
                     if (thisitem== 6) theAP=fulllist.substring(itemstart,i);
               thisitem++; itemstart=i+1;
             }
         }
     document.writeln('<tr><td colspan=4>Total Goods</td>');
     document.writeln('<td align=right><input type=hidden name=Total value='+presentValue(totprice)+'>'+presentValue(totprice)+'</td>');
     document.writeln('<td align=right>&nbsp;</td>');
     document.writeln('</tr>');
     document.writeln('</table><br>');
}

    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('TheShop');
        document.cookie='TheShop='+newItemList+'; expires=Friday, 31-Dec-2010 08:00:00 GMT';
        self.location = 'gift.htm';
    }

    function clearBasket() {
        if (confirm('Are you sure you wish to clear the basket?')) {
            index=document.cookie.indexOf('TheTeapotteryBasket');
            document.cookie='TheTeapotteryBasket=.';
            self.location='gift.htm';
        }
    }
    function changeCurrency(num) {
         index=document.cookie.indexOf('TheCurrency');
         document.cookie='TheCurrency='+num+'; expires=Friday, 31-Dec-2010 08:00:00 GMT';
         self.location='gift.htm';
    }

    function updateBasket() {
        newItemList='';
        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++;
                thiselement=document.itemsform.elements['quant'+itemlist].value;
                newItemList=newItemList+'['+partList+'|'+thiselement+']'
            } else if(fulllist.substring(i,i+1)=='|') {
                partList=fulllist.substring(itemstart,i);
            }
        }
        index=document.cookie.indexOf('TheShop');
        document.cookie='TheShop='+newItemList+'; expires=Friday, 31-Dec-2010 08:00:00 GMT';
        self.location='gift.htm';
    }