function body_css(){
	var body = $('body').css("position");
	if(body=='relative'){
		$('body').css("position","");
	}
}
/**
 * 商品数量加减
 * @param k “+”或者“-”
 */
function num(k) {
    var num = parseFloat($('#product_amount').val());
    var buy_limit = parseInt($('#buy_limit').val());
    if($('#product_amount').val()=='' || num<0){ num=0;}
    if(isNaN($('#product_amount').val())){num=0;}
    switch (k) {
        case "+":
            num = num + 1;
            if(num > buy_limit && buy_limit != 0){
                num = num - 1;
				showtoast('按拼团价格买每人限购'+buy_limit+'件，不能超过数量限制');body_css();return false;
            }
            break;
        case "-":
            if (num !== 1) {
                num = num - 1;
            } else {
				showtoast('数量不能小于1件');body_css();return false;
            }
            break;
    }
    $('#product_amount').val(num);
    $('#number').html(parseInt(num));
 /*   $("#goods_price").html(foramtmoney(goods_price*num,2));*/
}
/**
 * 属性拼团商品数量加减
 * @param k “+”或者“-”
 */
function p_num(k) {
    var num = parseFloat($('#p_product_amount').val());
    var buy_limit = parseInt($('#buy_limit').val());
    if($('#p_product_amount').val()=='' || num<0){ num=0;}
    if(isNaN($('#product_amount').val())){num=0;}
    switch (k) {
        case "+":
            num = num + 1;
            if(num > buy_limit && buy_limit != 0){
                num = num - 1;
                showtoast('按拼团价格买每人限购'+buy_limit+'件，不能超过数量限制');body_css();return false;
            }
            break;
        case "-":
            if (num !== 1) {
                num = num - 1;
            } else {
                showtoast('数量不能小于1件');body_css();return false;
            }
            break;
    }
    $('#p_product_amount').val(num);
    $('#number').html(parseInt(num));
 /*   $("#goods_price").html(foramtmoney(goods_price*num,2));*/
}
function addcart(k){
	var is_add = $('#is_add').val();
	if(is_add == 0){
        var add_msg = $('#add_msg').val();
		showtoast(add_msg);body_css();return false;
	}
    var url='';
    var arr=checkarrkey_str;
    var number=parseInt($('#product_amount').val());
    var act=parseInt($("#act").val());
    var order_id = $('#order_id').val();
    //var attr_price=combinationprice[arr]['attr_price'];
    var attrs=new Array();
    attrs=arr.split("_");
    var names='';
    for(i=0;i<attrs.length;i++){
        var name=$("#attr"+attrs[i]+"").html();
        var parent_name= $("#attr"+attrs[i]+"").parent().siblings("dt").html();
        var allname=parent_name+":"+name;
        names+=allname+' ';
    }
    var query = new Object;
    query.goods_id = $('#goods_id').val();
    if(arr){
        query.goods_attr = arr;
    }else{
        query.goods_attr=0;
    }
    if(k==1){
        query.type=14;
        url=APP+"Mobile/Goods/buy_now";
    }else if(k==2){
        query.type=2;
    }else if(k==3){
        if(order_id != ''){
            query.pid=order_id;
        }else{
            query.pid=0;            
        }
        query.type=6;
        url=APP+"Mobile/Goods/buy_now";
    }else if(k==4){
        query.type=11;
        url=APP+"Mobile/Goods/buy_now";
		if(spec_count > 0){
			query.spec_attr = $(".on").attr('attr');
		}else{
			query.spec_attr = 0;
		}
    }else if(k==5){
		query.type=12;
        url=APP+"Mobile/Goods/buy_now";
		number = 1;
	}else if(k==6){
        query.type=14;
        url=APP+"Mobile/Goods/buy_now";
    }else if(k==0){
        url=APP + "Mobile/Goods/addcart";
        query.type=3;
    }else{
		url=APP + "Mobile/Goods/addcart";
        query.type=0;
	}
    if(k==0){
        query.money=price;

    }
    // query.money=price;
	if(k != 4){
		query.name=names;
	}
    query.number = number;
    query.act = act;
    // query.score = score;
    $.ajax({
        url:url,
        data:query,
        type:"get",
        success:function(data) {
            if (k > 0) {
                if(k==3 && data.status == 1){
                    window.location.href=APP+"Mobile/Order/index/goods_id/"+data.goods_id+"/number/"+data.number+"/goods_attr/"+data.goods_attr+"/act/"+data.act+"/type/"+data.type+"/pid/"+data.pid;
                }else if((k==3 || k==1 || k==4) && (data.status == 0 || data.status == 2)){

                    if(data.app_data=='open_attr'){
                        showtoast(data.msg);body_css();
                        $('#areaMasks').attr('style',"display: block;");
                        $('#popup-mian').attr('style',"bottom: 0px;");
                    }else{
                        showtoast(data.msg);body_css();return false;
                    }
				}else if(k==4 && data.status == 1){
                    window.location.href=APP+"Mobile/Order/index/goods_id/"+data.goods_id+"/number/"+data.number+"/spec_attr/"+data.spec_attr+"/type/"+data.type;
                }else{
                    window.location.href=APP+"Mobile/Order/index/goods_id/"+data.goods_id+"/number/"+data.number+"/goods_attr/"+data.goods_attr+"/act/"+data.act+"/type/"+data.type;
                }
            } else {
                if (data.status == 0) {
                    // $.showErr(data.msg, 0, 'hc', function () {
                        // window.location.href = data.url;
                    // });
                    if(data.app_data=='open_attr'){
                        showtoast(data.msg);body_css();
                        $("#attr").next().next().fadeIn();
                        /*$("#areaMasks").fadeIn();*/
                        $("#attr").next().animate({"bottom": 0});
                    }else{
                        showtoast(data.msg);body_css();return false;
                    }
                } else if (data.status == 2) {
                    if (k == 0) {
						$('#cart_num').html(data.num);
						$('#areaMasks').attr('style',"display: none;");
						$('#popup-mian').attr('style',"bottom: -100%;");
						showtoast(data.msg);body_css();return false;
                        // $.showSuccess(data.msg, 0, 'hc');
						// window.location.reload();
                    } else {
                        window.location.href = APP + "Mobile/Order/index/ids/" + data.data;
                    }
                } else {
                    if(data.app_data=='open_attr'){
						showtoast(data.msg);body_css();
                        $("#attr").next().next().fadeIn();
                        /*$("#areaMasks").fadeIn();*/
                        $("#attr").next().animate({"bottom": 0});
                    }else{
						showtoast(data.msg);body_css();return false;
                    }
                }
            }
        }
    })
}
/**
 * 积分商品加入购物车
 */
function add_integral_cart(){
    var goods_id=$("#goods_id").val();
    var arr=checkarrkey_str;
    var number=parseInt($('#product_amount').val());

    var query = new Object;
    query.goods_id = goods_id;
    if(arr){
        query.goods_attr = arr;
    }else{
        query.goods_attr=0;
    }
    query.number=number;
    query.number = number;
    query.integra = integra;
    query.source = 1;
    query.type = 3;
    // alert(JSON.stringify(query));
    $.ajax({
        url:APP+"Mobile/Goods/buy_now",
        data:query,
        type:"get",
        success:function(data){
            if(data.status==1) {
                // alert(JSON.stringify(data));
                window.location.href = APP + "Mobile/Order/index/goods_id/" + data.goods_id + "/number/" + data.number  + "/integra/" + data.integra + "/type/" + data.type;
            }else {
                if (data.app_data == 'open_attr') {
                    $("#attr").next().next().fadeIn();
                    /*$("#areaMasks").fadeIn();*/
                    $("#attr").next().animate({"bottom": 0});
                }
                showtoast(data.msg);body_css();return false;
            }
        }
    })

}