$(document).ready(function () {
    if (document.getElementById("ShopAddressList")) {
        $("#ShopAddressList li").each(function () {
            $(this).click(function () { ShopAddressClick(this) });
            if ($(this).find(".def").html() != "")
                ShopAddressClick(this);
        });        
    }
});

//选择尺码
function SelectedSize(obj, val) {
    $(obj).parent().find("a").removeClass("on");
    $(obj).addClass("on");
    $("#CartSize").val(val);
}

//选择颜色
function SelectedColor(obj, val) {
    $(obj).parent().find("a").removeClass("on");
    $(obj).addClass("on");
    $("#CartColor").val(val);
}

//产品件数加减
function NumberJiaOrJian(obj, bit) { }

//删除购物车产品
function ShopCartDelete(id, url) {
    if (confirm("确定删除吗?")) {
        ShopCartLoadBefore();
        $.get(url, { Action: "get", type: "shopcartdelete", id: id, time: Math.random() }, function (data, textStatus) { ShopCartLoad(); });
    }
}

//清空购物车
function ShopCartClear(url) {
    if (confirm("确定清空购物车吗?")) {
        ShopCartLoadBefore();
        $.get(url, { Action: "get", type: "shopcartclear", time: Math.random() }, function (data, textStatus) { ShopCartLoad(); });
    }
}

//修改购物车件数
function ShopCartUpdate(id, obj, url) {
    if (Number(obj.value) > 0) {
        ShopCartLoadBefore();
        $.get(url, { Action: "get", type: "shopcartupdate", id: id, number: obj.value, time: Math.random() }, function (data, textStatus) { ShopCartLoad(); });
    } else {
        obj.select();
    }
}
//件数+1
function ShopCartUpdateJia(id, obj, url) {
    var input = $("#ShopCart").find(".ShopCartUpdate").eq(obj - 1);
    input.val(Number(input.val()) + 1);
    ShopCartUpdate(id, input.get(0), url);
}
//件数-1
function ShopCartUpdateJian(id, obj, url) {
    var input = $("#ShopCart").find(".ShopCartUpdate").eq(obj - 1);
    if (Number(input.val()) > 1) {
        input.val(Number(input.val()) - 1);
        ShopCartUpdate(id, input.get(0), url);
    }
}

//继续购物
function ShopCartShopping(url) { location.href = url; }
//下单付款
function ShopCartAddress(url) { location.href = url; }

//购物车加载前
function ShopCartLoadBefore() {
    if (document.getElementById("cartload"))
        $("#cartload").show();
}

//重新加载购物车列表
function ShopCartLoad() {
    $(".ShopCart .DynamicHtml").each(function () {
        DynamicHtml($(this));
    });
}

//删除购物车产品
function ShopAddressDelete(id, url) {
    if (confirm("确定删除吗?")) {
        $.get(url, { Action: "get", type: "shopaddressdelete", id: id, time: Math.random() },
            function (data, textStatus) {
                DynamicHtml($("#MemberShopAddress .DynamicHtml"));
        });
    }
}

//收件人地址copy付款人地址
function BillingToShopping() {
    $("#ShippingName").val($("#BillingName").val());
    $("#ShippingAddress").val($("#BillingAddress").val());
    $("#ShippingZip").val($("#BillingZip").val());
    $("#ShippingTel").val($("#BillingTel").val());
    $("#ShippingMobile").val($("#BillingMobile").val());
}

//获取选中收件人信息
function ShopAddressClick(obj) {
    var objattr = eval("(" + $(obj).find("label").html() + ")");
    $("#BillingName").val(objattr.BillingName);
    $("#BillingCountry").val(objattr.BillingCountry);
    $("#BillingProvince").val(objattr.BillingProvince);
    $("#BillingCity").val(objattr.BillingCity);
    $("#BillingAddress").val(objattr.BillingAddress);
    $("#BillingZip").val(objattr.BillingZip);
    $("#BillingTel").val(objattr.BillingTel);
    $("#BillingMobile").val(objattr.BillingMobile);

    $("#ShippingName").val(objattr.ShippingName);
    $("#ShippingCountry").val(objattr.BillingCountry);
    $("#ShippingProvince").val(objattr.BillingProvince);
    $("#ShippingCity").val(objattr.BillingCity);
    $("#ShippingAddress").val(objattr.ShippingAddress);
    $("#ShippingZip").val(objattr.ShippingZip);
    $("#ShippingTel").val(objattr.ShippingTel);
    $("#ShippingMobile").val(objattr.ShippingMobile);
}