<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>

<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" />
<%
    ctx.init(request, response);

	ValueObject params = null;
	ValueObject user = null;
	String message = null;
	String event   = null;

	HandlerStorage storage = ctx.getHandlerStorage();

	//user = storage.getUser();
	event = storage.getEvent();
	params = storage.getParams();

	RowSet fileListRowSet = storage.getRowSet("FileListRowSet");

	
	int size = (fileListRowSet != null ? fileListRowSet.size() : 0);
%>


<style type="text/css">
.view_title {
    BACKGROUND-COLOR            : #5F86B6                                   ;
    FONT-FAMILY                 : "굴림", "Verdana"                         ;
    FONT-SIZE                   : 9pt                                       ;
    COLOR                       : #ffffff                                   ;
    TEXT-INDENT                 : 9px                                      ;
}
</style>
<SCRIPT language="JavaScript">

var m_enc = "multipart/form-data";
var a_enc = "application/x-www-form-urlencoded";

function doClose() {
	
	var f = document.frames['display'].document.form2;
	
	if( f == null )
		close();

	var size = f.size.value;
	var array = new Object();
	
	if( size == 1 ) {

		var obj = new Object();
		obj.no           = f.no.value;
		obj.file_id      = f.file_id.value;
		obj.file_map_id  = f.file_map_id.value;
		obj.file_name    = f.file_name.value;
		obj.file_size    = f.file_size.value;

		try {

			if( f.open_corp_yn.checked )
				obj.open_corp_yn = 'Y';
			else
				obj.open_corp_yn = 'N';
		}
		catch(errorObject) {

			obj.open_corp_yn = f.open_corp_yn_value.value;
		}

		try {

			if( f.use_con_yn.checked )
				obj.use_con_yn = 'Y';
			else
				obj.use_con_yn = 'N';
		}
		catch(errorObject) {

			obj.use_con_yn = f.use_con_yn_value.value;
		}
		
		try {

			if( f.techreq_open_yn.checked )
				obj.techreq_open_yn = 'Y';
			else
				obj.techreq_open_yn = 'N';
		}
		catch(errorObject) {

			obj.techreq_open_yn = f.techreq_open_yn_value.value;
		}

		array = new Array(obj);
	}
	else if( size > 1 ) {

		array = new Array(size);

		for( var i = 0 ; i < size ; i++ ) {

			var obj = new Object();
			obj.no           = f.no[i].value;
			obj.file_id      = f.file_id[i].value;
			obj.file_map_id  = f.file_map_id[i].value;
			obj.file_name    = f.file_name[i].value;
			obj.file_size    = f.file_size[i].value;

			try {

				if( f.open_corp_yn[i].checked )
					obj.open_corp_yn = 'Y';
				else
					obj.open_corp_yn = 'N';
			}
			catch(errorObject) {

				obj.open_corp_yn = f.open_corp_yn_value[i].value;
			}

			try {

				if( f.use_con_yn[i].checked )
					obj.use_con_yn = 'Y';
				else
					obj.use_con_yn = 'N';
			}
			catch(errorObject) {

				obj.use_con_yn = f.use_con_yn_value[i].value;
			}
			
			try {

				if( f.techreq_open_yn[i].checked )
					obj.techreq_open_yn = 'Y';
				else
					obj.techreq_open_yn = 'N';
			}
			catch(errorObject) {

				obj.techreq_open_yn = f.techreq_open_yn_value[i].value;
			}
		
			array[i] = obj;
		}
	}
	returnValue = array;
	close();
}

function saveProc() {

	var f = document.form1;

	if( f.attach_file.value == "" ) {
	
		dlgAlert("파일을 선택하세요.");
		return;
	}
    f.fevent.value = "FileListWorker.Save";
    f.target = "worker";

	f.action = "FileListWorker.screen";
    f.encoding = m_enc;
    f.method = "post";

	//formSubmit(f, true);

	formSubmit(f, false);

	
}

// Form Lock 풀기
function resetFormProc() {

	resetFormSubmit();
}

function delProc() {
	//var f = document.frames['display'].document.form2;
	//var f = document.getElementById("display");

	
	var iframe = document.getElementById('display');
	var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
	var f = innerDoc.getElementById('form2');
	
	
	if( f.file_map_id == null ) {

		dlgAlert("삭제할 파일이 없습니다.");
		return;
	}

	var isCheck = isChecked(f.chk_file_map_id);

	if( !isCheck ) {
	
		dlgAlert("삭제할 파일을 선택하세요");
		return;	
	}

    f.fevent.value = "FileListWorker.Del";
    f.target = "worker";

	f.action = "FileListWorker.screen";
    f.encoding = a_enc;
    f.method = "post";

	formSubmit(f);
}

function changeOpenCorpYNProc(obj) {

	var f = document.frames['display'].document.form2;
	
	f.change_file_map_id.value = obj.value;

	if( obj.checked )
		f.change_open_corp_yn.value = "Y";
	else
		f.change_open_corp_yn.value = "N";

	f.fevent.value = "FileListWorker.Change";
    f.target = "worker";

	f.action = "FileListWorker.screen";
    f.encoding = a_enc;
    f.method = "post";

	f.submit();
}

function changeUseConYNProc(obj) {

	var f = document.frames['display'].document.form2;
	
	f.change_file_map_id.value = obj.value;

	if( obj.checked )
		f.change_use_con_yn.value = "Y";
	else
		f.change_use_con_yn.value = "N";

	f.fevent.value = "FileListWorker.Change";
    f.target = "worker";

	f.action = "FileListWorker.screen";
    f.encoding = a_enc;
    f.method = "post";

	f.submit();
}

function changeTechreqOpenYNProc(obj) {

	var f = document.frames['display'].document.form2;
	
	f.change_file_map_id.value = obj.value;

	if( obj.checked )
		f.change_techreq_open_yn.value = "Y";
	else
		f.change_techreq_open_yn.value = "N";

	f.fevent.value = "FileListTechreq.Change";
    f.target = "worker";

	f.action = "FileListWorker.screen";
    f.encoding = a_enc;
    f.method = "post";

	f.submit();
}

function reloadProc() {

	f = document.form1;

	f.fevent.value = "";
	f.action   = "FileListView.screen";
	f.method   = "post";
	f.encoding = a_enc;
	f.target   = "display";
	f.submit();
}

function resetProc() {

	f = document.form1;

	//f.reset();
}

function initPage() {

	reloadProc();
}

window.onunload = doClose;

window.onload = initPage;

</SCRIPT>
<STYLE>
BODY {
	padding : 0 0 0 0;
}
</STYLE>
<FORM name="form1">
<INPUT type="hidden" name="fevent"     	value="">
<INPUT type="hidden" name="file_gb"   	value="<%= params.get("file_gb") %>">
<INPUT type="hidden" name="id"        	value="<%= params.get("id") %>">
<INPUT type="hidden" name="is_modify" 	value="<%= params.get("is_modify") %>">
<INPUT type="hidden" name="is_corp"   	value="<%= params.get("is_corp") %>">
<INPUT type="hidden" name="is_con"    	value="<%= params.get("is_con") %>">
<INPUT type="hidden" name="is_techreq" 	value="<%= params.get("is_techreq") %>">
<INPUT type="hidden" name="mod_no"    	value="<%= params.get("mod_no") %>">
<INPUT type="hidden" name="sysGb" 	value="<%=params.get("sys_gb")%>">

   <div align="left" id="title">
    <ul>
     <li>첨부파일</li>
    </ul>
  </div> 
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100" />
			<col width="400" />
			<col width="*" />
		</colgroup>
		<tr>
			<th>파일선택</th>
			<td>
				<%	if( params.get("IS_MODIFY").equals("Y") ) { %>
	        	<!-- <INPUT type="file" name="attach_file" size="50" onChange="getObj(form1.attach_file, 0).value = this.value;" class="input" contenteditable="false"> -->
	        	<input id="attach_file" type="file" name="attach_file" onChange="getObj(form1.attach_file, 0).value = this.value;" class="input" contenteditable="false" multiple>
				<% 	} %>
			</td>
			<td class="button">
				<span class="btnSearch center"><a href="javascript:saveProc();" id="btnSave">파일저장</a></span>
				<span class="btnSearch center"><a href="javascript:delProc();" id="btnDel">파일삭제</a></span>
				<span class="btnSearch center"><a href="javascript:doClose();" id="btnClose">닫기</a></span>
			</td>
		</tr>
		<tr>
			<td colspan="3" style="text-align:center;border:0px;">
				<IFRAME width="99%" height="340px" name="display" id="display" src="" topmargin="0" leftmargin="0"></IFRAME>
			</td>
		</tr>
	</table>
<%-- <TABLE width="100%" cellpadding="0" cellspacing="0" border="0">
   	<TR>
    	<TD height="3" colspan="3"></TD>
   	</TR>
    <TR height="25">
        <TD width="3"></TD>
        <TD>
        
<%	if( params.get("IS_MODIFY").equals("Y") ) { %>
        	<!-- <INPUT type="file" name="attach_file" size="50" onChange="getObj(form1.attach_file, 0).value = this.value;" class="input" contenteditable="false"> -->
        	<input id="attach_file" type="file" name="attach_file" onChange="getObj(form1.attach_file, 0).value = this.value;" class="input" contenteditable="false" multiple>
<% 	} %>

        </TD>
        <TD align="right">
<%	if( params.get("IS_MODIFY").equals("Y") ) { 
%>							
            <TABLE cellpadding="0" cellspacing="0" border="0" width="250">
                <TR>		
 					<TD>		
 						<DIV onclick="JavaScript:saveProc();" class="button_style">
                            <TABLE border="0" cellpadding="0" cellspacing="0">
                                 <TR>
                                    <TD class="button_left1"></TD>
                                    <TD class="button_text1">파일추가</TD>
                                    <TD class="button_right"></TD>
                                    </TR>
                              </TABLE>
                        </DIV>
                    </TD>    
                    <td>    
                        <DIV onclick="JavaScript:delProc();" class="button_style">
                            <TABLE border="0" cellpadding="0" cellspacing="0">
                                 <TR>
                                      <TD class="button_left1"></TD>
                                    <TD class="button_text1">파일삭제&nbsp;&nbsp;&nbsp;</TD>
                                    <TD class="button_right"></TD>
                                    </TR>
                              </TABLE>
                        </DIV>
                       </td>

<% 	}
%>
					 <td>
						      <DIV onclick="JavaScript:doClose();" class="button_style">
		                 		<TABLE border="0" cellpadding="0" cellspacing="0">
                                 <TR>
                                      <TD class="button_left1"></TD>
                                    <TD class="button_text1">닫기&nbsp;&nbsp;&nbsp;</TD>
                                    <TD class="button_right"></TD>
                                    </TR>
                              </TABLE>
                        	</DIV>  
 					</td>
 			    </TR>
 			</TABLE>
 		</TD>
        <TD width="3"></TD>
    </TR>
   	 <TR>
    	<TD height="3" colspan="4"></TD>
   	</TR> 
   	<TR>
    	<TD colspan="6">
   		<IFRAME width="730" height="400" name="display" id="display" src="" topmargin="0" leftmargin="0"></IFRAME>
    	</TD>
   	</TR>
</TABLE> --%>

	 <IFRAME width="0" height="0"  name="worker"></IFRAME>

</FORM>