var index = 0;
    function goBuy() {
        ilist='';
        index=document.cookie.indexOf('esl-net-cart');
        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='buy.html?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 (confirm('Add '+newQuantity+' x '+newItem+' to cart? ')) {
                 if (newAP!='none') {
                     newAP=checkAdvanced(newAP);
                 }
 index=document.cookie.indexOf('esl-net-cart');
                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('esl-net-cart');
                 document.cookie='esl-net-cart='+newItemList+'; expires=Friday, 31-Dec-2010 08:00:00 GMT';
				 document.forms[1].submit()
				 // document.location = 'http://www.esl.net/basket.html'
				 
				 }
        }
    }