﻿
function SetCookie(name,value){//定义一个变量叫name和value
//alert(name);
    expires=new Date();
    expires.setTime(expires.getTime()+(86400*365));
    document.cookie=name+"="+value+"; expires="+expires.toGMTString()+"; path=/";
}

function Deletecookie(name) { //删除名称为name的Cookie 
	//alert(name);
	var exp = new Date(); 

exp.setTime (exp.getTime() - 1); 

var cval = GetCookie (name); 

document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); 


} 

function Clearcookie() //清除COOKIE 

{ 

var temp=document.cookie.split(";"); 

var loop3; 

var ts; 

for (loop3=0;loop3<temp.length;loop3++) 

{ 

ts=temp[loop3].split("=")[0]; 

if (ts.indexOf('mycat')!=-1) 

Deletecookie(ts); //如果ts含“mycat”则执行清除 
location="cart.asp"
} 

} 





function Clearcookie1() //清除COOKIE 

{ 

var temp=document.cookie.split(";"); 

var loop3; 

var ts; 

for (loop3=0;loop3<temp.length;loop3++) 

{ 

ts=temp[loop3].split("=")[0]; 

if (ts.indexOf('mycat')!=-1) 

Deletecookie(ts); //如果ts含“mycat”则执行清除 

} 

} 


function getCookieVal (offset) { //取得项名称为offset的cookie值 

var endstr = document.cookie.indexOf (";", offset); 

if (endstr == -1) 

endstr = document.cookie.length; 

return unescape(document.cookie.substring(offset, endstr)); 

} 

function GetCookie (name) { //取得名称为name的cookie值 

var arg = name + "="; 

var alen = arg.length; 

var clen = document.cookie.length; 

var i = 0; 

while (i < clen) { 

var j = i + alen; 

if (document.cookie.substring(i, j) == arg) 

return getCookieVal(j); 

i = document.cookie.indexOf(" ", i) + 1; 

if (i == 0) break; 

} 

return null; 

} 

///

function Addcat(catid,number){ //把商品添加到“手推车”函数

　SetCookie("mycat"+catid,catid+","+number); //把商品ID与数量写入Cookie 
  window.location="cart.asp";
　
}
function Addcat1(catid,number){ 
//alert("sdf");
  num=GetCookie("mycat"+catid);
  if(num==null)
  {
	  number=1;
   }else
   {
	 num1=parseInt(num.split(",")[1]);
	 number=num1+1;
   }
　//alert(number);
　SetCookie("mycat"+catid,catid+","+number); 
   
　　//var cat=window.open("showcat.asp","cat","toolbar=no,menubar=no,location=no,status=no,width=430,height=280"); 
     
   // cat.focus();
	location="cart.asp";
//打开一个新窗口来显示统计的商品信息，即显示“手推车”
}
function Deletecat(catid){ 
   //alert(catid);
　Deletecookie("mycat"+catid); 
  window.location="cart.asp";
}

