<%--
  - FileName   : dlgSearchZipCode.jsp
  - Author(s)  : ok
  - Date       : 2014.06.19
  - Copyright  : Copyright (c) 2013 www.udapsoft.co.kr, Inc.
  - Description: 우편번호 검색 팝업
--%>

<%@ 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();
    ValueObject user = storage.getUser();
    String event = storage.getEvent();
    
    RowSet sidoList = storage.getRowSet("sidoList");


    
    
    
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet1;
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	function _onReady(){
		/**
		 *	IBSheet object initialize
		 */
		gridInit(sheet1);
		
	
		/**
		 *	Application Initialize
		 */
		jQuery("#btnSearch").click(function() {
			
			if(jQuery("#Field2").val() == ""){
				if(document.getElementById("radAccType1").checked==true){
					alert('동이름을 입력해주세요');	
				}else{
					alert('도로명을 입력해주세요');
				}
				return;
			}
			
			jQuery("#addDiv").val(jQuery(":input:radio[name=radAccType]:checked").val());
	        jQuery("#fevent").val("GET_ZIP_LIST");
	    	var url = Modular.model.PageContext.CONTEXT_ROOT + "/common/lib/dlgSearchZipCode_sheet.screen";
	    	Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, "");
		});
		
		jQuery("#btnClose").click(function() {
			setTimeout(function(){parent.searchPostCodeClose(null);},100);
		}); 
		
		pageinit();
		
		sheet1.FitColWidth();		
	}
	
	function pageinit(){
		//sheet1.FitColWidth("16|84");
		changeDong();
	}
	
	function changeDong()
	{
		sheet1.RemoveAll();
		
		if(document.getElementById("radAccType1").checked==true){
// 			document.getElementById("dongName").innerHTML="동이름";
			$("#dong_title").text("동이름");
			sheet1.SetColHidden(2, 1);
		}else{
// 			document.getElementById("dongName").innerHTML="도로명";
			$("#dong_title").text("도로명");
			sheet1.SetColHidden(2, 0);
		}
		
		setGridSize();
	}
	
	/**
	 *	IBSheet object initialize
	 */
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:30};
		init_sheet.Cols = [
		    			{Header:'상태',			Type:"Status", 		SaveName:"STATUS", 	Width:0, 	Align:"Center", Hidden:"True"},
		    			{Header:'우편번호',	Type:"Text", 			SaveName:"ZIP",			Width:80, 	Align:"Center"},
		    			{Header:'새주소',		Type:"Text", 			SaveName:"ADDR", 		Width:280, 	Align:"Left"},
		    			{Header:'주소',			Type:"Text", 			SaveName:"OLDADDR", 	Width:180, 	Align:"Left"}
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(false);
	}

	
	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	

	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {
		
		if(document.getElementById("radAccType1").checked==true){
			sheet1.FitColWidth("16|84");
		}else{
			sheet1.FitColWidth("16|42|42");	
		}
	}

	/**
	 *	IBSheet Event: Click
	 */
	function sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		 sheet1Row = Row;
		 
	}
	
	/**
	 *	IBSheet Event: DBLCLICK
	 */
	function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		var retArray = new Array();
		
		retArray[0] = sheet1.GetCellValue(Row, 1);
		if($('input:radio[name="radAccType"]:checked').val() == "g")
	    {
		    retArray[1] = sheet1.GetCellValue(Row, 2);
			retArray[2] = sheet1.GetCellValue(Row, 3);
	    }
		else
	    {
		    retArray[1] = sheet1.GetCellValue(Row, 2);
			retArray[2] = sheet1.GetCellValue(Row, 2);
	    }
		setTimeout(function(){parent.searchPostCodeClose(retArray);},10);
// 		parent.searchPostCodeClose(retArray);
	 }
	
	function doKeyPress() {
	
	    if( event.keyCode == 13 ) {
	    	jQuery("#btnSearch").click();
	    }
	}	
	
	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
	}

	function autoResize(){
		var t1_height = document.getElementById("search-table").scrollHeight + document.getElementById("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		sheet1.SetSheetHeight(iframeHeight); 
	}
	
</SCRIPT>


<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>
<BODY onresize="autoResize()" >
<form id="form1" name="form1" method="post" modular:type="search" style="width:100%;height:100%;">
<INPUT type="hidden" name="fevent" id="fevent" value="">
<INPUT type="hidden" name="addDiv" id="addDiv" value="">
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="80" />
			<col width="100" />
			<col width="80" />
			<col width="*" />
			<col width="100" />
		</colgroup>
		<tr>
			<th>주소구분</th>
			<td>
		   		<input type="radio" name="radAccType" id="radAccType1" type="radio" value="g" checked="checked" onclick="changeDong();" />지번주소
        		<input type="radio" name="radAccType" id="radAccType2"  value="r" onclick="changeDong();" />도로명주소<BR> 				
			</td>
			<td class="button" rowspan="3">
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">검색</a></span>
<!-- 				<span class="btnSearch center"><a href="javascript:void(0);" id="btnClose">닫기</a></span> -->
			</td>
		</tr>
		<tr>
			<th>시도</th>
			<td>
				<select id="SIDO">
					<%
						for(int i = 0; i < sidoList.size(); i++)
						{
					%>
					<option value="<%=sidoList.getRow(i).get("sido")%>"><%=sidoList.getRow(i).get("sido")%></option>
					<%
						}
					%>
				</select>
			</td>
		</tr>
		</tr>
			<th id="dong_title">동이름</th>
			<td>
				<INPUT type="text" id="Field2" name="Field2" value="" maxlength="50" class="input" style="IME-MODE : active; width:90%;"  desc='동이름' onKeyPress="doKeyPress();">
			</td>
		</tr>
	</table>
	<!-- 검색조건 종료 -->

<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 450px; overflow: auto;">
	<script>createIBSheet('sheet1','100%', '450px');</script>
</div>
</FORM>
</BODY>