function BASEisNotNum(theNum)
{
    //判断是否为数字
    if ($.trim(theNum)=="")
        return true;
    for(var i=0;i<theNum.length;i++){
        oneNum=theNum.substring(i,i+1);
        if (oneNum<"0" || oneNum>"9")
            return true;
    }
    return false;
}
function BASEisNotInt(theInt)
{
    //判断是否为整数
    theInt=$.trim(theInt);
    if ((theInt.length>1 && theInt.substring(0,1)=="0") || BASEisNotNum(theInt)){
        return true;
    }
    return false;
}
/*
 * 设置购物中产品的数量
 */
function setProductNum(Obj,DOCDOMAIN,type){
    var product_id = $(Obj).next().attr("id");
    var num = $(Obj).val();
    if(parseInt(num) < 1 ){
        $(Obj).val($(Obj).next().val());
        return false;
    }
    if($(Obj).val() == $(Obj).next().val()){
        return false;
    }
    if(!BASEisNotInt($(Obj).val())){
        $.ajax({
            type: "post",
            url : DOCDOMAIN + "shoppingcart/setnum",
            dataType:'json',
            data: 'product_id=' + product_id + '&num=' + num + '&type=' + type,
            error: function(msg){
                window.location.reload();
                return false;
            },
            success: function(json){
                switch (json.flag) {
                    case 1:
                        window.location.reload();
                        break;
                    case 2:
                        $("#subtotal_" + product_id + "_" + type).html(json.subtotal);
                        $("#subpoint_" + product_id + "_" + type).html(json.subpoint);
                        $("#total").html(json.total);
                        $("#point_total").html(json.point_total);
                        $(Obj).show().next().hide();
                        break;
                    case 3:
                        $("#productnum_" + product_id + "_" + type).val(json.num);
                        $("#productnum_" + product_id + "_" + type).next().val(json.num);

                        $("#subtotal_" + product_id + "_" + type).html(json.subtotal);
                        $("#subpoint_" + product_id + "_" + type).html(json.subpoint);

                        $("#productnum_" + json.relate_id + "_" + type).val(json.num);
                        $("#productnum_" + json.relate_id + "_" + type).next().val(json.num);

                        $("#subtotal_" + json.relate_id + "_" + type).html(json.subtotal_relate);
                        $("#subpoint_" + json.relate_id + "_" + type).html(json.subpoint_relate);

                        $("#total").html(json.total);
                        $("#point_total").html(json.point_total);

                        $(Obj).show().next().hide();
                        break;
                    default:
                        window.location.reload();
                        break;
                }
            }
        });
    }else{
        $(Obj).val($(Obj).next().val());
    }
}
/*
 * 购物车中添加产品的数量
 */
function subProductNum(Obj,DOCDOMAIN,type){
    var product_id = $(Obj).attr("class");
    var num = parseInt($("#productnum_" + product_id + "_" + type).val());
    
    if(num > 1){
        $(Obj).hide().next().show();
        $.ajax({
            type: "post",
            url : DOCDOMAIN + "shoppingcart/subone",
            dataType:'json',
            data: 'product_id=' + product_id + '&type=' + type,
            error: function(msg){
                window.location.reload();
                return false;
            },
            success: function(json){
                switch (json.flag) {
                    case 1:
                        window.location.reload();
                        break;
                    case 2:
                        $("#productnum_" + product_id + "_" + type).val(json.num);
                        $("#productnum_" + product_id + "_" + type).next().val(json.num);

                        $("#subtotal_" + product_id + "_" + type).html(json.subtotal);
                        $("#subpoint_" + product_id + "_" + type).html(json.subpoint);

                        $("#total").html(json.total);
                        $("#point_total").html(json.point_total);

                        $(Obj).show().next().hide();
                        break;
                    case 3:
                        $("#productnum_" + product_id + "_" + type).val(json.num);
                        $("#productnum_" + product_id + "_" + type).next().val(json.num);

                        $("#subtotal_" + product_id + "_" + type).html(json.subtotal);
                        $("#subpoint_" + product_id + "_" + type).html(json.subpoint);

                        $("#productnum_" + json.relate_id + "_" + type).val(json.num);
                        $("#productnum_" + json.relate_id + "_" + type).next().val(json.num);

                        $("#subtotal_" + json.relate_id + "_" + type).html(json.subtotal_relate);
                        $("#subpoint_" + json.relate_id + "_" + type).html(json.subpoint_relate);

                        $("#total").html(json.total);
                        $("#point_total").html(json.point_total);
                        
                        $(Obj).show().next().hide();
                        break;
                    default:
                        window.location.reload();
                        break;
                }
            }
        });
    }else{
        return false;
    }
}
/*
 * 购物车内添加单个产品
 */
function addProductNum(Obj,DOCDOMAIN,type){
    var product_id = $(Obj).attr("class");
    $(Obj).hide().next().show();
    $.ajax({
        type: "post",
        url : "/shoppingcart/addone",
        dataType:'json',
        data: 'product_id=' + product_id + '&type=' + type,
        error: function(msg){
            //window.location.reload();
            return false;
        },
        success: function(json){
            switch (json.flag) {
                case 1:
                    //window.location.reload();
                    break;
                case 2:
                    $("#productnum_" + product_id + "_" + type).val(json.num);
                    $("#productnum_" + product_id + "_" + type).next().val(json.num);
                    $("#subtotal_" + product_id + "_" + type).html(json.subtotal);
                    $("#subpoint_" + product_id + "_" + type).html(json.subpoint);
                    $("#total").html(json.total);
                    $("#point_total").html(json.point_total);
                    $(Obj).show().next().hide();
                    break;
                case 3:
                    $("#productnum_" + product_id + "_" + type).val(json.num);
                    $("#productnum_" + product_id + "_" + type).next().val(json.num);

                    $("#subtotal_" + product_id + "_" + type).html(json.subtotal);
                    $("#subpoint_" + product_id + "_" + type).html(json.subpoint);

                    $("#productnum_" + json.relate_id + "_" + type).val(json.num);
                    $("#productnum_" + json.relate_id + "_" + type).next().val(json.num);

                    $("#subtotal_" + json.relate_id + "_" + type).html(json.subtotal_relate);
                    $("#subpoint_" + json.relate_id + "_" + type).html(json.subpoint_relate);

                    $("#total").html(json.total);
                    $("#point_total").html(json.point_total);

                    $(Obj).show().next().hide();
                    break;
                default:
                    //window.location.reload();
                    break;
            }
        }
    });
}
/*
 * 直接删除购物车内的单个产品
 */
function delProduct(Obj,DOCDOMAIN,type){
    var product_id = $(Obj).attr("class");
    if(confirm("You will remove this product in your shoppingcart,confirm?")){
        $(Obj).hide().next().show();
        $.ajax({
            type: "post",
            url : DOCDOMAIN + "shoppingcart/delproduct",
            dataType:'json',
            data: 'product_id=' + product_id + '&type=' + type,
            error: function(msg){
                window.location.reload();
                return false;
            },
            success: function(json){
                switch (json.flag) {
                    case 1:
                        window.location.reload();
                        break;
                    case 2:
                        $("#line_" + product_id + "_" + type).remove();
                        $("#total").html(json.total);
                        $("#point_total").html(json.point_total);
                        $(Obj).show().next().hide();
                        if(parseInt(json.total) < 1){
                            $("#shoppingcart_div_empty").show();
                            $("#shoppingcart_div").remove();
                        }
                        break;
                    case 3:
                        $("#line_" + product_id + "_" + type).remove();
                        $("#line_" + json.relate_id + "_" + type).remove();
                        $("#total").html(json.total);
                        $("#point_total").html(json.point_total);
                        $(Obj).show().next().hide();
                        if(parseInt(json.total) < 1){
                            $("#shoppingcart_div_empty").show();
                            $("#shoppingcart_div").remove();
                        }
                        break;
                    default:
                        window.location.reload();
                        break;
                }
            }
        });
    }else{
        return false;
    }
}