/**
	[OECRM] (C)2012~2099 OEdev.Net Inc.
	This is NOT a freeware, use is subject to license terms
	$Id: items.js 2014-05-04 OEdev $ 
*/
/*---------------------- 订单明细 Begin ------------------*/
//添加订单明细
function objAddOrderItems(my) {
	$('#load_itemtips').html('正在为您努力加载中...');
	var requesturl = document.URL;
	var filename = requesturl.split("?")[0];
	//统计imglist 个数
	var imgnum = $('.itemlist') ? $('.itemlist').length : 0;
	//当前最大排序
	var maxsort = parseInt($("input[name='itemmaxsort']").val());
	//ajax 排序 sort
	var sort = 0;
	if (maxsort>imgnum) {
		sort = maxsort;
	}
	else {
		sort = imgnum;
	}
	//URL
	var url = 'index.php?m=admin&c=ajax&a=addorderitem&sort='+sort+"&rnd="+get_rndnum(8);
	var dom = $("tr.itemlist");
	var at = dom.length>0 ? dom.eq(dom.length-1) : $('#list-top');
    $.ajax({
    url : url, 
    type: "GET",
	dataType: "json",
    success: function(data){
		var json = eval(data);
		objOrderItemAddtr(at, json.list, 0);
		$('#load_itemtips').empty();
		$("input[name='itemmaxsort']").val((maxsort+1));
    }
    });
	return false;
}

//删除元素
function objOrderItemDel(my, sortid) {
	//移除tr
	my.parent('td').parent('tr').remove();
	//统计imglist 个数
	var imgnum = $('.itemlist') ? $('.itemlist').length : 0;
	//imgmaxsort最大值
	var maxsort = parseInt($("input[name='itemmaxsort']").val());
	//如果没有相框 重置0
	if (imgnum == 0) {
		$("input[name='itemmaxsort']").val(0);
	}
	//有相框
	else {
		//如果删除的ID是当前最大的ID，则imgmaxsort-1
		if(sortid == maxsort) {
			$("input[name='itemmaxsort']").val((maxsort-1));
		}

	}
}

//统计数量
function objOrderItemCounts() {
	$("input[name='itemnum']").val(function(){return parseInt($(this).val())-1});
}
//增加一行TR
function objOrderItemAddtr(h, t, i){
	h.after(t);
	var l = i!=1?i:1;
	h.next('tr').find("input[type='text']").eq(l).focus();
}
/*---------------------- 订单明细 End --------------------*/
