function Basketadd(Pid,Pname,Pcost,Pwt)
{
//	alert(Pid + Pname + Pcost + Pwt); // 
//var cooktemp = document.cookie ;
var aa = Get_Cookie('pidCook') ;
if (aa == null) // if cookie has no content then:
{
//alert("Cookie has no values!!! : "); // this is executed if variable is not 10
SetCookie('pidCook',Pid);
SetCookie('nameCook',Pname);
SetCookie('costCook',Pcost);
SetCookie('quantCook',1);
SetCookie('wtCook',Pwt);
cooktemp = document.cookie ;
window.location.href=("checkout.php")
}
else 
{
//alert("Cookie has values!!! : "); // this is executed if variable is not 10
var aa = Get_Cookie('pidCook') ;
var bb = Get_Cookie('nameCook') ;
var cc = Get_Cookie('costCook') ;
var dd = Get_Cookie('quantCook') ;
var ee = Get_Cookie('wtCook') ;
//alert(aa + " <<ee!!! : "); // this is executed if variable is not 10
//document.write(aa + " " + bb + " "  + cc + " " + dd )
var ara = aa.split("ZZ") // cookie data into arrays
var arb = bb.split("ZZ")
var arc = cc.split("ZZ")
var ard = dd.split("ZZ")
var are = ee.split("ZZ")
var arl = ara.length // array length
//**********************************************************
var cexist=999
for(i=0;i<arl;i++)
{
if (Pid==ara[i])
{
cexist=i;
};
};
//**********************************************************
if (cexist!=999)
{

SetCookie('CurrItem',cexist) ;
window.location.href=("update.html");
}
else
{

ara[arl] = Pid; // add new cart item to end of arrays
arb[arl] = Pname;
arc[arl] = Pcost;
ard[arl] = 1;
are[arl] = Pwt;

var aw = ara.join("ZZ"); // make array data into a string
var bw = arb.join("ZZ"); 
var cw = arc.join("ZZ"); 
var dw = ard.join("ZZ");
var ew = are.join("ZZ");

SetCookie('pidCook',aw);
SetCookie('nameCook',bw);
SetCookie('costCook',cw);
SetCookie('quantCook',dw);
SetCookie('wtCook',ew);
cooktemp = document.cookie ;
//alert("Cookie had no values : " + cooktemp) ;
window.location.href=("checkout.php");
};};
}

function Get_Cookie(name) {
  var start = document.cookie.indexOf(name + '=');
  var len = start + name.length + 1;
  if ((!start) && (name != document.cookie.substring(0,name.length)))
    return null;
  if (start == -1)
    return null;
  var end = document.cookie.indexOf(';',len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len,end));
}

function readCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	}

function SetCookie(cookieName,cookieValue) {
 var today = new Date();
 var expire = new Date();
 //if (nDays==null || nDays==0) nDays=1;
 var nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}


function checkForm()
{
var aaa=(Number(document.shopform.a.value));
var bbb=(Number(document.shopform.b.value));
var ccc=(Number(document.shopform.c.value));
var ddd=(Number(document.shopform.d.value));
var eee=(Number(document.shopform.e.value));
var fff=(Number(document.shopform.f.value));
var ggg=(Number(document.shopform.g.value));
var hhh=(Number(document.shopform.h.value));
var iii=(Number(document.shopform.i.value));
var jjj=(Number(document.shopform.j.value));
ttlcs = (aaa + bbb + ccc + ddd + eee + fff + ggg + hhh + iii + jjj); 

if (ttlcs < 12) 
{
alert ("You need to select " + (12-ttlcs) + " more chocolates"); 
return false;
} 
else if (ttlcs > 12)
{
alert ("Too many selected! - you need to remove " + (ttlcs - 12) + " chocolates"); 
return false;
} 
else
{
var box = "Box-a" + aaa + "b" + bbb +  "c" + ccc +  "d" + ddd +  "e" + eee +  "f" + fff + "g" + ggg + "h" + hhh + "i" + iii + "j" + jjj;
//Basketadd('999', box ,'15.99','1.0');
return true;
}
}
