//打开签验
function openqianyuan() {
    $("#masking").show();
    $("#qianyan").show();
    $("#MyShipin").animate({ top: '160px', left: '50%', margin: '0 0 0 -387px', width: '280px', height: '280px' }, 500);
}
//校验主体（人脸识别）
swfobject.embedSWF("ckplayer/Index.swf", "Shipin1", "100%", "100%", "9.0.0");
function Paizhao() {
    var flash = (navigator.appName.indexOf("Microsoft") != -1) ? window["Shipin1"] : document["Shipin1"];
    flash.CallPaizhaos();
}
function PhotoPath(url) {
    purl = url;
    setTimeout(function () { document.getElementById("pzphoto").src = "/Resources/Face/" + url; }, 2000);
}
var face1 = "dc7247cc70c4a934cebd9a865606ed77";
var purl = "";
function callAS(json) {
    //alert(json);
    if (json == "") {
        document.getElementById("ld").innerHTML = "未能识别成功，请重试！";
    }
    else if (json == "1") {
        document.getElementById("ld").innerHTML = "正在进行人脸识别，请稍后！";
    }
    else {
        //document.getElementById("pp").src = "Resources/Face/" + purl;
        var obj = eval('(' + json + ')');
        document.getElementById("ld").innerHTML = "<img src='/Themes/Images/loading.gif' /><br />面部特征分析完毕，正在进行相似度比对！";
        var face2 = obj.photoface[0].face_id;
        $.get("FaceCompare.ashx",
                    { f1: face1, f2: face2 },
                    function (data) {
                        var strs = new Array();
                        strs = data.split(",");
                        if (strs.length > 1) {
                            document.getElementById("ld").innerHTML = strs[1];
                            State = 1;
                            document.getElementById("P_pz").disabled = "disabled";
                            document.getElementById("P_qd").disabled = "";
                            document.getElementById("P_qt").disabled = "disabled"
                        }
                        else {
                            document.getElementById("ld").innerHTML = data;
                            xyc = xyc + 1;
                        }
                    });
    }
}
//签到与签退
function Qiandao() {
    if (State == 0) {
        alert("请先拍照确认身份");
    }
    else if (State == 1) {
        //alert("签到成功！");
        State = 2;
        Tstate = 1;
        timedCount();
        document.getElementById("qianyan_title").innerHTML = "定时校验";
        document.getElementById("P_pz").disabled = "";
        document.getElementById("P_qt").disabled = "disabled";
        document.getElementById("P_qd").disabled = "disabled";
        $.get("/Ajax/Ajax_StudyAllOper.ashx", { action: "arrival" }, function (data) {
            signID = data;
            closeqianyuan();
            GetPlay();
        })
    }
    else if (State == 2) {
        //alert("签退成功！");
        State = 0;
        document.getElementById("P_pz").disabled = "";
        document.getElementById("P_qt").disabled = "disabled";
        document.getElementById("P_qd").disabled = "disabled";
        $.get("/Ajax/Ajax_StudyAllOper.ashx", { action: "sign", signID: signID }, function (data) {
            closeqianyuan();
        })
    }
    else {

    }
}
//计时器
var c = 0; //课程总培训时长
var xyt = 0, xyc = 0; //监听间隔,校验失败次数
var t = 0; //计时器间隔时间
function timedCount() {
    //初始化
    if (c == 0) {
        var numbers = document.getElementById("jindu_num").innerHTML;
        //alert(document.getElementById("jindu_num").innerHTML);
        c = Number(numbers) * 60;
    }
    if (isNaN(c)) {
        c = 0;
    }
    //alert(c);
    //增加进度
    if (Tstate == 1) {
        c = c + 1;
        xyt = xyt + 1;
        var min = parseInt(c / 60); // 分钟数
        var lastsecs = c % 60;
        document.getElementById("jindu_num").innerHTML = min + "." + lastsecs;
        var count = document.getElementById("jindu_count").innerHTML;
        document.getElementById("jindu_tiao").style.width = parseInt(min * 100 / count) + "px";
        //alert(parseInt(min * 100 / count));

        //校验(60秒拍照1次)
        if (xyt > 60) {
            Paizhao();
            xyt = 0;
            //alert("sd");
        }

        //当出现连续5次校验失败时，停止并提示
        if (xyc >= 5) {
            document.getElementById("qianyan_title").innerHTML = "定时拍照校验";
            State = 99;
            openqianyuan();
            Tstate = 0;
        }
    }
    setTimeout("timedCount()", 1000)

    //10秒回传1次数据
    t = t + 1;
    if (t > 10) {
        $.get("/Ajax/Ajax_StudyAllOper.ashx?action=Savedata&sID=" + signID + "&skID=" + Key + "&Tstate=" + Tstate);
    }
}

//放挂机程序
document.writeln("<div class=\"well\" id=\"guaji\"  style=\"position:absolute; left:50%; margin-left:-400px;top:25px; width:800px; font-size:12px; background:#000; border:1px #ccc solid; padding:5px; z-index:9999; display:none\"><div id=\"guaji_text\">您的电脑已经启动了防挂机验证程序,请在进度条走完前晃动鼠标或敲击任意键盘，否则学习系统将停止。</div><div id=\"guaji_err\" style=\"color:red; text-align:center; font-weight:bold;\"></div><div class=\"progress\" style=\"height:20px; border:1px #ccc solid; background-color:#FFFFFF; margin:5px;\"><div class=\"bar\" id=\"idlebar\" style=\"width: 0%;background-color:red; height:20px;\"></div></div></div>");
ifvisible.setIdleDuration(60);
ifvisible.idle(function () {
    $("#guaji_err").html("系统已经进入休眠，晃动鼠标可重新激活！");
    Tstate = 0;
    $("#guaji_err").show();
    $("#guaji_text").hide();
});
ifvisible.wakeup(function () {
    Tstate = 1;
    $("#guaji_text").show();
    $("#guaji_err").hide();
});
setInterval(function () {
    if (Tstate == 1) {
        var info = ifvisible.getIdleInfo();
        if (info.timeLeftPer < 3) {
            info.timeLeftPer = 0;
            info.timeLeft = ifvisible.getIdleDuration();
        }
        $("#idlebar").css("width", info.timeLeftPer + "%");
        if (info.timeLeftPer > 70) { $("#guaji").show(); } else { $("#guaji").hide(); }
    }
}, 100);