﻿var cartIsShow = false;
var cartIsShow2 = false;
function ShowHideCart() {

    if ($("#cartbody").css("display") == "none") {
        $("#cartbody").show();
        $("#cartSub").removeClass("open");
        $("#cartSub").addClass("close");
        SetCookie("ShoppCartOpenOrClose", "0");
    }
    else {
        $("#cartbody").hide();
        $("#cartSub").removeClass("close");        
        $("#cartSub").addClass("open");
        SetCookie("ShoppCartOpenOrClose", "1");
    }    
}
function ShowHideCart2() {
    var flag = getCookie("ShoppCartOpenOrClose");
    
    if ((flag == null || flag == "0")) {
        $("#cartbody").show();
        $("#cartSub").removeClass("open");
        $("#cartSub").addClass("close");
        //SetCookie("ShoppCartOpenOrClose", "1");
    }
    else {
        //$("#cartbody").hide();
        $("#cartSub").removeClass("close");
        $("#cartSub").addClass("open");
       // SetCookie("ShoppCartOpenOrClose", "0");
    }
}
function divCartDisplay(obj, e) {
    if (e.currentTarget) {
        if (e.relatedTarget != obj) {
            if (obj != e.relatedTarget.parentNode) {
                $("#upCart").hide();
            }
        }
    } else {
        if (e.toElement != obj) {
            if (obj != e.toElement.parentNode) {
                $("#upCart").hide();
            }
        }
    }
}

function divCartPlay(type) {

    if (type == 1) {
        $("#upCart").show();
    }
    else {
        $("#upCart").hide();
    }
}
function divPosition() {
    //    var movetop = $(document).scrollTop() + 233;
    //    var moveleft = document.body.clientWidth + document.body.scrollLeft - 174;

    var movetop =  43;
    var moveleft =  548;
    $("#upCart").css("top", movetop + "px");
    $("#upCart").css("left", moveleft + "px");
}
//写cookies函数
function SetCookie(name, value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 1; //此 cookie 将被保存 30 天
    var exp = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

$(document).ready(function() {
    try {
        //divPosition();
        //ShowHideCart2();
        $("#upCart").hide();
        $("#topCart").mouseover(function() { $("#upCart").show(); cartIsShow2 = true; });
        $("#topCart").mouseleave(function(event) { window.setTimeout(function() { if (!cartIsShow) { $("#upCart").hide(); cartIsShow2 = false; } }, 20) });
        $("#upCart").mouseover(function() { cartIsShow = true; cartIsShow2 = false; });
        $("#upCart").mouseleave(function() { window.setTimeout(function() { if (!cartIsShow2) { $("#upCart").hide(); } }, 20); cartIsShow = false; })
    } catch (e) { }
});
//$(window).resize(function() {
//    //divPosition();
//});
//$(window).scroll(function() {

//    //divPosition();
//});
//处理显示的数据
function showleftDiv(json) {
    
    var tbody = "";
    var cartAll = "";
    var packbag = " 340908 340877 340866 340855 ";
    if (json.myCart.length == 0) {
        $("#cartBottom").hide();
        //更新头部信息
        $("#proCount").html("0");
        $("#cardmoney").html("0.00");
    }
    else {
        //                <tr>
        //                    <td colspan="3">
        //                        商品
        //                    </td>
        //                </tr>
        //                <tr>
        //                    <td>
        //                        单价
        //                    </td>
        //                    <td>
        //                        数量
        //                    </td>
        //                    <td>
        //                        删除
        //                    </td>
        //              </tr>
        var flagcount = 0;
        var sUrl = "";
        var trs = "";
        for (var i = json.myCart.length - 1; i >= 0; i--) {
            if (flagcount > 6) {
                break;
            }
            else {
                sUrl = packbag.indexOf(json.myCart[i].SkuId + " ") > 0 ? "<a href='javascript:void(0)'>" + json.myCart[i].ItemName + "</a>" : "<a href='/ProDetail.aspx?p=" + json.myCart[i].SkuId + "' target='_blank'>" + json.myCart[i].ItemName + "</a>";

                trs = "<li><p>";
                trs += sUrl + "</p>";

                trs += "<em>￥" + json.myCart[i].UnitSellingPrice + "x";
                trs += json.myCart[i].Quantity + "</em>";
                trs += "<span><a href=\"javascript:DelItem(" + i + ")\">" + RS_btn_Del + "</span></a></li>";
                tbody = tbody + '' + trs;
            }
            flagcount++;
        }
        $("#cartBottom").show();

        //更新头部信息
        $("#proCount").html(json.TotalPieces);
        $("#cardmoney").html(json.TotalPrices);
    }
    cartAll += "<p>";
    cartAll += RS_js_TotalPro.replace("{0}", "<strong>" + json.TotalPieces + "</strong>");
    
    if (json.myCart.length > 7) {
        cartAll += "<a href='/Shoppingcart.aspx'><span style='color:red'> &nbsp;" + RS_lt_LookMore + "</span></a>";
    }
    cartAll += "</p>";
    cartAll += "<p>";
    cartAll += RS_js_TotalMoney + "<span style='color:red'>￥" + json.TotalPrices + "</span>" + RS_Yuan + "</p>";
    document.getElementById("cartItemlist").innerHTML = tbody;
    //$("#cartItemlist").html(tbody);
    $("#cartAll").html(cartAll);
    var ss = $("#cartItemlist").html();
    //alert(tbody);
    //alert(ss);
}
//处理显示的数据 已删除
function showleftDiv2(json) {
    var tbody = "";
    var packbag = " 340908 340877 340866 340855 ";
    if (json.myCart.length == 0) {
        $("#cartBottom").hide();
        //更新头部信息
        $("#proCount").html("0");
        $("#cardmoney").html("0.00");
    }
    else {
        //                <tr>
        //                    <td colspan="3">
        //                        商品
        //                    </td>
        //                </tr>
        //                <tr>
        //                    <td>
        //                        单价
        //                    </td>
        //                    <td>
        //                        数量
        //                    </td>
        //                    <td>
        //                        删除
        //                    </td>
        //              </tr>
        var flagcount = 0;
        for (var i = json.myCart.length - 1; i >= 0; i--) {
            if (flagcount > 6) {
                break;
            }
            else {
                var sUrl = packbag.indexOf(json.myCart[i].SkuId + " ") > 0 ? "<a href='javascript:void(0)'>" + json.myCart[i].ItemName + "</a>" : "<a href='/ProDetail.aspx?p=" + json.myCart[i].SkuId + "' target='_blank'>" + json.myCart[i].ItemName + "</a>";

                var trs = "<tr><td colspan=\"3\" style=\"padding-left:5px\">";
                //trs += "<a href='/ProDetail.aspx?p=" + json.myCart[i].SkuId + "' target='_blank'>" + json.myCart[i].ItemName + "</a></td></tr>";
                trs += sUrl + "</td></tr>";

                trs += "<tr><td style=\"padding-left:5px\">￥" + json.myCart[i].UnitSellingPrice + "</td>";
                trs += "<td>" + json.myCart[i].Quantity + "</td>";
                trs += "<td><a href=\"javascript:DelItem(" + i + ")\">" + RS_btn_Del + "</td>";
                tbody = tbody + '' + trs;
            }
            flagcount++;
        }
        $("#cartBottom").show();

        //更新头部信息
        $("#proCount").html(json.TotalPieces);
        $("#cardmoney").html(json.TotalPrices);
    }
    tbody += "<tr><td colspan=\"3\" style=\"padding-left:5px\">";
    tbody += RS_js_TotalPro.replace("{0}", json.TotalPieces);
    if (json.myCart.length > 7) {
        tbody += "<a href='/Shoppingcart.aspx'><span style='color:red'>" + RS_lt_LookMore + "</span></a>";
    }
    tbody += "</td></tr>";
    tbody += "<tr><td colspan=\"3\" style=\"padding-left:5px\">";
    tbody += RS_js_TotalMoney + "<span style='color:red'>￥" + json.TotalPrices + "</span>" + RS_Yuan + "</td></tr>";
    $("#cartItems").html(tbody);

}
//加加、减减
function showAddItem(skuId, type) {
    var qty = $("#txtQty" + skuId).val();
    if (/^[1-9][\d]*$/.test(qty)) {
        if (type == "add") {
            $("#txtQty" + skuId).val(parseInt(qty) + 1);
        }
        else {
            if (qty > 1) {
                $("#txtQty" + skuId).val(parseInt(qty) - 1);
            }
        }
    }
    else {
        alert(RS_js_NumberErr);
    }
}
//显示购物车的商品信息
function showCartInfo() {
    var date = new Date();
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "/DoshoppingCart.aspx?action=show&date=" + date.getTime(),
        success: showleftDiv
    });

}
//显示购物车中的信息(头部)
function showCartInfo2(currentHosturl) {
    $.ajax({
        type: "POST",
        dataType: "json",
        url: currentHosturl + "/DoshoppingCart.aspx?action=show&date=" + new Date().getTime(),
        success: function(json) {
            if (json.myCart.length == 0) {
                $("#proCount").html("0");
                $("#cardmoney").html("0.00");
            }
            else {
                $("#proCount").html(json.TotalPieces);
                $("#cardmoney").html(json.TotalPrices);
            }
        }
    });

}
//添加商品
function buyItem(skuId, imgpath) {
    var date = new Date();
    if (/^[1-9][\d]*$/.test(skuId)) {
        var qty = $("#txtQty" + skuId).val();
        //alert(skuId + "  " + qty);
        if (/^[1-9][\d]*$/.test(qty)) {
            var url = "/DoshoppingCart.aspx?action=Add&productId=" + skuId + "&qty=" + qty + "&imgpath=" + imgpath + "&date=" + date.getTime();
            $.getJSON(url, function(json) {
                if (json.successflag == "1") {
                    alert(RS_js_EnoughInventory);
                    showleftDiv(json);
                }
                else if (json.successflag == "2") {
                    alert(RS_js_EnoughInventory);
                    showleftDiv(json);
                }
                else if (json.successflag == "3" || json.successflag == "4") {                   
                    alert(RS_js_GroupBuyErr);
                    showleftDiv(json);
                }
                else if (json.successflag == "5") {
                    alert(RS_js_RestrictionErr);
                    showleftDiv(json);
                    }
                else if (json.successflag == "-1") {
                    alert(RS_js_ShipCartEnough);
                    showleftDiv(json);
                }

                else {
                    showleftDiv(json);
                }
            });
        }
        else {
            alert(RS_js_NumberErr);
        }
    }
    else {
        alert(RS_js_ProductUnExist);
    }
    //showCartInfo2();
}
function buyItem3(skuId, imgpath) {
    var date = new Date();
    if (/^[1-9][\d]*$/.test(skuId)) {

        var url = "/DoshoppingCart.aspx?action=Add&productId=" + skuId + "&qty=1&imgpath=" + imgpath + "&date=" + date.getTime();
        $.getJSON(url, function(json) {
            if (json.successflag == "1") {
                alert(RS_js_EnoughInventory);
                showleftDiv(json);
            }
            else if (json.successflag == "2") {
                alert(RS_js_EnoughInventory);
                showleftDiv(json);
            }
            else if (json.successflag == "3" || json.successflag == "4") {
                
                alert(RS_js_GroupBuyErr);
                showleftDiv(json);
            }
            else if (json.successflag == "5") {
                alert(RS_js_RestrictionErr);
                showleftDiv(json);
                }
            else {
                showleftDiv(json);
                alert(RS_js_ProductCartt);
            }
        });
    }
    else {
        alert(RS_js_ProductUnExist);
    }
    //showCartInfo2();
}
function buyItem2(obj, skuId, imgpath) {
    var oldstr = obj.value;
    var date = new Date();
    var qty = $("#txtQty" + skuId).val();
    //     alert(qty + " " + skuId);
    if (/^[1-9][\d]*$/.test(qty)) {
        var urls = "/DoshoppingCart.aspx?action=Add&productId=" + skuId + "&qty=" + qty + "&imgpath=" + imgpath + "&date=" + date.getTime();
        $.ajax({
            type: "POST",
            dataType: "json",
            url: urls,
            beforeSend: function() { obj.disabled = true; obj.value = RS_Running; }, //发送数据之前
            complete: function() { obj.disabled = false; obj.value = oldstr; }, //接收数据完毕
            success: function(json) {
               
                if (json.successflag == "1") {
                    alert(RS_js_EnoughInventory);
                    showleftDiv(json);
                }
                else if (json.successflag == "2") {
                    alert(RS_js_EnoughInventory);
                    showleftDiv(json);
                }
                else if (json.successflag == "3" || json.successflag == "4") {
                    alert(RS_js_GroupBuyErr);
                    showleftDiv(json);
                }
                else if (json.successflag == "5") {
                    alert(RS_js_RestrictionErr);
                    showleftDiv(json);
                }
                else if (json.successflag == "-1") {
                    alert(RS_js_ShipCartEnough);
                    showleftDiv(json);
                }
                else {
                    showleftDiv(json);
                }
                
            },
            error: function(e) {
                alert(e);
            }

        });

    }
    else {
        alert(RS_js_NumberErr);
    }

    //showCartInfo2();
}
//删除商品
function DelItem(itemIndex) {
    var date = new Date();
    //        $.get("DoshoppingCart.aspx?action=del&itemId="+itemIndex,function(data){
    //            //alert("Data loaaded:"+data);
    //        });
    //        //显示购物信息
    //        showCartInfo();
    $.getJSON("/DoshoppingCart.aspx?action=del&itemId=" + itemIndex + "&date=" + date.getTime(), showleftDiv);

    //showCartInfo2();
}
//处理回收站的数据
function showRecycleDiv(json) {
    //var tbody = "回收站：<br/>";
    var tbody = "";
    var packbag = " 340908 340877 340866 340855 ";
    if (json.myCart.length == 0) {
        $("#showInfo").html(RS_js_RecycleEmpty);
    }
    else {
        var trs = "<table class='table goodsList'>";
        trs += "<thead class=\"titleA\"><tr>";
        //trs+="<td class=\"proImg\"><img alt='' src='"+json.myCart[i].ImageUrl+"' alt=''/></td>";
        trs += "<td class='name'><h4>"+RS_lt_ProNm+"</h4></td>";
        trs += "<td class='price'>" + RS_lt_Price + "</td>";
        trs += "<td class='number'>" + RS_lt_Count + "</td>";
        trs += "<td class='total'>"+RS_lt_Total+"</td>";
        trs += "<td align='left' >" + RS_js_RellbackBuy + "</td>";
        trs += "<td align='left' >" + RS_js_AddFavor + "</td>";
        trs += "</tr></thead><tbody>";
        for (var i = 0; i < json.myCart.length; i++) {
            var sUrl = packbag.indexOf(json.myCart[i].SkuId + " ") > 0 ? "<a href='javascript:void(0)'>" + json.myCart[i].ItemName + "</a>" : "<a href='/ProDetail.aspx?p=" + json.myCart[i].SkuId + "' target='_blank'>" + json.myCart[i].ItemName + "</a>";

            trs += "<tr>";
            //trs+="<td class=\"proImg\"><img alt='' src='"+json.myCart[i].ImageUrl+"' alt=''/></td>";
            trs += "<td class='name'><h4>" + sUrl + "</h4></td>";
            trs += "<td class='price'>" + json.myCart[i].UnitSellingPrice + "</td>";
            trs += "<td class='number'>" + json.myCart[i].Quantity + "</td>";
            trs += "<td class='total'><span>" + json.myCart[i].ItemTotal + "</span></td>";
            trs += "<td align='center'><a href=\"javascript:rebuyItem(" + json.myCart[i].SkuId + ")\">" + RS_js_RellbackBuy + "</a></td>";
            //<a href=\"javascript:void(0)\">添加收藏</a>
            trs += "<td align='center'><a href=\"javascript:AddFactionvItem(" + json.myCart[i].SkuId + ")\">";
            if (json.myCart[i].SkuId != 340908 && json.myCart[i].SkuId != 340877 && json.myCart[i].SkuId != 340866 && json.myCart[i].SkuId != 340855) {
                trs += RS_js_AddFavor ;
            }
            trs += "</a></td>";
            trs += "</tr>";
        }
        trs += "</tbody></table>";
        tbody = tbody + '' + trs;
        $("#showInfo").html(tbody);
    }
}
//显示回收站的信息
function showRecycleCartInfo() {
    var date = new Date();
    $.getJSON("/DoshoppingCart.aspx?action=showDel&date=" + date.getTime(), showRecycleDiv);

}
//清空购物车
function clearCart() {
    var date = new Date();
    //         $.get("DoshoppingCart.aspx?action=clearall&date="+date.getTime(),function(data){
    //            //alert("Data loaaded:"+data);
    //        });
    $.getJSON("/DoshoppingCart.aspx?action=clearall&date=" + date.getTime(), showleftDiv);
}
//清空购物车
function clearshopcart() {
    if (confirm(RS_js_AskClearCart)) {
        clearCart2();
        //clearCart();
        //loadShoppingCart();
    }
}
//去结算
function linkShoppingCart() {
    //应先判断是否已经又购物
    document.location.href = "ShoppingCart.aspx";
}
//继续购物
function linkgoShopping() {
    document.location.href = "ProductList.aspx";
}
//*************************************************shoppingCart
//显示shoppingCart的信息
function loadShoppingCart() {
    var date = new Date();
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "/DoshoppingCart.aspx?action=updateAndShow&date=" + date.getTime(),
        success: showCartInfoDIv
    });
}
//处理购物车的数据
function showCartInfoDIv(json) {   
    var tbody = "";
    var packbag = " 340908 340877 340866 340855 ";
    if (json.myCart.length == 0) {
        //$("#cartPackage").hide();
        tbody += "<tr><tr class=\"lineC\"><td colspan='6'>"+RS_js_ShoppingCartEmpty+"</a>";
        //更新头部信息
        $("#proCount").html("0");
        $("#cardmoney").html("0.00");
        $("#totalPackagePrices").html("0.00");
    }
    else {
        //           <tr>
        //                <td>
        //                    商品名称
        //                </td>
        //                <td>
        //                    原单价
        //                </td>
        //                <td>
        //                    销售单价
        //                </td>
        //                <td>
        //                    数量
        //                </td>
        //                <td>
        //                    删除
        //                </td>
        //           </tr>
        for (var i = 0; i < json.myCart.length; i++) {
            var uniprice = new Number(json.myCart[i].UnitSellingPrice);
            var currentprice = new Number(json.myCart[i].UnitPrice);
            var totolprice = new Number(json.myCart[i].ItemTotal);
            var sUrl = packbag.indexOf(json.myCart[i].SkuId + " ") > 0 ? "<a href='javascript:void(0)'>" + json.myCart[i].ItemName + "</a>" : "<a href='/ProDetail.aspx?p=" + json.myCart[i].SkuId + "' target='_blank'>" + json.myCart[i].ItemName + "</a>";
            var trs = "<tr class=\"lineC\">";
            trs += "<td class='proImg'><img alt='' src='" + json.myCart[i].ImageUrl + "' alt='' width=\"49px\"/></td>";
            trs += "<td class='proImg'>" + json.myCart[i].SkuId + "</td>";

            trs += "<td class='name'><h4>" + sUrl + "</h4></td>";
            trs += "<td class='price'>" + currentprice.toFixed(2) + "</td>";
            trs += "<td class='price'>" + uniprice.toFixed(2) + "</td>";
            trs += "<td class='number'><input class=\"inputAdd\" onclick='UpdateItemAddone(" + i + "," + json.myCart[i].Quantity + ");' name=\"\" type=\"button\" /><input class=\"inputC showNumber\" onchange='changeQtyText(" + i + "," + json.myCart[i].Quantity + ",this.value)' id='txtCartqty" + i + "' value='" + json.myCart[i].Quantity + "'/><input class=\"inputSubtract\" onclick='UpdateItemMiniteone(" + i + "," + json.myCart[i].Quantity + ")' name=\"\" type=\"button\" /></td>";
            trs += "<td class='total'><span>" + totolprice.toFixed(2) + "</span></td>";
            trs += "<td class='control'><input class=\"delete\" name=\"\" onclick=\"javascript:DelItem3(" + i + ")\" type=\"button\" /></td>";
            tbody = tbody + '' + trs;
        }
        
        $("#cartPackage").show();
        //更新头部信息
        $("#proCount").html(json.TotalPieces);
        $("#cardmoney").html(json.TotalPrices);
        $("#totalPackagePrices").html(json.TotalPackagePrices);
    }
    //       alert(tbody);
    //       tbody+="<tr align='right'><td colspan=\"4\">";
    //       tbody+="共"+json.TotalPieces+"件商品!</td></tr>";
    $("#totalItemPrices").html(json.TotalPrices);
    $("#totalPoints").html(json.TotalPoint);
    $("#totalRefunds").html(json.TotalRefundPrice);
    $("#cartItemInfo").html(tbody);
    var prc = $("#totalPackagePrices").html();
    if (parseFloat(prc) > 0) {
        var radneedPackageList = document.forms[0].radneedPackage;
        for (i = 0; i < radneedPackageList.length; i++) {
            if (radneedPackageList[i].value == "1") {
                radneedPackageList[i].checked = true;
                break;
            }
        }
    }
    try {
        if (document.getElementById("radiffalse").checked) {
            changeCheckpageck('false');
        }
    } catch (e) { }
}
//恢复购买
function rebuyItem(skuId) {
    //        showRecycleCartInfo();
    var date = new Date();
    $.getJSON("/DoshoppingCart.aspx?action=backbuy&productId=" + skuId + "&date=" + date.getTime(), function(json) {
        showCartInfoDIv(json.myCart[0]);
        showRecycleDiv(json.myCart[1]);
    });
}
//增加一件
function UpdateItemAddone(itemindex, qty) {
    var newqty = qty + 1;
    var date = new Date();
    $.getJSON("/DoshoppingCart.aspx?action=updateItem&itemid=" + itemindex + "&qty=" + newqty + "&date=" + date.getTime(), function(json) {
        if (json.successflag == "1") {
            alert(RS_js_EnoughInventory);
            $("#txtCartqty" + itemindex).attr("value", qty);
        }
        else if (json.successflag == "2") {
        alert(RS_js_EnoughInventory);
            $("#txtCartqty" + itemindex).attr("value", qty);
            showleftDiv(json);
        }
        else if (json.successflag == "3" || json.successflag == "4") {
            
            alert(RS_js_GroupBuyErr);
            showleftDiv(json);
        }
        else if (json.successflag == "5") {
            alert(RS_js_RestrictionErr);
            showleftDiv(json);
        }
        else {
            //              $("#txtCartqty"+itemindex).attr("value",newqty);//修改显示数量
            showCartInfoDIv(json);
        }
    });
}
//删除所买的购物袋
function deleteAllPackage() {
    if (!confirm(RS_js_ConfirmDelBag)) {
        return;
    }
    else {
        var date = new Date();
        $.getJSON("/DoshoppingCart.aspx?action=delpackage&date=" + date.getTime(), function(json) {
            showCartInfoDIv(json);
        });
        //alert("fff");
    }
}
//退一件
function UpdateItemMiniteone(itemindex, qty) {
    if (qty <= 0) {
        return;
    }
    if (qty == 1) {
        if (!confirm(RS_js_ConfirmDelPro)) {
            return;
        }
        else {
            //删除商品
            DelItem2(itemindex);
        }
    }
    else {
        var newqty = qty - 1;
        var date = new Date();
        $.getJSON("/DoshoppingCart.aspx?action=updateItem&itemid=" + itemindex + "&qty=" + newqty + "&date=" + date.getTime(), function(json) {
            if (json.successflag == "1") {
                alert(RS_js_EnoughInventory);
                $("#txtCartqty" + itemindex).attr("value", qty);
                showCartInfoDIv(json);
            }
            else if (json.successflag == "2") {
            alert(RS_js_EnoughInventory);
                $("#txtCartqty" + itemindex).attr("value", qty);
                showCartInfoDIv(json);
            }
            else {
                showCartInfoDIv(json);
            }
        });
    }
}
//修改购买数量
function changeQtyText(itemindex, oldqty, qty) {
    if (/^[1-9][\d]*$/.test(qty)) {
        if (qty == 0) {
            if (!confirm(RS_js_ConfirmDelPro)) {
                return;
            }
            else {
                //删除商品
                DelItem2(itemindex);
            }
        }
        else {
            var date = new Date();
            $.getJSON("/DoshoppingCart.aspx?action=updateItem&itemid=" + itemindex + "&qty=" + qty + "&date=" + date.getTime(), function(json) {
                if (json.successflag == "1") {
                    alert(RS_js_EnoughInventory);
                    $("#txtCartqty" + itemindex).attr("value", oldqty);
                    showCartInfoDIv(json);
                }
                else if (json.successflag == "2") {
                alert(RS_js_EnoughInventory);
                    $("#txtCartqty" + itemindex).attr("value", oldqty);
                    showCartInfoDIv(json);
                }
                else if (json.successflag == "3" || json.successflag == "4") {
                    
                    alert(RS_js_GroupBuyErr);
                    showleftDiv(json);
                    showCartInfoDIv(json);
                }
                else if (json.successflag == "5") {
                    alert(RS_js_RestrictionErr);
                    showleftDiv(json);
                }
                else {
                    showCartInfoDIv(json);
                }
            });
        }
    }
    else {
        alert(RS_js_InputNumberErr);
        $("#txtCartqty" + itemindex).attr("value", oldqty);
    }
}
//删除shoppingCart的信息
function DelItem2(itemIndex) {
    var date = new Date();
    $.getJSON("/DoshoppingCart.aspx?action=DelshowRecyle&itemId=" + itemIndex + "&date=" + date.getTime(), function(json) {
        showCartInfoDIv(json.myCart[0]);
        showRecycleDiv(json.myCart[1]);
    });
    //   showRecycleCartInfo();
}
function DelItem3(itemIndex) {
    if (!confirm(RS_js_ConfirmDelPro)) {
        return false;
    }
    else {
        var date = new Date();
        $.getJSON("/DoshoppingCart.aspx?action=DelshowRecyle&itemId=" + itemIndex + "&date=" + date.getTime(), function(json) {
            showCartInfoDIv(json.myCart[0]);
            showRecycleDiv(json.myCart[1]);
        });
    }
}
//清空购物车
function clearCart2() {
    var date = new Date();
    $.getJSON("/DoshoppingCart.aspx?action=clearall&date=" + date.getTime(), showCartInfoDIv);
}
function changeCheckpageck(flag) {
    if (flag == "true") {
        if ($("#cartPackage").css("display") == "none") {
            $("#cartPackage").show();
        }
    }
    else {
        var prc = $("#totalPackagePrices").html();
        //alert(prc);
        if (parseFloat(prc) > 0) {
            deleteAllPackage();
            //            alert("请删除购物车中的购物袋！");
            //            var radneedPackageList=document.forms[0].radneedPackage;
            //            for(i=0;i<radneedPackageList.length;i++){
            //                    if(radneedPackageList[i].value=="1"){
            //                        radneedPackageList[i].checked=true;
            //                        break;
            //                    }
            //            }   
        }
        else {
            $("#cartPackage").hide();
        }
    }
}
//购物袋--start
function onfocuscheck(type) {
    var radpackagelist = document.forms[0].radpackageProduct;
    for (i = 0; i < radpackagelist.length; i++) {
        if (radpackagelist[i].value == type) {
            radpackagelist[i].checked = true;
            break;
        }
    }
}
function savePackageInfo(type, obj) {
    var regStr = /^[1-9][\d]*$/;
    if (!regStr.test(obj.value)) {
        $("#txtQty" + type).val("");
    }
    else {
        var allpakageprice = parseFloat($("#totalPackagePrices").html());
        var unitprice = parseFloat($("#PackageProductPrice" + type).html());
        var selectPricesum = unitprice * obj.value;
        allpakageprice = allpakageprice + selectPricesum;

        $("#totalPackagePrices").html("" + allpakageprice.toFixed(2));
        //alert(allpakageprice.toFixed(2));

        //----加入购物车(未定义)
        //buyItem(type);

    }
}
function buyPrakcageInfo(type, imgpath) {
    var regStr = /^[1-9][\d]*$/;
    if (!regStr.test($("#txtQty" + type).val())) {
        alert(RS_js_InputBuyCount);
        return;
    }
    else {
        //alert(type+":"+obj.value);
        var qty = $("#txtQty" + type).val();
        var url = "/DoshoppingCart.aspx?action=Add&productId=" + type + "&qty=" + qty + "&imgpath=" + imgpath + "&date=" + new Date().getTime();
        $.getJSON(url, function(json) {
            if (json.successflag == "1") {
                alert(RS_js_EnoughInventory);
            }
            else if (json.successflag == "2") {
            alert(RS_js_EnoughInventory);
        }
        else if (json.successflag == "3" || json.successflag == "4") {
           
            alert(RS_js_GroupBuyErr);
            showleftDiv(json);
        }
        else if (json.successflag == "5") {
            alert(RS_js_RestrictionErr);
            showleftDiv(json);
        }
        else {
                showCartInfoDIv(json);
            }
        });
    }
    //     var prc=$("#totalPackagePrices").html();
    //         //alert(prc);
    //     if(parseFloat(prc)>0){
    //        var radneedPackageList=document.forms[0].radneedPackage;
    //        for(i=0;i<radneedPackageList.length;i++){
    //                if(radneedPackageList[i].value=="1"){
    //                    radneedPackageList[i].checked=true;
    //                    break;
    //                }
    //        }   
    //     }
}
function enterSavaPackage() {

}
//购物袋--end

//去结算
function goGreateOrder() {
    var tPrice = $("#cardmoney").html();
    if (tPrice == "0.00") {
        //        $("#msg").html("您的购物车是空的!");
        alert(RS_js_ShoppingCartEmpty);
        return;
    }
    var date = new Date();
    $.get("/DoshoppingCart.aspx?action=greateOrder&date=" + date.getTime(), function(data) {
        window.location = data;
    });
}

//去收藏
function AddFactionvItem(itemId) {
    var date = new Date();
    $.ajax({
        type: "POST",
        url: "/Ajax/Ajax.ashx?type=AddFavorite&pid=" + itemId + "&date=" + date.getTime(),
        success: function(data) {
            if (data == "FALSE") {
                alert(RS_js_AddFavorErr);
            }
            else {
                if (data == "OK") {
                    alert(RS_js_AddFavorSuccess);
                }
                else {
                    alert(RS_js_AddFavorFaile);
                }
            }
        }
    });
}
