var To='/shopping_cart.html';
var TotalCount=0;
var TotalPrice=0;
function GoTo()
{
	window.document.location=To;
}
function setCook(id,name,descr,price,count,i)
{
	SetCookie('id'+i,id+'~'+name+'~'+descr+'~'+price+'~'+count);
}
function getCook(i)
{
	var tmp=String(GetCookie('id'+i));
	var tmpa=tmp.split('~');
	return tmpa;
}
function AddToCart(name,descr,price)
{
	id2=id=parseInt(GetCookie('id'));
	id++;
var argv = AddToCart.arguments;
var argc = AddToCart.arguments.length;
var idt = (argc > 3) ? argv[3] : id;
var tmp=GetCookie('id00');
if (idt==-1)
{
	if ((tmp)&&(descr))
	{
		return;
	}
	if (!tmp)
	{
		SetCookie('descr00',descr);
		SetCookie('id00',-1);
	}
	SetCookie('name00',name);
	SetCookie('price00',price);
	return;
}
var tmpa=Array();
	for (i=1;i<id;i++)
	{
		tmpa=getCook(i);
		if (tmpa[0]==idt)
		{
			setCook(tmpa[0],tmpa[1],tmpa[2],tmpa[3],parseInt(tmpa[4])+1,i);
//			SetCookie('count'+i,parseInt(GetCookie('count'+i))+1);
			GoTo();
			return;
		}
	}
	SetCookie('id',id);
	setCook(idt,name,descr,price,1,id);
/*	SetCookie('id'+id,idt);
	SetCookie('name'+id,name);
//	SetCookie('descr'+id,descr);
	SetCookie('price'+id,price);
	SetCookie('count'+id,1);*/
	GoTo();
}
function Quantity(i)
{
var tmp=getCook(i);
newstr=Edit.replace("_NAME_", "count"+i);
newstr=newstr.replace("_VALUE_",tmp[4]);
return newstr;
}
function ClearAll()
{
	SetCookie('id',0);
	window.location.reload();
}
function ToSubmit(i)
{
	ii=i;
	var type_;
	if (ii=='00')
	{
		switch (GetCookie('name00'))
		{
		case '1': type_=' U.S. Ground';break;
		case '39': type_=' Canada Ground';break;
		case '301': type_=' U.S. Next Day ';break;		
		case '302': type_=' Canada Next Day';break;		
		case '303': type_=' COD USA Ground ';break;
		default:	type_=' International ';
		}
//		return(' Shipping '+type_+' \$ '+GetCookie('price00'));
		return('');
	}
	var tmp=getCook(i);
	return (tmp[1]+'  \$ '+tmp[3]+'x'+tmp[4]+';');
}

function Description(i)
{
	var tmp=getCook(i);
	return tmp[2];
}
function Name(i)
{
	var tmp=getCook(i);
	return tmp[1];
}
function Price(i)
{
	var tmp=getCook(i);
	return tmp[3];
}
function Total(i)
{
	var tmp=getCook(i);
	return tmp[4];
}
function Summ(i)
{
	var t=parseInt(Total(i));
	var p=Price(i);
	var tmp=Math.floor(p*t*100+0.01)/100;
	TotalPrice+=tmp;
	TotalCount+=t;
	return(tmp);
}
function Remove(i)
{
	newstr=CheckBox.replace("_NAME_","delcount"+i);
	newstr=newstr.replace("_VALUE_",i);
	newstr=newstr.replace("_CH_","");
	return newstr;
}
function Update(n)
{
	for (var i=1;i<=n; i++)
	{
		if (eval('window.document.f1.count'+i))
		{
			var tmp=getCook(i);
			setCook(tmp[0],tmp[1],tmp[2],tmp[3],Math.abs(parseInt(eval('window.document.f1.count'+i+'.value'))),i);
			//SetCookie('count'+i,Math.abs(parseInt(eval('window.document.f1.count'+i+'.value'))));
/*			try
			{
				if (eval('window.document.f1.delcount'+i+'.checked'))
				{
					SetCookie('count'+i,0);
				}
			}
			catch(sss){}*/
			
		}
	}
	window.location.reload();
}
function ViewCart()
{
	var ss=s='';
	window.document.write(FormBegin);
	n=parseInt(GetCookie('id'));
	window.document.write(CartTableHeader);
	var tmp;
	for (i=1;i<=n;i++)
	{
		tmp=getCook(i);
		if (parseInt(tmp[4])!=0)
		{
			s+='<tr>';
			for (j=0;j<FuncList.length ;j++ )
			{
				s+='<td class="text_s"><br>'+eval(FuncList[j]+'('+i+')')+'</td>';
			}
			Summ(i);
			s+='</tr>';
			ss+=ToSubmit(i);
		}
	}
	window.document.write(s+CartTableBottom);
	var tmp=Additional.replace("_UPDATEACTION_",'onclick="Update('+n+')"');
	tmp=tmp.replace("_TOTALCOUNT_",TotalCount);
	tmp=tmp.replace("_TOTALPRICE_",Math.floor(TotalPrice*100+0.01)/100);
	tmp=tmp.replace("_TOTALPRICE_",Math.floor(TotalPrice*100+0.01)/100);
	tmp=tmp.replace("_TOTALPRICE_",Math.floor(TotalPrice*100+0.01)/100);
	tmp=tmp.replace("_TOTALPRICE_",Math.floor(TotalPrice*100+0.01)/100);
	tmp=tmp.replace("_TOTALPRICE_",Math.floor(TotalPrice*100+0.01)/100);
	tmp=tmp.replace("_TOSUBMIT_",ss);
	tmp=tmp.replace("_CLEAR_CART_ACTION_",'onclick="ClearAll()"');
	tmp=tmp.replace("_UID_",GetCookie('descr00'));
	window.document.write(tmp);
	window.document.write(FormEnd);
	ScriptToSet=ScriptToSet.replace("_TOTALPRICE_",Math.floor(TotalPrice*100+0.01)/100);
}
var as= new Date();
//AddToCart('1',as.getTime(),'0.00',-1);

