<%--
  - Author(s)  : Kim Myung HO
  - Date       : 2014.07.07
  - Description: 계약 작성
  --%>
  
<%@page import="java.sql.Clob"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="com.udapsoft.waf.common.util.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ include file="/jsp/work/taglib.jsp" %>
<%@ page import="kr.co.udapsoft.ebid.buyer.common.file.FileManager"%>
<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" />
<%
    ctx.init(request, response);
    HandlerStorage storage = ctx.getHandlerStorage();
    ValueObject params = storage.getParams();
    ValueObject user = storage.getUser();
   // RowSet CorpRowSet = storage.getRowSet("CorpRowSet");
    ValueObject ContInfo = storage.getValueObject("ContInfo");
    String RTN_REASON = "";
    boolean rtn = false;
    if(ContInfo.get("RTN_REASON").length() > 0){
    	RTN_REASON = ContInfo.get("RTN_REASON");
    	rtn = true;
    }

    /*계약서식 정보 START*/
    RowSet template = storage.getRowSet("template");
    /*계약서식 정보 END*/
    
    /*인지세 구분*/
    RowSet stampList = storage.getRowSet("stampRowSet");
    
    //변경계약일경우 이전 차수에서 데이터를 가져온다.
    ValueObject OldContInfo = null;
    if(params.get("ChgCont").equals("Y")){
    	OldContInfo = storage.getValueObject("OldContInfo");
    }
 
%>
<LINK href="/css/cont/cont_style.css" rel="stylesheet" type="text/css">
<script language="javascript" src="/js/cont/cont_util.js"></script>
<script language="javascript" src="/js/cont/lib.validate.js"></script>
<SCRIPT language="JavaScript">
/*예약함수*/
var sheet1;
var sheet1Row;
var sheet1PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;

	function _onReady(){
		/* STAMP_DUTY, PROMISE_DOC 인클루드 페이지 기능 */
		gridInit2(sheet2);
		gridInit3(sheet3);
		doSearchStamp();
		doSearchPromise();
		<% if(params.get("TEMPLATE_CD").equals("5")) {%>
			chgContHtml(); //2015.8.17
		<%}%>
		if(!(jQuery("#STATUS_CD").val() == '20' || jQuery("#STATUS_CD").val() == '30' || jQuery("#STATUS_CD").val() == '50')){
			jQuery("#p_issue_gb").attr("disabled",false);
			jQuery("#p_promise_gb").attr("disabled",false);
			
			if(jQuery("#p_issue_gb").val()=="00"||jQuery("#p_issue_gb").val()==""){
				jQuery("#btnAdd").hide();
				jQuery("#btnSaveStamp").hide();	
			}else{
				jQuery("#btnAdd").show();
				jQuery("#btnSaveStamp").show();	
			}
			
			if(jQuery("#p_promise_gb").val()=="00"||jQuery("#p_promise_gb").val()==""){
				jQuery("#btnPromiseAdd").hide();
				jQuery("#btnSavePromise").hide();	
			}else{
				jQuery("#btnPromiseAdd").show();
				jQuery("#btnSavePromise").show();	
			}
		}else{
			jQuery("#p_issue_gb").attr("disabled",true);
			jQuery("#p_promise_gb").attr("disabled",true);
			
			if(jQuery("#p_issue_gb").val()=="00"||jQuery("#p_issue_gb").val()==""||jQuery("#STATUS_CD").val() == '50'){
				jQuery("#btnAdd").hide();
				jQuery("#btnSaveStamp").hide();	
			}else{
				jQuery("#btnAdd").show();
				jQuery("#btnSaveStamp").show();	
			}
			
			if(jQuery("#p_promise_gb").val()=="00"||jQuery("#p_promise_gb").val()==""||jQuery("#STATUS_CD").val() == '50'){
				jQuery("#btnPromiseAdd").hide();
				jQuery("#btnSavePromise").hide();	
			}else{
				jQuery("#btnPromiseAdd").show();
				jQuery("#btnSavePromise").show();	
			}
		}
		//외주내역 팝업 2018.10.18
		jQuery("#btnItem").click(function() {			
			var win_id = "ItemPop";			
			var link = "/cont/outside/ContItemPopup.screen";
			link += "?pop_win_id="+win_id+"&mod_no="+"<%=ContInfo.get("MOD_NO")%>" + "&sub_cont_mod_id="+"<%=ContInfo.get("SUB_CONT_MOD_ID")%>"+"&digit="+"<%=ContInfo.get("SOSUNUM")%>"+"&edit_yn=Y" ;
			fLayerPop(win_id, link, 950,500, '','', 'NO');
		});	
		
		jQuery("#btnAdd").click(function() {
			var win_id = "_StampDutyPop";
			var link = "/cont/outside/stampDutyPop.screen";
			    link += "?pop_win_id="+win_id
			    link += "&p_move=I" 
			    link += "&p_cont_mod_id="+"<%=ContInfo.get("SUB_CONT_MOD_ID")%>"
			    link += "&p_issue_gb="+jQuery("#p_issue_gb").val()
			    link += "&p_who=E" ;
			    
			fLayerPop(win_id, link, 700,250, '', '', 'NO');
			/*
			var rowIdx = sheet2.DataInsert(-1);
			if(jQuery("#p_issue_gb").val()=="10"){
				sheet2.SetCellValue(rowIdx, "STAMP_DUTY_ISSUE_GB", "10");
			}else{
				sheet2.SetCellValue(rowIdx, "STAMP_DUTY_ISSUE_GB", "20");
			}*/
		});
		
		jQuery("#btnPromiseAdd").click(function() {
			var rowIdx = sheet3.DataInsert(-1);
			if(jQuery("#p_promise_gb").val()=="10"){
				sheet3.SetCellValue(rowIdx, "PROMISE_DOC_TYPE_GB", "10");
			}else{
				sheet3.SetCellValue(rowIdx, "PROMISE_DOC_TYPE_GB", "20");
			}
		});
		
		/**
		 *	Application Initialize
		 */
		jQuery("#btn_list").click(function() {
			jQuery("#fevent").val("");
			jQuery("#form1").attr("action", "/bid/outside/OrderReqeustList.screen");
			jQuery("#form1").attr("target", "_self");
			jQuery("#form1").attr("method", "post");
			jQuery("#form1").submit();
		});
		jQuery("#ELEC_CON_YN1").click(function() {
			jQuery("#ELEC_CON_YN1").attr("checked",true);
			jQuery("#ELEC_CON_YN2").attr("checked",false);
		});
		jQuery("#ELEC_CON_YN2").click(function() {
			jQuery("#ELEC_CON_YN1").attr("checked",false);
			jQuery("#ELEC_CON_YN2").attr("checked",true);
		});

		
		jQuery("#btnSave").click(function() {
			
			if(jQuery('#p_issue_gb').val() == '00' && sheet2.GetTotalRows() != 0 ){
				for(i=1; i <= sheet2.RowCount(); i++){
					if(sheet2.GetCellValue(i, "STATUS")!="D"){
						alert("인지세 발급 구분을 미발행으로 등록하려면\n인지세가 등록되어있거나 등록해서는 안됩니다.\n인지세를 삭제하여 주십시오.");
						return;
					}
				}
			}
			
			if(jQuery('#p_promise_gb').val() == '00' && sheet3.GetTotalRows() != 0 ){
				for(i=1; i <= sheet3.RowCount(); i++){
					if(sheet3.GetCellValue(i, "STATUS")!="D"){
						alert("서약서를 미발행으로 등록하려면\n서약서가 등록되어있거나 등록해서는 안됩니다.\n서약서를 삭제하여 주십시오.");
						return;
					}
				}
			}
			
			if(ck()){
				alert("[전자 계약 여부]는 필수 입니다.");
				return;
			}
			if(jQuery("#mod_gb").val() == ""){
				alert("변경내역을 선택해 주세요");
				return;
			}	
			//변경계약일경우 체크 프로세스 태운다. 2014-11-14 김명호 추가
			if(jQuery("#mod_gb").val() != "00"){
				if(!changeValCheck()){
					return;
				}						
			}		
			 
		    
			if(!checkTelno(jQuery("#O_TEL_NUM").val())) {
				alert("전화번호가 올바르지 않은 형식입니다");
				jQuery("#O_TEL_NUM").focus();
				return;
			}    			
			if(!checkTelno(jQuery("#O_HP").val())) {
				alert("휴대폰번호가 올바르지 않은 형식입니다");
				jQuery("#O_HP").focus();
				return;
			}  			
			if(!checkTelno(jQuery("#C_TEL_NUM").val())) {
				alert("전화번호가 올바르지 않은 형식입니다");
				jQuery("#C_TEL_NUM").focus();
				return;
			}    			
			if(!checkTelno(jQuery("#C_HP").val())) {
				alert("휴대폰번호가 올바르지 않은 형식입니다");
				jQuery("#C_HP").focus();
				return;
			}  				
			if(!checkEmail(jQuery("#O_EMAIL").val())){
				alert("이메일 형식이 올바르지 않습니다.");
				jQuery("#O_EMAIL").focus();
				return;
			}
			if(!checkEmail(jQuery("#C_EMAIL").val())){
				alert("이메일 형식이 올바르지 않습니다.");
				jQuery("#C_EMAIL").focus();
				return;
			}
			/*2016.5.11 */
			if(parseFloat_isNaN(jQuery("#con_supply_tamt").val().replace(/,/gi, ""))  <  parseFloat_isNaN(jQuery("#MIN_CONT_SUPPLY_TAMT").val().replace(/,/gi, ""))){
				alert("공급가액 과세가 기지급액("+jQuery("#MIN_CONT_SUPPLY_TAMT").val()+ ")보다 작습니다. (마이너스세금계산서 발행대상)");
				//return;
			}
		
			if(parseFloat_isNaN(jQuery("#con_supply_namt").val().replace(/,/gi, "")) < parseFloat_isNaN(jQuery("#MIN_CONT_SUPPLY_NAMT").val().replace(/,/gi, ""))){
				alert("공급가액 면세가"+jQuery("#MIN_CONT_SUPPLY_NAMT").val()+ "이 금액보다 크거나 같아야 합니다.");
				//return;
			}
			
			<%if((params.get("TEMPLATE_CD").equals("7")) || (params.get("TEMPLATE_CD").equals("8"))){%>
			//자유서식일경우 첨부 파일은 필수
			if(jQuery("#p_AttachFile1").val() == ""){
				alert('자유서식 계약일 경우 첨부파일은 필수 사항입니다.');							
				return;
			}	
			<%}%>
			if(!chkContHtml()){
				return;
			}
			 
			if (confirm("저장 하시겠습니까?")){
				var f = document.form1;
				submitXmlRequest("/cont/outside/ContWrite_form.screen", "PARTNER_EMP_CHK", f, "VALUEOBJECT");
				document.form1.isSubmit = false;
				
				/* var f = document.form1;
				jQuery("#fevent").val("FORM_SAVE");
				submitXmlRequest("/cont/outside/ContWrite_form.screen", "FORM_SAVE", f); */
			}
		});
		//변경계약 삭제
		jQuery("#btnDel").click(function() {			
			if (confirm("변경계약을  삭제 하시겠습니까?")){
				var f = document.form1;
				jQuery("#fevent").val("FORM_DEL");
				submitXmlRequest("/cont/outside/ContWrite_form.screen", "FORM_DEL", f);
			}
		});
		
		jQuery("#btnDelete").click(function() {			
			if (confirm("계약서를 삭제 하시겠습니까?")){
				var f = document.form1;
				jQuery("#fevent").val("FORM_DELETE");
				submitXmlRequest("/cont/outside/ContWrite_form.screen", "FORM_DELETE", f);
			}
		});	
		
		
		chgModGb(jQuery("#mod_gb").val());
	} 
	
	function ck(){
		if($("#ELEC_CON_YN1").attr("checked") == "checked"){
			return false;	
		}
		if($("#ELEC_CON_YN2").attr("checked") == "checked"){
			return false;
		}
		return true;
	}
	
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
	    	for(var i=1;i <= sheet1.RowCount();i++){
	    		if(sheet1.GetCellValue(i,"INFO_YN") == "N"){
	    			sheet1.SetCellFontColor(i,10,"#FF0000");
	    		}else{
	    			sheet1.SetCellFontColor(i,10,"#0100FF");
	    		}
	    	}
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {
		sheet1.FitColWidth();
	}
	
	
	//자동로그인 기능
	function f_gologin(login_id,login_pw){
		var f = document.form1;
		if('<%= user.get("ACCT_TYPE_CODE")%>' != "ADMIN"){
			dlgAlert("User who logged in as administrator only can do automatic log-in.");
			return;
		}
	
		f.login_id.value = login_id;
		f.login_pw.value = login_pw;
	
		if( !submitXmlRequest("/sign_on_check", "", document.form1) ) {
			alert("Log-in is being processed.");
		};
	
	}

	function goListProc(){
		 var f = document.form1;
		f.fevent.value ="";
	    f.action = "/cont/outside/ContTargetList.screen";
	    f.target = "_self";
	    f.submit();
	}

	function doResult(resultObj) {
		try {
			if( resultObj.getRequestEvent() == "PARTNER_EMP_CHK") {
				if( resultObj.getSuccess() ) {
					var vo = resultObj.getValueObject();
					var cnt = vo.get("EMP_CHK_CNT");
					if(cnt > 0){
						var f = document.form1;
						jQuery("#fevent").val("FORM_SAVE");
						submitXmlRequest("/cont/outside/ContWrite_form.screen", "FORM_SAVE", f);
					}else{
						if(confirm("등록된 업체담당자 정보와 일치하지 않습니다. 계속진행하시겠습니까?")){
							var f = document.form1;
							jQuery("#fevent").val("FORM_SAVE");
							submitXmlRequest("/cont/outside/ContWrite_form.screen", "FORM_SAVE", f);
						}else{
							return;
						}
					}
				}else {
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}
			if( resultObj.getRequestEvent() == "FORM_SAVE") {
				if( resultObj.getSuccess() ) {
					alert("계약서저장에 성공하였습니다.\n\n저장된 계약서는 외주_계약현황페이지에서 확인하실수 있습니다.");
					location.href="/cont/outside/ContIngList.screen";
 					//goListProc();
	 				jQuery("#save_gb").val("Y");
	 				doSaveStamp();
	 				doSavePromise();
				}
				else {
					dlgErrorMsg(resultObj);
				}
			}
			
			//계약서 삭제
			if( resultObj.getRequestEvent() == "FORM_DEL") {
				if( resultObj.getSuccess() ) {
					alert("정상적으로 삭제 처리 되었습니다.")
					goListProc();
				} else {
					dlgErrorMsg(resultObj);
				}
			}			
			//계약서 삭제
			if( resultObj.getRequestEvent() == "FORM_DELETE") {
				if( resultObj.getSuccess() ) {
					alert("정상적으로 삭제 처리 되었습니다.");
					goListProc();
				} else {
					dlgErrorMsg(resultObj);
				}
			}
			document.form1.isSubmit = false;
		}
		catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
	

	/*담당자 호출*/	
	function SearchUser(NAME,CODE){
		var win_id = "_searchUserPopup";
		var link = "/lib/dlgSearchUserPop.screen";
		    link += "?pop_win_id="+win_id;
		    link += "&deptNameYn=outside";
			link += "&NAME=" + NAME;
			link += "&CODE=" + CODE;
			
		fLayerPop(win_id, link, 700,400, '', '', 'NO');
	}
	/*담당자 호출 Return Value 처리*/	
	function SearchUserClose(result){
		if(result.length > 0){
			$("#O_USER_NAME").val(result[1]);
			$("#O_DIVISION").val(result[3]);
			$("#O_POSITION").val(result[5]);
			$("#O_TEL_NUM").val(result[6]);
			$("#O_HP").val(result[7]);
			$("#O_EMAIL").val(result[8]);
			$("#O_ACCT_ID").val(result[9]);
		}
		fLayerPopClose('_searchUserPopup');
	}	
    
	//계약서 조건변경 2015.8.17
	function chgContHtml(){
		var f = document.form1;
		f.chgContChk1.checked = false ;
		f.chgContChk2.checked = false ;
		f.chgContChk3.checked = false ;
		//f.chgContChk4.checked = false ;	//2023.02 선급금+선급금보증금률
		f.chgContChk5.checked = false ;
		f.chgContChk6.checked = false ;
		f.chgContChk7.checked = false ;  //2016.12.1 증권면제 
		chgContent(f.chgContChk1);
		chgContent(f.chgContChk2);;
		chgContent(f.chgContChk3);
		//chgContent(f.chgContChk4);	//2023.02 선급금+선급금보증금률
		chgContent(f.chgContChk5);
		chgContent(f.chgContChk6);
		chgContent(f.chgContChk7);
	}
	/*계약서 pdf script start*/
	function chkContHtml(){
		var f = document.form1;
		var c = $("#PDF_FILE_CNT").val();
		if(validate(f)){
			splitHtml(f, 'cont_html', false, c);
			splitHtml(f, 'cont_html_rm', true, c);
			
			//공사기간에 대해서 준공일이 착공일 보다 빠르면 안됨 처리		
			if(f.start_work_date_year.value+f.start_work_date_month.value+f.start_work_date_day.value > f.end_work_date_year.value+f.end_work_date_month.value+f.end_work_date_day.value){
				alert("공사 기간에 준공일이 착공일 보다 빠르게 셋팅 되었습니다.\n\n준공일을 다시 설정해 주시기 바랍니다.");
				return false;
			}
			//기성금에 대해서 현금 + 어음 은 100% 체크
			if(parseFloat_isNaN(f.pay_way_cash.value)+parseFloat_isNaN(f.pay_way_bill.value) != 100){
				alert("지급 방법에 현금과 어음의 합은 100%로 설정해 주시기 바랍니다.");
				f.pay_way_cash.focus();
				return false;
			}
			
			return true;
		}
		return false;
	}
	/*계약서 pdf script end*/	

	//첨부파일   
	function doAttachFile(obj) {
		 if(obj==''){
			alert("저장을 한 후 파일을 첨부할 수 있습니다.");
		}
		else if(obj != ''){ 
			viewFileListNew('SUB_CONT_MOD_ID', obj.value, document.getElementById("p_AttachFile1"), "Y", "cont/outside/<%=ContInfo.get("SUB_CONT_MOD_ID")%>");
		} 
	}
	/**
	 * 첨부파일 예약 함수
	 */
	function fileDown(file_id){
			var url="/common/file/FileDownloadServlet";
	 		url += "?file_id=" + file_id;
	 		
	 		window.open(url, "_fileDown", "toolbar=no, width=400, height=100, top=500, left=400, toolbar=no,directories=no,status=no,scrollbars=yes,resize=no,menubar=no,target=new")
	}	
	
	
	function erpCheckYn(){
	    alert("계약완료 후 변경 불가능합니다.");
	}
</SCRIPT>


<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>
<form id="form1" name="form1" method="post" modular:type="search">
<INPUT type="hidden" name="fevent" id="fevent" value="<%= params.get("fevent") %>">
<INPUT type="hidden" name="save_gb" id="save_gb" value="">
<INPUT type="hidden" name="acct_id" value="<%= params.get("acct_id") %>">
<!-- 검색 조건 시작-->
<INPUT type="hidden" name="p_dept_cd" value="<%= params.get("p_dept_cd") %>">
<INPUT type="hidden" name="p_dept_nm" value="<%= params.get("p_dept_nm") %>">
<INPUT type="hidden" name="p_dealer_nm" value="<%= params.get("p_dealer_nm") %>">
<INPUT type="hidden" name="p_cont_status" value="<%= params.get("p_cont_status") %>">
<INPUT type="hidden" name="ContFromDt" value="<%= params.get("ContFromDt") %>">
<INPUT type="hidden" name="ContToDt" value="<%= params.get("ContToDt") %>">
<INPUT type="hidden" name="p_build_nm" value="<%= params.get("p_build_nm") %>">
<!-- 검색 조건 끝-->
<INPUT type="hidden" name="CONT_STATUS" value="<%=ContInfo.get("CONT_STATUS")%>">
<INPUT type="hidden" name="SUB_CONT_MOD_ID" value="<%=ContInfo.get("SUB_CONT_MOD_ID")%>">
<INPUT type="hidden" name="STATUS_CD" value="<%=ContInfo.get("STATUS_CD")%>">
<INPUT type="hidden" name="O_CORP_ID" value="<%=ContInfo.get("O_CORP_ID")%>">
<INPUT type="hidden" name="C_CORP_ID" value="<%=ContInfo.get("C_CORP_ID")%>">
<INPUT type="hidden" name="O_ACCT_ID" id="O_ACCT_ID" value="<%=ContInfo.get("CON_CHARGE_ID")%>">
<INPUT type='hidden' name="ChgCont" value="<%= params.get("ChgCont") %>">

<!-- 계약서PDF정보  START-->
<INPUT type="hidden" name="TEMPLATE_CD" value="<%=params.get("TEMPLATE_CD") %>">
<INPUT type="hidden" name="CON_DOC_NO" value="<%=ContInfo.get("CON_DOC_NO") %>">
<INPUT type="hidden" name="MOD_NO" value="<%=ContInfo.get("MOD_NO") %>">
<INPUT type="hidden" name="PDF_FILE_CNT" value="<%=template.size()%>">
<!-- 계약서PDF정보  END-->

<INPUT type="hidden" name="O_REG_NO" value="<%=ContInfo.get("O_REG_NO") %>">

<INPUT type="hidden" name="MIN_CONT_SUPPLY_TAMT" value="<%=Formatter2.currency(ContInfo.get("MIN_CONT_SUPPLY_TAMT"), ContInfo.getInt("SOSUNUM"))%>">
<INPUT type="hidden" name="MIN_CONT_SUPPLY_NAMT" value="<%=Formatter2.currency(ContInfo.get("MIN_CONT_SUPPLY_NAMT"), ContInfo.getInt("SOSUNUM")) %>">


	<!-- 제목 및 버튼 -->
<table width="100%">
	<colgroup>
		<col width="500" />
		<col width="*" />
	</colgroup>
	<tr>
	   	<th>
		   <div align="left" id="title">
		    <ul>
		     <li>외주_<%if(params.get("ChgCont").equals("Y")){%>변경<%} %>계약대상 상세</li>
		    </ul>
		   </div>
	   </th>
	   <td align="right">
			<span class="btnSearch center" id="btnSave"><a href="javascript:void(0);">저장</a></span>
			<%if(ContInfo.get("MOD_NO").equals("0") && (ContInfo.get("STATUS_CD").equals("") || ContInfo.get("STATUS_CD").equals("00"))){%>
			<span class="btnSearch center" id="btnDelete"><a href="javascript:void(0);">삭제</a></span>
			<%}%>
			<span class="btnSearch center" id="btnItem"><a href="javascript:void(0);">계약내역</a></span>
			<span class="btnSearch center" id="btnList"><a href="javascript:goListProc();">목록</a></span>
		<%
		if((params.get("TEMPLATE_CD").equals("5")) || (params.get("TEMPLATE_CD").equals("8"))){	//변경계약일경우 변경내역 팝업 
					//변경 계약일경우 계약서 삭제 가능
		%>
			<span class="btnSearch center" id="btnDel"><a href="javascript:void(0);">변경계약서삭제</a></span>
		<%
		}
		%>
	   </td>
   	</tr>
</table>

<%
	/*
		계약 정보를 한페이지로 만들어서 include 시킴 (2014-08-14) 김명호
	*/	
	String isViewWrite = "W";
	String finalYn = "";
%>
<%@ include file="/jsp/ko_KR/buyer/cont/outside/ContInfo.jsp" %>
<div class="application-info  magT10">
	<div class="application-sub-title">
		<span class="title">계약정보</span>
	</div>
	<div style="text-align:center;">
    <%if (params.get("ChgCont").equals("Y")) {		//변경 계약서 일경우 추가 내역%>
    	변경구분
		<select name="mod_gb" onchange="chgModGb(this.value)">
			<option value="">-선택-</option>
			<option value="01" <%=ContInfo.get("MOD_GB").equals("01") ? "selected=selected":""%>>증액</option>
			<option value="02" <%=ContInfo.get("MOD_GB").equals("02") ? "selected=selected":""%>>감액</option>
			<option value="10" <%=ContInfo.get("MOD_GB").equals("10") ? "selected=selected":""%>>연장</option>
			<option value="11" <%=ContInfo.get("MOD_GB").equals("11") ? "selected=selected":""%>>연장증액</option>
			<option value="12" <%=ContInfo.get("MOD_GB").equals("12") ? "selected=selected":""%>>연장감액</option>
			<option value="20" <%=ContInfo.get("MOD_GB").equals("20") ? "selected=selected":""%>>단축</option>
			<option value="21" <%=ContInfo.get("MOD_GB").equals("21") ? "selected=selected":""%>>단축증액</option>
			<option value="22" <%=ContInfo.get("MOD_GB").equals("22") ? "selected=selected":""%>>단축감액</option>
			<option value="98" <%=ContInfo.get("MOD_GB").equals("98") ? "selected=selected":""%>>계약이관</option>
			<option value="99" <%=ContInfo.get("MOD_GB").equals("99") ? "selected=selected":""%>>기타</option>
		</select>
    <% } else { //당초 일경우 기본 값%>
    	<input type="hidden" name="mod_gb" id ="mod_gb" value="<%=ContInfo.get("MOD_GB")%>" />
    <% }%>
    	<font color="ffffff">......</font>
    	※<span style="background-color:yellow;text-align:center">노랑색</span>은 필수입력사항, <span style="text-align:center;background-color:#CCFF99;">연두색</span>은 계약서에 인쇄되지 않는 항목입니다.
	</div>
</div>

<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border:1px solid black;margin:5px 0px 5px 0px;">
	<tr>
		<td align="center" bgcolor="#efefef">
			<table width="770px" border="0" cellspacing="0" cellpadding="0">
				<tr>
				  <td align="center">
				  		<%
				  			for(int i = 0 ; i < template.size(); i ++){
				  		%>
				  		<input type="hidden" name="template_seq" value="<%=template.getRow(i).get("SEQ")%>">
				  		<input type="hidden" name="template_name" value="<%=template.getRow(i).get("TEMPLATE_NAME")%>">
				  		<input type="hidden" name="template_style" value="<%=template.getRow(i).get("TEMPLATE_STYLE")%>">
				  		<input type="hidden" name="option_yn" value="<%=template.getRow(i).get("OPTION_YN")%>">
				  		<%	if(i==0){ %>
						<span class="tab_on" id="tab_<%=template.getRow(i).get("SEQ")%>" onClick="tabView(<%=template.getRow(i).get("SEQ")%>)">
							<input type="hidden" name="check_yn_<%=template.getRow(i).get("SEQ")%>" value="A">
							<%=template.getRow(i).get("TEMPLATE_NAME")%>
						</span>
						<%	}else{ %>
						<span class="tab_off" id="tab_<%=template.getRow(i).get("SEQ")%>" onClick="tabView(<%=template.getRow(i).get("SEQ")%>)">
							<%if(template.getRow(i).get("OPTION_YN").equals("A")){%>
							<input type="hidden" name="check_yn_<%=template.getRow(i).get("SEQ")%>" value="A">
							<%}else if(template.getRow(i).get("OPTION_YN").equals("Y")){ %>
							<input type="checkbox" name="check_yn_<%=template.getRow(i).get("SEQ")%>" value="Y" <%if(template.getRow(i).get("DEFAULT_YN").equals("Y")){%>checked="checked"<%}%>>
							<%} %>
							<%=template.getRow(i).get("TEMPLATE_NAME")%>
						</span>
						<%	} %>
						<%} %>
				  </td>
				</tr>
			</table>
			<div id="__html" style="width:770px;border:1px solid black;padding:10px 10px 10px 10px;background-color:#FFFFFF;text-align:left;" >
				<%
			  			for(int i = 0 ; i < template.size(); i ++){
			  				String template_html = ClobUtils.getClob((Clob)template.getRow(i).getObject("TEMPLATE_HTML")); 
			  				String divHidden = template.getRow(i).get("SEQ").equals("0")?"":"none";
		  		%>
		  		<div style="display:<%=divHidden%>; padding-top: 10px;overflow:hidden;overflow-y:auto;<%=template.getRow(i).get("TEMPLATE_STYLE") %>" id="__html_<%=template.getRow(i).get("SEQ")%>">
				<%= template_html%>
				</div>
				<%} %>
			</div>
			<br />
		</td>
	</tr>
</table>			

<div class="application-info magT15">
	<div class="application-sub-title">
		<span class="title">계약서류</span>
	</div>
</div>
<TABLE class="form-table">
	<colgroup>
		<col width="120px" />
		<col/>
	</colgroup>

  <TR height="25">
  	<TH> 직접첨부</TH>
	<TD>
	   	<table width="100%">
	   		<colgroup>
	    		<col width="50%" />
				<col width="50%" />
	   		</colgroup>
	   		<tr>
	   		<td>
			    <TEXTAREA name="p_AttachFile1" id="p_AttachFile1" style="width:100%;height:50px;border:0;" rows="1" class="input" readOnly><%=FileManager.getFileListForTextarea("SUB_CONT_MOD_ID", ContInfo.get("SUB_CONT_MOD_ID")) %></TEXTAREA>
	   		</td>
	   		<td>
	   			<IMG id='search_spot_button' onClick="doAttachFile(document.form1.SUB_CONT_MOD_ID,1);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:pointer;'>
	   		</td>
	   		</tr>
	   	</table>	
 	</TD>
  </TR>
 </TABLE>

</form>

<script type="text/javascript">
<!--
/**
 * 상세 코드 검색
 */
function popSearchCodeDetail(bcd)
{
	var win_id = "_searchCodePopup";
	var link = "/sycs/code/dlgCodePopup.screen";
	    link += "?pop_win_id="+win_id;
	    link += "&p_basecd="+bcd;
	fLayerPop(win_id, link, 600,400, '', '', 'NO');

}
function SearchCodeDetailClose(result){
	if(result != null){
		if(result[2]=="SUB_ACMP_PAY_TYPE"){
			replaceInput(result[0],"pay_cond_gb"		,__html);
			replaceInput(result[1],"spn_pay_cond_gb"	,__html);			
		}
	}
	fLayerPopClose('_searchCodePopup');
}		 
//-->
</script>

<script>
//계약일자
<%
	String con_date_year = ""; 
	String con_date_month = "";
	String con_date_day = "";
	if(!ContInfo.get("CON_DATE").equals("")){
		con_date_year = ContInfo.get("CON_DATE").replaceAll("-","").substring(0,4);
		con_date_month = ContInfo.get("CON_DATE").replaceAll("-","").substring(4,6);
		con_date_day = ContInfo.get("CON_DATE").replaceAll("-","").substring(6,8);
	}
%>
replaceInput("<%=con_date_year%>","con_date_year",__html);
replaceInput("<%=con_date_month%>","con_date_month",__html);
replaceInput("<%=con_date_day%>","con_date_day",__html);

//공사기간
<%
	String start_work_date_year = ""; 
	String start_work_date_month = "";
	String start_work_date_day = "";
	if(!ContInfo.get("START_WORK_DATE").equals("")){
		start_work_date_year = ContInfo.get("START_WORK_DATE").replaceAll("-","").substring(0,4);
		start_work_date_month = ContInfo.get("START_WORK_DATE").replaceAll("-","").substring(4,6);
		start_work_date_day = ContInfo.get("START_WORK_DATE").replaceAll("-","").substring(6,8);
	}
	
	String end_work_date_year = ""; 
	String end_work_date_month = "";
	String end_work_date_day = "";
	if(!ContInfo.get("END_WORK_DATE").equals("")){
		end_work_date_year = ContInfo.get("END_WORK_DATE").replaceAll("-","").substring(0,4);
		end_work_date_month = ContInfo.get("END_WORK_DATE").replaceAll("-","").substring(4,6);
		end_work_date_day = ContInfo.get("END_WORK_DATE").replaceAll("-","").substring(6,8);
	}
	
%>
replaceInput("<%=start_work_date_year%>","start_work_date_year",__html);
replaceInput("<%=start_work_date_month%>","start_work_date_month",__html);
replaceInput("<%=start_work_date_day%>","start_work_date_day",__html);
replaceInput("<%=end_work_date_year%>","end_work_date_year",__html);
replaceInput("<%=end_work_date_month%>","end_work_date_month",__html);
replaceInput("<%=end_work_date_day%>","end_work_date_day",__html);

//나머지 계약정보
replaceInput("<%=ContInfo.get("CON_DOC_NO")%>","con_doc_no",__html);// 계약번호
replaceInput("<%=ContInfo.get("DEPT_NAME")%>","dept_name",__html);//현장명
replaceInput("<%=ContInfo.get("DEALER_NM")%>","dealer_nm",__html);//발주처
replaceInput("<%=ContInfo.get("BUILD_NAME")%>","build_name",__html);//계약명
replaceInput("<%=ContInfo.get("UND_CON_NAME")%>","und_con_name",__html);//원도급공사명
replaceInput("<%=ContInfo.get("SUB_UND_CON_NAME")%>","sub_und_con_name",__html);//하도급공사명
<% if(params.get("TEMPLATE_CD").equals("14")) {%>
	replaceInput("공사기간내(" + "<%=ContInfo.get("WORK_PLACE")%>" + ")","work_place",__html);//공사장소
<%}else{%>
	replaceInput("<%=ContInfo.get("WORK_PLACE")%>","work_place",__html);//공사장소
<%}%>

replaceInput("<%=ContInfo.get("PAY_WAY_CASH")%>","pay_way_cash",__html);//지급방법 현금
replaceInput("<%=ContInfo.get("PAY_WAY_BILL")%>","pay_way_bill",__html);// 지금방법 어음
replaceInput("<%=ContInfo.get("CON_AMT")%>","con_amt",__html);// 계약금액
replaceInput("<%=ContInfo.get("CON_SUPPLY_AMT")%>","con_supply_amt",__html);// 공급가액
replaceInput("<%=ContInfo.get("CON_SUPPLY_AMT")%>","con_supply_amt1",__html);// 공급가액
replaceInput("<%=ContInfo.get("CON_SUPPLY_TAMT")%>","con_supply_tamt",__html);// 공급가액 과세
replaceInput("<%=ContInfo.get("CON_SUPPLY_NAMT")%>","con_supply_namt",__html);// 공급가액 비과세
replaceInput("<%=ContInfo.get("CON_SURTAX_AMT")%>","con_surtax_amt",__html);// 계약부과세
replaceInput("<%=ContInfo.get("LABOR_AMT")%>","labor_amt",__html);// 노무비
replaceInput("<%=ContInfo.get("PREPAY_RATE")%>","prepay_rate",__html);// 선급금율
replaceInput("<%=ContInfo.get("PREPAY_AMT")%>","prepay_amt",__html);// 선급금액
replaceInput("<%=ContInfo.get("PREPAY_DAY")%>","prepay_day",__html);// 선급금지급일자조건1
replaceInput("<%=ContInfo.get("PREPAY_DAY2")%>","prepay_day2",__html);// 선급금지급일자조건2
replaceInput("<%=ContInfo.get("PREPAY_GUAR_AMT_RATE")%>","prepay_guar_amt_rate",__html);// 선급금보증율
replaceInput("<%=ContInfo.get("PREPAY_GUAR_AMT")%>","prepay_guar_amt",__html);// 선급금보증액
replaceInput("<%=ContInfo.get("PREPAY_SUPPLY_AMT")%>","prepay_supply_amt",__html);// 선급금 공급가액
replaceInput("<%=ContInfo.get("PREPAY_SUPPLY_TAMT")%>","prepay_supply_tamt",__html);// 선급금 과세
replaceInput("<%=ContInfo.get("PREPAY_SUPPLY_NAMT")%>","prepay_supply_namt",__html);// 선급금 면세
replaceInput("<%=ContInfo.get("PREPAY_SURTAX_AMT")%>","prepay_surtax_amt",__html);// 선급금 부과세
replaceInput("<%=ContInfo.get("CON_EST_GUAR_RATE")%>","con_est_guar_rate",__html);// 계약이행 보증금율
replaceInput("<%=ContInfo.get("CON_EST_GUAR_AMT")%>","con_est_guar_amt",__html);// 계약이행 보증금
replaceInput("<%=ContInfo.get("CON_GUAR_TERM")%>","con_guar_term",__html);// 계약이행보증기한 -->계약서항목 없음. 
replaceInput("<%=ContInfo.get("DEF_EST_GUAR_RATE")%>","def_est_guar_rate",__html);// 하자보증율
replaceInput("<%=ContInfo.get("DEF_GUAR_AMT")%>","def_guar_amt",__html);//하자보증금액
replaceInput("<%=ContInfo.get("DEF_EST_TERM")%>","def_est_term",__html);// 하자보증기간
replaceInput("<%=ContInfo.get("DELAY_RATE")%>","delay_rate",__html);// 지체상급율
replaceInput("<%=ContInfo.get("MONTH_ACMP_CNT")%>","month_acmp_cnt",__html);// 월기성지불횟수
replaceInput("<%=ContInfo.get("PAY_CON_RATE")%>","pay_con_rate",__html);// 하도급대금연동기준비율
replaceInput("<%=ContInfo.get("OBJ_RCPT_DAY")%>","obj_rcpt_day",__html);// 목적물 수령일
replaceInput("<%=ContInfo.get("PAY_COND_GB")%>","pay_cond_gb",__html);// 월기성지불횟수
replaceInput("<%=ContInfo.get("PAY_COND_GB_NM")%>","spn_pay_cond_gb",__html);// 목적물 수령일

replaceInput("<%=ContInfo.get("OBC_MID_BILL_DATE")%>","obc_mid_bill_date",__html);// 어음만기일
replaceInput("<%=ContInfo.get("OBC_MID_REQ_MONTH")%>","obc_mid_req_month",__html);// 월기성개월


// 본사정보
replaceInput("<%=ContInfo.get("O_MEMBER_NAME")%>", "o_member_name", __html);
replaceInput("<%=ContInfo.get("O_ADDRESS")%>", "o_address", __html);
replaceInput("<%=ContInfo.get("O_BOSS_NAME")%>", "o_boss_name", __html);
replaceInput("<%=ContInfo.get("O_DIVISION")%>", "o_division", __html);
replaceInput("<%=ContInfo.get("O_USER_NAME")%>", "o_user_name", __html);
replaceInput("<%=ContInfo.get("O_POSITION")%>", "o_position", __html);
replaceInput("<%=ContInfo.get("O_TEL_NUM")%>", "o_tel_num", __html);
replaceInput("<%=ContInfo.get("O_HP")%>", "o_hp", __html);
replaceInput("<%=ContInfo.get("O_EMAIL")%>", "o_email", __html);
// 업체정보
replaceInput("<%=ContInfo.get("C_MEMBER_NAME")%>", "c_member_name", __html);
replaceInput("<%=ContInfo.get("C_ADDRESS")%>", "c_address", __html);
replaceInput("<%=ContInfo.get("C_BOSS_NAME")%>", "c_boss_name", __html);
replaceInput("<%=ContInfo.get("C_DIVISION")%>", "c_division", __html);
replaceInput("<%=ContInfo.get("C_USER_NAME")%>", "c_user_name", __html);
replaceInput("<%=ContInfo.get("C_POSITION")%>", "c_position", __html);
replaceInput("<%=ContInfo.get("C_TEL_NUM")%>", "c_tel_num", __html);
replaceInput("<%=ContInfo.get("C_HP")%>", "c_hp", __html);
replaceInput("<%=ContInfo.get("C_EMAIL")%>", "c_email", __html);

//2016.12.9
<% if(params.get("TEMPLATE_CD").equals("5")) {%>
	replaceInput("<%=ContInfo.get("BEF_ETC")%>", "input_n1", __html);
	replaceInput("<%=ContInfo.get("AFT_ETC")%>", "input_n2", __html);
<%}%>

//한글로 변환할 금액, 금액 콤마처리
var f = document.forms["form1"];
if(f['kMoney']){
	var keyList = f['kMoney'].value.split(",");
	for(var keySeq = 0 ; keySeq < keyList.length ; keySeq ++){
		var key = keyList[keySeq];
		fSetKoreanMoney(f[key].value, 'spn_'+key);
		replaceInput(fnMakeComma2(f[key].value),key,__html)
	}
}


<%if (params.get("ChgCont").equals("Y")) {		//변경 계약서 일경우 추가 내역%>
// 원 계약서 정보
	replaceInput("<%=con_date_year%>","o_con_date_year",__html);
	replaceInput("<%=con_date_month%>","o_con_date_month",__html);
	replaceInput("<%=con_date_day%>","o_con_date_day",__html);

	replaceInput("<%=start_work_date_year%>","o_start_work_date_year",__html);
	replaceInput("<%=start_work_date_month%>","o_start_work_date_month",__html);
	replaceInput("<%=start_work_date_day%>","o_start_work_date_day",__html);
	
	<%if (ContInfo.get("MOD_NO").equals("1")){%>
	replaceInput("원","o_title_text",__html);
	<%}else{%>
	replaceInput("이 전","o_title_text",__html);
	<%}%>
	
<%
String O_end_work_date_year = ""; 
String O_end_work_date_month = "";
String O_end_work_date_day = "";
if(!OldContInfo.get("END_WORK_DATE").equals("")){
	O_end_work_date_year = OldContInfo.get("END_WORK_DATE").replaceAll("-","").substring(0,4);
	O_end_work_date_month = OldContInfo.get("END_WORK_DATE").replaceAll("-","").substring(4,6);
	O_end_work_date_day = OldContInfo.get("END_WORK_DATE").replaceAll("-","").substring(6,8);
}
%>	
	
	replaceInput("<%=O_end_work_date_year%>","o_end_work_date_year",__html);
	replaceInput("<%=O_end_work_date_month%>","o_end_work_date_month",__html);
	replaceInput("<%=O_end_work_date_day%>","o_end_work_date_day",__html);

	//나머지 계약정보

	replaceInput("<%=OldContInfo.get("PAY_WAY_CASH")%>","o_pay_way_cash",__html);//지급방법 현금
	replaceInput("<%=OldContInfo.get("PAY_WAY_BILL")%>","o_pay_way_bill",__html);// 지금방법 어음
	replaceInput("<%=OldContInfo.get("CON_AMT")%>","o_con_amt",__html);// 계약금액
	replaceInput("<%=OldContInfo.get("CON_SUPPLY_AMT")%>","o_con_supply_amt",__html);// 공급가액
	replaceInput("<%=OldContInfo.get("CON_SUPPLY_TAMT")%>","o_con_supply_tamt",__html);// 공급가액 과세
	replaceInput("<%=OldContInfo.get("CON_SUPPLY_NAMT")%>","o_con_supply_namt",__html);// 공급가액 비과세
	replaceInput("<%=OldContInfo.get("CON_SURTAX_AMT")%>","o_con_surtax_amt",__html);// 계약부과세
	replaceInput("<%=OldContInfo.get("LABOR_AMT")%>","o_labor_amt",__html);// 노무비
	replaceInput("<%=OldContInfo.get("PREPAY_RATE")%>","o_prepay_rate",__html);// 선급금율
	replaceInput("<%=OldContInfo.get("PREPAY_AMT")%>","o_prepay_amt",__html);// 선급금액
	replaceInput("<%=OldContInfo.get("PREPAY_GUAR_AMT_RATE")%>","o_prepay_guar_amt_rate",__html);// 선급금보증율
	replaceInput("<%=OldContInfo.get("PREPAY_GUAR_AMT")%>","o_prepay_guar_amt",__html);// 선급금보증액	
	replaceInput("<%=OldContInfo.get("PREPAY_SUPPLY_AMT")%>","o_prepay_supply_amt",__html);// 선급금 공급가액
	replaceInput("<%=OldContInfo.get("PREPAY_SUPPLY_TAMT")%>","o_prepay_supply_tamt",__html);// 선급금 과세
	replaceInput("<%=OldContInfo.get("PREPAY_SUPPLY_NAMT")%>","o_prepay_supply_namt",__html);// 선급금 면세
	replaceInput("<%=OldContInfo.get("PREPAY_SURTAX_AMT")%>","o_prepay_surtax_amt",__html);// 선급금 부과세
	replaceInput("<%=OldContInfo.get("CON_EST_GUAR_RATE")%>","o_con_est_guar_rate",__html);// 계약이행 보증금율
	replaceInput("<%=OldContInfo.get("CON_EST_GUAR_AMT")%>","o_con_est_guar_amt",__html);// 계약이행 보증금
	replaceInput("<%=OldContInfo.get("CON_GUAR_TERM")%>","o_con_guar_term",__html);// 계약이행보증기한 -->계약서항목 없음. 
	replaceInput("<%=OldContInfo.get("DEF_EST_GUAR_RATE")%>","o_def_est_guar_rate",__html);// 하자보증율
	replaceInput("<%=OldContInfo.get("DEF_GUAR_AMT")%>","o_def_guar_amt",__html);//하자보증금액
	replaceInput("<%=OldContInfo.get("DEF_EST_TERM")%>","o_def_est_term",__html);// 하자보증기간
	replaceInput("<%=OldContInfo.get("DELAY_RATE")%>","o_delay_rate",__html);// 지체상급율
	replaceInput("<%=OldContInfo.get("MONTH_ACMP_CNT")%>","o_month_acmp_cnt",__html);// 월기성지불횟수
	replaceInput("<%=OldContInfo.get("OBJ_RCPT_DAY")%>","o_obj_rcpt_day",__html);// 목적물 수령일
	
	replaceInput("<%=OldContInfo.get("OBC_MID_BILL_DATE")%>","o_obc_mid_bill_date",__html);// 어음만기일
	replaceInput("<%=OldContInfo.get("OBC_MID_REQ_MONTH")%>","o_obc_mid_req_month",__html);// 월기성개월
	
<% } %>

if(f['comma']){
	var keyList = f['comma'].value.split(",");
	for(var keySeq = 0 ; keySeq < keyList.length ; keySeq ++){
		var key = keyList[keySeq];
		replaceInput(fnMakeComma2(f[key].value),key,__html)
	}
}
</script>
