<%--
  - FileName   : PURHDAspList.jsp
  - Author(s)  : 
  - Date       : 2011-12-23
  - Copyright  : Copyright (c) 2002-2003 www.hwenc.com, Inc.
  -
  - Description: ASP Sync List 팝업
  --%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ include file="/jsp/work/taglib.jsp" %>

<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();
	
	String cate_gubun =   (String) storage.getObject("cate_gubun");
	
	String level =   (String) storage.getObject("level"); 
	if(level == null || level.equals("null")) level = "";
	
	String kind_big =   (String) storage.getObject("kind_big"); 
	String kind_mid =   (String) storage.getObject("kind_mid"); 
	String kind_small =   (String) storage.getObject("kind_small"); 
	
	String calTpCode = (String) storage.getObject("calTpCode");
	String returnMessage = storage.getMessage();
%>

<script type="text/javascript">
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/gi, "");
};
</script>

<script type="text/javascript">

	$(function(){
	    
	    $("#btn_close").click(function(){
	        setTimeout(function(){parent.fLayerPopClose('_categoryReg');},100);
	    });
	    
	    $("#btn_save").click(function(){
	    	doSave();
	    });
	    
	    
	    $("#search_item_button").click(function(){
	        var f = document.form1;
			
			var url = "/common/MatlCategoryCalTypePopup.screen";
			openPopup(url, "ItemWindow", "auto",680, 400);
	    });
	    
	});
	
	function doSave()
	{
		var f = document.form1;
		var level = "<%=level%>";
	 
		if(f.levelDepth.value.trim() == "")
		{
			alert("Level Depth를 입력해 주세요");
			return f.levelDepth.focus();
		}
		else if(f.categoryCode.value == "")
		{
			alert("그룹코드를 입력해 주세요");
			return f.categoryCode.focus();
		}
		else if(f.categoryNm.value == "")
		{
			alert("그룹명을 입력해 주세요");
			return f.categoryNm.focus();
		}
		else if(f.levelType.value == "" )
		{
			if(level == "2" || level == "3")
			{
				alert("levelType을 입력해 주세요");
				return f.levelType.focus();
			}	
		}
	 
		if (f.levelDepth.value == "2" || level == "1" )  //3자리 2019.01.16 추가 
		{
			if (f.categoryCode.value.length != 3){
				alert("그룹코드를 3자리로 지정해 주세요.");
				return f.categoryCode.focus();
			}
		} 
		else if (f.levelDepth.value == "3" || level == "2" )  //6자리 
		{
            if (f.categoryCode.value.length != 6){
            	alert("그룹코드를 6자리로 지정해 주세요.");
				return f.categoryCode.focus();
			}
		} 
		submitXmlRequest("/common/MatlCategoryTagAddPopup_form.screen", "SAVE_CATEGORY", f);
	}
	
	
	function doResult(resultObj) {
		try {
			if( resultObj.getRequestEvent() == "SAVE_CATEGORY" ) {
				if( resultObj.getSuccess() ) {
					alert("저장되었습니다.");
					parent.parent.tree.location.reload(true);
					winClose();
				}
				else {
					alert(resultObj.getMessage());
				}
				document.form1.isSubmit = false;
			}
		}
		catch(errorObject) {
	        showErrorDlg("doResult()", errorObject);
		}
	}
	
	function open_cate_type_data() {
		var f = document.form1;
		
		var url = "/common/MatlCategoryCalTypePopup.screen";
		openPopup(url, "ItemWindow", "auto", 530, 400);
	}
	
</script>


<form name="form1" method="post">
<input type="hidden" name="fevent" id="fevrnt" value="">

<input type="hidden" name="dept_cd">
<input type="hidden" name="dept_name">
<input type="hidden" name="acmp_yyyymm">
<input type="hidden" name="p_pur_cont_id">
<input type="hidden" name="q_sub_cont_id">
<input type="hidden" name="p_ac_unit_cd">
<input type="hidden" name="corp_count">
<input type="hidden" name="p_contractid">

<input type="hidden" name="cate_gubun" value="<%=cate_gubun%>">
<input type="hidden" name="level" value="<%=level%>">
<input type="hidden" name="kind_big" value="<%=kind_big%>">
<input type="hidden" name="kind_mid" value="<%=kind_mid%>">


<table border="0" cellspacing="0" cellpadding="0" width="90%" id="search-table">
	<!-- 검색조건 영역 : 시작 -->
	<tr>
		<td height="1">
			<table cellspacing="1" cellpadding="0" class="search-form-table">
				<col width="20%">
				<col width="50%">
				<col width="30%">

				<tr height="25"> 
    			<!-- 검색조건 타이틀 1 -->
    				<th>
    					그룹코드1
    				</th>
   					<td>
  						<input type="text" class="input" style="width: 98%;" name="categoryCode" value="<%=level.equals("1") ?  kind_big : kind_mid%>" />
					</td>
				    <td rowspan="4" class="search_button" align="center"> 
				    	<span class="btnSearch center"><a href="javascript:void(0);" id="btn_save">저장</a></span>
       					<span class="btnSearch center"><a href="javascript:void(0);" id="btn_close">닫기</a></span>
    				</td>
  				</tr>
  				<tr height="25"> 
  					<th>
    					그룹명
    				</th>
    				<td>
  						<input type="text" class="input" style="width: 98%;" name="categoryNm" value="" />
					</td>
  				</tr>
  				<tr height="25">
  					<th>
    					Level Depth
    				</th>
  					<td>
  						<input type="text" class="input" style="width: 98%;" name="levelDepth" value="<%=level.equals("") ? "1" :  Integer.parseInt(level) + 1 %>" readonly="readonly"/>
  					</td> 
  				</tr>
  				<tr height="25">
  					<th>
    					Level Type
    				</th>
  					<td>
  						<input type="text" class="input" style="width: 80%;" name="levelType" value="<%=level.equals("3") ?  calTpCode : ""%>" readonly="readonly"/>
  						<img id="search_item_button" src="/img/buyer/button/bt_search_right.gif" class="button"  style="vertical-align: middle; cursor: pointer;"/>
  					</td> 
  				</tr>
			</table>
		</td>
	</tr>
	<!-- 검색조건 영역 : 종료 -->

	<!-- 검색조건 영역, 테이터 영역 구분 여백 : 시작 -->
	<tr>
		<td height="1">
		</td>
	</tr>
	<!-- 검색조건 영역, 테이터 영역 구분 여백 : 종료 -->
</table>
</FORM>