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) {

  ans = value * 1000
  ans = Math.round(ans /10) + ""
  while (ans.length < 3) {ans = "0" + ans}
  len = ans.length
  ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
  return ('£' + ans);

	} 	
	 

function changeSpaces(tstring) {
        nstring='';
        for (var i=0; i <= tstring.length; i++) {
            if (tstring.charAt(i)==' ') { nstring=nstring+'^';
            } else 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();
	}
	
	

