
function TotalCount() {
    var OrderString = unescape(ReadOrderForm('shop_trolley')); //获取cookies中的购物车信息
    var strs = new Array(); //定义一个数组，用于存储购物车里的每一条信息
    strs = OrderString.split("|"); //用|分割出购物车中的每个产品
    document.getElementById("total").innerText = strs.length-1;
}

//<--Start--添加商品至购物车的函数,参数(商品编号,商品名称，商品数量，商品单价)
function SetOrderForm(item_no, item_price) {
    var cookieString = document.cookie;
    if (cookieString.length >= 4000) {
        alert("您的订单已满\n请结束此次订单操作后添加新订单！");
    }

    else {
        var mer_list = ReadOrderForm('shop_trolley');
        var Then = new Date();
        Then.setTime(Then.getTime() + 30 * 60 * 1000);
        var item_detail = "|" + item_no + "," + item_price;
        if (mer_list == false) {
            document.cookie = "shop_trolley=" + item_detail + ";expires=" + Then.toGMTString();
            if (confirm('转到购物车列表')) location.href = '1.asp';
            alert("您的订单已满\n请结束此次订单操作后添加新订单！");
        }
        else {
            if (mer_list.indexOf(escape(item_no)) != -1) {
                alert('此商品您已添加\n请进入订单修改数量！')
            }
            else {
                document.cookie = "shop_trolley=" + mer_list + escape(item_detail) + ";expires=" + Then.toGMTString();
                alert("已经加入您的订单！");
            }
        }
    }
}
//-->End

//<--End--订单更新
//<--清空购物车
function clearOrder() {
    var Then = new Date();
    document.cookie = "shop_trolley='';expires=" + Then.toGMTString();
}
//<--End

function ReadOrderForm(name) {
    var cookieString = document.cookie;
    if (cookieString == "") {
        return false;
    }
    else {
        var firstChar, lastChar;
        firstChar = cookieString.indexOf(name);
        if (firstChar != -1) {
            firstChar += name.length + 1;
            lastChar = cookieString.indexOf(';', firstChar);
            if (lastChar == -1) lastChar = cookieString.length;
            return cookieString.substring(firstChar, lastChar);
        }
        else {
            return false;
        }
    }
}