<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.eactive.eai.rms.common.login.SessionManager"%>
<%@ include file="/jsp/common/include/localemessage.jsp" %>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Expires", "0");
%>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/jsp/common/include/css.jsp"/>
<jsp:include page="/jsp/common/include/script.jsp"/>

<script language="javascript" >
	var url      = '<c:url value="/onl/admin/service/companyMan.json" />';
	var url_view = '<c:url value="/onl/admin/service/companyMan.view" />';
	var isDetail = false;
	
	function init(groupCoCd ,appCode ,companyCode ,bzwkDstcode ,callback){
		$.ajax({
			type : "POST",
			url:url,
			dataType:"json",
			data:{cmd: 'LIST_DETAIL_COMBO'},
			success:function(json){
				new makeOptions("CODE","NAME").setObj($("select[name=onlineYn]")).setData(json.ynList).setFormat(codeName3OptionFormat).rendering();
				new makeOptions("CODE","NAME").setObj($("select[name=bzwkDstcode]")).setData(json.listBiz).setFormat(codeName3OptionFormat).rendering();
				
				if (typeof callback === 'function') {
					callback(groupCoCd ,appCode ,companyCode ,bzwkDstcode);
				}
			},
			error:function(e){
				alert(e.responseText);
			}
		});
	}
	function detail(groupCoCd ,appCode ,companyCode ,bzwkDstcode){
		if (!isDetail){
			$('input[name=columnName]').focus();
			return;
		}
		
		$.ajax({  
			type : "POST",
			url:url,
			dataType:"json",
			data:{cmd: 'DETAIL', groupCoCd : groupCoCd ,appCode : appCode ,companyCode : companyCode ,bzwkDstcode : bzwkDstcode},
			success:function(json){
				var data = json;

				$("#ajaxForm input[type!=radio],#ajaxForm select,#ajaxForm textarea").each(function(){
					var name = $(this).attr("name");
					var tag  = $(this).prop("tagName").toLowerCase();
					$(tag+"[name="+name+"]").val(data[name.toUpperCase()]);
				});
				
				$("input[name=groupCoCd]").attr("readOnly", true);  
				$("input[name=appCode]").attr("readOnly", true); 
				$("input[name=companyCode]").attr("readOnly", true); 
				$("select[name=bzwkDstcode]").prop("disabled", true); 
				$("input[name=columnName]").css("background-color", "#E6E6E6");
				var selectedValue = $("select[name=bzwkDstcode]").val();
				$("#ajaxForm").append('<input type="hidden" name="bzwkDstcode" value="' + selectedValue + '">');
			},
			error:function(e){
				alert(e.responseText);
			}
		});
	}
	function isValid(){
		if ($('input[name=groupCoCd]').val()==""){
			alert("<%=localeMessage.getString("company.alert1")%>");
			$('input[name=groupCoCd]').focus();
			return false;
		}
		if ($('input[name=appCode]').val()==""){
			alert("<%=localeMessage.getString("company.alert2")%>");
			$('input[name=appCode]').focus();
			return false;
		}
		if ($('input[name=companyCode]').val()==""){
			alert("<%=localeMessage.getString("company.alert3")%>");
			$('input[name=companyCode]').focus();
			return false;
		}
		if ($('input[name=companyName]').val()==""){
			alert("<%=localeMessage.getString("company.alert4")%>");
			$('input[name=companyName]').focus();
			return false;
		}
		return true;
	}
	
	$(document).ready(function() {	
		
		var returnUrl = getReturnUrlForReturn();
		var groupCoCd ="${param.groupCoCd}";
		var appCode ="${param.appCode}";
		var companyCode ="${param.companyCode}";
		var bzwkDstcode ="${param.bzwkDstcode}";
		
		if (bzwkDstcode != "" && bzwkDstcode !="null"){
			isDetail = true;
		}	
		init(groupCoCd ,appCode ,companyCode ,bzwkDstcode,detail);
		
		
		$("#btn_modify").click(function(){
			var postData = $('#ajaxForm').serializeArray();
			if (!isValid())return;
			if (isDetail){
				postData.push({ name: "cmd" , value:"UPDATE"});
			}else{
				postData.push({ name: "cmd" , value:"INSERT"});
			}
			var bzwkName = $('select[name=bzwkDstcode] option:selected').text();
			bzwkName = bzwkName.split(']')[1];
			postData.push({name : "bzwkName", value : bzwkName})
			$.ajax({
				type : "POST",
				url:url,
				data:postData,
				success:function(args){
					alert("<%=localeMessage.getString("common.saveMsg")%>");
					goNav(returnUrl);//LIST로 이동
				},
				error:function(e){
					var txt = JSON.parse(e.responseText).errorMsg;
					alert(txt);
				}
			});
		});
		$("#btn_delete").click(function(){
			var postData = $('#ajaxForm').serializeArray();
			postData.push({ name: "cmd" , value:"DELETE"});
			$.ajax({
				type : "POST",
				url:url,
				data:postData,
				success:function(args){
					alert("<%=localeMessage.getString("common.deleteMsg")%>");
					goNav(returnUrl);//LIST로 이동
	
				},
				error:function(e){
					alert(e.responseText);
				}
			});
		});	
		$("#btn_previous").click(function(){
			goNav(returnUrl);//LIST로 이동
		});
		$("input[name=columnName]").click(function(){
			if (!isDetail) return;
			
			document.body.focus();
		});
		
		
		buttonControl(isDetail);
		titleControl(isDetail);
		
	/* 	$("#btn_search").click(function(){
			var key = "";
			var args = new Object();
	    	args['companyName'] = $('input[name=companyName1]').val();
		    var url='<c:url value="/onl/admin/service/companyMan.view" />';
		    url = url + "?cmd=POPUP";
		    var ret = showModal(url,args,1020,630, function(arg){
		    	var args = null;
		        if(arg == null || arg == undefined ) {//chrome
		            args = this.dialogArguments;
		            args.returnValue = this.returnValue;
		        } else {//ie
		            args = arg;
		        }
		        
		        if( !args || !args.returnValue ) return;
		        
		        var ret = args.returnValue;
		        console.log("ret",ret);
				key = ret['key'];
				$("input[name=companyName1]").val(key);
		    });
		}); */
	});
 
</script>
</head>
	<body>
		<div class="right_box">
			<div class="content_top">
				<ul class="path">
					<li><a href="#">${rmsMenuPath}</a></li>					
				</ul>					
			</div><!-- end content_top -->
			<div class="content_middle">
				<div class="search_wrap">
					<button type="button" class="cssbtn" id="btn_delete" level="W" status="DETAIL"><i class="material-icons">delete</i> <%= localeMessage.getString("button.delete") %></button>
					<button type="button" class="cssbtn" id="btn_modify" level="W" status="DETAIL,NEW"><i class="material-icons">save</i> <%= localeMessage.getString("button.modify") %></button>
					<button type="button" class="cssbtn" id="btn_previous" level="R" status="DETAIL,NEW"><i class="material-icons">arrow_back</i> <%= localeMessage.getString("button.previous") %></button>
<%-- 					<img src="<c:url value="/img/btn_delete.png"/>" alt="" id="btn_delete" level="W" status="DETAIL"/> --%>
<%-- 					<img src="<c:url value="/img/btn_modify.png"/>" alt="" id="btn_modify" level="W" status="DETAIL,NEW" />				 --%>
<%-- 					<img src="<c:url value="/img/btn_previous.png"/>" alt="" id="btn_previous" level="R" status="DETAIL,NEW"/> --%>
				</div>
				<div class="title"><%=localeMessage.getString("company.title")%> </div>	
				<form id="ajaxForm">
					<table class="table_row" cellspacing="0">
						<%-- <tr>
							<th style="width:25%;">업체명검색</th>
							<td>
								<input type="text" name="companyName1" style="width:calc(100% - 60px);" readonly>
								<img src="<c:url value="/img/btn_pop_search.png"/>" alt="" id="btn_search" level="R" status="DETAIL,NEW"/>
									
							</td>
						</tr> --%>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.groupCoCd")%></th><td><input type="text"  name="groupCoCd"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.appCode")%></th><td><input type="text"  name="appCode"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.compCd")%></th><td><input type="text"  name="companyCode"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.compName")%></th><td><input type="text"  name="companyName"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.bzwkDstcd")%></th>
							<td>
								<div class="select-style">
									<select name="bzwkDstcode"></select>
								</div>
							</td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.conNetInstcd")%></th><td><input type="text"  name="conNetInstiCode"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.conNetInstName")%></th><td><input type="text"  name="conNetInstiCodeName"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.onlineYn")%></th><td><div class="select-style"><select name="onlineYn"></select></div></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.compItcontName")%></th><td><input type="text"  name="companyItContactName"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.compItContTelNo")%></th><td><input type="text"  name="companyItContactTelNo"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.bzwkContName")%></th><td><input type="text"  name="bzwkContactName"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.bzwkContPrsnName")%></th><td><input type="text"  name="bzwkContactPerson"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.itContName")%></th><td><input type="text"  name="itContactPointName"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.itContPrsnName1")%></th><td><input type="text"  name="itContactPointPerson1"/></td>
						</tr>
						<tr>
							<th style="width:20%;"><%=localeMessage.getString("company.itContPrsnName2")%></th><td><input type="text"  name="itContactPointPerson2"/></td>
						</tr>
					</table>
				</form>
				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->	
	</body>
</html>

