 $(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();
	});
	$("#all_use_score").click(function(){
        count_order_total();
	});
     count_order_total();
     //切换支付方式
     $(".pay-ways-ul li").each(function(k){
         $(this).bind('click',function(){
             $(".pay-ways-ul li").removeClass('on');
             $(this).addClass('on');
             payment_id =$(this).find("input[name='paytype']").val();
             //alert(payment_id);
             count_order_total($(this));
         });
     });
});
//计算订单费用
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.account_money=$("input[name='account_money']").val();
	if($("#all_use_score").is(':checked')){
		query.score=1;
	}
    query.payment_id=payment_id;
    query.type=type;
	//query.payment_id=$("input[name='paytype']:checked").val();
    //alert($("input[name='paytype']:checked").val());
	$.ajax({
		url:APP+'Home/Order/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.pay_price==0){
                $(".pay-ways-ul li").each(function(k){
                    $(this).removeClass('on');
                })
            }
		}
	});
}
//提交订单
 var is_submit=false;
function submit_continue_order(){
    if(is_submit){
        return true;
    }
    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($("#all_use_score").is(':checked')){
        query.score=1;
    }
    query.payment_id=payment_id;
    //query.payment_id=$("input[name='paytype']:checked").val();
    if(query.score>0 || query.account_money){
        var html = '交易密码：<input type="password" name="pay_pwd" id="pay_pwd" class="ui-textbox" style="border: 1px solid #ddd;height: 26px;line-height: 26px;width: 200px;margin-left: 5px;"/>';
        $.weeboxs.open(html, {
            boxid: 'tui_box',
            contentType: 'text',
            showButton: true,
            showCancel: false,
            showOk: true,
            title: '输入交易密码',
            width: 250,
            type: 'hc',
            onopen: function () {
            }, onok: function () {
                is_submit=true;
                query.pay_pwd=$("input[name='pay_pwd']").val();
                $.ajax({
                    url: APP + "Order/sub_continue_order",
                    type: "post",
                    data: query,
                    dataType: "json",
                    success:function(obj){
                        $.weeboxs.close('tui_box');
                        if(obj.status==1){
                            if(obj.pay){
                                window.location.href=APP+"Pay/index/id/"+obj.pay;
                            }else{
                                $.showSuccess("支付成功",0,'hc')
                                window.location.href=APP+"Member/OrderInfo/index";

                            }
                        }else{
                            $.showErr(obj.msg,0,'hc');
                        }
                    }
                });
            }
        })
    }else{
        is_submit=true;
        $.ajax({
            url: APP + "Order/sub_continue_order",
            type: "post",
            data: query,
            dataType: "json",
            success:function(obj){
                if(obj.status==1){
                    if(obj.pay){
                        window.location.href=APP+"Pay/index/id/"+obj.pay;
                    }else{
                        $.showSuccess("支付成功",0,'hc');
                        window.location.href=APP+"Member/OrderInfo/index";
                    }
                }else{
                    $.showErr(obj.msg,0,'hc');
                }
            }
        });
    }
    //alert($("input[name='paytype']:checked").val());

}
 