






    function goBuy() {



        ilist='';



        index=document.cookie.indexOf('GDCookie');



        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://granitedigital.safeserver.com/catalog/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;



    }







function checkAdvanced(adv,advField1) {



     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 (field1!='none' && advField1 != field1) applicable=false;



            if (applicable==true) {



                newAdv = newAdv+ '{'+field1+'~'+advFrom+'~'+advTo+'~'+advPrice+'~'+advPrice2+'}'



            }



        } else if (adv.substring(j,j+1)=='~') {



            if (thisadv==1) field1 = 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;



        }



    }



    if (newAdv=='') newAdv='none';



    return newAdv;



}



    function buyItem(newItem,newPrice,newTaxable,newWeight,newField1,newAP,newQuantity) {



        if(newQuantity<=0) {



            rc = alert('The quantity entered is incorrect');



        } else {



            if (confirm('Add '+newQuantity+' x '+newItem+' to basket? ')) {



                 if (newAP!='none') {



                     newAP=checkAdvanced(newAP,newField1);



                 }



                index=document.cookie.indexOf('GDCookie');



                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  && theField1 == newField1) {



                             amended=true;



                             tempquantity=eval(thequantity)+eval(newQuantity);



                             newItemList=newItemList+'['+theItem+'|'+thePrice+'|'+theTaxable+'|'+theWeight+'|'+theField1+'|'+newAP+'|'+tempquantity+']';



                         } else {



                             newItemList=newItemList+'['+theItem+'|'+thePrice+'|'+theTaxable+'|'+theWeight+'|'+theField1+'|'+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) theField1=fulllist.substring(itemstart,i);



                         if (thisitem== 6) theAP=fulllist.substring(itemstart,i);



                         thisitem++;itemstart=i+1;



                     }



                 }



                 if (amended==false) {



                     newItemList=newItemList+'['+newItem+'|'+newPrice+'|'+newTaxable+'|'+newWeight+'|'+newField1+'|'+newAP+'|'+newQuantity+']'; }



                 index = document.cookie.indexOf('GDCookie');



                 document.cookie='GDCookie='+newItemList+'; expires=Friday, 31-Dec-2010 08:00:00 GMT';



            }



        }



    }



