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

function clearBasket() {
         index=document.cookie.indexOf('Order');
         document.cookie = 'Order=; path=/';
         }
		 
function goBack() {
	if (document.referrer) {
		window.location.href = document.referrer;
	} else {
		window.location.href = '../index.htm';
	}
		 }


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 showCount() {
         document.writeln(itemcount);
         }

function showTotal() {
         document.writeln(presentValue(goodstotal));
         }

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) {
						 
				codeEnd=newCodeDesc.indexOf(':');				 
				newCode=newCodeDesc.substring(':',codeEnd);
				newDesc=newCodeDesc.substring((codeEnd+1),newCodeDesc.length);
				
				addItem(newCode,newDesc,newPrice,newWeight,newQuantity,basketPath);
				
				}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}




















