var userid = parseInt($('#userid').val());
var login_token = $('#login_token').val();
var table_id = parseInt($('#table_id').val());
var game_id = parseInt($('#game_id').val());
var account = $('#account').val();
var number_tab_id;
var ludan;
var isCBoot = false;
var isopentime = false;
var num = 0;
var card_info=[];
var isWin={
    win_player_1:null,
    win_player_2:null,
    win_player_3:null,
    text:[]
};

var websocket = io(websocketProtocol+"://"+websocketUrl+"/?table_id="+table_id+"&account="+account+"&connect=space&userid="+userid+"&login_token="+login_token,{transports: ['websocket']});
websocket.on('reconnecting', (timeout) => {
    //触发重连
    layer.msg('服务断开,正在重新连接...', {
        icon: 16,
        shade: 0.6,
        time:0,
    });
});
websocket.on('reconnect', (timeout) => {
    //重连成功
    layer.closeAll();
    layer.msg('服务重新连接成功');
});
//事件  发送*******************************************************************************************************************
var startBet = function(){
    websocket.emit('startBet',{table_id : table_id, number_tab_id : number_tab_id});
};
var endBet = function (){
    websocket.emit('endBet',{table_id : table_id, number_tab_id : number_tab_id});
};
var startRob = function(){
    websocket.emit('startRob',{table_id : table_id, number_tab_id : number_tab_id});
};
var endRob = function(){
    websocket.emit('endRob',{table_id : table_id, number_tab_id : number_tab_id});
};
var resetNumberTab = function(){
    isCBoot = true;
    var betStatus = $("#number_tab_status").val();
    if(betStatus == 1 || betStatus == 2){
        layer.confirm(lang.is_reset_number,{btn: [lang.confirm,lang.cancel],title:lang.message}, function(index){
            websocket.emit('resetNumberTab',{table_id : table_id});
            isCBoot = false;
            layer.close(index);
        },function(index){
            isCBoot = false;
        });
    }else{
        layer.msg(lang.reset_number_fail_3);
    }
};
var changeBoot = function(){
    isCBoot = true;
    var betStatus = $("#number_tab_status").val();
    if(betStatus == 0 || betStatus == 3){
        layer.confirm(lang.is_to_boot,{btn: [lang.confirm,lang.cancel],title:lang.message}, function(index){
            websocket.emit('changeBoot',{table_id : table_id});
            isCBoot = false;
            layer.close(index);
        },function(index){
            isCBoot = false;
        });
    }else{
        layer.msg(lang.change_boot_false);
    }
};
var resetBoot = function(){
    layer.confirm(lang.is_to_balance,{btn: [lang.confirm,lang.cancel],title:lang.message}, function(index){
        websocket.emit('resetBoot',{table_id : table_id});
        layer.close(index);
    });
};
var opening = function(){
    $('.control-box .btn-box2 span').removeClass('on');
    if(game_id == 1){
        var opening = $('#opening').val();
        var banker_pair = $('#result_banker_pair').val();
        var player_pair = $('#result_player_pair').val();
        if(opening > 0){
            websocket.emit('openingBaccarat',{table_id : table_id, number_tab_id : number_tab_id,opening : opening,banker_pair : banker_pair,player_pair:player_pair,luck_six:0});
        }
    }else if(game_id == 2){
        var opening = $('#opening').val();
        if(opening > 0){
            websocket.emit('openingDt',{table_id : table_id, number_tab_id : number_tab_id,bet:opening});
        }
    }
};

var retreated = function(){
    var result = $('#update_ludan_result').val();
    if(result){
       layer.msg('修改结果中...', {
           icon: 16,
           shade: 0.6,
           time:0,
       });
       var result_arr =  result.split('-');
       if(game_id == 1){
           var opening = result_arr[0];
           var pair = result_arr[1];
           websocket.emit('resetBaccarat',{table_id : table_id, number_tab_id : number_tab_id,opening : opening,pair : pair,luck_six:0});

       }else if(game_id == 2){
           var opening = result_arr[0];
           websocket.emit('resetDt',{table_id : table_id, number_tab_id : number_tab_id,opening:opening});

       }
    }


}

//事件  发送*******************************************************************************************************************
//事件返回*********************************************************************************************************************
websocket.on('onlineLogin',function(data){
    if (data.table_id === table_id) {
        if(data.status === true){
            setNumberInfo(data.round);
            setBetStatus(data.round.number_tab_status)
            clearBetAmount();
            waybillFunc();
            getResultToatl(data.round.boot_id)
            showForecast();
        }else{
            layer.msg(lang[data.msg],{time:0});
        }
    }

});
websocket.on('RepeatedEntry',function(data){
    websocket.close();
    layer.msg(lang[data.msg]);
    setTimeout(function (){
        window.location.href='/login/logout';
    },2000);
});
websocket.on('startBet',function(data){
    if(data.status === true && data.table_id === table_id){
        mp3List = ['start.mp3'];
        audioMp3(mp3List).Play();
        setBetStatus(data.round.number_tab_status);
    }else{
        if (data.table_id != undefined && data.table_id == table_id) {
            layer.msg(lang[data.msg]);
        }
    }
});
websocket.on('startRob',function(data){
    if(data.status === true && data.table_id == table_id){
        mp3List = ['start_rob.mp3'];
        audioMp3(mp3List).Play();
        $("#number_rob_status").val(1);
    }else{
        if (data.table_id != undefined && data.table_id == table_id) {
            layer.msg(lang[data.msg]);
        }
    }
});
websocket.on('startRobCountDown',function(data){
    if(data.status === true && data.table_id == table_id && data.count_down >= 0){
        $('.nobegin-tip').html('抢庄中');
        countDownRob(data.count_down);
    }else{
        if (data.table_id != undefined && data.table_id == table_id) {
            layer.msg(lang[data.msg]);
        }
    }
});
websocket.on('endRob',function(data){
    $('.nobegin-tip').html('');
    if(data.status === true && data.table_id == table_id){
        $('#number_rob_status').val(2);
        startBet();
    }else{
        if (data.table_id != undefined && data.table_id == table_id) {
            layer.msg(lang[data.msg]);
        }
    }
});
websocket.on('resetNumberTab',function(data){
    if(data.status === true && data.table_id == table_id){
        setNumberInfo(data.round);
        setBetStatus(data.round.number_tab_status);
        clearBetAmount();

        // 识别相关
        if (scanner_type == 2) {
            initScanParams();
        }
        //

        $(".countdown").css({"opacity":0,"display":"none"});
        $(".countdown .grab-count").removeClass("count-active");
        $(".begincard .box").animate({"opacity":"0"},function(){
            $(".begincard").fadeOut();

            $(".table-info .nobegin-tip").fadeIn();
            $('.box1').css("background-color","rgba(0, 0, 0, 0.5)");
            $('.box2').css("background-color","rgba(0, 0, 0, 0.5)");
            $('.box3').css("background-color","rgba(0, 0, 0, 0.5)");
            $('.box4').css("background-color","rgba(0, 0, 0, 0.5)");
            $(".begincard .box .list .card").removeClass("begin")
            $(".begincard .card .topleft").html("")
            $(".begincard .card .bottomright").html("")
            $(".list .card .face").css("background-image","")
            $(".begincard .list .draw .rotate").css("display",'none');
        });
        card_info=[];
    }else{
        layer.msg(lang[data.msg]);
    }
});
websocket.on('changeBoot',function(data){
    if(data.status === true && data.table_id == table_id){
        setNumberInfo(data.round);
        setBetStatus(data.round.number_tab_status);
        clearBetAmount();
        waybillFunc();
        getResultToatl(data.round.boot_id)
        showForecast();

    }else{
        layer.msg(lang[data.msg]);
    }
});
websocket.on('resetBoot',function(data){
    if(data.status === true && data.table_id == table_id){
        setNumberInfo(data.round);
        setBetStatus(data.round.number_tab_status);
        clearBetAmount();
        waybillFunc();
        getResultToatl(data.round.boot_id)
        showForecast();

    }else{
        layer.msg(lang[data.msg]);
    }
});
websocket.on('startBetCountDown',function(data){
    if(data.status == true && data.table_id == table_id){
        countDown(data.count_down);
    }
});
websocket.on('endBet',function(data){
    if(data.status === true && data.table_id == table_id){
        if (interval_time > 0) {
            var doIntervalTime = parseInt(interval_time) + 1;
            var intervalTime = setInterval(function(){
                doIntervalTime--;
                $(".countdown .num").html(doIntervalTime)
                $(".countdown").css({"opacity":1,"display":"block"});
                $(".countdown .grab-count").addClass("count-active");
                $(".countdown .round-txt-item").addClass("color-red");
                if(doIntervalTime == 0) {
                    clearInterval(intervalTime);
                    $(".countdown").css({"opacity":0,"display":"none"});
                    $(".countdown .grab-count").removeClass("count-active");
                    $(".countdown .round-txt-item").removeClass("color-red");
                    if(game_id == 4 || game_id == 5){
                        $(".banker_result").html('');
                        $(".player_1_result").html('');
                        $(".player_2_result").html('');
                        $(".player_3_result").html('');
                    }
                    $('#opening').val(0);
                    $('#result_banker_pair').val(0);
                    $('#result_player_pair').val(0);
                    $(".countdown").css({"opacity":0,"display":"none"});
                    $(".countdown .grab-count").removeClass("count-active");
                    setBetStatus(data.round.number_tab_status);
                    c = parseInt($('#wait_time').val());
                }
            },1000);
        } else {
            $(".countdown").css({"opacity":0,"display":"none"});
            $(".countdown .grab-count").removeClass("count-active");
            mp3List = ['stop_2.mp3'];
            audioMp3(mp3List).Play();
            if(game_id == 4 || game_id == 5){
                $(".banker_result").html('');
                $(".player_1_result").html('');
                $(".player_2_result").html('');
                $(".player_3_result").html('');
            }
            if(game_id == 6){
                $('#toning_result').val('');
                $(".toning-result-num").removeClass("active");
            }
            $(".countdown").css({"opacity":0,"display":"none"});
            $(".countdown .grab-count").removeClass("count-active");
            setBetStatus(data.round.number_tab_status);

            // 识别相关
            if (scanner_type == 2 && game_id == 1) {
                doScanCards();
            } else if (scanner_type == 2 && game_id == 2) {
                doDtScanCards();
            } else if (scanner_type == 2 && game_id == 4) {
                doNnScanPositionCard();
                doNnScanCards();
            }
        }

        //

    }else{
        if (data.table_id != undefined && data.table_id == table_id) {
            layer.msg(lang[data.msg]);
        }
    }
});
websocket.on('openingBaccarat',function(data){
    if(data.status === true && data.table_id == table_id){
        showPng(data.round.opening,data.round.pair,1);
        gameResult(data);
        setNumberInfo(data.round);
        setBetStatus(data.round.number_tab_status);
        getResultToatl(data.round.boot_id)
        clearBetAmount();
        waybillFunc();
        showForecast();

    }else{
        layer.msg(lang[data.msg]);
    }
});
websocket.on('openingDt',function(data){
    if(data.status === true && data.table_id == table_id){
        showPngDt(data.round.opening,1);
        gameResult(data);
        setNumberInfo(data.round);
        setBetStatus(data.round.number_tab_status);
        clearBetAmount();
        waybillFunc();
        getResultToatl(data.round.boot_id)
        showForecast();

    }else{
        layer.msg(lang[data.msg]);
    }
});
websocket.on('resetBaccarat',function(data){
    layer.closeAll();
    if(data.status === true && data.table_id == table_id){
        $('#update_ludan').hide();
        waybillFunc();
        showForecast();
    }else{
        layer.msg(data.msg);
    }
});
websocket.on('resetDt',function(data){
    layer.closeAll();
    if(data.status === true && data.table_id == table_id){
        $('#update_ludan').hide();
        waybillFunc();
        showForecast();
    }else{
        layer.msg(data.msg);
    }
});
//事件返回*********************************************************************************************************************

//启动执行
$(function(){
    checkLimit()
    getLang();
    $(document).keydown(function (e){
        var inputId= $(":text:focus").attr("id");
        if(inputId != 'cny_limit_bp' && inputId != 'cny_limit_tie' && inputId != 'cny_limit_pair' && inputId != 'usd_limit_bp' && inputId != 'usd_limit_tie' && inputId != 'usd_limit_pair'){
            if(e.keyCode == 13){

                var cookieValue = $.cookie("enter_time");
                if(!cookieValue){
                    $.cookie("enter_time", 1, { expires: 1/86400*3 });
                }else{
                    layer.msg('Please hold on');
                    return false
                }

                if(isCBoot == true){
                    $('.layui-layer-btn0').click();
                    isCBoot = false;
                }else{
                    //var keycode = $('#keycode').val();
                    var numberTabStatus = $('#number_tab_status').val();
                    //if(keycode == '6'){
                    if (numberTabStatus == 0) {
                        if(!isopentime){
                            var is_rob = $('#is_rob').val();
                            if(is_rob == 1){
                                startRob();
                            }else{
                                startBet();
                            }
                            $('#keycode').val('');
                        }else{
                            layer.msg("请稍等!");
                        }
                    }else if (numberTabStatus == 2) {
                        opening();
                    }
                }
            }
            //开局
            if(e.keyCode == 111){
                $('#keycode').val('6');
            }
            //修改当前状态
            if(e.keyCode == 109){
                $('#update_ludan').toggle();
            }
            //换靴
            if(e.keyCode == 107){
                changeBoot();
                $('#keycode').val('');
            }
            //退出登录
            if(e.keyCode == 106){
                if(table_type == 1){
                    cutout();
                    $('#keycode').val('');
                }else{
                    if(bet_type == 2){
                        cutout();
                        $('#keycode').val('');
                    }else{
                        loginout();
                        $('#keycode').val('');
                    }
                }
            }
            //取消
            if(e.keyCode == 110){
                console.log($(":text:focus").attr("id"));
                $('#opening').val('0');
                $('#result_banker_pair').val('0');
                $('#result_player_pair').val('0');
                $('#openingElement').hide();
                $('#update_ludan').hide();
                $('.layui-layer-btn1').click();
            }
            // 停止倒计时
            if(e.keyCode == 96){
                endBet();
            }
            var betStatus = $("#number_tab_status").val();
            if(betStatus == 2){
                if(e.keyCode == 105){
                    $('#opening').val('1');
                    $('#result_banker_pair').val('0');
                    $('#result_player_pair').val('0');
                    $('#dt_pair').val('0');
                    $('#openingElement').show();
                    if(game_id == 1){
                        showPng(1,0,0);
                    }else{
                        showPngDt(1,0);
                    }
                }
                if(e.keyCode == 103){
                    $('#opening').val('2');
                    $('#result_banker_pair').val('0');
                    $('#result_player_pair').val('0');
                    $('#dt_pair').val('0');
                    $('#openingElement').show();
                    if(game_id == 1){
                        showPng(2,0,0);
                    }else{
                        showPngDt(2,0)
                    }
                }
                if(e.keyCode == 104){
                    $('#opening').val('3');
                    $('#result_banker_pair').val('0');
                    $('#result_player_pair').val('0');
                    $('#dt_pair').val('0');
                    $('#openingElement').show();
                    showPng(3,0,0);
                }
                if(e.keyCode == 102){
                    if(game_id == 1){
                        var result = $('#opening').val();
                        $('#result_banker_pair').val('1');
                        $('#result_player_pair').val('0');
                        if(result == 1){
                            showPng(1,1,0);
                        }
                        if(result == 2){
                            showPng(2,1,0);
                        }
                        if(result == 3){
                            showPng(3,1,0);
                        }
                    }
                }
                if(e.keyCode == 100){
                    if(game_id == 1){
                        var result = $('#opening').val();
                        $('#result_player_pair').val('2');
                        $('#result_banker_pair').val('0');
                        if(result == 1){
                            showPng(1,2,0);
                        }
                        if(result == 2){
                            showPng(2,2,0);
                        }
                        if(result == 3){
                            showPng(3,2,0);
                        }
                    }
                }
                if(e.keyCode == 101){
                    if(game_id == 1){
                        var result = $('#opening').val();
                        $('#result_banker_pair').val('1');
                        $('#result_player_pair').val('2');
                        if(result == 1){
                            showPng(1,3,0);
                        }
                        if(result == 2){
                            showPng(2,3,0);
                        }
                        if(result == 3){
                            showPng(3,3,0);
                        }
                    }
                }
            }
        }
    })
    $(window).resize(function(){
        requestData(ludan);
    })
    audio.addEventListener("ended", nextAudio);
    getTime();
    // 日期
    setInterval(function(){
        getTime();
    }, 1000);
    // 侧栏控台
    $(".control-box").hover(function(){
        $(".control-box").stop().animate({right:"0"})
    },function(){
        $(".control-box").stop().animate({right:"-410px"})
    })
    // 多语言切换
    $('#language').change(function(){
        var language = $('#language').val();
        if(language == "cn" || language == "tw" || language == "en"){
            $.get("/index/lang?lang="+language,function(data){
                location.reload();
            })
        }
    });
    $("#confirm_update_ludan").click(function (){
        retreated();
    });
    $("#cancel_update_ludan").click(function (){
        $('#update_ludan').hide();
    });
    // 色碟方法
    $('.toning-result-num').click(function () {
        $('#toning_result').val(parseInt($(this).html()));
        $(this).addClass("active").siblings().removeClass("active");
    })

    // 牛牛识别
    if (scanner_type == 2 && game_id == 4) {
        $('.begincard .card').find(".face").on('click', function() {
            openAllCardsPanel(this);
        });
    }

})
function loginout(){
    isCBoot = true;
    layer.confirm(lang.is_to_logout,{btn: [lang.confirm,lang.cancel],title:lang.message}, function(index){
        window.location.href='/login/logout';
        isCBoot = false;
        layer.close(index);
    },function(index){
        isCBoot = false;
    });
};
function showPng(opening, pair,isVoice){
    if(opening == 1 && pair == 0) {
        $('#openingPng').attr('src','/static/result_img/3in1/banker.png');
        if(isVoice){
            mp3List = ['banker_win.mp3'];
        }

    }
    if(opening == 1 && pair == 1) {
        $('#openingPng').attr('src','/static/result_img/3in1/banker_bpair.png');
        if(isVoice){
            mp3List = ['banker_win.mp3','banker_pair.mp3'];
        }

    }
    if(opening == 1 && pair == 2) {
        $('#openingPng').attr('src','/static/result_img/3in1/banker_ppair.png');
        if(isVoice){
            mp3List = ['banker_win.mp3','player_pair.mp3'];
        }

    }
    if(opening == 1 && pair == 3) {
        $('#openingPng').attr('src','/static/result_img/3in1/banker_bpair_ppair.png');
        if(isVoice){
            mp3List = ['banker_win.mp3','banker_pair.mp3','player_pair.mp3'];
        }

    }
    if(opening == 2 && pair == 0) {
        $('#openingPng').attr('src','/static/result_img/3in1/player.png');
        if(isVoice){
            mp3List = ['player_win.mp3'];
        }


    }
    if(opening == 2 && pair == 1) {
        $('#openingPng').attr('src','/static/result_img/3in1/player_bpair.png');
        if(isVoice){
            mp3List = ['player_win.mp3','banker_pair.mp3'];
        }

    }
    if(opening == 2 && pair == 2) {
        $('#openingPng').attr('src','/static/result_img/3in1/player_ppair.png');
        if(isVoice){
            mp3List = ['player_win.mp3','player_pair.mp3'];
        }

    }
    if(opening == 2 && pair == 3) {
        $('#openingPng').attr('src','/static/result_img/3in1/player_bpair_ppair.png');
        if(isVoice){
            mp3List = ['player_win.mp3','banker_pair.mp3','player_pair.mp3'];
        }

    }
    if(opening == 3 && pair == 0) {
        $('#openingPng').attr('src','/static/result_img/3in1/tie.png');
        if(isVoice){
            mp3List = ['tie.mp3'];
        }

    }
    if(opening == 3 && pair == 1) {
        $('#openingPng').attr('src','/static/result_img/3in1/tie_bpair.png');
        if(isVoice){
            mp3List = ['tie.mp3','banker_pair.mp3'];
        }

    }
    if(opening == 3 && pair == 2) {
        $('#openingPng').attr('src','/static/result_img/3in1/tie_ppair.png');
        if(isVoice){
            mp3List = ['tie.mp3','player_pair.mp3'];
        }

    }
    if(opening == 3 && pair == 3) {
        $('#openingPng').attr('src','/static/result_img/3in1/tie_bpair_ppair.png');
        if(isVoice){
            mp3List = ['tie.mp3','banker_pair.mp3','player_pair.mp3'];
        }

    }
    if(isVoice){
        audioMp3(mp3List).Play();
    }

}

function showPngDt (opening,isVoice){
    if(opening == 1) {
        $('#openingPng').attr('src','/static/result_img/3in1/drogon.png');
        if(isVoice){
            mp3List = ['dragon_win.mp3'];
        }
    }
    if(opening == 2) {
        $('#openingPng').attr('src','/static/result_img/3in1/tiger.png');
        if(isVoice){
            mp3List = ['tiger_win.mp3'];
        }
    }
    if(opening == 3) {
        $('#openingPng').attr('src','/static/handle/result_img/3in1/tie.png');
        if(isVoice){
            mp3List = ['tie.mp3'];
        }
    }
    if(isVoice){
        audioMp3(mp3List).Play();
    }
}

function gameResult(data){
    var result_imgsrc='',Result='';
    switch(true){
        case data.round.opening==1:// 庄
            Result='banker';
            $(".begincard .card-box .banker-card").addClass("win").siblings().removeClass("win");
            break;
        case data.round.opening==2:// 闲
            Result='player';
            $(".begincard .card-box .player-card").addClass("win").siblings().removeClass("win");
            break;
        case data.round.opening==3:// 和
            Result='tie'
            break;
    }
    if(data.round.pair==1){
        result_imgsrc=Result+'_bpair'
    }else if(data.round.pair==2){
        result_imgsrc=Result+'_ppair'
    }else if(data.round.pair==3){
        result_imgsrc=Result+'_bpair_ppair'
    }else{
        result_imgsrc=Result
    }
    var src='/static/result_img/3in1/'+result_imgsrc+'.png'
    $(".begincard .player-card .draw .text ").html(lang.player_all+' '+data.round.player+' '+lang.point)
    $(".begincard .banker-card .draw .text ").html(lang.banker_all+' '+data.round.banker+' '+lang.point);
    $('#openingElement').show();
    $('#openingElement').addClass("blink");
    isopentime=false;
    setTimeout(function(){

        $('#openingElement').removeClass("blink");
        $('#openingElement').hide();
        $('#opening').val('0');
        $('#result_banker_pair').val('0');
        $('#result_player_pair').val('0');
    },3000)
}
//获取当前语言包
function getLang(){
    $.ajax({
        url:"/index/get_lang",
        type:"POST",
        dataType:"JSON",
        async:false,
        success:function(data){
            if(data.status === 1){
                lang = data.lang;
            }
        }
    })
}
//倒计时
function countDown(time) {
    $(".countdown .num").html(time)
    $(".countdown").css({"opacity":1,"display":"block"});
    $(".countdown .grab-count").addClass("count-active");
    if(time == 10){
        mp3List = ['time_tip_10.mp3'];
        audioMp3(mp3List).Play();
    }
    if(time < 9 && time > 0){
        mp3List = ['time.mp3'];
        audioMp3(mp3List).Play();
    }
    if(time<=0){
        mp3List = ['stop_2.mp3'];
        audioMp3(mp3List).Play();
        $(".countdown").css({"opacity":0,"display":"none"});
        $(".countdown .grab-count").removeClass("count-active");
        return;
    }
}
//播放声音
function audioMp3(mp3List){
    var mp3=new Object();
    mp3.mp3List=mp3List;
    mp3.url="/static/handle/mp3/";
    mp3.auto_play=false;
    mp3.loop=false;
    mp3.Play=function(){
        audio.src=this.url+this.mp3List[0];
        audio.play();
    }
    mp3.Muted=function(){
        audio.muted ? audio.muted = false : audio.muted = true;
    }
    mp3.volumeAdd=function(){
        if(audio.volume.toFixed(1)>=1){
            audio.volume=1
        }else{
            audio.volume = audio.volume + 0.1;
        }
    }
    mp3.volumeMinus=function(){
        if(audio.volume.toFixed(1)<=0){
            audio.volume=0
        }else{
            audio.volume = audio.volume - 0.1;
        }
    }
    return mp3;
}
//显示牌面
var showCard = function(showCard){
    $(".begincard").fadeIn(function(){
        $(".begincard .box").animate({"opacity":"1"});
        $(".table-info .nobegin-tip").fadeOut();
    });
    $.each(showCard,function(i,v){
        if(v.number!=false){
            var _thisdata={"status":true,round:v}
            Flop(_thisdata);
        }
    })
}
//是否显示补牌
function isShowSupport(isSupport){
    if(isSupport.is_bopai){
        if(isSupport.player_3 == 1){
            $('.begincard .player-card .draw .rotate').css("display","inline-block")
        }
        if(isSupport.banker_3 == 1){
            $('.begincard .banker-card .draw .rotate').css("display","inline-block")
        }
    }
}
function Flop(data){
    var whichpoker='',pokerindex='',pokercard='';
    if(data.status==true){
        var which = data.round.position;
        if(game_id == 1){
            switch(which){
                case 11:
                    whichpoker='player-card';
                    pokerindex=1;
                    card_info["player_2"]=data.round.number;
                    break;
                case 12:
                    whichpoker='player-card';
                    pokerindex=0;
                    card_info["player_1"]=data.round.number;
                    break;
                case 13:
                    whichpoker='player-card';
                    pokerindex=2;
                    card_info["player_3"]=data.round.number;
                    break;
                case 21:
                    whichpoker='banker-card';
                    pokerindex=1;
                    card_info["banker_2"]=data.round.number;
                    break;
                case 22:
                    whichpoker='banker-card';
                    pokerindex=0;
                    card_info["banker_1"]=data.round.number;
                    break;
                case 23:
                    whichpoker='banker-card';
                    pokerindex=2;
                    break;
            }
        }else{
            switch(which){
                case 11:
                    whichpoker='player-card';
                    pokerindex=0;
                    card_info["player_1"]=data.round.number;
                    break;
                case 21:
                    whichpoker='banker-card';
                    pokerindex=0;
                    card_info["banker_1"]=data.round.number;
                    break;
            }
        }

        if(game_id==1){
            let support = isBopai(card_info);
            isShowSupport(support);
        }
        pokercard = data.round.card;
        var $poker = $('.begincard '+'.'+ whichpoker+' .card');
        var pokersrc="/static/handle/faces/"+pokercard+".svg";
        if(pokercard<200){
            var color="#000"
        }else if(pokercard<300){
            var color="#f13b3d"
        }else if(pokercard<400){
            var color="#000"
        }else if(pokercard<500){
            var color="#f13b3d"
        }
        if(data.round.number == 1){
            data.round.number = "A";
        }
        if(data.round.number == 11){
            data.round.number = "J";
        }
        if(data.round.number == 12){
            data.round.number = "Q";
        }
        if(data.round.number == 13){
            data.round.number = "K";
        }
        $poker.eq(pokerindex).find(".topleft").html(data.round.number);
        $poker.eq(pokerindex).find(".bottomright").html(data.round.number);
        $poker.eq(pokerindex).find(".topleft").css("color",color);
        $poker.eq(pokerindex).find(".bottomright").css("color",color);

        if(pokerindex==2){
            $('.begincard '+'.'+ whichpoker +' .draw .rotate').css("display","inline-block");
            $poker.eq(pokerindex).addClass("begin");
            $poker.eq(pokerindex).find(".face").css("background-image","url("+pokersrc+")");
            $(".begincard .banker-card .draw .text").css("text-align","left");
            $(".begincard .player-card .draw .text").css("text-align","right");
        }else{
            $poker.eq(pokerindex).addClass("begin");
            $poker.eq(pokerindex).find(".face").css("background-image","url("+pokersrc+")");
        }
    }
}
//百家乐判断是否要博牌
function isBopai(card_info){
    card_info["length"]=0;
    for( var i in card_info) { card_info["length"]++; }
    var bopai_info = Array(3);
    if(card_info.length<4){
        bopai_info['is_bopai'] = false;
        bopai_info['banker_3'] = 0;
        bopai_info['player_3'] = 0;
        card_info=[];
        return bopai_info;
    }
    else {
        if (card_info['banker_1'] > 10) {
            card_info['banker_1'] = 10;
        }
        if (card_info['banker_2'] > 10) {
            card_info['banker_2'] = 10;
        }
        if (card_info['banker_3'] > 10) {
            card_info['banker_3'] = 10;
        }
        if (card_info['player_1'] > 10) {
            card_info['player_1'] = 10;
        }
        if (card_info['player_2'] > 10) {
            card_info['player_2'] = 10;
        }
        if (card_info['player_3'] > 10) {
            card_info['player_3'] = 10;
        }
        var card_length = card_info.length;
        var banker_result = (card_info['banker_1'] + card_info['banker_2']) % 10;
        var player_result = (card_info['player_1'] + card_info['player_2']) % 10;
        if (card_length == 4) {
            if (player_result == 8 || player_result == 9) {
                bopai_info['is_bopai'] = false;
                bopai_info['banker_3'] = 0;
                bopai_info['player_3'] = 0;

            }
            else if (banker_result == 8 || banker_result == 9) {
                bopai_info['is_bopai'] = false;
                bopai_info['banker_3'] = 0;
                bopai_info['player_3'] = 0;
            }
            else if (player_result == 0 || player_result == 1 || player_result == 2 || player_result == 3 || player_result == 4 || player_result == 5) {
                bopai_info['is_bopai'] = true;
                bopai_info['banker_3'] = 0;
                bopai_info['player_3'] = 1;

            }
            else if (banker_result == 0 || banker_result == 1 || banker_result == 2 || banker_result == 3 || banker_result == 4 || banker_result == 5) {
                bopai_info['is_bopai'] = true;
                bopai_info['banker_3'] = 1;
                bopai_info['player_3'] = 0;

            }
            else if (player_result == 6 || player_result == 7) {
                bopai_info['is_bopai'] = false;
                bopai_info['banker_3'] = 0;
                bopai_info['player_3'] = 0;

            }
        }
        else if (card_length == 5) {
            if (card_info['player_3'] > 0) {
                if (banker_result == 0 || banker_result == 1 || banker_result == 2) {
                    bopai_info['is_bopai'] = true;
                    bopai_info['banker_3'] = 1;
                    bopai_info['player_3'] = 0;
                }
                else if (banker_result == 3) {
                    if (card_info['player_3'] == 1 || card_info['player_3'] == 2 || card_info['player_3'] == 3 || card_info['player_3'] == 4 || card_info['player_3'] == 5 || card_info['player_3'] == 6 || card_info['player_3'] == 7 || card_info['player_3'] == 9 || card_info['player_3'] == 10) {
                        bopai_info['is_bopai'] = true;
                        bopai_info['banker_3'] = 1;
                        bopai_info['player_3'] = 0;
                    }
                    else if (card_info['player_3'] == 8) {
                        bopai_info['is_bopai'] = false;
                        bopai_info['banker_3'] = 0;
                        bopai_info['player_3'] = 0;
                    }
                }
                else if (banker_result == 4) {
                    if (card_info['player_3'] == 2 || card_info['player_3'] == 3 || card_info['player_3'] == 4 || card_info['player_3'] == 5 || card_info['player_3'] == 6 || card_info['player_3'] == 7) {
                        bopai_info['is_bopai'] = true;
                        bopai_info['banker_3'] = 1;
                        bopai_info['player_3'] = 0;
                    }
                    else if (card_info['player_3'] == 1 || card_info['player_3'] == 8 || card_info['player_3'] == 9 || card_info['player_3'] == 10) {
                        bopai_info['is_bopai'] = false;
                        bopai_info['banker_3'] = 0;
                        bopai_info['player_3'] = 0;
                    }
                }
                else if (banker_result == 5) {
                    if (card_info['player_3'] == 4 || card_info['player_3'] == 5 || card_info['player_3'] == 6 || card_info['player_3'] == 7) {
                        bopai_info['is_bopai'] = true;
                        bopai_info['banker_3'] = 1;
                        bopai_info['player_3'] = 0;

                    }
                    else  if (card_info['player_3'] == 1 || card_info['player_3'] == 2 || card_info['player_3'] == 3 || card_info['player_3'] == 8 || card_info['player_3'] == 9 || card_info['player_3'] == 10) {
                        bopai_info['is_bopai'] = false;
                        bopai_info['banker_3'] = 0;
                        bopai_info['player_3'] = 0;
                    }
                }
                else if (banker_result == 6) {
                    if (card_info['player_3'] == 6 || card_info['player_3'] == 7) {
                        bopai_info['is_bopai'] = true;
                        bopai_info['banker_3'] = 1;
                        bopai_info['player_3'] = 0;
                    }
                    else if (card_info['player_3'] == 1 || card_info['player_3'] == 2 || card_info['player_3'] == 3 || card_info['player_3'] == 4 || card_info['player_3'] == 5 || card_info['player_3'] == 8 || card_info['player_3'] == 9 || card_info['player_3'] == 10) {
                        bopai_info['is_bopai'] = false;
                        bopai_info['banker_3'] = 0;
                        bopai_info['player_3'] = 0;
                    }
                }
                else if (banker_result == 7) {
                    bopai_info['is_bopai'] = false;
                    bopai_info['banker_3'] = 0;
                    bopai_info['player_3'] = 0;
                }
            } else {
                bopai_info['is_bopai'] = false;
                bopai_info['banker_3'] = 0;
                bopai_info['player_3'] = 0;
            }
        }
        card_info=[];
        return bopai_info;
    }
}
var showCardNn = function(data){
    $(".begincard").fadeIn(function(){
        $(".begincard .box").animate({"opacity":"1"});
        $(".begincard .box1").animate({"top":"100%","opacity":"1"});
        $(".begincard .box2").animate({"top":"100%","opacity":"1"});
        $(".begincard .box3").animate({"top":"100%","opacity":"1"});
        $(".begincard .box4").animate({"top":"100%","opacity":"1"});
    });
    card_number_info = data;
    if(card_number_info.length > 0){
        for(var i=0;i<card_number_info.length;i++){
            if(card_number_info[i]['order_num'] == 0){
                pokercard=card_number_info[i]['card'];
                pokersrc="/static/poker/"+pokercard+".png";
                $('.begincard .position-card .card').css("opacity",1);
                $('.begincard .position-card .card').find(".face").css("background-image","url("+pokersrc+")");
            }else{
                pokercard=card_number_info[i]['card'];
                order_num = card_number_info[i]['order_num'];
                card_cow = card_number_info[i]['order_num'].substring(0,1);
                card_list = card_number_info[i]['order_num'].substring(1,2) - 1;
                if(card_cow == 1){
                    box_name = 'player-1-card';
                    if(card_number_info[i]['result']){
                        $('.player_1_result').html(card_number_info[i]['result']);
                    }
                }else if(card_cow == 2){
                    box_name = 'player-2-card';
                    if(card_number_info[i]['result']){
                        $('.player_2_result').html(card_number_info[i]['result']);
                    }
                }else if(card_cow == 3){
                    box_name = 'player-3-card';
                    if(card_number_info[i]['result']){
                        $('.player_3_result').html(card_number_info[i]['result']);
                    }
                }else if(card_cow == 4){
                    box_name = 'banker-card';
                    if(card_number_info[i]['result']){
                        $('.banker_result').html(card_number_info[i]['result']);
                    }
                }
                $poker=$('.begincard '+'.'+ box_name+' .card');
                pokersrc="/static/poker/"+pokercard+".png";
                $poker.eq(card_list).find(".face").css("background-image","url("+pokersrc+")")
                $('.begincard '+'.'+ box_name).find(".card").eq(card_list).css('opacity',1);
            }
        }
    }
}
// 桌子状态
var setBetStatus = function (BetStatus){
    $('#number_tab_status').val(BetStatus.bet_status);
    $('#betstatus').html(lang[BetStatus.bet_msg]);
};
// 获取桌子数据
var setNumberInfo = function (round){
    number_tab_id = round.number_tab_id
    $('#boot_num').val(round.boot_num);
    $('#number_tab_number').val(round.number_tab_number);
    $('#boot_id').val(round.boot_id);
};
// 重置下注数目
var clearBetAmount = function (){
    $('#banker_amount').html(0);
    $('#player_amount').html(0);
    $('#tie_amount').html(0);
    $('#banker_pair_amount').html(0);
    $('#player_pair_amount').html(0);
    $('#all_amount').html(0);
};
//修改或者删除录单后从新获取number
var getNumber = function (){
    var query = new Object();
    query.number_tab_id = number_tab_id;
    $.ajax({
        url:"/index/get_number",
        type:"POST",
        dataType:"JSON",
        data:query,
        async:false,
        success:function(data){
            if(data.status == 1){
                $('#number').html(data.data);
            }
        }
    })
};
function nextAudio(){
    num+=1
    if(num<mp3List.length){
        audio.src="/static/handle/mp3/"+mp3List[num];
        audio.play();
    }else{
        audio.pause();
        audio.currentTime = 0.0;
        num=0;
    }
}
function countDownRob(time) {
    var table_id = $('#table_id').val();
    $(".countdown .num").html(time);
    $(".countdown").css({"opacity":1,"display":"block"});
    $(".countdown .grab-count").addClass("count-active");
    //$(".countdown").fadeIn();
    if(time < 5 && time > 0){
        mp3List = ['time.mp3'];
        audioMp3(mp3List).Play();
    }
    if(time<=0){
        // mp3List = ['end_rob.mp3'];
        // audioMp3(mp3List).Play();
        $(".countdown").css({"opacity":0,"display":"none"});
        $(".countdown .grab-count").removeClass("count-active");
        webSocket.send('{"connect":"space","mode":"endRob","number_tab_id":"'+parseInt(number_tab_id)+'","table_id":"'+parseInt(table_id)+'"}');
        return;
    }
}
function getTime() {
    var today = new Date();
    var h = today.getHours();
    var minute = today.getMinutes()
    var s = today.getSeconds();
    if (h < 10) {
        h = "0" + h;
    }
    if (minute < 10) {
        minute = "0" + minute;
    }
    if (s < 10) {
        s = "0" + s;
    }
    if(lang.lang == 'en-us'){
        var strDate = new Date();
        strDate = strDate.toDateString()
        strDate += " " + h + ":" + minute + ":" + s;
    }else if(lang.lang == 'zh-cn'){
        var strDate = (" " + today.getFullYear() + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日" + h + ":" + minute + ":" + s);
    }else if(lang.lang == 'zh-tw'){
        var strDate = (" " + today.getFullYear() + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日" + h + ":" + minute + ":" + s);
    }
    var n_day = today.getDay();
    switch (n_day) {
        case 0:
            var week = lang.sunday;
            break;
        case 1:
            var week = lang.monday;
            break;
        case 2:
            var week = lang.tuesday;
            break;
        case 3:
            var week = lang.wednesday;
            break;
        case 4:
            var week = lang.thursday;
            break;
        case 5:
            var week = lang.friday;
            break;
        case 6:
            var week = lang.saturday;
            break;
        case 7:
            var week = lang.sunday;
            break;
    }
    $('.date .weekend').html(week);
    $('.date .time').html(strDate);
}
// 请求所有路单数据，执行画布刷新
function waybillFunc(){
    var data = new Object;
    data.boot_id = $('#boot_id').val();
    data.game_id = game_id;
    var url="/index/waybill"
    $.ajax({
        url:url,
        type:"POST",
        dataType:"JSON",
        data:data,
        success:function(data){
            ludan = data;
            requestData(ludan);
        }
    });
}
function requestData(data,ask,askroad){
    var ask=ask||false;
    var askroad=askroad||{
        "askshowroad":false,
        "askbigRoad":false,
        "askbigEyeRoad":false,
        "askpathway":false,
        "askroach":false,
        "asksanxingRoad":false,
    };

    bigH=$(".canvas-box.big").height();
    bigW=$(".canvas-box.big").width();
    // 计算单位
    unitbig=bigH/6;
    // 计算列个数

    colbig=Math.floor(bigW/unitbig);
    smallH=$(".canvas-box.small").height();
    smallW=$(".canvas-box.small").width();
    unitsmall=smallH/6;
    colsmall=Math.floor(smallW/unitsmall);
    CanvasTable("#canvas1",unitsmall,6,colsmall,data,ask,askroad);
    CanvasTable("#canvas2",unitsmall,6,colsmall,data,ask,askroad);
    CanvasTable("#canvas3",unitbig,6,colbig,data,ask,askroad);
}
function CanvasTable(Id,unit,rows,cols,data,ask,askroad){
    var width=unit*cols,height=unit*rows;
    $(Id).attr("width",width)
    $(Id).attr("height",height)
    var canvasId=$(Id);
    var ctb=canvasId[0].getContext('2d');
    ctb.lineWidth = 1;//线条宽度
    ctb.strokeStyle = "#919191";//线条颜色
    ctb.beginPath();
    ctb.moveTo(0, 0.5);
    ctb.lineTo(width, 0.5);
    for (var i = 0; i <= rows; i++) {
        ctb.moveTo(0, unit*i);
        ctb.lineTo(width, unit*i);
    }
    ctb.closePath();
    ctb.stroke();
    ctb.beginPath();
    ctb.moveTo(0.5, 0);
    ctb.lineTo(0.5, height);
    for (var j = 1; j <= cols; j++) {
        ctb.moveTo(unit*j,0);
        ctb.lineTo(unit*j,height);
    }
    ctb.closePath()
    ctb.stroke();
    if(data.status){
        switch(true){
            // 判断是否滚动
            case Id=="#canvas3":
                var showRoad=data.waybill.showRoad;
                if(showRoad!=''){
                    var roadType="showWay";
                    cutRoad(roadType,ctb,unit,showRoad,cols,ask,askroad.askshowroad);
                }
                break;
            case Id=="#canvas1":
                var bigRoad=data.waybill.bigRoad;
                if(bigRoad!=''){
                    if(bigRoad[0].result==3&&bigRoad[0].show_x==1&&bigRoad[0].show_y==1){
                        BigPathTie(ctb,unit,bigRoad[0].tie_num)
                    }else{
                        var roadType="bigWay";
                        cutRoad(roadType,ctb,unit,bigRoad,cols,ask,askroad.askbigRoad);
                    }
                }
                break;
            case Id=="#canvas2":
                var bigEyeRoad=data.waybill.bigEyeRoad;
                var pathway=data.waybill.pathway;
                var roach=data.waybill.roach;
                var sanxingRoad=data.waybill.sanxingRoad;
                if(bigEyeRoad!=''){
                    var roadType="bigeyeWay"
                    cutRoad(roadType,ctb,unit,bigEyeRoad,cols,ask,askroad.askbigEyeRoad);
                };
                if(pathway!=''){
                    var roadType="littlWay"
                    cutRoad(roadType,ctb,unit,pathway,cols,ask,askroad.askpathway);
                };
                if(roach!=''){
                    var roadType="roachWay";
                    cutRoad(roadType,ctb,unit,roach,cols,ask,askroad.askroach);
                };
                if(sanxingRoad!=''){
                    var roadType="sanxingWay";
                    cutRoad(roadType,ctb,unit,sanxingRoad,cols,ask,askroad.askroach);
                };
                break;
        }
    }
}
// 前端路单数据截取
function cutRoad(roadType,ctb,unit,roadData,cols,ask,askroad){
    var L=roadData.length;
    var new_roadData=[];
    var Tab=0
    if(roadType=="showWay"||roadType=="bigWay"){
        if(ask&&askroad){
            Tab=cols;
        }else{
            Tab=cols-1;
        }
    }else{
        if(ask&&askroad){
            Tab=cols-1;
        }else{
            Tab=cols-2;
        }
    }
    var start_x=cols/2+0.25;
    var sanxingSatrtX = cols/2+0.5;
    if(L>=1){
        var last_x=roadData[L-1].show_x;
        if(last_x>Tab){
            var cut=last_x-Tab
            $.each(roadData,function(i,v){
                if(v.show_x>cut){
                    new_roadData.push(v);
                }
            })
        }else{
            new_roadData=roadData;
            cut=0;
        }
    }else{
        new_roadData=roadData;
        cut=0;
    }
    $.each(new_roadData,function(i,v){
        if(roadType=="roachWay"){
            CockrochPath(ctb,unit,start_x,v.show_x-cut,v.show_y,v.result)
        }else if(roadType=="littlWay"){
            LittlePath(ctb,unit,v.show_x-cut,v.show_y,v.result)
        }else if(roadType=="bigeyeWay"){
            BigeyePath(ctb,unit,v.show_x-cut,v.show_y,v.result)
        }else if(roadType=="showWay"){
            SoloPath(ctb,unit,v.show_x-cut,v.show_y,v.result,v.pair,v.lucky_six)
        }else if(roadType=="bigWay"){
            BigPath(ctb,unit,v.show_x-cut,v.show_y,v.result,v.tie_num,v.pair)
        }else if(roadType=="sanxingWay"){
            sanxingPath(ctb,unit,sanxingSatrtX,v.show_x-cut,v.show_y,v.result)
        }
    })
}
// 局数 数，文字X坐标，文字Y坐标，文字大小风格
function Font_tie(ctb,num,Font_x,Font_y,fontsize){
    if(num!==undefined){
        ctb.beginPath();
        ctb.font=fontsize;
        ctb.textAlign = 'center';
        ctb.textBaseline = 'middle';
        ctb.fillStyle ="#242424";
        ctb.fillText(num,Font_x,Font_y);
        ctb.stroke();
    }
}
function SoloPath(ctb,unit,x,y,type,corners,luckySix){
    ctb.beginPath();
    ctb.lineWidth = 0.5;
    ctb.strokeStyle = "#000";
    var radius=unit/2||0;
    if(type==1){
        var color='#b20a00';
        if(game_id == 2){
            var fonts = lang.dragon;
        }else{
            if(luckySix == 1){
                var fonts = 6;
            }else{
                var fonts = lang.banker;
            }
        }
        ctb.strokeStyle = "#ff4a68";
    }else if(type==2){
        var color='#0543bc';
        if(game_id == 2){
            var fonts = lang.tiger;
        }else{
            var fonts = lang.player;
        }
        ctb.strokeStyle = "#7e7df6";
    }else if(type==3){
        var color='#1d8701',
            fonts= lang.tie;
        ctb.strokeStyle = "#71df57";
    }
    ctb.arc(radius+unit*(x-1), radius+unit*(y-1), unit*0.45, 0, Math.PI * 2);
    ctb.fillStyle=color;
    ctb.fill();
    ctb.font="bold "+unit*0.6+"px Arial";
    ctb.fillStyle ="#fff" ; // 颜色
    ctb.textAlign = 'center';
    ctb.textBaseline = 'middle';
    ctb.fillText(fonts,radius+unit*(x-1),radius+unit*(y-1));
    ctb.stroke();
    var corner_xy=unit/3.5
    if(corners==1){
        corner(ctb,unit,x,y,corner_xy,'#ff2202');
    }else if(corners==2){
        corner(ctb,unit,x,y,-corner_xy,'#0337ff');
    }else if(corners==3){
        corner(ctb,unit,x,y,corner_xy,'#ff2202');
        corner(ctb,unit,x,y,-corner_xy,'#0337ff');
    }
}
//角标
function corner(ctb,unit,x,y,corner_xy,corner_color){
    var radius=unit/2
    ctb.beginPath();
    ctb.lineWidth = 0.5;
    ctb.strokeStyle = "#fff";
    ctb.arc(radius+unit*(x-1)-corner_xy, radius+unit*(y-1)-corner_xy, unit*0.13, 0, Math.PI * 2);
    ctb.fillStyle=corner_color;
    ctb.fill();
    ctb.stroke();
}
// 大路
function BigPath(ctb,unit,x,y,type,slash,corners){
    ctb.beginPath();
    ctb.lineWidth = unit*0.15;
    var radius=unit/2
    if(type==2){
        var color="#0543bc";
    }else if(type==1){
        var color="#b20a00"
    }
    ctb.strokeStyle = color;
    ctb.arc(radius+unit*(x-1),radius+unit*(y-1), unit*0.38, 0, Math.PI * 2);
    ctb.closePath()
    ctb.stroke();
    if(slash!=0){
        ctb.beginPath();
        linewidth=unit*0.2;
        ctb.lineWidth = 3;//线条宽度
        ctb.lineCap = "round";
        ctb.strokeStyle = "#1d8701";//线条颜色
        ctb.moveTo(radius+unit*(x-1)-linewidth,radius+unit*(y-1)+linewidth);
        ctb.lineTo(radius+unit*(x-1)+linewidth,radius+unit*(y-1)-linewidth);
        ctb.stroke();
        if(slash>0){
            Font_tie(ctb,slash,radius+unit*(x-1), radius+unit*(y-1),unit*0.66+"px Arial");
        }
    }
    var corner_xy=unit/3.5
    if(corners==1){
        corner(ctb,unit,x,y,corner_xy,'#ff2202');
    }else if(corners==2){
        corner(ctb,unit,x,y,-corner_xy,'#0337ff');
    }else if(corners==3){
        corner(ctb,unit,x,y,corner_xy,'#ff2202');
        corner(ctb,unit,x,y,-corner_xy,'#0337ff');
    }
}

// 大路 第一局 和
function BigPathTie(ctb,unit,order){
    ctb.beginPath();
    ctb.lineWidth = 2.5;//线条宽度
    ctb.strokeStyle = "#3faa96";//线条颜色
    ctb.lineCap = "round";
    ctb.moveTo(unit*0.15,unit/2);
    ctb.lineTo(unit*0.85,unit/2);
    ctb.stroke();
    Font_tie(ctb,order,unit/2, unit/2,unit*0.55+"px Arial");
}
// 大眼路
function BigeyePath(ctb,unit,x,y,type){
    ctb.beginPath();
    ctb.lineWidth = unit*0.10;
    var radius=unit/2
    if(type==2){
        var color="#0543bc";
    }else if(type==1){
        var color="#b20a00"
    }
    ctb.strokeStyle = color;
    ctb.arc(radius/2+radius*(x-1),radius/2+radius*(y-1), unit*0.17, 0, Math.PI * 2);
    ctb.closePath()
    ctb.stroke();
}
// 三星路
function sanxingPath(ctb,unit,start_x,x,y,type){
    ctb.beginPath();
    ctb.lineWidth = unit*0.15;
    if(type==2){
        var color="#0543bc";
    }else if(type==1){
        var color="#b20a00"
    }
    ctb.strokeStyle = color;
    ctb.arc(start_x*unit+unit*(x-1),unit*3.5+unit*(y-1), unit*0.38, 0, Math.PI * 2);
    ctb.closePath()
    ctb.stroke();
}
//小路
function LittlePath(ctb,unit,x,y,type){
    ctb.beginPath();
    ctb.lineWidth = 0;
    var radius=unit/2
    if(type==2){
        var color="#0543bc";
    }else if(type==1){
        var color="#b20a00"
    }
    ctb.strokeStyle = color;
    ctb.fillStyle=color;
    ctb.arc(radius/2+radius*(x-1),unit*3.25+radius*(y-1), unit*0.16, 0, Math.PI * 2);
    ctb.closePath()
    ctb.stroke();
    ctb.fill();
}
function CockrochPath(ctb,unit,start_x,x,y,type){
    var radius=unit/2,
        linewidth=unit*0.16;
    ctb.beginPath();
    ctb.lineCap = "round";
    ctb.lineWidth = 4;//线条宽度
    if(type==2){
        var color="#0543bc";
    }else if(type==1){
        var color="#b20a00"
    }
    ctb.strokeStyle = color;
    ctb.moveTo(start_x*unit+radius*(x-1)-linewidth,radius/2+radius*(y-1)+linewidth);
    ctb.lineTo(start_x*unit+radius*(x-1)+linewidth,radius/2+radius*(y-1)-linewidth);
    ctb.stroke();
}

function getResultToatl (BootId){
    var query = new Object();
    query.table_id = table_id;
    query.boot_id = BootId;
    $.ajax({
        url:'/index/get_result_total',
        data:query,
        dataType:"json",
        type:"POST",
        async:false,
        success:function(data){
            if(data.code == 1){
                var resultToatl = data.data;
                $('#result_total_player').html(resultToatl.player);
                $('#result_total_banker').html(resultToatl.banker);
                $('#result_total_tie').html(resultToatl.tie);
                if(game_id == 1){
                    $('#result_total_bankerpair').html(resultToatl.bankerPair);
                    $('#result_total_playerpair').html(resultToatl.playerPair);
                    $('#result_total_luckysix').html(resultToatl.luckySix);
                }
            }
        }
    });
}
var showForecast = function(){
    var len = 0;
    // 庄自动问路
    var bankerResult = getLudanBanker();
    if(bankerResult.status == true){
        var bankerResult = bankerResult.waybill;
        // 大眼路
        if(bankerResult.bigEyeRoad!=""){
            len = bankerResult.bigEyeRoad.length - 1;
            if(bankerResult.bigEyeRoad[len].result == 1){
                $('#bankerask').find('.circle').css('border-color','#b20a00').css('display','block');
            }else if(bankerResult.bigEyeRoad[len].result == 2){
                $('#bankerask').find('.circle').css('border-color','#0543bc').css('display','block');
            }
        }
        // 小路
        if(bankerResult.pathway!=""){
            len = bankerResult.pathway.length - 1;
            if(bankerResult.pathway[len].result == 1){
                $('#bankerask').find('.round').css('border-color','#b20a00').css('background-color','#b20a00').css('display','block');
            }else if(bankerResult.pathway[len].result == 2){
                $('#bankerask').find('.round').css('border-color','#0543bc').css('background-color','#0543bc').css('display','block');
            }
        }
        // 曱甴路
        if(bankerResult.roach!=""){
            len = bankerResult.roach.length - 1;
            if(bankerResult.roach[len].result == 1){
                $('#bankerask').find('.bar').removeClass('blue').removeClass('red');
                $('#bankerask').find('.bar').addClass('red').css('display','block');
            }else if(bankerResult.roach[len].result == 2){
                $('#bankerask').find('.bar').removeClass('blue').removeClass('red');
                $('#bankerask').find('.bar').addClass('blue').css('display','block');
            }
        }
    }
    // 闲自动问路
    var playerResult = getLudanPlayer();
    if(playerResult.status == true){
        var playerResult = playerResult.waybill;
        // 大眼路
        if(playerResult.bigEyeRoad!=""){
            var len = playerResult.bigEyeRoad.length - 1;
            if(playerResult.bigEyeRoad[len].result == 1){
                $('#playerask').find('.circle').css('border-color','#b20a00').css('display','block');
            }else if(playerResult.bigEyeRoad[len].result == 2){
                $('#playerask').find('.circle').css('border-color','#0543bc').css('display','block');
            }
        }
        // 小路
        if(playerResult.pathway!=""){
            len = playerResult.pathway.length - 1;
            if(playerResult.pathway[len].result == 1){
                $('#playerask').find('.round').css('border-color','#b20a00').css('background-color','#b20a00').css('display','block');
            }else if(playerResult.pathway[len].result == 2){
                $('#playerask').find('.round').css('border-color','#0543bc').css('background-color','#0543bc').css('display','block');
            }
        }
        // 曱甴路
        if(playerResult.roach!=""){
            len = playerResult.roach.length - 1;
            if(playerResult.roach[len].result == 1){
                $('#playerask').find('.bar').removeClass('blue').removeClass('red');
                $('#playerask').find('.bar').addClass('red').css('display','block');
            }else if(playerResult.roach[len].result == 2){
                $('#playerask').find('.bar').removeClass('blue').removeClass('red');
                $('#playerask').find('.bar').addClass('blue').css('display','block');
            }
        }
    }
};
// 换靴时隐藏自动问路
var hiddenForecast = function(){
    $('#bankerask').find('.circle').css('display','none');
    $('#bankerask').find('.round').css('display','none');
    $('#bankerask').find('.bar').css('display','none');
    $('#playerask').find('.circle').css('display','none');
    $('#playerask').find('.round').css('display','none');
    $('#playerask').find('.bar').css('display','none');
}
var getLudanBanker = function(){
    var next = new Object;
    next.boot_id = $('#boot_id').val();
    next.game_id = game_id;
    next.forecast = 1;
    $.ajax({
        url:"/index/waybill",
        type:"POST",
        dataType:"JSON",
        data:next,
        async:false,
        success:function(data){
            askData = data;
        }
    });
    return askData;
}
//闲问路
var getLudanPlayer = function(){
    var next = new Object;
    next.boot_id = $('#boot_id').val();
    next.game_id = game_id;
    next.forecast = 2;
    $.ajax({
        url:"/index/waybill",
        type:"POST",
        dataType:"JSON",
        data:next,
        async:false,
        success:function(data){
            askData = data;
        }
    });
    return askData;
}

function confirmResult(id,result){
    $('.control-box .btn-box2 span').eq(0).removeClass('on');
    $('.control-box .btn-box2 span').eq(1).removeClass('on');
    $('.control-box .btn-box2 span').eq(2).removeClass('on');
    var is_on=$("#"+id).hasClass("on");
    if(is_on){
        $("#"+id).removeClass("on")
    }else{
        $("#"+id).addClass("on")
    }
    $('#opening').val(result);
}
function confirmResultPair(id,result){
    if(result == 1){
        if($('#result_banker_pair').val() == 0){
            $("#"+id).addClass("on")
            $('#result_banker_pair').val(1);
        }else{
            $("#"+id).removeClass("on")
            $('#result_banker_pair').val(0);
        }
    }else if(result == 2){
        if($('#result_player_pair').val() == 0){
            $("#"+id).addClass("on")
            $('#result_player_pair').val(2);
        }else{
            $("#"+id).removeClass("on")
            $('#result_player_pair').val(0);
        }
    }else{
        layer.msg(lang.data_error);
    }
}
function setCurrencyLimit(){
    var currencyArr = []
    $('input[name="currencyType"]:checked').each(function(){
        currencyArr.push($(this).val())
    });
    var limit_bp = '';
    var limit_tie = '';
    var cnyLimit_bp = '';
    var cnyLimit_tie = '';
    var usdLimit_bp = '';
    var usdLimit_tie = '';
    if(game_id == 1){
        var cnyLimit_pair = '';
        var usdLimit_pair = '';
    }

    if($.inArray('CNY',currencyArr) >= 0){
        window.localStorage.setItem(table_id+"_CNY",'1')

        var cny_limit_bp = $('#cny_limit_bp').val();
        window.localStorage.setItem(table_id+"_cny_limit_bp",cny_limit_bp)
        cnyLimit_bp = 'CNY:'+cny_limit_bp

        var cny_limit_tie = $('#cny_limit_tie').val();
        window.localStorage.setItem(table_id+"_cny_limit_tie",cny_limit_tie)
        cnyLimit_tie = 'CNY:'+cny_limit_tie

        if(game_id == 1){
            var cny_limit_pair = $('#cny_limit_pair').val();
            window.localStorage.setItem(table_id+"_cny_limit_pair",cny_limit_pair)
            cnyLimit_pair = 'CNY:'+cny_limit_pair
        }
    }else{
        window.localStorage.setItem(table_id+"_CNY",'')
        window.localStorage.setItem(table_id+"_cny_limit_bp",'')
        window.localStorage.setItem(table_id+"_cny_limit_tie",'')
        if(game_id == 1){
            window.localStorage.setItem(table_id+"_cny_limit_pair",'')
        }
    }
    if($.inArray('USD',currencyArr) >= 0){
        window.localStorage.setItem(table_id+"_USD",'1')

        var usd_limit_bp = $('#usd_limit_bp').val();
        window.localStorage.setItem(table_id+"_usd_limit_bp",usd_limit_bp)
        usdLimit_bp = 'USD:'+usd_limit_bp

        var usd_limit_tie = $('#usd_limit_tie').val();
        window.localStorage.setItem(table_id+"_usd_limit_tie",usd_limit_tie)
        usdLimit_tie = 'USD:'+usd_limit_tie

        if(game_id == 1){
            var usd_limit_pair = $('#usd_limit_pair').val();
            window.localStorage.setItem(table_id+"_usd_limit_pair",usd_limit_pair)
            usdLimit_pair = 'USD:'+usd_limit_pair
        }
    }else{
        window.localStorage.setItem(table_id+"_USD",'')
        window.localStorage.setItem(table_id+"_usd_limit_bp",'')
        window.localStorage.setItem(table_id+"_usd_limit_tie",'')
        if(game_id == 1){
            window.localStorage.setItem(table_id+"_usd_limit_pair",'')
        }
    }
    limit_bp = cnyLimit_bp + '&nbsp;&nbsp;' + usdLimit_bp;
    $('.showLimitBP').html(limit_bp)
    limit_tie = cnyLimit_tie + '&nbsp;&nbsp;' + usdLimit_tie
    $('.showLimitTie').html(limit_tie)
    if(game_id == 1){
        limit_pair = cnyLimit_pair + '&nbsp;&nbsp;' + usdLimit_pair
        $('.showLimitPair').html(limit_pair)
    }
}
function checkLimit(){
    var cny = window.localStorage.getItem(table_id+"_CNY")
    if(cny){
        $('input[name=currencyType][value=CNY]').prop('checked',true)
    }else{
        $('input[name=currencyType][value=CNY]').prop('checked',false)
    }
    var usd = window.localStorage.getItem(table_id+"_USD")
    if(usd){
        $('input[name=currencyType][value=USD]').prop('checked',true)
    }else{
        $('input[name=currencyType][value=USD]').prop('checked',false)
    }
    var cny_limit_bp = window.localStorage.getItem(table_id+"_cny_limit_bp")
    $('#cny_limit_bp').val(cny_limit_bp)
    var cny_limit_tie = window.localStorage.getItem(table_id+"_cny_limit_tie")
    $('#cny_limit_tie').val(cny_limit_tie)
    if(game_id == 1){
        var cny_limit_pair = window.localStorage.getItem(table_id+"_cny_limit_pair")
        $('#cny_limit_pair').val(cny_limit_pair)
    }

    var usd_limit_bp = window.localStorage.getItem(table_id+"_usd_limit_bp")
    $('#usd_limit_bp').val(usd_limit_bp)
    var usd_limit_tie = window.localStorage.getItem(table_id+"_usd_limit_tie")
    $('#usd_limit_tie').val(usd_limit_tie)
    if(game_id == 1){
        var usd_limit_pair = window.localStorage.getItem(table_id+"_usd_limit_pair")
        $('#usd_limit_pair').val(usd_limit_pair)
    }

    var limit_bp = '';
    var limit_tie = '';
    if(game_id == 1){
        var limit_pair = '';
    }
    if(cny){
        limit_bp += "CNY:"+cny_limit_bp
        limit_tie += "CNY:"+cny_limit_tie
        if(game_id == 1){
            limit_pair += "CNY:"+cny_limit_pair
        }
    }
    if(usd){
        limit_bp += "  USD:"+usd_limit_bp
        limit_tie += "  USD:"+usd_limit_tie
        if(game_id == 1){
            limit_pair += "  USD:"+usd_limit_pair
        }
    }
    if(!limit_bp){
        limit_bp = '&nbsp;'
    }
    if(!limit_tie){
        limit_tie = '&nbsp;'
    }
    if(game_id == 1){
        if(!limit_pair){
            limit_pair = '&nbsp;'
        }
    }

    $('.showLimitBP').html(limit_bp)
    $('.showLimitTie').html(limit_tie)
    if(game_id == 1){
        $('.showLimitPair').html(limit_pair)
    }



}
