function cartsc1() {
    document.getElementById("cartDiv1").style.top = (document.documentElement.scrollTop + (document.documentElement.clientHeight - document.getElementById("cartDiv1").offsetHeight) / 2) + "px";
    document.getElementById("cartDiv1").style.left = (document.documentElement.scrollLeft + (document.documentElement.clientWidth - document.getElementById("cartDiv1").offsetWidth) / 2) + "px";
}
function scall() {
    cartsc1();
}
window.onscroll = scall; window.onresize = scall; window.onload = scall;
function gotocartlist() {
    window.location.href = "/member/cartlist.aspx";
}
function showcart() {
    document.getElementById("cartDiv1").style.display = "";
    cartsc1();
}
function closecart() {
    document.getElementById("cartDiv1").style.display = "none";
}
function GetRTime(id) {
    var NowTime = new Date();
    var nMS = TimeArray[id].getTime() - NowTime.getTime();
    var nD = Math.floor(nMS / (1000 * 60 * 60 * 24));
    var nH = Math.floor(nMS / (1000 * 60 * 60)) % 24;
    var nM = Math.floor(nMS / (1000 * 60)) % 60;
    var nS = Math.floor(nMS / 1000) % 60;
    var nMS = Math.floor(nMS / 100) % 10;
    if ((nD - 30) >= 0 && nH >= 0 && nM >= 0 && nS >= 0) {
        document.getElementById("RemainD" + id).innerHTML = "<span>" + (nD - 30) + "</span>天<span>" + nH + "</span>时<span>" + nM + "</span>分<span>" + nS + "</span>秒";
    }
    else {
        document.getElementById("RemainD" + id).innerHTML = "已过期！";
    }
    setTimeout("GetRTime(" + id + ")", 1000);
}
var catalogid = document.getElementById("Scatalogid0").innerHTML;
var ImgVisualPath = "/products/" + catalogid + "/";
function swithImg(image) {
    document.getElementById("ProductMaxImage0").src = ImgVisualPath + image;
}
function swithImg(image, id) {
    document.getElementById("ProductMaxImage" + id).src = image;
}
function getImg(para1, para2, itemid, cent_priceid, packageid) {
    catalogid = document.getElementById("Scatalogid" + itemid).innerHTML;
    var imageid = document.getElementById("Simageid" + itemid).innerHTML;
    ImgVisualPath = "/products/" + catalogid + "/";
    if (para1 != "0") {
        document.getElementById("para1" + itemid).innerHTML = para1;
        document.getElementById("para2" + itemid).innerHTML = "0";
    }
    if (para2 != "0") {
        document.getElementById("para2" + itemid).innerHTML = para2;
    }
    var _para1 = document.getElementById("para1" + itemid).innerHTML;
    var _para2 = document.getElementById("para2" + itemid).innerHTML;
    var _UserClick = parseInt(document.getElementById("UserClick").innerHTML);
    _UserClick = _UserClick + 1;
    document.getElementById("UserClick").innerHTML = _UserClick;
    send_request("/admin/getpara.aspx?para1=" + _para1 + "&para2=" + _para2 + "&imageid=" + imageid + "&itemid=" + itemid + "&priceid=" + cent_priceid + "&packageid=" + packageid + "&guid=" + _UserClick, ImgVisualPath);
}
var http_request = false;
function send_request(url, ImgVisualPath) {
    http_request = false;
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType("text/html");
        }
    }
    else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Xsxml2.XMLHTTP");
            http_request.setRequestHeader("Content-Type", "text/xml");
        }
        catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
                http_request.setRequestHeader("Content-Type", "text/xml");
            } catch (e) { }
        }
    }
    if (!http_request) { return false; alert('false.'); }
    http_request.onreadystatechange = processRequest;
    http_request.open("get", url, true); http_request.send(null);
}
function processRequest() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            var arrayAsJSONText = http_request.responseText;
            var continents = eval(arrayAsJSONText);
            var _len = continents.length;
            var itemid = continents[_len - 1];
            var headsplit = 0;
            for (var j = 0; j < _len; j++) {
                if (continents[j] == "@") {
                    headsplit = j;
                }
            }
            var para1html = "";
            for (i = 0; i < headsplit; i++) {

                para1html = para1html + continents[i];
            }
            document.getElementById("order_paraid1" + itemid).innerHTML = para1html;
            document.getElementById("ProductMaxImage" + itemid).src = ImgVisualPath + continents[headsplit + 1];
            var intsplit = 0;
            for (var j = headsplit; j < _len; j++) {
                if (continents[j] == "#") {
                    intsplit = j;
                }
            }
            var flg = 0;
            if (itemid == 0) {
                var sicoid = document.getElementById("ImgArrayID" + itemid).innerHTML;
                if (sicoid != "") {
                    var arrmp = sicoid.split(",");
                    for (i = 0; i < arrmp.length; i++) {
                        flg = 0;
                        for (var j = intsplit + 1; j < _len - 1; j++) {
                            if (continents[j] == arrmp[i]) {
                                flg = 1;
                            }
                        }
                        if (flg == 1) {
                            document.getElementById("ProductMixImage" + itemid + "" + arrmp[i]).style.display = "";
                        }
                        else {
                            if (intsplit != 0) {
                                document.getElementById("ProductMixImage" + itemid + "" + arrmp[i]).style.display = "none";
                            }
                        }
                    }
                }
            }
            var para2html = "";
            for (i = headsplit + 2; i < intsplit; i++) {
                para2html = para2html + continents[i];
            }
            document.getElementById("order_paraid2" + itemid).innerHTML = para2html;
            document.getElementById("Odstock" + itemid).innerHTML = continents[_len - 3];
            if (continents[_len - 2] != 0) {
                document.getElementById("Odprice" + itemid).innerHTML = continents[_len - 2];
            }
        }
        else {
            //alert("程序调用失败!");
        }
    }
}
function swithPara(id) {
    var paracount = parseInt(document.getElementById("paracount").innerHTML);
    for (var i = 1; i <= paracount; i++) {
        document.getElementById("paradata" + i).style.display = "none";
    }
    document.getElementById("paradata" + id).style.display = "";
}
function tocart(count, actionTypeid, packageid) {
    var _StockCheck = parseInt(document.getElementById("StockCheck").innerHTML);
    var _UserClick = parseInt(document.getElementById("UserClickCart").innerHTML);
    if (count > 0) {
        var _Vcent_priceid = parseInt(document.getElementById("Vcent_priceid0").innerHTML);
        var checkstock = true;
        var flg, flg1, para1, para2, productid, ImgArrayID, Odstock, Odprice, url;
        flg = true;
        flg1 = true;
        if (actionTypeid == 1) {
            url = "/member/tocart.aspx?packageid=" + packageid + "&cart=";
        } else {
            url = "/member/tocartonly.aspx?packageid=" + packageid + "&cart=";
        }
        var forstar = 1;
        var endstar = count + 1
        var ordercount = 1;
        if (count == 1) {
            forstar = 0;
            endstar = 1;
        }
        for (var i = forstar; i < endstar; i++) {
            productid = parseInt(document.getElementById("Sproductid" + i).innerHTML);
            if (count == 1) {
                ImgArrayID = parseInt(document.getElementById("ImgArrayID_" + i).innerHTML);
                ordercount = parseInt(document.getElementById("ordercount").value);
            }
            else {
                ImgArrayID = parseInt(document.getElementById("ImgArrayID" + i).innerHTML);
            }
            para1 = parseInt(document.getElementById("para1" + i).innerHTML);
            para2 = parseInt(document.getElementById("para2" + i).innerHTML);
            Odstock = parseInt(document.getElementById("Odstock" + i).innerHTML);
            Odprice = parseInt(document.getElementById("Odprice" + i).innerHTML);
            if (ImgArrayID == 2) {
                if (para1 == 0 || para2 == 0) {
                    flg = false;
                }
                else {
                    url = url + productid + "_" + para1 + "_" + para2 + "_" + ordercount + "|";
                }
            }
            else if (ImgArrayID == 1) {
                if (para1 == 0) {
                    flg = false;
                }
                else {
                    url = url + productid + "_" + para1 + "_0_" + ordercount + "|";
                }
            }
            else {
                url = url + productid + "_0_0_" + ordercount + "|";
            }
            if (Odstock == 0 && checkstock == true) {
                flg1 = false;
            }
        }
        if (flg == false) {
            alert("您没有选择所有订购参数！");
        }
        else {
            if (_StockCheck == 1 && (flg1 == false || (count == 1 && ordercount > Odstock))) {
                alert("商品没有库存！");
            }
            else {
                if (actionTypeid == 1) {
                    if (_UserClick == 0) {
                        alert("您还没有登录！请先登录！");
                        window.location.href = "/member/login.aspx";
                    }
                    else {
                        window.location.href = url;
                    }
                }
                else {
                    AddtoCart(url);
                }
            }
        }
    }
}
function tocartTeam(count, actionTypeid) {
    var _StockCheck = parseInt(document.getElementById("StockCheck").innerHTML);
    var _UserClick = parseInt(document.getElementById("UserClickCart").innerHTML);
    var flg, flg1, para1, para2, productid, ImgArrayID, Odstock, Odprice, url;
    flg = true;
    flg1 = true;
    var ordercount = 1;
    if (actionTypeid == 1) {
        url = "/member/tocart.aspx?packageid=0&cart=";
    } else {
        url = "/member/tocartonly.aspx?packageid=0&cart=";
    }
    productid = parseInt(document.getElementById("Sproductid" + count).innerHTML);
    ImgArrayID = parseInt(document.getElementById("ImgArrayID_" + count).innerHTML);
    ordercount = parseInt(document.getElementById("ordercount" + count).value);
    para1 = parseInt(document.getElementById("para1" + count).innerHTML);
    para2 = parseInt(document.getElementById("para2" + count).innerHTML);
    Odstock = parseInt(document.getElementById("Odstock" + count).innerHTML);
    Odprice = parseInt(document.getElementById("Odprice" + count).innerHTML);
    if (Odstock == 0 || ordercount > Odstock) {
        flg1 = false;
    }
    if (ImgArrayID == 2) {
        if (para1 == 0 || para2 == 0) {
            flg = false;
        }
        else {
            url = url + productid + "_" + para1 + "_" + para2 + "_" + ordercount + "|";
        }
    }
    else if (ImgArrayID == 1) {
        if (para1 == 0) {
            flg = false;
        }
        else {
            url = url + productid + "_" + para1 + "_0_" + ordercount + "|";
        }
    }
    else {
        url = url + productid + "_0_0_" + ordercount + "|";
    }
    if (flg == false) {
        alert("您没有选择订购参数！");
    }
    else {
        if (flg1 == false && _StockCheck == 1) {
            alert("商品没有库存！");
        }
        else {
            if (actionTypeid == 1) {
                if (_UserClick == 0) {
                    alert("您还没有登录！请先登录！");
                    window.location.href = "/member/login.aspx";
                }
                else {
                    window.location.href = url;
                }
            }
            else {
                AddtoCart(url);
            }
        }
    }
}
function AddtoCart(url) {
    var _UserClick = parseInt(document.getElementById("UserClickCart").innerHTML);
    if (_UserClick == 0) {
        alert("您还没有登录！请先登录！");
        window.location.href = "/member/login.aspx";
    }
    else {
        _UserClick = _UserClick + 1;
        document.getElementById("UserClickCart").innerHTML = _UserClick;
        cart_send_request(url + "&guid=" + _UserClick);
    }
}
function cart_send_request(url) {
    cart_http_request = false;
    if (window.XMLHttpRequest) {
        cart_http_request = new XMLHttpRequest();
        if (cart_http_request.overrideMimeType) {
            cart_http_request.overrideMimeType("text/html");
        }
    }
    else if (window.ActiveXObject) {
        try {
            cart_http_request = new ActiveXObject("Xsxml2.XMLHTTP");
            cart_http_request.setRequestHeader("Content-Type", "text/xml");
        }
        catch (e) {
            try {
                cart_http_request = new ActiveXObject("Microsoft.XMLHTTP");
                cart_http_request.setRequestHeader("Content-Type", "text/xml");
            } catch (e) { }
        }
    }
    if (!cart_http_request) { return false; alert('false.'); }
    cart_http_request.onreadystatechange = cart_processRequest;
    cart_http_request.open("get", url, true); cart_http_request.send(null);
}
function cart_processRequest() {
    if (cart_http_request.readyState == 4) {
        if (cart_http_request.status == 200) {
            var arrayAsJSONText = cart_http_request.responseText;
            var arrmp = arrayAsJSONText.split("|");
            if (parseInt(arrmp[1]) != 0 && parseInt(arrmp[2]) != 0) {
                document.getElementById("cartItemsMsg").innerHTML = "当前 " + arrmp[0] + " 件商品，￥" + arrmp[1] + " 元（" + arrmp[2] + "积分）";
                document.getElementById("cartdivView").innerHTML = "共<span id=\"ctotalnumber\">" + arrmp[0] + "</span>件;￥<span id=\"ctotalprice\">" + arrmp[1] + "</span>;<span id=\"ctotalcent\">" + arrmp[2] + "</span>分&nbsp;";
            }
            else if (parseInt(arrmp[1]) != 0) {
                document.getElementById("cartItemsMsg").innerHTML = "当前 " + arrmp[0] + " 件商品，￥" + arrmp[1] + " 元";
                document.getElementById("cartdivView").innerHTML = "共<span id=\"ctotalnumber\">" + arrmp[0] + "</span>件;￥<span id=\"ctotalprice\">" + arrmp[1] + "</span><span id=\"ctotalcent\"></span>&nbsp;";
            }
            else {
                document.getElementById("cartItemsMsg").innerHTML = "当前 " + arrmp[0] + " 件商品，" + arrmp[2] + "积分";
                document.getElementById("cartdivView").innerHTML = "共<span id=\"ctotalnumber\">" + arrmp[0] + "</span>件;<span id=\"ctotalprice\"></span><span id=\"ctotalcent\">" + arrmp[2] + "</span>分&nbsp;";
            }
            showcart();
        }
        else {
            //alert("程序调用失败!");
        }
    }
}