;(function(global,undefined) {
    "use strict" //使用js严格模式检查，使语法更规范
    var _global;
    var npDWebSignSeal = {
        waitcmddata:"",
        waitcmdext:"",
        Model:"server",//demo,oes,server
        uKey:false,
        AppVersion: "4,3,2,1",
        SignData:"",
        SignSha1:"",
        User:"测试用户",
        HttpAddress:"",
        RemoteID:"0100018",
        lPosX:"",
        lPosY:"",
        strTagName:"",
        strSealPath:"",
        strSealName:"",
        StoreData:"",
        StoreDatalist:[],
        seallist:[],
        sealId:"",
        isVerify:1,
        userId:"1135 C8D4 0000 0000 1C5E",
        sysId:"1",
        sysPwd:"123456",
        keyDN:"",
        KeySN:"",
        webSignList:[],
        n_seal_id:"",
        n_verify:"",
        n_seal_time:"",
        n_user_id:"",
        n_cert_id:"",
        n_id:"",
        OES:document.getElementById("oes_make"),
        GetSer: function () {
            var serhttp=this.HttpAddress.split("api");
            return serhttp[0];
        },
        SetSignData: function (n1){
            if(n1!=""){
                var strData=n1.split("+DATA:");
                if(strData.length>0)
                    this.SignData=strData[1];
                else
                    this.SignData=n1;
            }else{
                this.SignData="dianju";
            }
            return 0;
        },
        SetCurrUser: function (n1){
            if(n1!=""){
                this.User=n1;
            }else{
                this.User="测试用户";
            }
        },
        SetPosition: function (n1,n2,n3) {
            this.strTagName=n3;
            this.lPosX=n1;
            this.lPosY=n2;
        },
        showDiv: function () {
            document.getElementById('popDiv').style.display='block';
            document.getElementById('bg').style.display='block';
        },
        closeDiv: function () {
            document.getElementById('popDiv').style.display='none';
            document.getElementById('bg').style.display='none';
        },
        showMsg: function () {
            document.getElementById('msgDiv').style.display='block';
            document.getElementById('msgbg').style.display='block';
        },
        closeMsg: function () {
            document.getElementById('msgDiv').style.display='none';
            document.getElementById('msgbg').style.display='none';
        },
        showSealinfo: function () {
            var tbody=document.getElementById("msgbody");
            var slists='<tr style="background:#fff;">'+
                '<td>印章编号：</td>'+
                '<td>'+npDWebSignSeal.n_seal_id+'</td>'+
                '</tr>'+
                '<tr style="background:#fff;">'+
                '<td>节点名称：</td>'+
                '<td>'+npDWebSignSeal.n_seal_name+'</td>'+
                '</tr>'+
                '<tr style="background:#fff;">'+
                '<td>签章时间：</td>'+
                '<td>'+npDWebSignSeal.n_seal_time.substring(0,4)+'年'+npDWebSignSeal.n_seal_time.substring(4,6)+'月'+npDWebSignSeal.n_seal_time.substring(6,8)+'日'+npDWebSignSeal.n_seal_time.substring(8,10)+'时'+npDWebSignSeal.n_seal_time.substring(10,12)+'分'+npDWebSignSeal.n_seal_time.substring(12,14)+'秒</td>'+
                '</tr>';
            tbody.innerHTML=slists;
            this.showMsg();
        },
        showUser: function () {
            var tbody=document.getElementById("msgbody");
            var slists='<tr style="background:#fff;">'+
                '<td>证书SN：</td>'+
                '<td>'+npDWebSignSeal.n_user_id+'</td>'+
                '</tr>'+
                '<tr style="background:#fff;">'+
                '<td>证书DN：</td>'+
                '<td>'+npDWebSignSeal.n_cert_id+'</td>'+
                '</tr>';
            tbody.innerHTML=slists;
            this.showMsg();
        },
        showAbout: function () {
            var tbody=document.getElementById("msgbody");
            var slists='<tr style="background:#fff;">'+
                '<td>公司信息：</td>'+
                '<td>XX信息技术有限公司</td>'+
                '</tr>'+
                '<tr style="background:#fff;">'+
                '<td>版本号：</td>'+
                '<td>3,1,5,2</td>'+
                '</tr>';
            tbody.innerHTML=slists;
            this.showMsg();
        },
        GetSealId: function () {
            var seallist=document.getElementsByName("sealsRadios");
            for(var i=0; i<seallist.length; i ++){
                if(seallist[i].checked){
                    npDWebSignSeal.sealId=seallist[i].value;
                }
            }
            npDWebSignSeal.closeDiv();
            npDWebSignSeal.addseal();
        },
        GetSN:function (){
            this.GetValue("GET_CARDLIC_INFO:","npDWebSignSeal.retGetCard","","");
        },
        retGetCard:function (data){
            if(data.retstr!=""){
                this.GetSerialNumber("npDWebSignSeal.retGetSN","","");
            }else{
                alert("未授权的智能卡");
            }
        },
        retGetSN:function (data){
            if(data.retstr==""){
                alert("未发现有效的智能卡");
            }else{
                npDWebSignSeal.userId=data.retstr;
                npDWebSignSeal.GetSealList();
            }
        },
        GetSignP1:function (strbase64){
            this.GetValueEx("GET_DATA_SIGNMODE_P",0,"STRDATA:"+strbase64,0,"","npDWebSignSeal.retGetSignP1","","");
        },
        retGetSignP1:function (data){
            var sign=data.retstr;
            var xmlData = "<?xml version=\'1.0\' encoding=\'UTF-8\'?><root><BASE_DATA><SYS_ID>"+npDWebSignSeal.sysId+"</SYS_ID><SYS_PSW>"+npDWebSignSeal.sysPwd+"</SYS_PSW></BASE_DATA><info><user><userFlag>1</userFlag><certInfo>"+npDWebSignSeal.userId+"</certInfo></user><seal><sealId>"+npDWebSignSeal.sealId+"</sealId><sealName>"+npDWebSignSeal.strSealName+"</sealName><seal_position>"+npDWebSignSeal.strTagName+"</seal_position><seal_x>"+npDWebSignSeal.lPosX+"</seal_x><seal_y>"+npDWebSignSeal.lPosY+"</seal_y><oriData_sha1>"+npDWebSignSeal.SignSha1+"</oriData_sha1><signRes>"+sign+"</signRes></seal></info></root>";
            $.ajax({
                url:this.GetSer()+"getSignData",
                type:"post",
                async:false,
                dataType:"xml",
                data:{
                    xmlStr:xmlData
                },
                success:function(data){
                    var isflog=data.documentElement.childNodes[0].childNodes[0].textContent;
                    if(isflog==0) {
                        var newseal = data.childNodes[0].childNodes[0].childNodes[2].textContent;
                        if (newseal == "") {
                            alert("无效证书");
                        } else {
                            npDWebSignSeal.StoreDatalist[npDWebSignSeal.strSealName] = newseal;
                            npDWebSignSeal.StoreData = newseal;
                        }
                    }else{
                        alert(data.documentElement.childNodes[0].childNodes[1].textContent);
                    }
                },
                error:function(data){
                    console.log("e:"+data);
                }
            });
            npDWebSignSeal.ShowWebSeals();
        },
        GetSha1: function (){
            var xmlData = "<?xml version=\'1.0\' encoding=\'UTF-8\'?><root><BASE_DATA><SYS_ID>"+this.sysId+"</SYS_ID><SYS_PSW>"+this.sysPwd+"</SYS_PSW></BASE_DATA><info><user><userFlag>1</userFlag><certInfo>"+this.userId+"</certInfo></user><seal><sealId>"+this.sealId+"</sealId><sealName>"+this.strSealName+"</sealName><seal_position>"+this.strTagName+"</seal_position><seal_x>"+this.lPosX+"</seal_x><seal_y>"+this.lPosY+"</seal_y><oriData>"+this.SignData+"</oriData></seal></info></root>";
            $.ajax({
                url:this.GetSer()+"sealSha1",
                type:"post",
                async:false,
                dataType:"xml",
                data:{
                    xmlStr:xmlData
                },
                success:function(data){
                    var isflog=data.documentElement.childNodes[0].childNodes[0].textContent;
                    if(isflog==0) {
                        npDWebSignSeal.SignSha1=data.childNodes[0].childNodes[0].childNodes[2].textContent;
                        npDWebSignSeal.GetSignP1(npDWebSignSeal.SignSha1);
                    }else{
                        alert(data.documentElement.childNodes[0].childNodes[1].textContent);
                    }
                },
                error:function(data){
                    console.log("e:"+data);
                    npDWebSignSeal.SignSha1="";
                }
            });
        },
        GetSign: function (){
            var xmlData = "<?xml version=\'1.0\' encoding=\'UTF-8\'?><root><BASE_DATA><SYS_ID>"+this.sysId+"</SYS_ID><SYS_PSW>"+this.sysPwd+"</SYS_PSW></BASE_DATA><info><user><userFlag>1</userFlag><certInfo>"+this.userId+"</certInfo></user><seal><sealId>"+this.sealId+"</sealId><sealName>"+this.strSealName+"</sealName><seal_position>"+this.strTagName+"</seal_position><seal_x>"+this.lPosX+"</seal_x><seal_y>"+this.lPosY+"</seal_y><oriData>"+this.SignData+"</oriData></seal></info></root>";
            $.ajax({
                url:this.GetSer()+"addSeal",
                type:"post",
                async:false,
                dataType:"xml",
                data:{
                    xmlStr:xmlData
                },
                success:function(data){
                    var isflog=data.documentElement.childNodes[0].childNodes[0].textContent;
                    if(isflog==0) {
                        var newseal = data.documentElement.childNodes[0].childNodes[2].textContent;
                        if (newseal == "") {
                            alert("无效证书");
                        } else {
                            npDWebSignSeal.StoreDatalist[npDWebSignSeal.strSealName] = newseal;
                            npDWebSignSeal.StoreData = newseal;
                        }
                    }else{
                        alert(data.documentElement.childNodes[0].childNodes[1].textContent);
                    }
                },
                error:function(data){
                    console.log("e:"+data);
                }
            });
        },
        AddSeal: function (n1,n2){
            this.strSealPath=n1;
            if(n2==""){
                this.strSealName="ws"+Math.round(Math.random()*1000);
            }else{
                this.strSealName=n2;
            }
            if(this.uKey){
                this.GetSN();
            }else{
                this.GetSealList();
            }
        },
        GetSealList: function (){
            var _that=this;
            if(_that.Model=="demo"){
                var tbody=document.getElementById("tbody");
                var slists='<tr style="background:#fff;">'+
                    '<td><input name="sealsRadios" type="radio" value="seal" /></td>'+
                    '<td>1</td>'+
                    '<td>北京电子印章技术有限公司公章</td>'+
                    '</tr>'+
                    '<tr style="background:#fff;">'+
                    '<td><input name="sealsRadios" type="radio" value="sign" /></td>'+
                    '<td>2</td>'+
                    '<td>北京电子印章技术有限公司法人章</td>'+
                    '</tr>';
                tbody.innerHTML=slists;
                _that.showDiv();
            }else if(_that.Model=="oes") {
                document.getElementById("oes_make").SetValue("SET_SEALSERV_ADDR", this.HttpAddress);
                var seallists = document.getElementById("oes_make").DecodeBase64(document.getElementById("oes_make").GetSealList());
                //var seallists ="1;公章;2;私章;3;法人章;4;演示章;";
                var seallist = seallists.split(";");
                if (seallist.length >= 2) {
                    var tbody = document.getElementById("tbody");
                    var slists = '';
                    for (var i = 0; i < seallist.length; i++) {
                        if(seallist[i]!=""){
                            if (i % 2 == 0) {
                                slists += '<tr style="background:#fff;">';
                                slists += '<td><input name="sealsRadios" type="radio" value="' + seallist[i] + '" /></td><td>' + seallist[i] + '</td>';
                            } else {
                                slists += '<td>' + seallist[i] + '</td>';
                                slists += '</tr>';
                            }
                        }
                    }
                    tbody.innerHTML = slists;
                    _that.showDiv();
                }else if(sealist.length==1){
                    _that.sealId=seallist[1];
                    _that.addseal();
                }else{
                    alert("没有印章权限");
                }
            }else if(_that.Model=="server"){
               var xmlData = "<?xml version=\'1.0\' encoding=\'UTF-8\'?><root><BASE_DATA><SYS_ID>"+this.sysId+"</SYS_ID><SYS_PSW>"+this.sysPwd+"</SYS_PSW></BASE_DATA><user><userFlag>1</userFlag><certInfo>"+this.userId+"</certInfo></user></root>"
                $.ajax({
                    url:_that.GetSer()+"getSealList",
                    type:"post",
                    dataType:"xml",
                    async:false,
                    data:{
                        xmlStr:xmlData
                    },
                    success:function(data){
                        var isflog=data.documentElement.childNodes[0].childNodes[0].textContent;
                        if(isflog==0){
                            var sealist=data.documentElement.childNodes[1].childNodes;
                            var tbody = document.getElementById("tbody");
                            var slists = '';
                            if(sealist.length>=2){
                                for(var i=0;i<sealist.length;i++){
                                    var sealid=sealist[i].childNodes[0].textContent;
                                    var sealname=sealist[i].childNodes[1].textContent;
                                    slists += '<tr style="background:#fff;">';
                                    slists += '<td><input name="sealsRadios" type="radio" value="' + sealid + '" /></td><td>' + sealid + '</td>';
                                    slists += '<td>' + sealname + '</td>';
                                    slists += '</tr>';
                                }
                                tbody.innerHTML = slists;
                                _that.showDiv();
                            }else if(sealist.length==1){
                                _that.sealId=sealist[0].childNodes[0].textContent;
                                _that.addseal();
                            }else{
                                alert("没有印章权限");
                            }
                        }else{
                            alert(data.documentElement.childNodes[0].childNodes[1].textContent);
                        }
                    },
                    error:function(data){
                    }
                });
            }
        },
        addseal:function (){
            //调用国产化组件，签章
            var inputid="advice"+this.strSealName;
            if(document.getElementById(inputid)){
                var signstr=document.getElementById(inputid).value;
            }else{
                var signstr = "";
            }
            if(this.Model=="demo") {

            }else if(this.Model=="oes"){
                if(signstr){
                    var pcOriDataBase64=document.getElementById("oes_make").EncodeBase64(signstr);
                }else{
                    var pcOriDataBase64="";
                }
                var sealdata=document.getElementById("oes_make").GetSeal(this.sealId);

                var sealname=this.strSealName;
                var newseal=document.getElementById("oes_make").CreateWebSeal(sealname.toString(), this.strTagName, "", parseInt(this.lPosX), parseInt(this.lPosY), this.User, sealdata);
                npDWebSignSeal.StoreDatalist[npDWebSignSeal.strSealName]=newseal;
                npDWebSignSeal.StoreData=newseal;
            }else if(this.Model=="server"){
                if(this.uKey){
                    this.GetSha1();
                }else{
                    this.GetSign();
                }
            }
            this.ShowWebSeals();
            return this.strSealName;
        },
        LockSeal: function (n1,n2){
            return 0;
        },
        LockSealPosition: function () {
            return 0;
        },
        GetStoreData: function () {
            var storelist = this.StoreDatalist;
            var storedata="";
            for(var ii in storelist){
                storedata+=storelist[ii];
            }
            return storedata;
        },
        GetStoreDataEx: function (n1) {
            if(n1==""){
                return this.GetStoreData();
            }else if(document.getElementById(n1)){
                return this.StoreDatalist[n1];
            }else{
                return "";
            }
        },
        SetStoreData: function (n1) {
            if(n1!=""){
                var isnew=n1.indexOf("::WebSignDataEnd;");
                if(isnew<0){
                    this.convertWebsignData(n1);
                }else{
                    var store=n1.split("::WebSignDataEnd;");
                    for(var i=0;i<store.length;i++){
                        if(store[i]!=""){
                            var strstore=store[i]+"::WebSignDataEnd;";
                            var sealname=strstore.split(";seal_name:");
                            var sealid=sealname[1].split(";");
                            this.StoreDatalist[sealid[0]]=strstore;
                        }
                    }
                }
            }
        },
        convertWebsignData: function (n1) {
            if(npDWebSignSeal.Model=="oes") {

            }else if(npDWebSignSeal.Model=="server"){
                $.ajax({
                    url:npDWebSignSeal.GetSer()+"convertWebsignData",
                    type:"post",
                    dataType:"text",
                    async:false,
                    data:{
                        xmlStr:n1
                    },
                    success:function(data){
                        if(data!=""){
                            var stores=data.split("::WebSignDataEnd;");
                            for(var i=0;i<stores.length;i++){
                                if(stores[i]!=""){
                                    var strstore=stores[i]+"::WebSignDataEnd;";
                                    var sealname=strstore.split(";seal_name:");
                                    var sealid=sealname[1].split(";");
                                    npDWebSignSeal.StoreDatalist[sealid[0]]=strstore;
                                }
                            }
                        }
                    },
                    error:function(data){
                        alert(data);
                    }
                });
            }
        },
        ShowWebSeals: function () {
            var storelist = this.StoreDatalist;
            if(this.Model=="demo") {
                if (!document.getElementById(this.strTagName)) {
                    document.body.innerHTML += '<div id="' + this.strSealName + '" style="position: absolute;left: ' + this.lPosX + 'px;top:' + this.lPosY + 'px;z-index:1000;"><img src="./common/seal.gif"/></div>';
                } else {
                    var idtagx = parseInt(document.getElementById(this.strTagName).getBoundingClientRect().left) + parseInt(this.lPosX) + parseInt(document.body.scrollLeft);
                    var idtagy = parseInt(document.getElementById(this.strTagName).getBoundingClientRect().top) + parseInt(this.lPosY) + parseInt(document.body.scrollTop) - 10;
                    document.getElementById(this.strTagName).innerHTML += '<div id="' + this.strSealName + '" style="position: absolute;left: ' + idtagx + 'px;top:' + idtagy + 'px;z-index:1000;"><img title="签章用户：'+this.User+'&#10;文档验证：通过" src="./common/'+this.sealId+'.gif"/></div>';
                }
                this.RightMenu(this.strSealName);
            }else if(this.Model=="oes") {
                for (var ii = 0; ii < storelist.length; ii++) {
                    var store = storelist[ii];
                    if (store != "") {
                        document.getElementById("oes_make").FreeWebSealObj();
                        var openseal = document.getElementById("oes_make").OpenWebSeal(store, '');
                        var nextid = document.getElementById("oes_make").GetNextWebSeal('');
                        while (nextid != "") {
                            var signstr = "";
                            var inputid = "advice" + nextid;
                            if (document.getElementById(inputid)) {
                                signstr = document.getElementById(inputid).value;
                            }
                            if (signstr.length > 1) {
                                var pcOriDataBase64 = document.getElementById("oes_make").EncodeBase64(signstr);
                            } else {
                                var pcOriDataBase64 = "";
                            }
                            var verid = document.getElementById("oes_make").VerifyWebSeal(nextid, "");
                            var idgif = document.getElementById("oes_make").GetWebSealImg(nextid);
                            var idtagname = document.getElementById("oes_make").GetWebSealTagName(nextid);
                            var idtagxy = document.getElementById("oes_make").GetWebSealTagPos(nextid);//返回的格式为:x,y,w,h
                            var idtagpos = idtagxy.split(',');
                            if (document.getElementById(idtagname)) {
                                var idtagx = parseInt(document.getElementById(idtagname).getBoundingClientRect().left) + parseInt(idtagpos[0]) + parseInt(document.body.scrollLeft);
                                var idtagy = parseInt(document.getElementById(idtagname).getBoundingClientRect().top) + parseInt(idtagpos[1]) + parseInt(document.body.scrollTop) - 10;
                                var idtagw = idtagpos[2];
                                var idtagh = idtagpos[3];

                                if (!document.getElementById(nextid)) {
                                    if (!document.getElementById(idtagname)) {
                                        document.body.innerHTML += '<div id="' + nextid + '" style="position: absolute;left: ' + idtagx + 'px;top:' + idtagy + 'px;z-index:1000;" onselectstart="return false;" unselectable="on" style="-moz-user-select:none;"><img  title="签章用户：'+this.User+'&#10;文档验证：通过" src="data:image/gif;base64,' + idgif + '"  ondragstart="return false;"/></div>';
                                    } else {
                                        document.getElementById(idtagname).innerHTML += '<div id="' + nextid + '" style="position: absolute;left: ' + idtagx + 'px;top:' + idtagy + 'px;z-index:1000;" onselectstart="return false;" unselectable="on" style="-moz-user-select:none;"><img  title="签章用户：通过" src="data:image/gif;base64,' + idgif + '"  ondragstart="return false;"/></div>';
                                    }
                                } else {
                                    document.getElementById(nextid).style = "position: absolute;z-index:1000;left: " + idtagx + "px;top:" + idtagy + "px;";
                                }
                            }

                            this.RightMenu(this.strSealName);
                            nextid = document.getElementById("oes_make").GetNextWebSeal(nextid);
                        }
                    }

                }
            }else if(this.Model=="server"){
                var nextnote="";
                for(var ii in storelist){
                    this.seallist[nextnote]=ii;
                    nextnote=ii;
                    var store = storelist[ii];
                    if (store != "") {
                        var verifyData = "<?xml version=\'1.0\' encoding=\'UTF-8\'?><root><BASE_DATA><SYS_ID>"+this.sysId+"</SYS_ID><SYS_PSW>"+this.sysPwd+"</SYS_PSW></BASE_DATA><info><sealRes>"+store+"</sealRes><verify><sealName>"+ this.strSealName +"</sealName><oriData>"+this.SignData+"</oriData></verify></info></root>";
                        $.ajax({
                            url:this.GetSer()+"verifyDoc",
                            type:"post",
                            dataType:"xml",
                            async:false,
                            data:{
                                xmlStr:verifyData
                            },
                            success:function(data){
                                var isflog=data.documentElement.childNodes[0].childNodes.length;
                                if(isflog>0) {
                                    var seallist = data.documentElement.childNodes[0].childNodes;
                                    for (var i = 0; i < seallist.length; i++) {
                                        var verify = seallist[i].childNodes[0].textContent;
                                        var verify_v = (verify == "true") ? "通过" : "不通过";
                                        var cert_id = seallist[i].childNodes[1].textContent;
                                        var seal_x = seallist[i].childNodes[2].textContent;
                                        var seal_y = seallist[i].childNodes[3].textContent;
                                        var user_id = seallist[i].childNodes[4].textContent;
                                        var seal_id = seallist[i].childNodes[5].textContent;
                                        var seal_name = seallist[i].childNodes[6].textContent;
                                        var seal_time = seallist[i].childNodes[7].textContent;
                                        var seal_postion = seallist[i].childNodes[8].textContent;
                                        var seal_picture = seallist[i].childNodes[9].textContent;
                                        npDWebSignSeal.webSignList[seal_name] = [seal_name, seal_id, verify, seal_time, user_id, cert_id, ii];
                                        if (document.getElementById(seal_postion)) {
                                            var idtagx = parseInt(document.getElementById(seal_postion).getBoundingClientRect().left) + parseInt(seal_x) + parseInt(document.body.scrollLeft);
                                            var idtagy = parseInt(document.getElementById(seal_postion).getBoundingClientRect().top) + parseInt(seal_y) + parseInt(document.body.scrollTop) - 10;
                                            if (!document.getElementById(seal_name)) {
                                                if (!document.getElementById(seal_postion)) {
                                                    document.body.innerHTML += '<div id="' + seal_name + '" style="position: absolute;left: ' + idtagx + 'px;top:' + idtagy + 'px;z-index:1000;" onselectstart="return false;" unselectable="on" style="-moz-user-select:none;"><img  title="签章用户：' + user_id + '&#10;签章时间：' + seal_time.substring(0, 4) + '年' + seal_time.substring(4, 6) + '月' + seal_time.substring(6, 8) + '日' + seal_time.substring(8, 10) + '时' + seal_time.substring(10, 12) + '分' + seal_time.substring(12, 14) + '秒&#10;文档验证：' + verify_v + '" src="data:image/gif;base64,' + seal_picture + '"  ondragstart="return false;"/></div>';
                                                } else {
                                                    document.getElementById(seal_postion).innerHTML += '<div id="' + seal_name + '" style="position: absolute;left: ' + idtagx + 'px;top:' + idtagy + 'px;z-index:1000;" onselectstart="return false;" unselectable="on" style="-moz-user-select:none;"><img  title="签章用户：' + user_id + '&#10;签章时间：' + seal_time.substring(0, 4) + '年' + seal_time.substring(4, 6) + '月' + seal_time.substring(6, 8) + '日' + seal_time.substring(8, 10) + '时' + seal_time.substring(10, 12) + '分' + seal_time.substring(12, 14) + '秒&#10;文档验证：' + verify_v + '" src="data:image/gif;base64,' + seal_picture + '"  ondragstart="return false;"/></div>';
                                                }
                                            } else {
                                                document.getElementById(seal_name).style = "position: absolute;z-index:1000;left: " + idtagx + "px;top:" + idtagy + "px;";
                                            }
                                            npDWebSignSeal.RightMenu(seal_name);
                                        }
                                    }
                                }
                            },
                            error:function(data){
                                console.log(data);
                            }
                        });
                    }
                }

            }
        },
        FindSeal: function (n1,n2) {
            if(this.Model=="oes"){
                document.getElementById("oes_make").OpenWebSeal(this.StoreData,'');
                var nextid=document.getElementById("oes_make").GetNextWebSeal(n1);
            }else if(this.Model=="server"){
                var nextid=this.seallist[n1];
                if(typeof(nextid) == "undefined"){
                    nextid="";
                }
            }
            return nextid;
        },
        DelSeal: function () {
            this.CheckKey();
        },
        CheckKey:function (){
            this.GetValueEx("GET_DATA_SIGNMODE_P",0,"STRDATA:dsfgfdgdfg",0,"","npDWebSignSeal.CheckSN","","");
        },
        CheckSN:function (data){
            if(data.retstr!=""){
                this.GetSerialNumber("npDWebSignSeal.retCheckSN","","");
            }
        },
        retCheckSN:function (data){
            if(data.retstr==""){
                alert("未发现有效的智能卡");
            }else{
                if(npDWebSignSeal.n_user_id==data.retstr){
                    var my = document.getElementById(npDWebSignSeal.n_seal_name);
                    if (my != null){
                        my.parentNode.removeChild(my);
                        delete npDWebSignSeal.StoreDatalist[npDWebSignSeal.n_seal_name];
                    }
                }else{
                    alert("没有删除权限");
                }
            }
        },
        SetSealSignData: function (n1,n2) {
            this.SignData=n2;
            return 0;
        },
        SetDocAutoVerify: function (n1,n2) {
            this.isVerify=n2;
            return 0;
        },
        ShowSeal:function(n1,n2){
            if(n1==""){
                for(var ii in this.StoreDatalist){
                    if(n2==0){
                        document.getElementById(ii).style.display="none";
                    }else{
                        document.getElementById(ii).style.display="";
                    }
                }
            }else{
                if(document.getElementById(n1)){
                    if(n2==0){
                        document.getElementById(n1).style.display="none";
                    }else{
                        document.getElementById(n1).style.display="";
                    }
                }
            }
        },
        RightMenu: function (n1){
            //提取到函数外面作为全局变量
            var rm=document.getElementById("rightMenu");

            //自定义一个浏览器右键菜单，单击右键是显示它
            //oncontextmenu上下文菜单事件，右键菜单
            document.getElementById(n1).oncontextmenu=function (e) {
                npDWebSignSeal.n_seal_name=npDWebSignSeal.webSignList[this.id][0];
                npDWebSignSeal.n_seal_id=npDWebSignSeal.webSignList[this.id][1];
                npDWebSignSeal.n_verify=npDWebSignSeal.webSignList[this.id][2];
                npDWebSignSeal.n_seal_time=npDWebSignSeal.webSignList[this.id][3];
                npDWebSignSeal.n_user_id=npDWebSignSeal.webSignList[this.id][4];
                npDWebSignSeal.n_cert_id=npDWebSignSeal.webSignList[this.id][5];
                npDWebSignSeal.n_id=npDWebSignSeal.webSignList[this.id][6];
                //document.documentElement.oncontextmenu=function (e) {
                //显示我们自己定义的右键菜单
                //1.找到菜单
                //提取到函数外面作为全局变量

                //兼容Event对象
                e=e || window.event;

                //2.设置菜单的位置等于鼠标的坐标
                //判断：如果鼠标的位置+菜单的宽度>网页的宽度，那么就改为右边定位
                //鼠标坐标
                var mx=e.clientX+parseInt(document.body.scrollLeft);
                var my=e.clientY+parseInt(document.body.scrollTop);
                //菜单宽度
                var rmWidth=parseInt(rm.style.width);
                //网页的宽度(高度用同样的方法解决)
                var pageWidth=document.documentElement.clientWidth;
                //console.log(pageWidth);
                if((mx+rmWidth)<pageWidth)
                {
                    rm.style.left=mx+"px";
                    rm.style.top=my+"px";
                }
                else
                {
                    rm.style.right=mx+"px";
                    rm.style.top=my+"px";
                }

                //3.显示右键菜单
                rm.style.display="block";

                //阻止默认的右键菜单显示
                return false;
            };
        },
        MoreCallBack: function (data) {
            if(data.calldata < (this.waitcmddata.length-1960)){
                var cmdbody=this.waitcmddata.substring(data.calldata,(data.calldata+1960));
                var url="http://127.0.0.1:13426/moredata?cmdbody="+cmdbody+"&CallData="+(data.calldata+1960);
                url = encodeURI(url).replace(/%20/g,"\+");
                $.jsonp({
                    "url": url
                });
            }else{
                var cmdbody=this.waitcmddata.substring(data.calldata,this.waitcmddata.length);
                var url="http://127.0.0.1:13426/execcmd?cmdbody="+cmdbody+this.waitcmdext;
                url = encodeURI(url).replace(/%20/g,"\+");
                $.jsonp({
                    "url": url
                });
            }
        },
        ConnectServ:function(cmddata,CallBack,CallData,ErrMsg){
            npDWebSignSeal.AIPping();
            if(cmddata.length > 1960){
                this.waitcmddata = "CMDDATA:"+encodeURI(cmddata).replace(/%20/g,"\+");
                this.waitcmdext = "&CallBack="+CallBack+"&CallData="+CallData+"&ErrMsg="+ErrMsg;
                var cmdbody=waitcmddata.substring(0,1960);
                var url="http://127.0.0.1:13426/moredata?cmdbody="+cmdbody+"&CallData=1960";
                // alert(url);
                $.jsonp({
                    "url": url
                });
            }else{
                var url="http://127.0.0.1:13426/execcmd?cmdbody=CMDDATA:"+encodeURIComponent(cmddata).replace(/%20/g,"\+")+"&CallBack="+CallBack+"&CallData="+CallData+"&ErrMsg="+ErrMsg;
                // alert(url);
                $.jsonp({
                    "url": url
                });
            }
        },
        MonitorServEvent:function(MonitorMode,CallBack,CallData,ErrMsg){
            var url="http://127.0.0.1:13426/getevent?MMode="+MonitorMode+"&CallBack="+CallBack+"&CallData="+CallData+"&ErrMsg="+ErrMsg;
            $.jsonp({
                "url": url
            });
        },
        GetSerialNumber:function(CallBack,CallData,ErrMsg){
            var cmddata= "133";
            this.ConnectServ(cmddata,CallBack,CallData,ErrMsg);
        },
        GetValueEx:function(pcName,lValuetype,pcValueName,lParam,pcParam,CallBack, CallData, ErrMsg){
            var cmddata = "120;|;3,"+pcName+"|;|2,"+lValuetype+"|;|3,"+pcValueName+"|;|2,"+lParam+"|;|3,"+pcParam;
            this.ConnectServ(cmddata,CallBack,CallData,ErrMsg);
        },
        GetValue:function(pcName,CallBack, CallData, ErrMsg){
            var cmddata = "24;|;3,"+pcName;
            this.ConnectServ(cmddata,CallBack,CallData,ErrMsg);
        },

        SetValue:function(pcName,pcValue,CallBack, CallData, ErrMsg){
            var cmddata = "23;|;3,"+pcName+"|;|3,"+pcValue;
            this.ConnectServ(cmddata,CallBack,CallData,ErrMsg);
        },
        AIPping:function () {
            AttackAPI.PortScanner.scanPort(npDWebSignSeal.rebAIPping);
        },
        rebAIPping:function(n1){
            alert(n1);
        }
    }
    // 最后将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    !('plugin' in _global) && (_global.npDWebSignSeal = npDWebSignSeal);
}());

/****************************************************************************************************

 检测本地ukey服务

 *****************************************************************************************************/
var AttackAPI = {
    PortScanner: {}
};
var apilog=0;
AttackAPI.PortScanner.scanPort = function (callback) {
    var img = new Image();
    img.onerror = function () {
        if (!img) {
            return;
        }
        img = undefined;
        //callback('open');
    };
    img.onload = img.onerror;
    img.src = 'http://127.0.0.1:13426';

    setTimeout(function () {
        if (!img) {
            return;
        }
        img = undefined;
        if(apilog==0){
            apilog++;
            npDWebSignSeal.AIPping();
        }else{
            callback('客户端服务异常');
        }
    }, 1000);
};


/****************************************************************************************************

 设置印章列表和右键菜单

 *****************************************************************************************************/
var rmenu='<ul id="rightMenu" style="width: 100px;z-index:1001;text-align: left;">'+
    '<li onclick="npDWebSignSeal.DelSeal();">&nbsp;&nbsp;删除印章</li>'+
    '<li onclick="npDWebSignSeal.showSealinfo()">&nbsp;&nbsp;签章信息</li>'+
    '<li onclick="npDWebSignSeal.showUser()">&nbsp;&nbsp;身份信息</li>'+
    '<li onclick="npDWebSignSeal.showAbout()">&nbsp;&nbsp;关于我们</li>'+
    '</ul>';
document.body.innerHTML+=rmenu;
var slist='<div id="popDiv" class="sealdiv" style="display:none;z-index:1002;">'+
    '<table style="text-align: center;line-height: 30px;font-size: 12px;border: 1px solid #000;background:#f3f3f3;">'+
        '<tr style="background:#ccc;font-weight: bold;">'+
            '<td colspan="3" >选择要使用的印章</td>'+
        '</tr>'+
        '<tr style="font-weight: bold;">'+
            '<td style="width:40px">选择</td>'+
            '<td style="width:60px">印章编号</td>'+
            '<td style="width:200px">印章名称</td>'+
        '</tr>'+
        '<tbody id="tbody">'+
        '</tbody>'+
        '<tr>'+
            '<td colspan="3">'+
                '<input type="button" value="确定" onclick="npDWebSignSeal.GetSealId()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
                '<input type="button" value="取消" onclick="npDWebSignSeal.closeDiv()">'+
            '</td>'+
        '</tr>'+
    '</table>'+
    '</div>'+
    '<div id="bg" class="bg" style="display:none;"></div>';
document.body.innerHTML+=slist;

var smsg='<div id="msgDiv" class="sealdiv" style="display:none;z-index:1003;">'+
    '<table style="text-align: center;line-height: 30px;font-size: 12px;border: 1px solid #000;background:#f3f3f3;">'+
    '<tr style="background:#ccc;font-weight: bold;">'+
    '<td colspan="3" >详细信息</td>'+
    '</tr>'+
    '<tbody id="msgbody">'+
    '</tbody>'+
    '<tr>'+
    '<td colspan="3">'+
    '<input type="button" value="确定" onclick="npDWebSignSeal.closeMsg()">'+
    '</td>'+
    '</tr>'+
    '</table>'+
    '</div>'+
    '<div id="msgbg" class="bg" style="display:none;"></div>';
document.body.innerHTML+=smsg;
//不需要积隐藏右键菜单
document.documentElement.onclick=function () {
    var rm=document.getElementById("rightMenu");
    rm.style.display="none";
}
window.onresize = function(){
    npDWebSignSeal.ShowWebSeals();
}
/****************************************************************************************************

获取网页签章WebObj的对象

 *****************************************************************************************************/
export function GetWebObj(){
    // if(navigator.userAgent.indexOf("Chrome")>0 || navigator.userAgent.indexOf("Firefox")>0){
        var WebObj=npDWebSignSeal;
    // }else {
    //     var WebObj = document.getElementById("DWebSignSeal");
    // }
    return WebObj;
}
