	function addToCard(intSellsOut, intProductId){

		var blnSellsOut = intSellsOut=="1";
		
		if(blnSellsOut){
			addToSoldCookie(intProductId);
			markSold(intProductId);
		
		}

		
		var collextra = document.getElementsByName("EXTRA_PRODUCT");
		if(document.getElementById("tax").getAttribute("origvalue")){
			document.getElementById("tax").value = parseFloat(document.getElementById("tax").getAttribute("origvalue"));
			document.getElementById("amount").value = parseFloat(document.getElementById("amount").getAttribute("origvalue"));
			document.getElementById("os0").value = document.getElementById("os0").getAttribute("origvalue");
			document.getElementById("item_name").value = document.getElementById("item_name").getAttribute("origvalue");
		}
		var spnPrice = document.getElementById("spnPrice");


		var blnChecked = false;
		var blnTwo = false;
		for(var i=collextra.length-1;i>=0; i--){
			var el = collextra[i];
			if (el.checked){
				var price = parseFloat(el.getAttribute("PRICE"));
				var vat = parseFloat(el.getAttribute("VAT"));
				var blnLocSellsOut = el.getAttribute("SELLS_OUT_FLAG")=="1";
				var intLocProductId = el.getAttribute("PRODUCT_ID");
				
				if(el.getAttribute("HIDE_PRICE_AND_ROUND_FLAG")=="1" && price>0){
				
					if(blnChecked) blnTwo=true
					blnChecked = true;
					price = Math.round(price/(price+vat)*Math.round(price+vat)*100)/100
					//vat -> 0 for the moment
					
					//vat = Math.round(price*0.175/(price+vat)*Math.round(price+vat)*100)/100;
					vat =0
				
				}
				document.getElementById("amount").value = parseFloat(document.getElementById("amount").value) + price;
				document.getElementById("tax").value = parseFloat(document.getElementById("tax").value) + vat;
				document.getElementById("os0").value += ", "+el.getAttribute("REFERENCE");
				document.getElementById("item_name").value += ", "+el.getAttribute("PRODUCT_NAME");

				if(blnLocSellsOut){
					addToSoldCookie(intLocProductId);
					markSold(intLocProductId);
				
				}


			}
			
		}

	//for some reason emma has chosen that a large pendant and earrings takes off £1. hack for this.		
		if(blnTwo && (parseFloat(document.getElementById("amount").value) + parseFloat(document.getElementById("tax").value)) > 100){
//			document.getElementById("amount").value = parseFloat(document.getElementById("amount").value) - 0.85;
//			document.getElementById("tax").value = parseFloat(document.getElementById("tax").value) -0.15;	
			document.getElementById("amount").value = parseFloat(document.getElementById("amount").value) - 1.00;
			document.getElementById("tax").value = parseFloat(document.getElementById("tax").value) -0.00;	
		} 
		//dressed hamper validation
		if(document.getElementById("prod41form")){
			if(spnPrice && spnPrice.getAttribute("SHOW_PRICE_FLAG")=="0"){
				//blnChecked must be true
				if(!blnChecked){
					alert("Please pick an item to go in your hamper");
					return
				}
			}
		}
		
		//gift voucer validation
		if(document.getElementById("prod33form")){
			var intChosen = 0;
			if(spnPrice && spnPrice.getAttribute("SHOW_PRICE_FLAG")=="0"){
				for(var i=0;i<collextra.length; i++){
					var el = collextra[i];
					if (el.checked){
						intChosen +=1;
					}
				}
			}
			if(intChosen<1){
					alert("Please choose a voucher price");
					return
			
			}
			if(intChosen>1){
					alert("Please only choose one voucher price");
					return
			
			}
		}

		document.forms['prod' + intProductId + 'form'].submit();
	}
	function z(){}
	
	function chooseExtra(intProductId){
		var el = event.srcElement;
		var spnPrice = document.getElementById("spnPrice");
		
		var origPrice=parseFloat(document.getElementById("amount").getAttribute("origvalue"));
		var origVat=parseFloat(document.getElementById("tax").getAttribute("origvalue"));
		if(spnPrice && spnPrice.getAttribute("SHOW_PRICE_FLAG")=="0"){
			var collextra = document.getElementsByName("EXTRA_PRODUCT");
			var blnChecked = false;
			var blnTwo = false;
			for(var i=0;i<collextra.length; i++){
				var el = collextra[i];
				if (el.checked && el.getAttribute("HIDE_PRICE_AND_ROUND_FLAG")=="1"){
					var price = parseFloat(el.getAttribute("PRICE"));
					var vat = parseFloat(el.getAttribute("VAT"));
					if(blnChecked) blnTwo=true
					blnChecked = true;
					price = Math.round(price/(price+vat)*Math.round(price+vat)*100)/100
					//vat -> zero for the moment
	//				vat = Math.round(price*0.175/(price+vat)*Math.round(price+vat)*100)/100
					vat = 0;

					origPrice += price;

					origVat += vat;
					
				}
			}

		//for some reason emma has chosen that a large pendant and earrings takes off £1. hack for this.		
			if(blnTwo && (origPrice + origVat) > 100){
				origPrice -= 1.00;
				origVat -=0.00;	
			} 

			if(blnChecked)
				spnPrice.innerHTML = "&pound;"+(origPrice + origVat);		
			else		
				spnPrice.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";		
		}
	}	

	function addToSoldCookie(intProductId){
		var strCookie = document.cookie;
		
		var strProdList = getCookie("soldProducts");
		if(strProdList.length > 0)
			strProdList += ",";
		strProdList += "["+intProductId+"]";

		document.cookie ='soldProducts=' + strProdList + '; path=/'
	
	}
	
	function getCookie(strKey){
		var strCookie = document.cookie;
		var arr_strCookie = strCookie.split("; ");
		for(var i in arr_strCookie){
			var item = arr_strCookie[i];
			var arr_strInfo = item.split("=");
			if(strKey == arr_strInfo[0]){
				if(arr_strInfo[1])
					return (arr_strInfo[1]);
				else
					return "";
			}
		
		}
		return "";
	}
	
	function markSold(intProductId){
		document.getElementById("spnProdBuy" + intProductId).innerHTML = "SOLD";
	}
