function cart_num_qg(itemtype,merchid,paytype,stepValue,unit_price,min_num,add_price)
{
	var size_field = document.getElementById("QTY_"+itemtype+"_"+paytype+"_"+merchid);
  
	//if(stepValue != 0)
  //{
        if(size_field)
        {
		size_field.value = parseInt(size_field.value) + parseInt(stepValue);
	
		if(size_field.value < 0)
			size_field.value = 0;
		else if(size_field.value > 9999)
			size_field.value = 9999;
	
	//	AJAX.SubmitUsePost("cart.php","Action=update&itemtype="+itemtype+"&merchid="+merchid+"&mthd="+paytype+"&qty="+size_field.value);
			$.ajax(
			{
				type : "POST",
				url  : "/photo/cart.php",
				data : "Action=update&itemtype="+itemtype+"&merchid="+merchid+"&mthd="+paytype+"&qty="+size_field.value,
				success : function(msg){}
			}
			);
        }
	//}
	
	var div = document.getElementById("div_"+itemtype+"_"+paytype+"_"+merchid);

	// 设置新价格
	var field_price = document.getElementById("price_"+itemtype+"_"+paytype+"_"+merchid);
	var curValue = parseFloat(field_price.value);
	var newValue=0;
	if(min_num && add_price && min_num != 0 && add_price!=0 && min_num != '' && add_price!='')
	{
	   var fv =parseInt(size_field.value);
	   var tempcount=fv-min_num;
	   if(tempcount > 0)
	   {
	   	  newValue=unit_price * min_num +tempcount * add_price;
	   }
	   else
	   {
	   	  newValue=unit_price * fv;
	   }
	}
	else
	{
	   newValue = unit_price * parseInt(size_field.value);
	}
	field_price.value = newValue;

	// 获新老价格差
	var subValue = newValue - curValue;
	
	if(subValue != 0)
	{
		if(paytype == 1)
		{
			
			div.innerHTML = "￥"+FormatNumber(newValue,2);
			var div_total_price = document.getElementById("div_total_price");
			var field_total_price = document.getElementById("cart_total_price");
			var cur_total_price = parseFloat(field_total_price.value);
			field_total_price.value = cur_total_price + subValue;
			div_total_price.innerHTML = "￥"+FormatNumber(cur_total_price + subValue,2);
            if($('#packbuy').val()==1)
            {
                
            }else if(FormatNumber(cur_total_price + subValue,2)<69)
            {
                $("#mes").html('再购买<em id="total" class="redPx20" style="font-size:14px">'+FormatNumber(69-cur_total_price - subValue,2)+'</em>元，满69就可以免普通快递运费了哦' );
            }else
            {
               $("#mes").html('已经超过69,免普通快递运费');
            }
		}
		else
		{
			div.innerHTML = newValue+" 积分";
			
			var div_total_price = document.getElementById("div_total_points");
			var field_total_price = document.getElementById("cart_total_points");
			var cur_total_price = parseFloat(field_total_price.value);
			field_total_price.value = cur_total_price + subValue;
			div_total_price.innerHTML = (cur_total_price + subValue) + " 积分";
		}
	}
	if(typeof checkout_set_ui_price_info!="undefined")
	{
	  checkout_set_ui_price_info();
	}
}
function cart_deleteItem(itemtype,merchid,paytype)
{
	
	var div = document.getElementById("tr_"+itemtype+"_"+paytype+"_"+merchid);
	var div_cart=document.getElementById("cart_item_innerHTML");
	var size_field = document.getElementById("QTY_"+itemtype+"_"+paytype+"_"+merchid);
	size_field.value = 0;
	$.ajax(
			{
				type : "POST",
				url  : "/photo/cart.php",
				data : "Action=update&itemtype="+itemtype+"&merchid="+merchid+"&mthd="+paytype+"&qty=0",
				success : function(msg)
				{
					var arr=msg.split("{taoxi}");	
					for(var i=0;i<arr.length;i++)
					{ 
						var div=document.getElementById("tr_merch_1_"+arr[i]);
						if(div)
						{
							div.style.display = 'none';
						}
					}
				}
			}
	);
	cart_num_qg(itemtype,merchid,paytype,0,0);
	div.style.display = 'none';	
	$("tr[@merchprint=merchprint]").each(function(){
		if(this.id.indexOf("print_merch") > -1)
		{
			this.style.display='none';
		}
	});
	
}
function checkout_set_ui_price_info(){
	if(typeof(set_ui_price_info) == "function"){
		set_ui_price_info();
	}	
}
function cart_validateNumberValue(boxId){
	var tBox = document.getElementById(boxId);
	var tBoxVal = parseInt(tBox.value);
	if (isNaN(tBoxVal) || tBoxVal < 0)
	{
		tBoxVal = 1;
	}
	tBox.value = tBoxVal;
}
function cart_num_qg_merch(itemtype,merchid,paytype,stepValue,unit_price)
{
	var size_field = document.getElementById("QTY_"+itemtype+"_"+paytype+"_"+merchid);
  
	//if(stepValue != 0)
  //{
		size_field.value = parseInt(size_field.value) + parseInt(stepValue);
	
		if(size_field.value < 0)
			size_field.value = 0;
		else if(size_field.value > 9999)
			size_field.value = 9999;
	  // alert(size_field);
	//	AJAX.SubmitUsePost("cart.php","Action=update&itemtype="+itemtype+"&merchid="+merchid+"&mthd="+paytype+"&qty="+size_field.value);
		
		$.ajax(
			{
				type : "POST",
				url  : "/photo/cart.php",
				data : "Action=update&itemtype="+itemtype+"&merchid="+merchid+"&mthd="+paytype+"&qty="+size_field.value,
				success : function(msg){}
			}
		);
	//}
	
	var div = document.getElementById("div_"+itemtype+"_"+paytype+"_"+merchid);

	// 设置新价格
	var field_price = document.getElementById("price_"+itemtype+"_"+paytype+"_"+merchid);
	var curValue = parseFloat(field_price.value);
	var newValue = unit_price * parseInt(size_field.value);
    
	field_price.value = newValue;

	// 获新老价格差
	var subValue = newValue - curValue;
	
	if(subValue != 0)
	{
		if(paytype == 1)
		{
			div.innerHTML = "￥"+FormatNumber(newValue,2);
			
			var div_total_price = document.getElementById("div_total_price");
			var field_total_price = document.getElementById("cart_total_price");

			var cur_total_price = parseFloat(field_total_price.value);
			field_total_price.value = cur_total_price + subValue;
			div_total_price.innerHTML = "￥"+FormatNumber(cur_total_price + subValue,2);
		}
		else
		{
			div.innerHTML = newValue+" 积分";
            
			//var div_total_price = document.getElementById("div_total_points");
			//var field_total_price = document.getElementById("cart_total_points");
			//var cur_total_price = parseFloat(field_total_price.value);
            var cur_total_price=$("#div_total_point").html();
            var current_point=$("#current_point").html();  
			//field_total_price.value = cur_total_price + subValue;
			//div_total_price.innerHTML = (cur_total_price + subValue) + " 积分";
            var div_total_price=parseFloat(cur_total_price)+subValue;  
            if(div_total_price=='')
            {
                $("#div_total_point").html('0');
            }
            else{  
                $("#div_total_point").html(div_total_price);
            } 
           //if(current_point>=div_total_price){$("#J_QB").attr("onClick","submitForm()");}else{$("#J_QB").attr("onClick","alert('您的积分不足');return false");} 
		}
	}
	if(typeof checkout_set_ui_price_info!="undefined")
	{
	  checkout_set_ui_price_info();
	}
}
function cart_deleteItem_merch(itemtype,merchid,paytype)
{
	
	var div = document.getElementById("tr_"+itemtype+"_"+paytype+"_"+merchid);
	var div_cart=document.getElementById("cart_item_innerHTML");
	var size_field = document.getElementById("QTY_"+itemtype+"_"+paytype+"_"+merchid);
	size_field.value = 0;
    
//	AJAX.SubmitUsePost("cart.php","Action=update&itemtype="+itemtype+"&merchid="+merchid+"&mthd="+paytype+"&qty=0",div_cart);
	$.ajax(
			{
				type : "POST",
				url  : "/photo/cart.php",
				data : "Action=update&itemtype="+itemtype+"&merchid="+merchid+"&mthd="+paytype+"&qty="+size_field.value,
				success : function(msg)
				{
				}
			}
	);
	
	cart_num_qg_merch(itemtype,merchid,paytype,0,0);
	div.style.display = 'none'; 

	//如果是冲印，则删除推荐商品
	
	
}


function FormatNumber(srcStr,nAfterDot){
	var srcStr,nAfterDot;
	var resultStr,nTen;
	srcStr = ""+srcStr+"";
	strLen = srcStr.length;
	dotPos = srcStr.indexOf(".",0);
	if (dotPos == -1){
		resultStr = srcStr+".";
		for (i=0;i<nAfterDot;i++){
			resultStr = resultStr+"0";
		}
		return resultStr;
	}
	else{
		if ((strLen - dotPos - 1) >= nAfterDot){
			nAfter = dotPos + nAfterDot + 1;
			nTen =1;
			for(j=0;j<nAfterDot;j++){
				nTen = nTen*10;
			}
			resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
			return resultStr;
		}
		else{
			resultStr = srcStr;
			for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){
				resultStr = resultStr+"0";
			}
			return resultStr;
		}
	}
}
