
//购物车
$(document).ready(function(){
	$('input[@name=quantity]').keyup(function(){
	    $(this).val($(this).val().replace(/\D/g,""));   //替换非数字
	    var memberPrice = $(this).siblings('input[@name=memberPrice]').val();   //会员单价
	    var itemPrice = $(this).siblings('input[@name=fieldItemPrice]').val();  //配件单价
	    var oItemTotal = $(this).parent().next().find('span');  //显示每项商品价格的元素
	    
	    if(Number($(this).val()) < 1 || $(this).val() == "")
	    {
	        $(this).val('');
	        oItemTotal.html('0');
	        return false;
	    }
	    else
	    {
	        var itotal = Number(memberPrice) * Number($(this).val()) + Number(itemPrice) * Number($(this).val());
	        oItemTotal.html(itotal.toFixed(2));
	    }
	    
	    var total = 0;
		var total_quantity = 0;
		var total_weight = 0;
		var total_score = 0;
		
		$('span.itemTotal').each(function(){
		    total = Number(total) + Number($(this).html());
		});
		
		$('input[@name=quantity]').each(function(){
		    total_quantity = Number(total_quantity) + Number($(this).val())
		}); 
		
		$('input[@name=weight]').each(function(){
		    total_weight = Number(total_weight) + Number($(this).val()) * Number($(this).siblings('@[name=quantity]').val());
		}); 
		//如果使用积分制度,显示积分
		if(markUnit == '1'){
		    $('input[@name=score]').each(function(){
		        total_score = Number(total_score) + Number($(this).val()) * Number($(this).siblings('@[name=quantity]').val());
		    });
		    $('#totalScore').html(total_score);
		    if($('#totalScore').html()==''){$('#totalScore').html('0');}
		} 
		
		$('#total').html(total.toFixed(2));
		$('#total_quantity').html(total_quantity);
		$('#totalWeight').html(Number(total_weight/1000).toFixed(3));
		
		var recordID = $(this).siblings('input[@name=recordID]').val()
		var weburl = "ajax.aspx?recordID="+recordID+"&q=" + $(this).val() + "&ran=" + Math.random();
		$.get(weburl);
	   
	}); //end keyup
	
	$('input[@name=quantity]').blur(function(){
	    if(Number($(this).val()) < 1 || $(this).val() == "")
	    {
	        $(this).val('1');
	        
	        var memberPrice = $(this).siblings('input[@name=memberPrice]').val();   //会员单价
	        var itemPrice = $(this).siblings('input[@name=fieldItemPrice]').val();  //配件单价
	        var oItemTotal = $(this).parent().next().find('span');  //显示每项商品价格的元素
	        
	        var itotal = Number(memberPrice) * Number($(this).val()) + Number(itemPrice) * Number($(this).val());
	        oItemTotal.html(itotal.toFixed(2));
	        
	        var total = 0;
		    var total_quantity = 0;
    		
		    $('span.itemTotal').each(function(){
		        total = Number(total) + Number($(this).html());
		    });
    		
		    $('input[@name=quantity]').each(function(){
		        total_quantity = Number(total_quantity) + Number($(this).val())
		    }); 
    		
		    $('#total').html(total.toFixed(2));
		    $('#total_quantity').html(total_quantity);
    		
		    var recordID = $(this).siblings('input[@name=recordID]').val()
		    var weburl = "ajax.aspx?recordID="+recordID+"&q=" + $(this).val() + "&ran=" + Math.random();
		    $.get(weburl);
	        
	    }
	});
	
});