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

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


//读取身份证
function readIdInfo() {
    // logger('读取身份证');
    var lx = GetQuery('Lx');
    send_command(
        "idReaderReadInfo",
        "nothing",
        function (receivedData) {
            var idInfo = JSON.parse(receivedData);
            if (idInfo.status==100){
                // alert(idInfo);
            function saveInfo(){
                m_info=receivedData;
                save_info(m_info);
                delete m_info;
                delete receivedData;
                window.location.href = "/Ytj/qygsdz/caiji/"+type
                $.ajax({
                    "cache":false,
                    "url": "/Ytj/GsYw/CheckRz?card=" + idInfo.idCardNo+"&name="+encodeURI(idInfo.name),
                    "type": "get",
                    "dataType": "json",
                    "success": function (json) {
                        if(json.code==0) {
                            var data = json.data;
                            if (data[5]!=("成功")) {

                                $("#code").css("display", "block");
                                $(".Animation").css("display", "none");

                                $("#name").text(data[0])
                                $("#sfzh").text(data[1])
                                $("#sfsm").text(data[2])
                                $("#zcbj").text(data[3])
                                $("#jzrq").text(data[4])
                                $("#cxjg").text(data[5])
                            } else {
                                window.location.href = "/Ytj/qygsdz/caiji/"+type
                            }
                        }else {
                            alert('身份证读取错误,请联系工作人员!');
                            return false;
                        }
                    }
                });

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

function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}

function GetQuery(key) {
    var search = location.search.slice(1); //得到get方式提交的查询字符串
    var arr = search.split("&");
    for (var i = 0; i < arr.length; i++) {
        var ar = arr[i].split("=");
        if (ar[0] == key) {
            if (unescape(ar[1]) == 'undefined') {
                return "";
            } else {
                return unescape(ar[1]);
            }
        }
    }
    return "";
}

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;
}
