<%--
  - FileName   : dlgSearchSpotDept_Unitcd.jsp
  - Author(s)  : gyeongmo an
  -
  - Description: 부서 검색
  --%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="kr.co.hsnc.common.sql.RowSet" %>
<%@ page import="kr.co.hsnc.common.util.ValueObject" %>
<%@ page import="com.udapsoft.waf.system.*" %>
<%@ page import="com.udapsoft.waf.common.*" %>
<%@ page import="kr.co.udapsoft.common.*" %>
<%@ page import="com.udapsoft.waf.common.ui.HTMLMaker" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>

<%@ 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 user = ctx.getUser();
	
	ValueObject params = storage.getParams();
	String event = storage.getEvent();
	
	request.setCharacterEncoding("utf-8");
	
	// 콤보박스 : 발전사업본부 추가로 인한 라디오버튼에서 콤보박스로 변경 By hanwool	2012-07-25
	RowSet DivisionRowSet = storage.getRowSet("DivisionRowSet");//사업부 리스트
	
	// sheet 에서 띄웠는지 체크
	String sheetOpenYn = "N";
	if(params.get("sheetOpenYn").equals("Y")) {
		sheetOpenYn = "Y";
	}
	String returnRow = "";
	String returnCol1 = "";
	String returnCol2 = "";
	if(!params.get("returnRow").equals("")) {
		returnRow = params.get("returnRow");
	}
	if(!params.get("returnCol1").equals("")) {
		returnCol1 = params.get("returnCol1");
	}
	if(!params.get("returnCol2").equals("")) {
		returnCol2 = params.get("returnCol2");
	}
%>

<SCRIPT language="JavaScript">
/*예약함수*/
var sheet1;
var sheet1Row;
var sheet1PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;

function _onReady(){
	gridInit(sheet1);
	//검색어 기능 수정 -2011.01.31 한지훈(검색어가 있는 경우 자동검색 없는 경우 자동검색 하지 않음.)
	deptDisplayControl();
	document.form01.dept_nm.value = "";
	
	jQuery("#btnSearch").click(function() {
		var deadflg_value 		= $(':radio[name="deadflg"]:checked').val();
		document.form01.deadflg_value.value = deadflg_value;
		jQuery("#fevent").val("SpotDept");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/lib/dlgSearchSpotDept_Unitcd_search_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form01"), 30, "");
	});
	
	jQuery("#btnClose").click(function() {
	 	setTimeout(function(){
	 			if('<%=sheetOpenYn%>' == "Y") {
	 				parent.searchSiteClose(null,'<%=returnRow%>', '<%=returnCol1%>', '<%=returnCol2%>');
	 			} else {
	 				dlgSearchSpotDeptEnd(null,'<%=params.get("obj_dept_cd")%>', '<%=params.get("obj_dept_nm")%>');	
	 			}
	 		},100);
	});
	
	
	jQuery("#btnSearch").click();
	
	
}

function gridInit(sheetName){
	var init_sheet = {};
	init_sheet.Cfg = {SearchMode:2, Page:30};
	init_sheet.Cols = [
		       			{Header:'현장코드',		Type:"Text",	SaveName:"DEPT_CD",		Width:70, 	Align:"Center", Edit:"false"},
		    			{Header:'현장명',			Type:"Text",	SaveName:"DEPT_NM",		Width:250, 	Align:"Left", Edit:"false"},
		    			{Header:'사업부코드',		Type:"Text", 	SaveName:"AC_UNIT_CD", 			Width:0, 	Align:"Left", Hidden:"True"},
		    			{Header:'사업부',			Type:"Text", 	SaveName:"AC_UNIT_NM", 			Width:65,	Align:"Left", Edit:"false"},
		    			{Header:'기준통화',		Type:"Text", 	SaveName:"STD_CURRENCY_CD", 			Width:50, 	Align:"Center", Edit:"false", Hidden:"True"  },    
		    			{Header:'기준소수점',		Type:"Text",	SaveName:"STD_DIGIT", 			Width:67, 	Align:"Center", Edit:"false", Hidden:"True"  },
	];

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

function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
	returnValue = new Array(sheet1.GetCellValue(Row, 0),sheet1.GetCellValue(Row, 1));
    //window.close();
    //parent.searchSiteClose(returnValue);
    
    var retArray = new Array();
    retArray[0] = sheet1.GetCellValue(Row, 0);
    retArray[1] = sheet1.GetCellValue(Row, 1);
    
    document.form01.rtnVal0.value = sheet1.GetCellValue(Row, 0);
    document.form01.rtnVal1.value = sheet1.GetCellValue(Row, 1);
    
	doSelect_dept_change(retArray[0], retArray[1]);
}
 
function sheet1_OnSearchEnd(code, message) {
	setGridSize();	
}

function setGridSize() {
	sheet1.FitColWidth();
}

function deptDisplayControl() {
	var radioObj = document.getElementsByName("ac_unit_cd");
	var accType = "<%=user.get("ACCT_TYPE_CODE")%>";
	if( accType != "ADMIN" && accType != "EXECUTIVE" ){
		for( i = 0; i <radioObj.length; i++ ){
			if( accType.substring(0,2) == radioObj[i].value ){
				radioObj[i].checked = true;
			}else {
				radioObj[i].disabled = true;
			}
		}
	}
}

function prcKeyPress()
{
  	if( event.keyCode == 13 )
  	{
  		jQuery("#btnSearch").click();
	}
}

//키처리
document.onkeydown = function(){
	//F5 새로고침
	if(event.keyCode == "116"){
		jQuery("#btnSearch").click();
	}
	//ESC 창닫기
	if(event.keyCode == "27"){
		window.close();
	} 
}

function sheet1_OnSmartResize(Width, Height) { 
	sheet1.FitColWidth();
	autoResize();
	
}

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

//현장 변경
function doSelect_dept_change(dept_cd, dept_nm)
{				 

	var f = document.form01;

	f.site_code.value       = dept_cd ;
    f.dept_nm.value         = dept_nm ;
    f.action = "/lib/dlgSearchSpotDept_Change.screen";
    f.target = "worker_set";
    
    formSubmit(f);
}

function doSelect() 
{  
	var retArray = new Array();
	retArray[0] = document.form01.rtnVal0.value;	// 부서코드
	retArray[1] = document.form01.rtnVal1.value;	// 부서명
	
	//window.returnValue = retArray;
	//self.close();
	
	if('<%=sheetOpenYn%>' == "Y") {
		parent.searchSiteClose(retArray,'<%=returnRow%>', '<%=returnCol1%>', '<%=returnCol2%>');
	} else {
		dlgSearchSpotDeptEnd(retArray,'<%=params.get("obj_dept_cd")%>', '<%=params.get("obj_dept_nm")%>');
	}
}

</SCRIPT>

<SCRIPT language="JavaScript" src="/js/common.js"></SCRIPT>

<modular:search id="form01">
	<modular:key id="fevent" />
</modular:search>
<BODY onresize="autoResize()" >
<FORM id="form01" name="form01" method="post" modular:type="search">
<INPUT type="hidden" name="fevent" id="fevent" value="">

<INPUT type="hidden" name="site_code" >
<INPUT type="hidden" name="site_ac_unit_cd" >
<INPUT type="hidden" name="site_ac_unit_nm" >
<INPUT type="hidden" name="site_std_currency_cd" >     <!-- 현장의 기준통화(2010.08.30 최기완) -->
<INPUT type="hidden" name="site_local_currency_cd" >   <!-- 현장의 현지통화(2010.09.08 최기완) -->
<INPUT type="hidden" name="site_std_currency_digit" >  <!-- 현장의 기준통화소수점(2010.09.08 최기완) -->
<INPUT type="hidden" name="site_local_currency_digit" ><!-- 현장의 현지통화소수점(2010.09.08 최기완) -->
<INPUT type="hidden" name="site_krw_currency_digit" >  <!-- 현장의 원화통화소수점(2010.09.08 최기완) -->
<INPUT type="hidden" name="IN_DEPT_CD" >
<INPUT type="hidden" name="nation" value="<%=ctx.get("nation") %>" >
<INPUT type="hidden" name="ntype" value="<%=ctx.get("ntype") %>" >
<%-- <INPUT type="hidden" name="prp_key" value="<%=params.get("prp_key") %>" > --%>
<INPUT type="hidden" name="prp_key" value="Y" >


<INPUT type="hidden" name="rtnVal0" value="" >
<INPUT type="hidden" name="rtnVal1" value="" >
<INPUT type="hidden" name="rtnVal2" value="" >
<INPUT type="hidden" name="rtnVal3" value="" >
<INPUT type="hidden" name="rtnVal4" value="" >
<INPUT type="hidden" name="rtnVal5" value="" >
<INPUT type="hidden" name="rtnVal6" value="" >
<INPUT type="hidden" name="rtnVal7" value="" >
<INPUT type="hidden" name="deadflg_value" value="" >

<INPUT type="text" value="auto summit for disable" size="0" style="display:none;">
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100" />
			<col width="*" />
			<col width="150" />
		</colgroup>
		<tr>
			<th>현장명</th>
			<td>
		   		<INPUT  class="input" type="text" name="dept_nm" size="48" maxlength="50" value="" onKeyPress="prcKeyPress()" style="IME-MODE : active;"> 				
			</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>
				<%= HTMLMaker.getSelectTag( DivisionRowSet, "DETAILCD", "DETAILNM", "ac_unit_cd", "width:190px;height=18px;","","",10,"","onChange=jQuery(\'#btnSearch\').click();" ) %>&nbsp;
			</td>
		</tr>
		<tr>
			<th>진행구분</th>
			<td>
				<LABEL for="deadflg_0"><INPUT id="deadflg_0" type="radio" name="deadflg" value="" onClick="jQuery('#btnSearch').click();">전체</LABEL>
				<LABEL for="deadflg_1"><INPUT id="deadflg_1" type="radio" name="deadflg" value="0" onClick="jQuery('#btnSearch').click();" checked>진행</LABEL>
			 	<LABEL for="deadflg_2"><INPUT id="deadflg_2" type="radio" name="deadflg" value="1" onClick="jQuery('#btnSearch').click();">완료</LABEL>
			</td>
		</tr>
	</table>
	<!-- 검색조건 종료 -->
	
<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 380px; overflow: auto;">
	<script>createIBSheet('sheet1','100%', '380px');</script>
</div>

<IFRAME width="0" height="0" name='worker_set'></IFRAME>
</FORM>
</BODY>
