function ajaxgoodstype(catid,goodsid){
    $.get(APP+"Shop/Goods/attr_html.html", {catid:catid,goodsid:goodsid}, function(data){
		$("#ajaxtable_group_type").html(data);
	});
}
function addRow(obj,type,attr_id){//属性+
	var html = $(obj).parent().parent().html();
	html = html.replace("addRow", "delRow");
	html = html.replace("+", "-");
	if(type==1){//货品
		var num=parseInt($("input[name='count']").val())+1;
		$("input[name='count']").val(num);
		html = html.replace(/\]\[1\]/g, "]["+num+"]");
		html = html.replace(/showdiv_1/g, "showdiv_"+num);
		html = html.replace("add", "del");
		$("<tr id='showdiv_"+num+"'>"+html+"</tr>").insertAfter($(obj).parent().parent());
		$('#showdiv_'+num).find('input').val('');
		$('#showdiv_'+num).find('select').val('');
	}else if(type=='ser'){//货品
		var num=parseInt($("input[name='count']").val())+1;
		$("input[name='count']").val(num);
		html = html.replace(/\]\[1\]/g, "]["+num+"]");
		html = html.replace(/showdiv_1/g, "showdiv_"+num);
		html = html.replace("add", "del");
		$("<tr id='showdiv_"+num+"'>"+html+"</tr>").insertAfter($(obj).parent().parent());
		$('#showdiv_'+num).find('input').val('');
		$('#showdiv_'+num).find('select').val('');
	}else{//属性
		var num=parseInt($("input[name='"+attr_id+"_count']").val())+1;
		$("input[name='"+attr_id+"_count']").val(num);
		html = html.replace(/\]\[1\]/g, "]["+num+"]");
		html = html.replace(/showdiv_1/g, "showdiv_"+num);
		html = html.replace(/img1_button/g, "img"+num+"_button");
		html = html.replace(/_img1_id/g, "img"+num+"_id");
		$("<div class='clearfix attribute mb10' id='showdiv_"+num+"_"+attr_id+"'>"+html+"</div>").insertAfter($(obj).parent().parent());
		$('#showdiv_'+num+"_"+attr_id).find('input').val('');
		$('#showdiv_'+num+"_"+attr_id).find('select').val('');
		$('#showdiv_'+num+"_"+attr_id).find('img').attr('src','/Public/images/add_img_icon.png');
	}
}
function delRow(obj){//属性-
	$(obj).parent().parent().remove();
}
function check_same(obj){//检查配置
	var selectbox = $(obj).parent().parent().find("select");
	var row_value = '';
	for(i=0;i<selectbox.length;i++)
	{
		if($(selectbox[i]).val()!='')
			row_value += $(selectbox[i]).val();
		else
		{
			$(obj).parent().parent().find("input[name='stock_cfg[]']").val("");
			return;
		}
	}
	//开始检测是否存在该配置
	var stock_cfg = $("input[name='stock_cfg[]']");
	for(i=0;i<stock_cfg.length;i++)
	{
		if(row_value==$(stock_cfg[i]).val()&&row_value!=''&&stock_cfg[i]!=obj)
		{
			$.showSuccess('属性规格组合重复');
			$(obj).parent().parent().find("input[name='stock_cfg[]']").val("");
			$(obj).val("");
			return;
		}
	}
	$(obj).parent().parent().find("input[name='stock_cfg[]']").val(row_value);
}
function check_attr_sn(obj){//检查货品编号是否重复
	var attr_sn = '';
	if($(obj).val()!=''){
		attr_sn = $(obj).val(); 
	}else{
		$(obj).parent().parent().find("input[name='goods_attr_sn[]']").val("");
		return;
	}
	//开始检测
	var goods_attr_sn = $("input[name='goods_attr_sn[]']");
	var errmsg = '【'+attr_sn+'】此货品编号已存在，请重新输入';
	if($(obj).parent().parent().find("input[name='goods_attr_sn[]']").val()!=attr_sn){
		for(i=0;i<goods_attr_sn.length;i++){
			if(attr_sn==$(goods_attr_sn[i]).val()&&attr_sn!=''&&goods_attr_sn[i]!=obj){
				$.showSuccess(errmsg);
				$(obj).parent().parent().find("input[name='goods_attr_sn[]']").val("");
				$(obj).val("");
				return;
			}
		}
		var query = new Object();
		query.goods_attr_sn = attr_sn;
		var url = APP + "Shop/Goods/check_goods_attr_sn.html"
		$.ajax({
			url: url,
			data: query,
			type: "post",
			dataType: "json",
			success: function (data) {
				if (data.info==1) {
					$.showSuccess(errmsg);
					$(obj).parent().parent().find("input[name='goods_attr_sn[]']").val("");
					$(obj).val("");
					return;
				}else{
					$(obj).parent().parent().find("input[name='goods_attr_sn[]']").val(attr_sn);
				}
			}
		});
	}
}
//商品的上下架
function stock_status(id, type) {
	var url = APP + "Shop/Goods/stock_status.html"
	$.get(url, {
		id: id,
		type: type
	}, function(jsondata) {
		var return_data = eval("(" + jsondata + ")");
		$("#" + type + "_" + id + " img").attr('src', THEME_PATH + 'common/images/status_' + return_data + '.gif');
	});
}