function buyItem(newItem, newPrice, newTaxable, newWeight, newAP, newQuantity) {
	
	// check that quantity is at least 1
	if(newQuantity<=0) { rc = alert('Please select the quantity you require'); } 
	
	else {
		
		// get user confirm of addition to basket
		if (confirm('Add '+newQuantity+' x '+newItem+' to your purchases? ')) {
			
			// retrieve existing basket
			index=document.cookie.indexOf('EmcurBasket');
			
			// set start and end points
			countbegin=(document.cookie.indexOf('=',index)+1);
			countend=document.cookie.indexOf(';',index);
			if(countend == -1) { countend=document.cookie.length; }
			
			// retrieve all products into one string
			fulllist = document.cookie.substring(countbegin,countend);
			
			// set new product flag and instantiate variables
			amended = false;
			newItemList=''; itemlist=0;

			// cycle through products
			for (var i=0; i<=fulllist.length; i++) {
				// start of product details
				if (fulllist.substring(i,i+1) == '[') {
					thisitem=1;
					itemstart=i+1;
					fullstart=i+1;
				}
				// end of product details
				else if (fulllist.substring(i,i+1) == ']') {
					itemend=i;
					thequantity=fulllist.substring(itemstart,itemend);
					itemlist++;
					if (theItem==newItem ) {
						// if item exists already amend current entry in list
						amended=true;
						tempquantity=eval(thequantity)+eval(newQuantity);
						newItemList=newItemList+'['+theItem+'|'+thePrice+'|'+theTaxable+'|'+theWeight+'|'+newAP+'|'+tempquantity+']';
					}
					else {
						// else add new product to list
						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('EmcurBasket');
			document.cookie='EmcurBasket='+newItemList;
	    }
	}
}
