function logger(msg) {
    document.getElementById("logger").innerHTML = msg;
}

//离开关闭身份证读卡器
function stopidcard() {
    send_command(
        "stopRead",
        "nothing",
        function (receivedData) {
            //logger(receivedData);
        });
}

//读取身份证
function readIdInfo() {
    // logger('读取身份证');
 
    send_command(
        "idReaderReadInfo",
        "nothing",
        function (receivedData) {
            var idInfo = JSON.parse(receivedData);
            if (idInfo.status == 100) {
                function saveInfo() {
                    m_info = receivedData;
                    save_info(m_info);

                    var idInfo = read_info();
                    var info = JSON.parse(idInfo);
                    var id = info.idCardNo;


                    //window.location.href = "/GtgshPrint/Index?JingYingCard=" + compileStr(id);

                      $.ajax({
                        url: "/GtgshPrint/GetFlgData",
                        type: "post",
                        data: { JingYingCard: id },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                           
                            if (data.printCount == "1") {
                                if (data.Success != "1") {//没有审核通过
                                    var ShenHeDate = data.ShenHeDate;
                                    var ShenHeNote = data.ShenHeNote;
                                    var GtName = data.GtName;
                                    window.location.href = "/GtgshPrint/PrintHtml?JingYingCard=" + compileStr(id) + "&Flg=" + data.Success + "&ShenHeDate=" + ShenHeDate + "&ShenHeNote=" + ShenHeNote + "&GtName=" + GtName + "";
                                } else {
                                    window.location.href = "/GtgshPrint/ChengNuoShu?JingYingCard=" + compileStr(id) + "&BSID=" + compileStr(data.BSID);

                                    //window.location.href = "/GtgshPrint/Index?JingYingCard=" + compileStr(id);
                                }
                            } else {
                                window.location.href = "/GtgshPrint/Index?JingYingCard=" + compileStr(id);
                            }
                           
                        },
                        error: function (data) {
                            var dialog = jqueryAlert({
                                'style': 'wap',
                                'icon': '../../Content/Alert/img/error.png',
                                'content': '读取信息失败',
                                'closeTime': 2000,
                            })
                        }
                    });



                    delete m_info;
                    delete receivedData;
                }
                saveInfo();
            }
            else if (idInfo.status == 200) {
                //alert('身份证连接错误！请重试！');
                return false;
            }
        });
}



readIdInfo();


function compileStr(code) { //对字符串进行加密         
    var c = String.fromCharCode(code.charCodeAt(0) + code.length);
    for (var i = 1; i < code.length; i++) {
        c += String.fromCharCode(code.charCodeAt(i) + code.charCodeAt(i - 1));
    }
    return escape(c);
}


function uncompileStr(code) {       //对字符串进行解密  
    code = unescape(code);
    var c = String.fromCharCode(code.charCodeAt(0) - code.length);
    for (var i = 1; i < code.length; i++) {
        c += String.fromCharCode(code.charCodeAt(i) - c.charCodeAt(i - 1));
    }
    return c;
}