 $(function(){
	$("#add_address").click(function(){
		add_address();
	});
     $("#account_money").bind("blur",function(){
         $("#all_use_money").prop("checked","checked");
         count_order_total();
     });
	$("#all_use_money").click(function(){
        if($("#all_use_money").prop("checked")==false){
            $("#all_use_money").prop("checked",'');
            $("#account_money").val(0);
        }
        count_order_total();
	});
     $("input[name='paytype']").bind("click",function(){
         count_order_total();
     });
     //切换支付方式
     $(".order-pay-style dl dd ").each(function(k){
         $(this).bind('click',function(){
             if($(this).find("input[name='paytype']").is(':checked')){
                 payment_id =$(this).find("input[name='paytype']").val();
             }else{
                 payment_id=0;
             }
             count_order_total();
         });
     });
     count_order_total();
});
//计算订单费用
function count_order_total(){
    var type=parseInt($("#is_addcart").val());
	var query=new Object();
	query.ids=order_id;
	if($("#all_use_money").is(':checked')){
		query.use_account=1;
	}
    query.type=type;
	query.account_money=$("input[name='account_money']").val();

	query.payment_id=payment_id;
    //alert($("input[name='paytype']:checked").val());
	$.ajax({
		url:APP+'Mobile/PurOrder/count_order_total',
		data:query,
		dataType:'json',
		success:function(obj){
			$("#count_total").html(obj.html);
			$("input[name='account_money']").val(obj.total_info.account_money);
            if(obj.total_info.payment_info){
                $("#pay_style").html(obj.total_info.payment_info.name);
            }else{
                $("#pay_style").html("请选择支付方式");
            }
            if(obj.total_info.pay_price==0){
                payment_id=0;
            }
		}
	});
}
//提交订单
function submit_continue_order(){
    var type=parseInt($("#is_addcart").val());
    var query=new Object();
    query.ids=order_id;
    if($("#all_use_money").is(':checked')){
        query.use_account=1;
    }
    query.type=type;
    query.account_money=$("input[name='account_money']").val();
    if(type==3){
        query.score=1;
    }else {
        if ($("#all_use_score").is(':checked')) {
            query.score = 1;
        }
    }
    query.payment_id=payment_id;
    //alert($("input[name='paytype']:checked").val());
  /*  if (query.account_money || query.score) {
        $("#sub_order").next().next().fadeIn();
        *//*$("#areaMasks").fadeIn();*//*
        $("#sub_order").next().animate({"bottom": 0});
        var pay_pwd=$("#pay_pwd").val();
        if(!pay_pwd)return false;
        query.pay_pwd=$("#pay_pwd").val();
    }*/
    $.ajax({
        url: APP + "Mobile/PurOrder/sub_continue_order",
        type: "post",
        data: query,
        dataType: "json",
        success:function(obj){
            if(obj.status==1){
                if(obj.pay){
                    window.location.href=APP+"Mobile/PurOrder/order_success/id/"+obj.pay;
                }else{
                    window.location.href=APP+"Mobile/PurOrder/order_success/order_ids/"+obj.data;
                }
            }else if(obj.status==3){
                $("#sub_order").next().next().fadeIn();
                /*$("#areaMasks").fadeIn();*/
                $("#sub_order").next().animate({"bottom": 0});
                var pay_pwd=$("#pay_pwd").val();
                if(!pay_pwd)return false;
                query.pay_pwd=$("#pay_pwd").val();
                $.ajax({
                    url: APP + "Mobile/PurOrder/sub_continue_order",
                    type: "post",
                    data: query,
                    dataType: "json",
                    success:function(obj){
                        if(obj.status==1){
                            if(obj.pay){
                                window.location.href=APP+"Mobile/PurOrder/order_success/id/"+obj.pay;
                            }else{
                                window.location.href=APP+"Mobile/PurOrder/order_success/order_ids/"+obj.data;
                            }
                        }else{
                            $.showErr(obj.msg,0,'hc');
                        }
                    }
                });
            }else{
                $.showErr(obj.msg,0,'hc');
            }
        }
    });
}
 