function AddCoupon(){
	var couponCode = $('#couponCode').val();
	if(couponCode.length==0|| couponCode.length<30){
		alert("抵用券号码不能为空或者不正确");
		$('#couponCode').focus();
		return;
	}else{
		$.ajax({
            url: "/Shop.do",
            type: "post",
            data: "action=addcoupon&couponCode=" + couponCode,
            dataType: "json",
            async: false,
            cache: false,
            beforeSend: function(){
                showExeMsg();
            },
            complete: function(){
                hiddenExeMsg();
            },
            success: function(msg){
                if (msg.success == true && msg.msg == "ok") {
                    location.reload();
                }
                else {
                    alert(msg.msg);
                }
            }
        });
	}
}
function UserAddCoupons(){
    var claimCode = $("#claimCode").val();
    if (claimCode.length == 0 || claimCode.length < 30 || claimCode.length > 40) {
        $('#error_msg').hide();
        $("#error_msg").html("优惠券号码不能为空,或号码不正确");
        $('#error_msg').show("fast");
        return;
    }
    else {
        $.ajax({
            url: "/Member.do",
            type: "post",
            data: "action=addcoupon&claimCode=" + claimCode,
            dataType: "json",
            async: false,
            cache: false,
            beforeSend: function(){
                showExeMsg();
            },
            complete: function(){
                hiddenExeMsg();
            },
            success: function(msg){
                if (msg.success == true && msg.msg == "ok") {
                    location.reload();
                }
                else {
                    $('#error_msg').hide();
                    $("#error_msg").html(msg.msg);
                    $('#error_msg').show("fast");
                }
            }
        });
    }
}
function DeleteFavorite(id){

        if (confirm("确认要删除吗？")) {
            $.ajax({
                url: "/Member.do?action=deleteonefavorite&id=" + id,
                dataType: "json",
                async: false,
                cache: false,
                beforeSend: function(){
                    showExeMsg();
                },
                complete: function(){
                    hiddenExeMsg();
                },
                success: function(msg){
                    if (msg.success == true && msg.msg == "ok") {
                        location.reload();
                    }
                    else {
                        alert(msg.msg);
                    }
                }
            });
        }
}
function DeleteMoreFavorite(){
	var ids = [];
    $("input[name=box][checked]").each(function(){
        ids.push($(this).val());
    });
    ids = ids.join(',');
	if (ids != null && ids.length>0) {
			if (confirm("确认删除选中的收藏吗？")) {
				$.ajax({
					url: "/Member.do",
					type: "post",
					data: "action=deletemorefavorite&box=" + ids,
					dataType: "json",
					async: false,
					cache: false,
					beforeSend: function(){
						showExeMsg();
					},
					complete: function(){
						hiddenExeMsg();
					},
					success: function(msg){
						if (msg.success == true && msg.msg == "ok") {
							location.reload();
						}
						else {
							alert(msg.msg);
						}
					}
				});
			}
	}else{
		alert("请选择要删除的对象","警告对话框");
	}
}
function deleteAddress(id){
	if (confirm("确认要删除吗？")) {
            $.ajax({
                url: "/Member.do?action=deleteaddress&id=" + id,
                dataType: "json",
                async: false,
                cache: false,
                beforeSend: function(){
                    showExeMsg();
                },
                complete: function(){
                    hiddenExeMsg();
                },
                success: function(msg){
                    if (msg.success == true && msg.msg == "ok") {
                        location.reload();
                    }
                    else {
                        alert(msg.msg);
                    }
                }
            });
        }
}
function DeleteProductReview(id){
	if (confirm("确认要删除吗？")) {
            $.ajax({
                url: "/Member.do?action=deleteevaluate&id=" + id,
                dataType: "json",
                async: false,
                cache: false,
                beforeSend: function(){
                    showExeMsg();
                },
                complete: function(){
                    hiddenExeMsg();
                },
                success: function(msg){
                    if (msg.success == true && msg.msg == "ok") {
                        location.reload();
                    }
                    else {
                        alert(msg.msg);
                    }
                }
            });
        }
}
//设置购物车里的商品数量
function setProductCount(productid,str){
	var actionStr = "";
	if(str=="reduce"){
		actionStr="productcountreduce";
	}else if(str=="add"){
		actionStr="productcountincrease";
	}
	$.ajax({
                url: "/Shop.do?action="+actionStr+"&id=" + productid,
                dataType: "json",
                async: false,
                cache: false,
                beforeSend: function(){
                    showExeMsg();
                },
                complete: function(){
                    hiddenExeMsg();
                },
                success: function(msg){
                    if (msg.success == true && msg.msg == "ok") {
                        location.reload();
                    }
                    else {
                        alert(msg.msg);
                    }
                }
            });
}
function ClearAllCart(){
var ids = [];
    $("input[name=box][checked]").each(function(){
        ids.push($(this).val());
    });
    ids = ids.join(',');
	if (ids != null && ids.length>0) {
			if (confirm("确认删除选中的收藏吗？")) {
				$.ajax({
					url: "/Shop.do",
					type: "post",
					data: "action=clearallcart&box=" + ids,
					dataType: "json",
					async: false,
					cache: false,
					beforeSend: function(){
						showExeMsg();
					},
					complete: function(){
						hiddenExeMsg();
					},
					success: function(msg){
						if (msg.success == true && msg.msg == "ok") {
							location.reload();
						}
						else {
							alert(msg.msg);
						}
					}
				});
			}
	}else{
		alert("请选择要删除的对象","警告对话框");
	}
	
}
function AddCart(){
	$("#addcart").submit();
	/*
	var productattr = $("#productAttr").html();
	var productid = $("#productId").val();
	var productCount = $("#productCount").val();
	if (productCount > 0) {
		$.ajax({
			url: "/Shop.do",
			type: "post",
			data: "action=addcart&id=" + productid + "&productCount=" + productCount + "&productAttr=" + productattr,
			dataType: "json",
			async: false,
			cache: false,
			beforeSend: function(){
				showExeMsg();
			},
			complete: function(){
				hiddenExeMsg();
			},
			success: function(msg){
				if (msg.success == true && msg.msg == "ok") {
					if(confirm("添加成功！是否现在进入购物车？")){
						location.href="/my_cart.vm";
					}
				}
				else {
					alert(msg.msg);
				}
			}
		});
	}else{
		alert("商品数量保证为1");
	}
	*/
}
function NowBuy(){
	$("#action").val("nowbuy");
	$("#addcart").submit();
}
function deleteItem(id){
	$.ajax({
                url: "/Shop.do?action=deleteitem&id=" + id,
                dataType: "json",
                async: false,
                cache: false,
                beforeSend: function(){
                    showExeMsg();
                },
                complete: function(){
                    hiddenExeMsg();
                },
                success: function(msg){
                    if (msg.success == true && msg.msg == "ok") {
                        location.reload();
                    }
                    else {
                        alert(msg.msg);
                    }
                }
            });
}
function checkpay(){
var item = $("input[name=paymentgatway][checked]").val();
if(!item){
alert("请选择一个支付方式");
return false;
}
}
function CancelOrder(orderId){
	if(orderId!=""){
		if(confirm("你确认取消订单号为："+orderId+" 吗？")){
			var yuanyin = prompt("请输入取消的原因：","");
			if(!yuanyin){
				alert("请输入取消订单原因");
			}else{
				$.ajax({
                url: "/Member.do?action=cancelorder&orderid=" + orderId+"&msg="+yuanyin,
                dataType: "json",
                async: false,
                cache: false,
                beforeSend: function(){
                    showExeMsg();
                },
                complete: function(){
                    hiddenExeMsg();
                },
                success: function(msg){
                    if (msg.success == true && msg.msg == "ok") {
                        location.reload();
                    }
                    else {
                        alert(msg.msg);
                    }
                }
            });
			}
		}
	}
}
function InsertCart(productid,productcount){
	$.ajax({
                url: "/Shop.do?action=addcart&id=" + productid+"&productCount="+productcount,
                dataType: "json",
                async: false,
                cache: false,
                beforeSend: function(){
                    showExeMsg();
                },
                complete: function(){
                    hiddenExeMsg();
                },
                success: function(msg){
                    if (msg.success == true && msg.msg == "ok") {
						alert("加入购物车成功");
						location.reload();
                    }
                    else {
                        alert(msg.msg);
                    }
                }
            });
}

