<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/webpage/include/taglib.jsp"%>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/a";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>电子签章</title>
    <%--<meta http-equiv="X-UA-Compatible" content="IE=9" />--%>
    <script src="${ctxStatic}/iSignature/js/jquery-1.4.2.min.js"></script>
    <link rel='stylesheet' type='text/css' href='${ctxStatic}/iSignature/css/iWebProduct.css' />
    <script type="text/javascript">

        var url = getRootPath_dc();
        var mRecordID = "${iSignatureDocument.id}";
        var mFilePath = "${iSignatureDocument.filePath}";
        var mFileName = "${iSignatureDocument.fileName}";

        var mIsExsitRId = true;

        function getRootPath_dc() {
            var pathName = window.location.pathname.substring(1);
            var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
            if (webName == "") {
                return window.location.protocol + '//' + window.location.host;
            }
            else {
                return window.location.protocol + '//' + window.location.host + '/' + webName;
            }
        }
    </script>
    <script language="javascript">
        var nClick = 1;//鼠标点击次数
        var ToolBarId;
        var MenuId;
        function init(){
            /*iWebPDF2018.COMAddins("KingGrid.ComControl").Object.Copyright = "";  //设置授权码*/
            document.getElementById('activeBox').style.height = document.documentElement.clientHeight- 10 +"px";
            document.getElementById('activeTable').style.height = getHeight('activeBox')- 15  +"px";
            document.getElementById('iWebPDF2018').style.height = getHeight('activeTd') +"px";
            /*getRealSysTime();*/
        }
        //获取id的高度
        function  getHeight(id){
            return document.getElementById(id).offsetHeight;
        }
        //状态信息
        function addState(value){
            $("#state").html(value);
        }
        //清空批注
        function DelAllAnnots(){
            try{
                if ( 0 == iWebPDF2018.Documents.Count ){
                    alert("没有已打开文档");
                    return;
                }

                var nPage = iWebPDF2018.Documents.ActiveDocument.Pages.Count;
                for(var i=0; i < nPage; i++)
                {
                    var nAnnot = iWebPDF2018.Documents.ActiveDocument.Pages(i).Annots.Count;
                    for(var j = nAnnot-1;j >= 0;j--)
                    {
//				iWebPDF2018.Documents.ActiveDocument.pages(i).Annots(j).Delete();
                        var annot = iWebPDF2018.Documents.ActiveDocument.pages(i).Annots(j);

                        if( annot.Subtype != "Widget")      //批注对象为构件类型时不能删除，会崩溃
                        {
                            annot.Delete();
                        }
//如果是要指定删除的可以==“Text”  Text为文字批注  Line为线 Square为矩形 Circle为圆形批注 Stamp为图章批注
                    }
                    iWebPDF2018.Documents.ActiveDocument.Pages(i).Refresh();
                }
                iWebPDF2018.Documents.ActiveDocument.Views.ActiveView.Refresh();
            }catch(e){
                alert(e.description);
            }
        }
        //锁定批注
        function LockAnnots(){
            try{
                if ( 0 == iWebPDF2018.Documents.Count ){
                    alert("没有已打开文档");
                    return;
                }
                var nAnnot = iWebPDF2018.Documents.ActiveDocument.Pages.Item(0).Annots.Count;
                for(var i=0; i<nAnnot; i++)
                {
                    iWebPDF2018.Documents.ActiveDocument.Pages.Item(0).Annots.item(i).Locked = true;

                }

            }catch(e){
                alert(e.description);
            }
        }

        //解除锁定批注
        function UnlockAnnots(){
            try{
                if ( 0 == iWebPDF2018.Documents.Count ){
                    alert("没有已打开文档");
                    return;
                }
                var nAnnot = iWebPDF2018.Documents.ActiveDocument.Pages.Item(0).Annots.Count;
                for(var i=0; i<nAnnot; i++)
                {
                    iWebPDF2018.Documents.ActiveDocument.Pages.Item(0).Annots.item(i).Locked = false;
                }

            }catch(e){
                alert(e.description);
            }
        }

        //普通模式
        function NormalMode(){
            try{

                var n = iWebPDF2018.CommandBars.Count;

                for(var i=0; i<n; i++)
                {
                    var CommandBar = iWebPDF2018.CommandBars.item(i);
                    CommandBar.Visible = true;
                }

                addState("普通模式。");
            }catch(e){
                addState("普通模式进入失败。");
                alert(e.description);
            }
        }

        //批注模式
        function AnnotMode(){
            try{

                var n = iWebPDF2018.CommandBars.Count;

                for(var i=0; i<n; i++)
                {
                    var CommandBar = iWebPDF2018.CommandBars.item(i);

                    var name = CommandBar.Name;
                    if(name == "MenuBar" ||name == "Rotate" ||name == "Zoom" ||name == "Find" ||name == "DigitalSignature")
                    {
                        CommandBar.Visible = false;
                    }
                    else
                    {
                        CommandBar.Visible = true;
                    }
                }

                addState("批注模式设置成功。");
            }catch(e){
                addState("批注模式设置失败。");
                alert(e.description);
            }
        }

        //盖章模式
        function SigMode(){
            try{

                var n = iWebPDF2018.CommandBars.Count;

                for(var i=0; i<n; i++)
                {
                    var CommandBar = iWebPDF2018.CommandBars.item(i);

                    var name = CommandBar.Name;
                    if(name == "MenuBar" ||name == "File" ||name == "Rotate" ||name == "Zoom" ||name == "Standard" ||name == "Find" ||name == "Annots" ||name == "Comments")
                    {
                        CommandBar.Visible = false;
                    }
                    else
                    {
                        CommandBar.Visible = true;
                    }
                }

                addState("盖章模式设置成功。");
            }catch(e){
                addState("盖章模式设置失败。");
                alert(e.description);
            }
        }

        //添加文本域
        function addTextField(){
            try{
                if ( 0 == iWebPDF2018.Documents.Count )
                {
                    alert("没有已打开文档");
                    return;
                }

                var nCount = iWebPDF2018.Documents.ActiveDocument.Fields.Count;
                var field =iWebPDF2018.Documents.ActiveDocument.Fields.Add(3);

                var widget = field.AddToPage(0);
                widget.FromUserRect(100, 750, 250, 780);
                widget.UpdateAppearance();

                field.Name = "TextField";
                field.Value = "KingGrid";
                field.Visible = true;

                iWebPDF2018.Documents.ActiveDocument.Views.ActiveView.Refresh();

                addState("添加文本域成功。");
            }catch(e){
                addState("添加文本域失败。");
                alert(e.description);
            }

        }


        //跳转到第一个域
        function gotoFields(){
            try{
                if ( 0 == iWebPDF2018.Documents.Count ){
                    alert("没有已打开文档");
                    return;
                }
                var fields = iWebPDF2018.Documents.ActiveDocument.Fields;
                if(fields.Count != 0){
                    fields(0).Goto();
                }else{
                    alert("文档中不存在域");
                }
                addState("跳转至第一个域成功。");
            }catch(e){
                addState("跳转至第一个域失败。");
                alert(e.description);
            }
        }

        //获取域个数
        function GetFileds(){

            try{
                if ( 0 == iWebPDF2018.Documents.Count )
                {
                    alert("没有已打开文档");
                    retrun;
                }
                var fields = iWebPDF2018.Documents.ActiveDocument.Fields;
                var count=fields.Count;
                alert("域的个数" + count);

                addState("获取域个数成功。");
            }catch(e){
                addState("获取域个数失败。");
                alert(e.description);
            }


        }

        //删除所有域
        function delAllFields(){
            try{
                if ( 0 == iWebPDF2018.Documents.Count )
                {
                    alert("没有已打开文档");
                    return;
                }
                var fields = iWebPDF2018.Documents.ActiveDocument.Fields;
                var count = fields.Count;

                for(var i=0; i<count; i++)
                {
                    var sigfield = fields(0);
                    sigfield.Delete();
                }
                iWebPDF2018.Documents.ActiveDocument.Views.ActiveView.Refresh();
                addState("删除成功");
            }catch(e){
                addState("删除失败");
                alert(e.description);
            }
        }

        //是否允许文本域输入 (域交互)
        function IsAllowInteraction(){
            try{
                if ( 0 == iWebPDF2018.Documents.Count ){
                    alert("没有已打开文档");
                    return;
                }

                var Res = false;
                var document = iWebPDF2018.Documents.ActiveDocument;
                var fields = document.Fields;
                var cnt = fields.Count;
                if (cnt)
                {
                    nClick++;
                    if(nClick%2)
                    {
                        Res = false;
                        alert("禁止文本域输入！");
                    }
                    else
                    {
                        Res = true;
                        alert("允许文本域输入！");
                    }
                    for(var i = 0 ;i < cnt; i++)
                    {
                        fields.Item(i).AllowInteraction = Res;
                    }
                    addState("域交互控制成功！");
                }
            }catch(e){
                addState("域交互控制失败");
                alert(e.description);
            }
        }

        //文档转图片
        function FileToPic(){
            try{
                var picPath = "c:\\p1.png";
                var res = iWebPDF2018.Documents.ActiveDocument.Pages.Item(0).ExportPNG(picPath);
                if (!res)
                {
                    alert("首页图片保存为："+picPath);
                }
                addState("图片转文档成功！");
            }catch(e){
                addState("图片转文档失败！");
                alert(e.description);
            }
        }
        function insertImage(url)

        {
            if ( 0 == iWebPDF2018.Documents.Count )
            {
                alert("没有已打开文档");
                retrun;
            }
            var annot = iWebPDF2018.Documents.ActiveDocument.Pages(0).Annots.Add(12);
            annot.FromDeviceRect(100,100,200,40);
            annot.BlendMode = "Multiply";
            annot.Title = "Admin";
            annot.Color = 255;
            annot.ImageAppearance(url);
            iWebPDF2018.Documents.ActiveDocument.Views.ActiveView.Refresh();
        }
    </script>
</head>
<body onload="init()" onresize="init()" style="overflow-y:hidden;overflow-x:hidden">
<table id="maintable"  cellspacing='0' cellpadding='0' >
    <!-- head -->
    <tr><td height="34px" class="title" width="80%">
        <span>主题：${iSignatureDocument.subject}</span>
        <span style="display: none">编号：${iSignatureDocument.recordId}</span>
        <span style="margin-left: 50px;">
            <c:if test="${ not empty contractNumPath}">
            <span>编号：${contractNum}</span>
            <span><button href="javascript:void(0)" class="nav-btn nav-btn-add" onclick="insertImage('${contractNumPath}');">生成编号图片</button></span>
            </c:if>
		<%--作者：--%>
		<%--<c:if test="${empty iSignatureDocument.id}">--%>
            <%--${fns:getUser().name}--%>
        <%--</c:if>--%>
		<%--<c:if test="${not empty iSignatureDocument.id}">--%>
            <%--${fns:getUserById(iSignatureDocument.updateBy.id).name}--%>
        <%--</c:if>--%>
	</span>
    </td>
        <td class="title"><span><a href="#" id="saveFile" >保存文档</a></span>
            <span><a href="#" onclick="return window.close();">返回</a></span>
        </td>

    </tr>
    <!-- end head -->

    <!-- showList -->
    <tr><td id="showtr" colspan="2" >
        <table id="functionBox" border="0">
            <tr>

                <td id="activeBox">
                    <form id="iWebPDF"   method="post" action="${ctx}/isignature/iSignatureDocument/saveP" onSubmit="return window.close();">
                    </form>
                    <table id="activeTable" >
                        <tr>
                            <td colspan="2" id="activeTd"><script src="${ctxStatic}/iSignature/js/iWebPDF2018.js"></script></td>
                        </tr>

                        <%--<tr>
                            <td height="10px" align="left" class="statue">状态：<span id="state"></span></td>
                            <td align="right" id="systime">时间：</td>
                        </tr>--%>
                    </table>
                </td>
            </tr>
        </table>
    </td></tr>
    <!-- end showList -->

    <!-- footer -->
    <tr ><td colspan="2" height="30px"  class="footer"><table><tr><td align="center">江西金格科技股份有限公司 版权所有</td></tr></table></td></tr>
    <!-- end footer -->
</table>
<script src="${ctxStatic}/iSignature/js/iWebProduct.js"></script>
</body>
</html>