goodstotal=0;
itemlist=0;
itemcount=0;

if (document.cookie) {

  index=document.cookie.indexOf('Order');
  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+1;
       thisitem=1;
       } else if (fulllist.substring(i,i+1)==']') {
            itemend=i;
            thequantity=fulllist.substring(itemstart,itemend);
            itemtotal=0;
            tempcount=thequantity;
            itemtotal=(eval(theprice*thequantity));
            itemcount=itemcount+(eval(tempcount));
            temptotal=itemtotal*100;
            goodstotal=goodstotal+itemtotal;
            itemlist=itemlist+1;

       } else if (fulllist.substring(i,i+1)=='|') {
            if (thisitem== 1) theitem=fulllist.substring(itemstart,i);
            if (thisitem== 2) thedesc=fulllist.substring(itemstart,i);
            if (thisitem== 3) theprice=fulllist.substring(itemstart,i);
            if (thisitem== 4) theweight=fulllist.substring(itemstart,i);
            thisitem++; itemstart=i+1;
       }
     }

  } else {
   document.cookie = 'Order=; path=/';
  }

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 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 addItem(newCode,newDesc,newPrice,newWeight,newQuantity,basketPath) {
         if (newQuantity<=0) {
             rc = alert('The quantity entered is incorrect');
             } else {
				 
                 index=document.cookie.indexOf('Order');
                 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 (theCode==newCode ) {
                             amended=true;
                             tempquantity=eval(thequantity)+eval(newQuantity);
                             newItemList=newItemList+'['+theCode+'|'+theDesc+'|'+thePrice+'|'+theWeight+'|'+tempquantity+']';
                         } else {
                             newItemList=newItemList+'['+theCode+'|'+theDesc+'|'+thePrice+'|'+theWeight+'|'+thequantity+']';
                         }
                     } else if (fulllist.substring(i,i+1)=='|') {
                         if (thisitem==1) theCode=fulllist.substring(itemstart,i);
                         if (thisitem==2) theDesc=fulllist.substring(itemstart,i);
                         if (thisitem== 3) thePrice=fulllist.substring(itemstart,i);
                         if (thisitem== 4) theWeight=fulllist.substring(itemstart,i);
                         thisitem++;itemstart=i+1;
                     }
                 }
                 if (amended==false) {
                     newItemList=newItemList+'['+newCode+'|'+newDesc+'|'+newPrice+'|'+newWeight+'|'+newQuantity+']';
                     }
                 index = document.cookie.indexOf('Order');
                 document.cookie='Order='+newItemList+'; path=/';

                 }
				 self.location = basketPath;
                }
				
				
function addOption(newCodeDesc,newPrice,newWeight,newQuantity,basketPath) {
         if (newQuantity<=0) {
             rc = alert('The quantity entered is incorrect');
             } else {
				 
                 index=document.cookie.indexOf('Order');
                 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;
				 
				 codeEnd=newCodeDesc.indexOf('=');
				 
				 newCode=newCodeDesc.substring('=',codeEnd);
				 newDesc=newCodeDesc.substring((codeEnd+1),newCodeDesc.length);		 
				 
				 
                 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 (theCode==newCode ) {
                             amended=true;
                             tempquantity=eval(thequantity)+eval(newQuantity);
                             newItemList=newItemList+'['+theCode+'|'+theDesc+'|'+thePrice+'|'+theWeight+'|'+tempquantity+']';
                         } else {
                             newItemList=newItemList+'['+theCode+'|'+theDesc+'|'+thePrice+'|'+theWeight+'|'+thequantity+']';
                         }
                     } else if (fulllist.substring(i,i+1)=='|') {
                         if (thisitem==1) theCode=fulllist.substring(itemstart,i);
                         if (thisitem==2) theDesc=fulllist.substring(itemstart,i);
                         if (thisitem== 3) thePrice=fulllist.substring(itemstart,i);
                         if (thisitem== 4) theWeight=fulllist.substring(itemstart,i);
                         thisitem++;itemstart=i+1;
                     }
                 }
                 if (amended==false) {
                     newItemList=newItemList+'['+newCode+'|'+newDesc+'|'+newPrice+'|'+newWeight+'|'+newQuantity+']';
                     }
                 index = document.cookie.indexOf('Order');
                 document.cookie='Order='+newItemList+'; path=/';

                 }
				 self.location = basketPath;
                }
				

function MM_openBrWindow(theURL,winName,features) { //v2.0
  newWindow=window.open(theURL,winName,features);
  newWindow.focus();
	}
	
	
