
<%
/************************************************************@@
  * Program Name	: doc_regist.jsp
  * Description		: /집계자/자료 등록
  * Author			: 기현테크
  * Create Date		: 2010.11.18
  * History			:
@@************************************************************/
%>

<%@ page contentType="text/html; charset=UTF-8"
    import="java.net.URLEncoder"
    import="java.net.URLDecoder"
    import="kr.co.kihyun.beans.user.HttpSSOLogin"
    import="java.util.Calendar"
    import="java.text.SimpleDateFormat"
    import="java.util.*"
    import="kr.co.kihyun.lang.Encoder"
    import="kr.co.kihyun.lang.MString"
    import="kr.co.kihyun.lang.MInteger"
    import="kr.co.kihyun.lang.MLong"
    import="kr.co.kihyun.text.html.ServletUtil"
    import="kr.co.kihyun.moumi.MoumiConfig"
    import="kr.co.kihyun.moumi.doc.MDoc"
    import="kr.co.kihyun.util.MDate"
    import="kr.co.kihyun.text.excel.Excel"
    import="kr.co.kihyun.text.html.TagFilter"
    import="kr.co.kihyun.text.html.HtmlUtil"
    import="kr.co.kihyun.lang.StringConverter"
    import="kr.co.kihyun.text.html.CallbackHandler"
    import="java.util.ResourceBundle"
    import="kr.co.kihyun.beans.entity.*"
    import="javax.jdo.PersistenceManager"
    import="javax.jdo.Transaction"
    import="kr.co.kihyun.beans.entity.util.*"
    import="org.slf4j.Logger"
    import="org.slf4j.LoggerFactory"
%>

<%@ include file="/totsys/common/inc/sec/secure.inc.jsp"%>

<%
Logger LOG = LoggerFactory.getLogger(this.getClass());

PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
Transaction tx = pm.currentTransaction();
try{
	/********** session내의 userId **********/
	String usID = HttpSSOLogin.getLoginID(request);
	int sysAuth = HttpSSOLogin.getSysAuth(request);

	if(sysAuth == MoumiConfig.SUB_TOTPER && MoumiConfig.isMonitor()){
		String connURL="history.go(-1);";
		out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.tot_report.submit")+MoumiConfig.getMessageBundle().getString("moumi.message.popup.doc_regist_jsp_AuthCheck")));
		out.println(ServletUtil.getJavaScript(connURL));
		return;
	}

	/************ Parameter values ************/
	String docID = clearXSS(request.getParameter("docID"),"");
	String choice = clearXSS(request.getParameter("choice"),"");
	String deptIDs = clearXSS(URLDecoder.decode(MString.checkNull(request.getParameter("deptIDs")), "UTF-8"),"");
	String execNum = clearXSS(request.getParameter("execNum"),"");
	String execDate = clearXSS(request.getParameter("execDate"), "");
	String userIDs = clearXSS(URLDecoder.decode(MString.checkNull(request.getParameter("userIDs")), "UTF-8"),"");
	String userNames = clearXSS(URLDecoder.decode(MString.checkNull(request.getParameter("userNames")), "UTF-8"),"");
	String deptTypes = clearXSS(MString.checkNull(request.getParameter("deptTypes")),"");
    String deptNames = clearXSS(URLDecoder.decode(MString.checkNull(request.getParameter("deptNames")), "UTF-8"),"");
	String handyName = clearXSS(Encoder.toJava(request.getParameter("handyName")),"");
	String totRange = clearXSS(MString.checkNull(request.getParameter("totRange")),"");
	String appendType = clearXSS(MString.checkNull(request.getParameter("appendType")),TotDocAppendType.COPY.toString());
	String docName = clearXSS(Encoder.toJava(MString.checkNull(request.getParameter("docName"))),"");
	String usrFilenames = clearXSS(Encoder.toJava(MString.checkNull(request.getParameter("usrFilenames"))),"");
	String svrFilenames = clearXSS(Encoder.toJava(MString.checkNull(request.getParameter("svrFilenames"))),"");
	String[] usrFileNameList = usrFilenames.split(";");
	String[] svrFileNameList = svrFilenames.split(";");
	String accAuth = clearXSS(request.getParameter("accAuth"),"");
	String repDocID = clearXSS(request.getParameter("repDocID"),"");
	String docGroupID = clearXSS(request.getParameter("docGroupID"),"");
	String isFromFormBox = clearXSS(request.getParameter("isFromFormBox"),"");
	String tableCount  = clearXSS(request.getParameter("tableCount"),"");
	String isDynaTable = clearXSS(request.getParameter("isDynaTable"),"");
	String mode = clearXSS(request.getParameter("mode"),"");
	String notify = Encoder.toJava(MString.checkNull(request.getParameter("notify")));
	String tableDefines = MString.checkNull(request.getParameter("tableDefines"));
	String itemNames = MString.checkNull(Encoder.toJava(request.getParameter("itemNames")));
	String tableNums = MString.checkNull(Encoder.toJava(request.getParameter("tableNums")));
	String colNums = MString.checkNull(Encoder.toJava(request.getParameter("colNums")));
	String rowNums = MString.checkNull(Encoder.toJava(request.getParameter("rowNums")));
	String itemSizes = MString.checkNull(Encoder.toJava(request.getParameter("itemSizes")));
	String itemDescs = MString.checkNull(Encoder.toJava(request.getParameter("itemDescs")));


	String itemExprs = MString.checkNull(Encoder.toJava(request.getParameter("itemExprs")));
	String itemTypes = MString.checkNull(Encoder.toJava(request.getParameter("itemTypes")));
	String docForm = MString.checkNull(Encoder.toJava(request.getParameter("docForm")));
	String backDash = MString.checkNull(Encoder.toJava(request.getParameter("backDash")));
	String step = MString.checkNull(request.getParameter("step"));
	String startMethod = clearXSS(request.getParameter("startMethod"),"0");
	String endMethod = clearXSS(request.getParameter("endMethod"),LimitByDeadlineStrategy.class.getSimpleName().toString());

	if("1".equals(step)){
		session.removeAttribute("docForm");
		session.removeAttribute("notify");
	}

	if(backDash.equals("back")){
		if((String)session.getAttribute("docForm")=="" || (String)session.getAttribute("docForm")==null){
		}
		else{
			docForm=(String)session.getAttribute("docForm");
		}
	}

	/**************** 추가 끝 **************/
	Long reuseDocID = MLong.parseLong(request.getParameter("reuseDocID"),null);
	//String reuseDocName = Encoder.toJava(clearXSS(request.getParameter("reuseDocName"),""));

        //LJH
        //String reuseDocName = clearXSS(URLDecoder.decode(request.getParameter("reuseDocName"), "UTF-8"),"");
        String reuseDocName = clearXSS(URLDecoder.decode(MString.checkNull(request.getParameter("reuseDocName")), "UTF-8"),"");

	//String isFromFormBox = request.getParameter("isFromFormBox");
	String totType = clearXSS(request.getParameter("totType"),"");
	if(MString.isNull(totType)) totType = "1step";

	/*********** doc value *****************/
	String repDocForm = "";

	if(reuseDocID != null){
		TotDoc totDoc = null;
		totDoc = reuseDocID == null ? null : pm.getObjectById(TotDoc.class, reuseDocID);
		repDocForm = totDoc.getForm();
		repDocForm = TagFilter.convertSingle(repDocForm);
		repDocForm = StringConverter.toOneLine(repDocForm);
	}
        int formSize = repDocForm.getBytes().length;
//        System.out.println("formSize ::::: " + formSize);

        int docFormSize = docForm.getBytes().length;
//        System.out.println("formSize ::::: " + docFormSize);
	/********** 현재 년, 월, 일 **********/
	int ONE_DAY = 1000 * 60 * 60 * 24;
	Long today = new Date().getTime();
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat timeFormat = new SimpleDateFormat("HH");

	String deptCount="0";
	String userCount="0";
	if(!deptIDs.equals("")){
		String[] dtcount = deptIDs.split(",");
		deptCount=Integer.toString(dtcount.length);
	}
	if(!userIDs.equals("")){
		String[] uscount = userIDs.split(",");
		userCount=Integer.toString(uscount.length);
    }

%>

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title><%=MoumiConfig.getTitle()%></title>
<link rel="stylesheet" href="/totsys/common/css/text.css" type="text/css">
<link rel="stylesheet" href="/totsys/common/css/kecttep.css" type="text/css">
<link rel="stylesheet" href="/totsys/common/css/SquareButtons.css" type="text/css">
<link rel="stylesheet" href="/totsys/common/css/contentStyle.css" type="text/css">
<link rel="stylesheet" href="/totsys/common/css/basic.css" type="text/css">
<!--<script defer="defer"src="/totsys/common/js/rollover.js"></script>
<script defer="defer" src="/totsys/common/js/util.js"></script>
<script defer="defer" src="/totsys/common/js/calendar.js"></script>
<script defer="defer" src="/totsys/common/js/drag.js"></script>
<script defer="defer" src="/totsys/common/js/date.js"></script>
<script defer="defer" src="/totsys/common/js/checkNum.js"></script>
<SCRIPT defer="defer" src='/totsys/common/js/editor.js'></SCRIPT>
<SCRIPT defer="defer" src='/totsys/common/js/encode.js'></SCRIPT>-->
<script src="/totsys/common/js/rollover.js"></script>
<script src="/totsys/common/js/util.js"></script>
<script src="/totsys/common/js/calendar.js"></script>
<script src="/totsys/common/js/drag.js"></script>
<script src="/totsys/common/js/date.js"></script>
<script src="/totsys/common/js/checkNum.js"></script>
<script src='/totsys/common/js/editor.js'></script>
<script src='/totsys/common/js/encode.js'></script>
<script src='/totsys/common/js/mouse.js'></script>
<script src="/totsys/common/js/jquery-1.12.4.min.js"></script>
<script>
	
    var isEdited=false;
    <%
    if (backDash.equals("back")) {
            if (!MString.isNull((String) session.getAttribute("docForm"))) {
    %>
    isEdited = true;
    <%
            }
    }
    %>
    $(document).ready(function() {
		$("#ifrm_EditCtrl").on("focus",function(){
            if(isEdited==false) EditCtrl.document.body.innerHTML = ""; 
            isEdited=true;
		});
		
		if(navigator.userAgent.indexOf("Chrome") != -1){
			$(".overlay").show();
			$(".overlay").click(function(){
	    		if(isEdited==false) EditCtrl.document.body.innerHTML = ""; 
	    		$(".overlay").hide();
	    		$('#ifrm_EditCtrl').focus();
	            isEdited=true;
	        });
		}
		
    	//파일집계시 입력 부분 숨김
    	$('[name=appendType]').change(function(){
    		if(this.value=='FILE'){
    			$('#ifrm_EditCtrl').css('visibility','hidden');
    		}else{
    			EditCtrl.document.body.innerHTML = '<center>아래한글,엑셀,워드등에서 작성한 조사서식을 복사하여 붙여넣는 창 입니다.<br>* 엑셀이나 한글에서 작성한 수식(계산식)은 적용되지 않습니다. *</center>'
                    +'<br><center>[주의]붙여넣기 한 서식안에 예시를 작성하는 경우, 예시란에는 빈칸(공백)이 없어야 합니다.</center>';
    			$('#ifrm_EditCtrl').css('visibility','');
    		}
    	});
    	// disabled 용법 수정
    	if(isEdited){
    		//$(EditCtrl.document.body).attr('disabled','true');
    	}
    	init();
        setValue();
        dform.docName.focus();
        fromFormBox('<%= reuseDocID %>', '<%= reuseDocName %>');
        fn_resizeEditCtrl();
        //html 인코딩된 주석제거,포커스 문제 해결
        try{
              EditCtrl.document.body.onpaste=function(){
            	  console.log('붙여넣기');
                setTimeout(function(){
	                var html=EditCtrl.document.body.innerHTML;
	                if(html.search(/\&lt;!--[\s\S]*?--\&gt;/g,'')>-1){
			          	html=html.replace(/\&lt;!--[\s\S]*?--\&gt;/g,'');
			          	$(EditCtrl.document.body).html(html);
		       		}
	                if(html.search("table")>-1){
			          	html=html.replace(border="0",border="1"); //table 테두리 보이게 수정
			          	$(EditCtrl.document.body).html(html);	                	
	                }
	                $(EditCtrl.document.body).append('<br/>');
	                EditCtrl.document.body.focus();
	             },0);
              };
             }catch(e){}

    });
    $(window).resize(function() {
        fn_resizeEditCtrl();
    });

    function setValue(){
        if ("<%= docName %>" != "") {
            dform.docName.value="<%= docName %>";
            dform.deptIDs.value="<%= deptIDs %>";
            dform.deptCount.value="<%= deptCount %>";
            dform.deptTypes.value="<%= deptTypes %>";
            dform.deptNames.value="<%= deptNames %>";
            dform.userIDs.value="<%= userIDs %>";
            dform.userNames.value="<%= userNames %>";
            dform.userCount.value="<%= userCount %>";
            //dform.handyName.value="<%= handyName %>";
            //dform.notify.value="<%--= notify --%>";
            dform.accAuth["<%= accAuth %>"].checked = true;
            //dform.totRange["<%= totRange %>"].checked = true;
            dform.usrFilenames.value="<%= usrFilenames %>";
            dform.svrFilenames.value = "<%= svrFilenames %>";
        } else {
            init();
            //EditCtrl.document.body.innerHTML = '<center><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.formCopy")%></center>';
              EditCtrl.document.body.innerHTML = '<center>아래한글,엑셀,워드등에서 작성한 조사서식을 복사하여 붙여넣는 창 입니다.<br>* 엑셀이나 한글에서 작성한 수식(계산식)은 적용되지 않습니다. *</center>'
                                                +'<br><center>[주의]붙여넣기 한 서식안에 예시를 작성하는 경우, 예시란에는 빈칸(공백)이 없어야 합니다.</center>';

        }
    }

    function viewNote(){
        var width = 600;
        var height = 410;
        var leftpos = (screen.width - width) / 2;
        var toppos = (screen.height - height) / 2;
        window.open("/totsys/common/web/note/popup_manual.jsp","","width="+width+", height="+height+", toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left= "+ leftpos +" ,top= "+ toppos);
    }

    function openWin(theURL,features) { //v2.0
        var farwindow = null;
        farwindow = window.open(theURL,'farwindow',features);
        farwindow.focus();
    }

    function browseFile() { //v2.0
        document.write('<input type="file" name = "upFile" >');
    }

    function browseOld() { //v2.0
        document.write('<input type="file" name = "upFile" >');
    }

    function formSubmit(){

        //var fn = dform.formFileName.value;
        //ban lower case var ext = fn.substring(fn.indexOf('.')+1,fn.length).toLowerCase();
        //td 안닫힌 태그 닫기
		var temp=$('<div>'+EditCtrl.document.body.innerHTML+'</div>');
		temp.find('td').each(function(i,o){
			try{
				if(o.outerHTML.toLowerCase().indexOf('</td>')==-1){
					o.outerHTML+='</td>';
				}
			}catch(e){}

		});
        //dform.copyForm.value = EditCtrl.document.body.innerHTML;
        dform.copyForm.value = temp.html();
        var dformData = dform.copyForm.value;
        var formMaxSize = 307200;
        var formCurrentSize = dformData.length;
        var array_table = dformData.split("<TABLE ");

        //ie10,11 호환성 문제 수정
		if(array_table.length==1){
			array_table = dformData.split("<table ");
		}

        if(array_table.length == 1 && dformData.indexOf("\"DataInput\"") == -1){
            alert("<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.formCheck")%>");
            return;
        }else if (array_table.length > 16){
            alert("<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.totalCount15")%>");
            return;
        }else if (dform.docName.value == '') {
            alert("<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.dataNameCheck")%>");
            dform.docName.focus();
            return;
        //}else if (containsChars(dform.docName,'￦/?"<>|!,*&^%$#@~;')) {
        }else if (containsChars(dform.docName,'\'\\')) {
            alert("<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.dataNameSymboleCheck")%>");
            dform.docName.focus();
            return;
        }else if (containsChars(dform.docName,'\`\\') || containsChars(dform.docName,'\%\\') || containsChars(dform.docName,'\&\\')) {
            alert("<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.dataNameSymboleCheck")%>");
            dform.docName.focus();
            return;
        }else if (containsChars(dform.docName,'?') || containsChars(dform.docName,'*') || containsChars(dform.docName,'<') || containsChars(dform.docName,'>')) {
            alert("<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.dataNameSymboleCheck")%>");
            dform.docName.focus();
            return;
        }else if (containsChars(dform.docName,'/')) {
            alert("<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.dataNameSymboleCheck")%>");
            dform.docName.focus();
            return;
        }else if (containsChars(dform.docName,'\"\\')) {
            alert("<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.dataNameSymboleCheck")%>");
            dform.docName.focus();
            return;
        }else if (dform.accAuth[0].checked == false && dform.accAuth[1].checked == false && dform.accAuth[2].checked == false && dform.accAuth[3].checked == false) {
            alert("<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.publicCheck")%>");
            return;
        }else if (dform.deptIDs.value.length == '') {
            alert("<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.submitDevisionCheck")%>");
            //2014.09.15 Update by KWON,HAN
            //deptSelect();
            deptSelect2();
            return;
        } else if (getByteSize(dform.docName.value) >= 200) {
            // 자료명의 데이터 길이수 체크. 2014.12.01 by YOUNGJUN,CHO
            // 200 byte 가 넘지 않도록 자료명의 길이를 제한한다.
            alert("자료명의 길이는 한글기준 66자 이내여야 합니다.");
            dform.docName.focus();
            return;
        } else if (formCurrentSize > formMaxSize) {
            // 복사한 서식의 크기 체크. 2015.05.11 by JS KIM
            // 300 Kbyte 가 넘지 않도록 복사한 서식의 크기를 제한한다.
            alert("생성한 서식의 전체 크기는 300K 이내여야 합니다. \n\n" + "현재 크기는 약" + Math.round(dformData.length/1024) + "K 입니다");
            return;
        }

        //++++++++++++++++++++++++++++++++++++++++ Begin +++++++++++++++++++++++++++++++++++++++++++
        // 문서생성시 셀내에 내용이 긴 경우(2000 byte가 초과하는 경우)에 저장시 에러가 발생한다.
        // 에러 원인을 사용자에게 노티하기 위해 셀 내의 내용의 길이를 체크하도록 추가함. Add by YOUNGJUN,CHO 2014.12.03

        // 파일집계가 아닌 경우에 체크.
        if (dformData.indexOf("\"DataInput\"") == -1) {

            // moumi_tot_item 'des' 의 length 제한에 유효한지 여부.(true:유효함(이하), false:유효하지않음(초과))
            var isAvailDes = true;

            // moumi_tot_item 'des' 의 length.
            var totItemDesMaxLength = 2000;  // 테이블의 컬럼 길이를 수정하는 경우 변경필요.(기존 500 byte -> 변경 2,000 byte)
            var desByteSize = 0;            // 오버플로우된 내용의 byte size. (알림용)
            var desText;                   // 오버플로우된 내용의 text. (알림용)

            // 에디터에 작성된 html 을 pastedHtml 변수에 저장.
            //alert(EditCtrl.document.body.innerHTML);
            var pastedHtml = EditCtrl.document.body.innerHTML;
            //alert($(pastedHtml).find("td").length);

            // 모든 td 태그를 탐색.
            $.each( $(pastedHtml).find("td"), function(index) {

                // td 태그내 html tag 를 제외한 text 의 byte size 를 계산.(한글 3 byte)
                desByteSize = getByteSize($(this).text());

                // 입력된 내용의 byte size 가 테이블 컬럼의 길이를 초과하는 경우, 유효하지 않은 des 가 있는 것임. (isAvailDes = false 으로 세팅.)
                if ( desByteSize > totItemDesMaxLength ) {
                    isAvailDes = false;

                    //alert($(EditCtrl.document.body).find("td:eq("+index+")").html());

                    // 에디터 영역의 td 태그에 input, textarea 처럼 focus 또는 select 이벤트를 발생시킬 수 없다.
                    //$(EditCtrl.document.body).find("td:eq("+index+")").select();

                    // 오버플로우되는 내용을 desText 변수에 저장. (알림용)
                    desText = $(EditCtrl.document.body).find("td:eq("+index+")").text();

                    // 알림용 desText 의 텍스트 길이가 긴 경우 생략처리. (임의로 100글자까지로 정함)
                    if (desText.length > 100) {
                        desText = desText.substring(0, 100) + "\n\r..생략..";
                    }

                    return false;   // for문의 break와 동일.
                }
            });

            // 오버플로우가 발생된 경우, alert 으로 문제원인과 안내 메세지를 출력하고 return 으로 submit 되지 않게 함.
            if (isAvailDes === false) {
                alert("셀안의 내용이 너무 깁니다. (입력된 내용 : " + desByteSize + " byte)"
                    + "\n\r하나의 셀에는 최대 " + totItemDesMaxLength + " byte 까지의 데이터만 입력가능 합니다."
                    + "\n\n한글기준 166자, 영문/숫자 " + totItemDesMaxLength + "자 이내로 입력해주세요."
                    + "\r\r**************** 셀 내용 일부 ****************"
                    + "\n\r" + desText);
                return;
            }
        }
        //++++++++++++++++++++++++++++++++++++++++ End +++++++++++++++++++++++++++++++++++++++++++

        dform.submit();
    }

    function containsChars(input,chars) {
        for (var inx = 0; inx < input.value.length; inx++) {
            if (chars.indexOf(input.value.charAt(inx)) != -1)
                return true;
        }
        return false;
    }

    function AllDataRemove(){
        dform.deptIDs.value='';
    }

    function ShowDocPool(accAuth){
        isEdited=true;
        //document.all.type1.style.display="none";
        //document.all.type2.style.display="inline";
        //document.all.type3.style.display="none";
        document.dform.isFromFormBox.value="true";
        window.open('./popup_form_list.jsp?accAuth='+accAuth,'makepoll','width=800,height=480,scrollbars=yes,resizable=yes');
    }

    function ShowFile(){
        //document.all.type3.style.display="none";
        //document.all.type2.style.display="none";
        //document.all.type1.style.display="inline";
        document.dform.isFromFormBox.value="false";
    }

    function FileCopy(){
        //document.all.type3.style.display="none";
        //document.all.type2.style.display="none";
        //document.all.type1.style.display="inline";
        EditCtrl.document.body.innerHTML = '"DataInput"';
     	// disabled 용법 수정
   		//$(EditCtrl.document.body).attr('disabled','true');
        isEdited = true;
    }

    function ShowCopy(){
        //document.all.type1.style.display="none";
        //document.all.type2.style.display="none";
        //document.all.type3.style.display="inline";
        document.dform.isFromFormBox.value="false";
    	 // disabled 용법 수정
   		//$(EditCtrl.document.body).removeAttr('disabled');

//        EditCtrl.document.body.innerHTML = '<center>아래한글,엑셀,워드등에서 작성한 조사서식을 복사하여 붙여넣는 창 입니다.</center>';
        EditCtrl.document.body.innerHTML = '<center>아래한글,엑셀,워드등에서 작성한 조사서식을 복사하여 붙여넣는 창 입니다.<br>* 엑셀이나 한글에서 작성한 수식(계산식)은 적용되지 않습니다. *</center>'
                                                +'<br><center>[주의]붙여넣기 한 서식안에 예시를 작성하는 경우, 예시란에는 빈칸(공백)이 없어야 합니다.</center>';
        isEdited = false;
        //window.open('./popup_copy_form.jsp','makecopy','width=950,height=595,scrollbars=no,resizable=no');
    }

    function inputText(){
        window.open('./popup_input_form.jsp','makepoll','width=870,height=550,scrollbars=yes,resizable=yes');
    }

    function deptSelect() {
    /*
        var urlname = "/totsys/common/web/report_dept/new_dept_list.jsp?formName=dform&section=1&deptIDs="+dform.deptIDs.value+"&deptTypes="+dform.deptTypes.value;
        var height = screen.height;
        var width = screen.width;
        var leftpos = width / 2 - 350;
        var toppos = height / 2 - 350;
        post= window.open(urlname, "post","width=713, height=475, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + leftpos + ",top=" + toppos);
        post.focus();
    */
        etc.deptIDs.value=dform.deptIDs.value;
        etc.deptTypes.value=dform.deptTypes.value;
      //etc.deptNames.value=dform.deptNames.value;
        etc2.deptNames.value = encodeURL(dform.deptNames.value);

        var height = screen.height;
        var width = screen.width;
        var leftpos = width / 2 - 350;
        var toppos = height / 2 - 350;
        //post= window.open("", "post","width=713, height=475, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + leftpos + ",top=" + toppos);
        post= window.open("","post","width=900,height=600,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left="+leftpos+",top="+toppos);
        etc.target="post";
        etc.submit();
    }

    function deptSelect2() {
        //2014.11.07 : Delete, Add by KWON,HAN
        //etc2.deptIDs.value=dform.deptIDs.value;
        //etc2.deptTypes.value=dform.deptTypes.value;
        ////etc2.deptNames.value=dform.deptNames.value;
        //etc2.deptNames.value = encodeURL(dform.deptNames.value);
        etc2.deptCount.value = dform.deptCount.value;
        //===============================

        var height = screen.height;
        var width = screen.width;
        var leftpos = width / 2 - 350;
        var toppos = height / 2 - 350;
        post2= window.open("","post2","width=900,height=600,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left="+leftpos+",top="+toppos);
        etc2.target="post2";
        etc2.submit();
    }

    function fromFormBox(reuseDocID, reuseDocName) {
            if (reuseDocID != 'null') {

                EditCtrl.document.body.focus();

                if(confirm(reuseDocName+"<%=MoumiConfig.getMessageBundle().getString("moumi.message.popup.dataReuse")%>")){
                    //document.all.type1.style.display="none";
                    //document.all.type2.style.display="inline";
                    //document.all.type3.style.display="none";

                    dform.docName.value = reuseDocName;
                    dform.reuseDocID.value = reuseDocID;
                    //dform.oldFormName.value = reuseDocName;
                    //dform.appendType[3].checked = true;             //서식함 활용 체크되게
                    document.getElementById("rd<%= TotDocAppendType.REUSE%>").checked = true;  //서식함 활용 체크되게
                    //window.open('./popup_copy_form.jsp?reuseDocID=','makecopy','width=950,height=595,scrollbars=no,resizable=no');

                    EditCtrl.document.body.innerHTML = '<%= repDocForm %>';
                } else {
                    history.go(-1);
                }
            } else {
                <%if(!docForm.equals("") && docForm !=null){%>
                    <% if(TotDocAppendType.valueOf(appendType) == TotDocAppendType.FILE) {%>
                        init();
                        EditCtrl.document.body.innerHTML = '"DataInput"';
                     // disabled 용법 수정
                   		//$(EditCtrl.document.body).attr('disabled',true);
                    <% } else {%>
                        init();
                        //init2();
                        EditCtrl.document.body.innerHTML = '<%=StringConverter.toOneLine(TagFilter.convertSingle(docForm))%>';
                        //EditCtrl2.document.body.innerHTML = '<%--=StringConverter.toOneLine(TagFilter.convertSingle(notify))--%>';
                    <%}%>
                <%}%>
            }
    }

    function pageInit() {
        setValue();
        dform.docName.focus();
    }

    // Add by YOUNGJUN,CHO 2014.11.13 : 에디터 영역의 height 을 브라우저 창 크기에 맞게 동적으로 변경되도록 처리하는 함수.(expression 은 되도록 쓰지않아야 한다.)
    function fn_resizeEditCtrl() {
        var ifrm_EditCtrl = document.getElementById("ifrm_EditCtrl");
        ifrm_EditCtrl.style.height = document.body.clientHeight - 190;
    }
</script>
</head>

<!--<body BGCOLOR="#FFFFFF" onload="init();setValue();dform.docName.focus();fromFormBox('<%--= reuseDocID --%>', '<%--= reuseDocName --%>');fn_resizeEditCtrl();" onresize="fn_resizeEditCtrl()">-->
<body>
<span id="SetWin" style="position: absolute; z-index: 10; visibility: hidden; background: silver; border: 1px solid rgb(51, 51, 51); line-height: 1.4em; padding: 3px; top: 63px; left: 1080px; width: auto; height: auto;"></span>
<table>
	<jsp:include page="/totsys/common/inc/totper/top/top.jsp" flush="true" />
        <tr>
            <td></td>
            <td>
                <table>
                    <jsp:include page="/totsys/common/inc/title/title.jsp" flush="true" />
                    <tr>
                        <!-- 내용-->
                        <td>
                            <form name="etc" method="post" action="/totsys/common/web/report_dept/new_dept_list.jsp">
                                <input type="hidden" name="formName" value="dform">
                                <input type="hidden" name="section" value="1">
                                <input type="hidden" name="deptTypes">
                                <input type="hidden" name="deptNames">
                                <input type="hidden"	name="deptIDs">
                            </form>
                            <form name="etc2" method="post" action="/totsys/common/web/report_dept/new_dept_list2.jsp">
                                <input type="hidden" name="formName" value="dform">
                                <input type="hidden" name="section" value="1">
                                <input type="hidden" name="deptTypes">
                                <input type="hidden" name="deptNames">
                                <input type="hidden"	name="deptIDs">
                                <input type="hidden" name="deptCount">
                            </form>
                            <form name="dform"	action="/servlet/kr.co.kihyun.beans.totsys.doc.HttpFormReader"	method="post" enctype="multipart/form-data">
                                <input type="hidden" name="docGroupID" value="<%=MDoc.TOT_DOC%>">
                                <input type="hidden" name="isFromFormBox" value="<%=isFromFormBox%>">
                                <input type="hidden" name="totType" value="<%=totType%>">
                                <input type="hidden" name="copyForm">
                                <input type="hidden" name="deptIDs">
                                <input type="hidden" name="deptTypes">
                                <input type="hidden" name="deptNames">
                                <input type="hidden" name="deptCount">
                                <input type="hidden" name="userIDs">
                                <input type="hidden" name="userNames">
                                <input type="hidden" name="userCount">
                                <input type="hidden" name="userID" value="usID">
                                <input type="hidden" name="reuseDocID" value="<%=reuseDocID%>">
                                <INPUT type="hidden" name="fileCount" value="<%=MString.isNull(usrFileNameList[0]) == true ? 0 : usrFileNameList.length%>">
                                <INPUT type="hidden" name="usrFilenames" value="<%=usrFilenames%>">
                                <INPUT type="hidden" name="svrFilenames" value="<%=svrFilenames%>">
                                <INPUT type="hidden" name="fileInfos">
                                <INPUT type="hidden" name="notify">
                                <!-- 새로 추가된 부분 -->
                                <INPUT type="hidden" name="choice" value="<%=choice%>">
                                <INPUT type="hidden" name="isDynaTable" value="<%=isDynaTable%>">
                                <INPUT type="hidden" name="mode" value="<%=mode%>">
                                <INPUT type="hidden" name="tableDefines" value="<%=tableDefines%>">
                                <INPUT type="hidden" name="tableCount" value="<%=tableCount%>">
                                <INPUT type="hidden" name="itemNames" value="<%=itemNames%>">
                                <INPUT type="hidden" name="tableNums" value="<%=tableNums%>">
                                <INPUT type="hidden" name="colNums" value="<%=colNums%>">
                                <INPUT type="hidden" name="rowNums" value="<%=rowNums%>">
                                <INPUT type="hidden" name="itemSizes" value="<%=itemSizes%>">
                                <INPUT type="hidden" name="itemDescs" value="<%=itemDescs%>">
                                <INPUT type="hidden" name="itemExprs" value="<%=itemExprs%>">
                                <INPUT type="hidden" name="itemTypes" value="<%=itemTypes%>">
                                <INPUT type="hidden" name="backDash" value="<%=backDash%>">
                                <INPUT type="hidden" name="totRange" value="1">
                                <table>
                                    <tr>
                                        <td>
                                            <table class="kecttep_list_table">
                                                <tr>
                                                    <!-- Begin : 자료명 //-->
                                                    <td class="kecttep_tdmenu_middle" style="width: 110px; padding-left: 20px;">
                                                        <%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.doc")%><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.name")%>
                                                    </td>
                                                    <td class="kecttep_last_graytd" style="padding-left: 10px; padding-right: 10px; width: 100px" >
                                                        <input name="docName" type="text" class="inputtxt" value="<%=reuseDocName%>" size="100" style="ime-mode: active;" />
                                                    </td><!-- End : 자료명 //-->

                                                    <!-- Begin : 시행번호 //-->
                                                    <td class="kecttep_tdmenu_middle" style="width: 110px; padding-left: 20px;">
                                                        <%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.executionCode")%>
                                                    </td>
                                                    <td class="kecttep_last_graytd" style="padding-left: 10px;" >
                                                        <%= HttpSSOLogin.getDeptName(request)%>_
                                                        <input name="execNum" type="text" class="inputtxt" style="width: 50px" value="<%=execNum%>">
                                                        (<input name="execDate" type="text" size="10" value="<%=execDate%>" readonly onclick="showSetWin('dform.execDate');"
                                                                style="cursor: pointer;" class="inputtxt"><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.day")%>&nbsp;
                                                            <a href="#" onclick="showSetWin('dform.execDate');">
                                                                <img alt="달력" src="/totsys/common/images/date.gif"></a>)
                                                    </td><!-- End : 시행번호 //-->
                                                </tr>
                                                <tr>
                                                    <!-- Begin : 서식형태 //-->
                                                    <td class="kecttep_tdmenu_middle" style="padding-left: 20px;">
                                                        <%= TotDocType.FORM_DOC%><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.form")%>
                                                    </td>
                                                    <td class="kecttep_last_graytd" style="padding-left: 7px;" >
                                                        <label class="label-cotent1" onmouseover="balloon_on('한글이나 엑셀에서 작성한 파일을 붙여넣기 하여 서식을 생성한 후 취합하는 방법(서식외 첨부파일 제출 가능)',this,5,0)" onmouseout="balloon_off()">
                                                            <input type="radio" name="appendType" value="<%= TotDocAppendType.COPY%>" onclick="ShowCopy();"
                                                                    <%= TotDocAppendType.valueOf(appendType) == TotDocAppendType.COPY ? " checked" : ""%>>
                                                                    <%= TotDocType.FORM_DOC%>+<%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.file")%>
                                                        </label>
                                                        <label class="label-cotent1" onmouseover="balloon_on('한글이나 엑셀에서 작성한 파일을 붙여넣기 하여 서식을 생성한 후 취합하는 방법(서식 입력만 가능)',this,5,0)" onmouseout="balloon_off()">
                                                            <input type="radio" name="appendType" value="<%= TotDocAppendType.SYSTEM%>" onclick="ShowCopy();"
                                                                   <%= TotDocAppendType.valueOf(appendType) == TotDocAppendType.SYSTEM ? " checked" : ""%>>
                                                            <%= TotDocType.FORM_DOC%><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.copy")%>
                                                        </label>
                                                        <label class="label-cotent1" onmouseover="balloon_on('첨부파일로 제출된 자료를 취합(압축저장)하는 방법',this,5,0)" onmouseout="balloon_off()">
                                                            <input type="radio" name="appendType" value="<%= TotDocAppendType.FILE%>" onclick="FileCopy();"
                                                                   <%-- <%= reuseDocID == null && TotDocAppendType.valueOf(appendType) == TotDocAppendType.FILE ?  " checked" : "" %>> --%>
                                                                   <%= TotDocAppendType.valueOf(appendType) == TotDocAppendType.FILE ? " checked" : ""%>>
                                                            <%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.file")%><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.tot_doc")%>
                                                        </label>

                                                        <label class="label-cotent1" onmouseover="balloon_on('이전에 집계한 서식을 다시 재사용하여 문서를 생성하는 방법',this,5,0)" onmouseout="balloon_off()">
                                                            <input id="rd<%= TotDocAppendType.REUSE%>" type="radio" name="appendType" value="<%= TotDocAppendType.REUSE%>" onclick="ShowDocPool('<%= MoumiConfig.PER%>');"
                                                                   <%-- <%= reuseDocID != null  && TotDocAppendType.valueOf(appendType) == TotDocAppendType.REUSE ? " checked" : ""%>> --%>
                                                                   <%= TotDocAppendType.valueOf(appendType) == TotDocAppendType.REUSE ? " checked" : ""%>>
                                                            <%= TotDocType.FORM_DOC%><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.box")%><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.upTake")%>
                                                        </label>
                                                    </td><!-- End : 서식형태 //-->

                                                    <!-- Begin : 서식공유범위 //-->
                                                    <td class="kecttep_tdmenu_middle" style="padding-left: 20px;">
                                                        <%=MoumiConfig.getMessageBundle().getString("moumi.message.doc")%><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.type.share")%>
                                                    </td>
                                                    <td class="kecttep_last_graytd" style="padding-left: 7px;" >
                                                      	<label class="label-cotent1" onmouseover="balloon_on('문서를 생성한 담당자만 자료 관리',this,5,0)" onmouseout="balloon_off()">
                                                            <input  name="accAuth" value="0" type="radio"<%= "0".equals(accAuth) ? " checked" : ""%>><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.personal")%>
                                                        </label>
                                                        <label class="label-cotent1" onmouseover="balloon_on('문서를 생성한 담당자와 동일 부서 사용자에게 취합자료 공유',this,5,0)" onmouseout="balloon_off()">
                                                            <input name="accAuth" value="1" type="radio"<%= "1".equals(accAuth) ? " checked" : ""%>><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.devision")%>
                                                        </label>
                                                        <label class="label-cotent1" onmouseover="balloon_on('문서를 생성한 담당자와 동일 기관 사용자에게 취합자료 공유',this,5,0)" onmouseout="balloon_off()">
                                                            <input name="accAuth" value="2" type="radio"<%= "2".equals(accAuth) ? " checked" : ""%>><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.coporation")%>
                                                        </label>
                                                        <label class="label-cotent1" onmouseover="balloon_on('전체 기관 사용자에게 취합 자료 공유(학교사용자 제외)',this,5,0)" onmouseout="balloon_off()">
                                                            <input name="accAuth" value="3" type="radio"<%= "3".equals(accAuth) ? " checked" : ""%>><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.all")%>
                                                        </label>
                                                    </td><!-- End : 서식공유범위 //-->
                                                </tr>
                                                <tr>
                                                    <td class="kecttep_tdmenu_middle" style="padding-left: 20px;">
                                                        <%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.dataInputDevision")%>
                                                    </td>
                                                    <td class="kecttep_last_graytd" style="padding-left: 10px;">
	                                                    <!-- Begin : 제출기관지정 버튼 //-->
	                                                        <a href="#" onClick="javascript:deptSelect2();">
	                                                            <span style="width: 99px; cursor: pointer;">
	                                                                <!--<img src="/totsys/common/images/person.png" height="12">&nbsp;<%//=MoumiConfig.getMessageBundle().getString("moumi.message.button_large.submitDept")%>-->
	                                                                <img src="/totsys/common/images/bt_dept_select2.gif" height="24" alt="<%=MoumiConfig.getMessageBundle().getString("moumi.message.button_large.submitDept")%>" />
	                                                            </span>
	                                                        </a>
	                                                    <!--// End : 제출기관지정 버튼 -->
	
	                                                    <!-- Begin : 제출기관지정 결과 //-->
	                                                        <%if (deptCount.equals("0")) {%>
	                                                        <input name="deptCountText" type="text"
	                                                               style="width: 200px; border: 0; color: black; padding-top: 3px;"
	                                                               value="&nbsp;<%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.submitDevision")%>" readonly>
	                                                        <%} else {%>
	                                                        <input name="deptCountText" type="text"
	                                                               style="width: 200px; border: 0; color: black; padding-top: 3px;"
	                                                               value="&nbsp;<%=deptCount%><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.devisionSelect")%>"
	                                                               align="middle">
	                                                        <%}%>
	                                                    <!--// End : 제출기관지정 결과 -->
                                                    </td>
                                                    <!-- Begin : 입력요령 //-->
                                                    <td class="kecttep_tdmenu_middle" style="padding-left: 20px;">
                                                        <%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.input")%><%=MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.trick")%>
                                                    </td>
                                                    <td class="kecttep_last_graytd" style="padding-left: 10px;" >
                                                        <a href="#" onClick="javascript:inputText();">
                                                            <span>
                                                                <!--<img src="/totsys/common/images/regist2.png">&nbsp;<%//=MoumiConfig.getMessageBundle().getString("moumi.message.button_large.inputWrite")%>-->
                                                                <img src="/totsys/common/images/bt_psd.gif" alt="<%=MoumiConfig.getMessageBundle().getString("moumi.message.button_large.inputWrite")%>" />
                                                            </span>
                                                        </a>
                                                    </td>
                                                    <!--// End : 입력요령 -->
                                                </tr>
                                                <tr>
                                                    <td colspan="4"></td>
                                                </tr>
                                                <tr>
                                                    <td colspan="4">
                                                        <table>
                                                            <tr>
                                                                <td></td>
                                                            </tr>
                                                            <!-- 내용 -->
                                                            <tr>
                                                                <td class="editMain" style="border:1px solid #dedcec;">
                                                                <div>
                                                                	<iframe name='EditCtrl' id="ifrm_EditCtrl" class="contentFrame" onblur='nowkong.SaveSelection();'>
                                                                    </iframe>
                                                                    <div class="overlay hide"></div>
                                                                    <iframe class="iframeHidden" id='i_fontcolor'></iframe>
                                                                    <iframe class="iframeHidden" id='i_backcolor'></iframe>
                                                                    <iframe class="iframeHidden" id='i_image'></iframe>
                                                                    <iframe class="iframeHidden" id='i_link'></iframe>
                                                                    <iframe class="iframeHidden" id='i_emoticon'></iframe>
                                                                    <div id='editctrl' style='display: block; width: auto; height: auto;'>

                                                                        <!--
                                                                        Update by YOUNGJUN,CHO 2014.11.13
                                                                        expression 을 사용해서 브라우저 창 사이즈 조절시 에디터 영역의 height 을 동적으로 변경하려고 사용한듯 한데,
                                                                        expression 사용은 지양해야 한다. 브라우저에서 expression 을 계속 실행하기 때문에 깜빡임 현상이 발생할 수 있다.
                                                                        (거의 ms 마다 실행되고 IE8 부터는 expression 을 지원하지 않는 것으로 알고 있음.)

                                                                        body onload, onresize 에 에디터 영역의 height 을 동적으로 조절하도록 자바스크립트 함수를 추가하여 처리함.
                                                                        -->
                                                                        <!--<iframe name='EditCtrl' style="width:100%;height:expression(document.body.clientHeight-190)" scrolling='YES'-->
                                                                        
                                                                    </div>
																</div>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td></td>
                                    </tr>

                                    <tr>
                                        <td class="center"><!-- 이전, 다음단계 -->
	                                        <a href="javascript:void(0);" onclick="formSubmit();">
	                                            <span>
	                                                <!--<img src="/totsys/common/images/next3.png" />&nbsp;<%//=MoumiConfig.getMessageBundle().getString("moumi.message.button_large.next")%>-->
	                                                <img src="/totsys/common/images/bt_nextb.gif" alt="<%=MoumiConfig.getMessageBundle().getString("moumi.message.button_large.next")%>" />
	                                            </span>
	                                        </a>
                                        </td>
                                    </tr>
                                </table>
                            </form>
                        </td>
                    </tr>
                </table>
            </td>
            <td></td>
        </tr>


</table>
</body>
</html>
<%
}catch(Exception ex){
	ex.printStackTrace();
	out.println(kr.co.kihyun.text.html.ServletUtil.getJavaScript("location='/servlet/kr.co.kihyun.beans.user.HttpSSOLogin?mode=logout';"));
}finally{
    	/********** session내의 doc info reset **********/
			MDoc.initSession(session);
			if (tx.isActive()) {
				tx.rollback();
			}
			pm.close();
}
%>
