function AddToCart(j,w,t,B,l){
	var h=w;
	var q="";
	var f=document.getElementById("Units_"+w);
	var A=readCookie("CartID");
	var v=document.getElementById("Grouping_"+w);
	var F=document.getElementById("Related_"+w);
	var e=document.getElementById("catProdTd_"+w);
	var n=document.getElementById("catProdAttributes_"+w);
	var u=document.getElementById("catProdAttributes2_"+w);
	var s=document.getElementById("catProdInstructions_"+w);
	var c="";
	var p=new Array();
	var C=false;
	var a=false;
	var m;
	var g=0;
	var E;
	var d=true;
	var attrError = "ERROR: Before adding to your cart, please choose the Grind Type, and if relevant select Decaf or Regular (optional on some coffees).";
	if(f){
		m=f.value;
		if(m<0){
			alert(OshopLang.RemoveError);
			return false
		}
	}else{
		m=1
	}
	if(A==null||A==""){
		A=-1
	}
	E=document.getElementById("catCartSummary");
	if(v){
		if(v.nodeName=="SELECT"){
			h=v.value
		}else{
			var r=v.getElementsByTagName("input");
			for(var z=0;z<r.length;z++){
				if(r[z].checked){
					h=r[z].value;
					break
				}
			}
		}
	}
	if(F){
		q=GetCheckListValue(F);
		if(q.length>0){
			g=q.split(",").length
		}
	}
	if(s){
		c=s.value
	}
	if(n){
		var o=n.getElementsByTagName("select");
		if(o){
			if(c.length>0){
				c+=";";
			}
			for(var z=0;z<o.length;z++){
				if(o[z].value.length>0){
					c+=o[z].value+";";
				}
			}
		}
	}
	if(u){
		var D=0;
		var o=u.getElementsByTagName("select");
		var y;
		var x;
		var k="";
		if(o){
			for(var z=0;z<o.length;z++){
				if(o[z].value.length>0){
					p[D]=o[z].value+"|1";
					D++
				}else{
					if(o[z].getAttribute("mandatory")){
						alert(attrError);
						return
					}
				}
			}
		}
		var o=u.getElementsByTagName("input");
		if(o){
			for(var z=0;z<o.length;z++){
				if(o[z].type=="checkbox"||o[z].type=="radio"){
					if(k!=o[z].getAttribute("name")){
						if(z>0&&!x&&o[z-1].getAttribute("mandatory")){
							alert(attrError);
							return
						}
						x=false
					}
					if(o[z].checked){
						p[D]=o[z].id+"|1";
						D++;
						x=true
					}
					k=o[z].getAttribute("name")
				}else{
					if(o[z].value.length>0){
						p[D]=o[z].id+"|"+o[z].value;
						D++;
						x=true
					}else{
						if(o[z].getAttribute("mandatory")){
							alert(attrError);
							return
						}
					}
				}
			}
			if(o.length>
			0&&(o[o.length-1].type=="checkbox"||o[o.length-1].type=="radio")){
				if(!x&&o[z-1].getAttribute("mandatory")){
					alert(attrError);
					return
				}
			}
		}

	}
	if(E){
		if(E.getAttribute("Vertical")=="True"){
			C=true
		}
		if(E.getAttribute("Quote")=="True"){
			a=true
		}
	}
	var b=CMS.CatalogueRetrieve.ServerSideAddItemToOrder(A,j,h,m,q,p,c,C,B,a,t,d);
	g=parseInt(g)+parseInt(m);
	createCookie("CartID",b.value[0],2);
	if(E){
		E.innerHTML=b.value[2]
	}
	switch(b.value[1]){
		case 0:if(!l){
			if(e){
				e.innerHTML=b.value[3];
				ProcessJS(e)
			}
			alert(g+Oshoplang.Added)
		}else{
			document.location="/OrderRetrievev2.aspx?CatalogueID="+j
		}
		break;
		case 1:alert(Oshoplang.OutOfStock);
		break;
		case 2:if(!l){
			if(e){
				e.innerHTML=b.value[3];
				ProcessJS(e)
			}
			alert(g+Oshoplang.PreOrder)
		}else{
			document.location="/OrderRetrievev2.aspx?CatalogueID="+j
		}
		break;
		case 3:alert(Oshoplang.MinLimit);
		break;
		case 4:alert(Oshoplang.MaxLimit);
		break
	}
	if(typeof AddProductExtras=="function"){
		AddProductExtras(j,h,b.value[1])
	}
}
