
<%/************************************************************@@
			 * Program Name	: group_dept_list.jsp
			 * Description	: 사용자정의 그룹변경
			 * Author		: 기현테크
			 * Create Date	: 2010-11-27
			 * History		:
			 @@************************************************************/%>

<%@ page contentType="text/html; charset=UTF-8"
	import="kr.co.kihyun.lang.MString" import="kr.co.kihyun.moumi.Moumi"
	import="java.net.URLDecoder" import="kr.co.kihyun.lang.Encoder"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.beans.user.UserGroup"%>

<%@ include file="/totsys/common/inc/sec/secure.inc.jsp"%>

<%
	/********** session내의 userId **********/
	String usID = HttpSSOLogin.getLoginID(request);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>제출부서 선택</TITLE>
<link rel="stylesheet" href="/totsys/common/css/text.css"
	type="text/css">
<link rel="stylesheet" href="/totsys/common/css/kecttep.css" type="text/css">
<link rel="stylesheet" href="/totsys/common/css/SquareButtons.css"
	type="text/css">
<style>
a:link {
	font-style: none;
	line-height: normal;
	color: #004080;
	text-decoration: none;
}

a:visited {
	font-style: none;
	line-height: normal;
	color: #3366CC;
	text-decoration: none;
}

a:active {
	font-style: none;
	line-height: normal;
	color: #535353;
	text-decoration: none;
}

a:hover {
	font-style: none;
	line-height: normal;
	color: #FF6600;;
	text-decoration: none;
}

img {
	border: none;
}
</style>
<script src="/totsys/common/js/org_search.js"></script>
<script Language="javascript">
var tstate = false;
var delstate = false;
var userGroup = false; // 사용자정의 그룹인지 여부지정 변수

var selid=''; // 지금 선택한 부서
var selname='';
var seltype='';
var idList = ''; // 선택되어진 부서 리스트
var nameList = '';
var typeList = '';
var orgSearch = new OrgSearch(onNodeCallback);
var focusedButton = null;

function ProcKeyDown() {
	keyPressed = String.fromCharCode(window.event.keyCode);
	if ((keyPressed == '\r') || (keyPressed == '\n')){
		if(focusedButton == null) {
			document.getElementById('nextButton').focus();
		}
	}
}

function previous() {
	try {
		var locationString = document.leftFrame.location + '';
		if(locationString.indexOf('group_list.jsp') !== -1)		// onNodeCallback does not works for group_list.jsp yet.
			return;
		orgSearch.previous(document.searchForm.keyword.value);
	} catch (e) {
		alert(e);
		return;
	}
}

function next() {
	try {
		var locationString = document.leftFrame.location + '';
		if(locationString.indexOf('group_list.jsp') !== -1)		// onNodeCallback does not works for group_list.jsp yet.
			return;
		orgSearch.next(document.searchForm.keyword.value);
	} catch (e) {
		alert(e);
		return;
	}
}

function onNodeCallback(node) {
	for(i = 0; i < node.pathList.length; i++)
		document.leftFrame.openF(node.pathList[i]);
	document.leftFrame.selectItem(node.id, node.type);
	userList(node.id, node.name, node.type);
}

// 부서 추가
function deptConfirm(){
    
	if(selid == '' ){
		alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.deptConfirm")%>');
	}else if(seltype == "group"){
                            modSelect();

		}else{
		id = selid;
		name = selname;
		type = seltype;

		if(	idList == '' ){
			document.list.idList.value = idList = id;
			idList=idList+"";
			document.list.nameList.value = nameList = name;
			nameList=nameList+"";
			document.list.typeList.value = typeList = type;
			typeList=typeList+"";
		}else{
			var isAdd = listAdd(idList, id, typeList, type);
			document.list.idList.value = idList;
			document.list.typeList.value = typeList;
			if(isAdd){
				listAddn(nameList, name);
			}
			document.list.nameList.value = nameList;
		}
		document.list.submit();
	}
    
}

function listAdd(idList1, idList2, tList, tItem){
	var arrayID1 = idList1.split(",");
	var arrayType = tList.split(",");

	var isEquals = true;
	
	if(idList1 == ''){	
		idList = idList1;
		typeList = tList;
		return false;
	}
	for(var i=0; i < arrayID1.length; i++){
		if(idList2 == arrayID1[i] && tItem == arrayType[i]){
			isEquals = false;
			break;
		}
	}
	if(isEquals){
		idList1 += ","+idList2;
		tList += ","+tItem;
	}				
	idList = idList1;
	typeList = tList;
	return isEquals;
}

function listAddn(nameList1, nameList2){
	var arrayName1 = nameList1.split(",");

	if(nameList1 == ''){
		nameList = nameList1;
		return;
	}

	nameList1 += ","+nameList2;
	nameList = nameList1;
	
	return;
}

// 부서삭제
function deptDelete(){
	if(idList != '' ){
		deptFrame.movelist();
		document.list.submit();
	}
}

function leftFrameDel(name, id, type){
	name = lastStrDel(name, ",");
	id = lastStrDel(id, ",");
	type = lastStrDel(type, ",");
	if(nameList == '' && idList == ''){
		document.list.nameList.value = nameList = name;					
		document.list.idList.value = idList = id;
		document.list.typeList.value = typeList = type;
		
	}else{
		delList(id, name, type);
		document.list.nameList.value = nameList;	
		document.list.idList.value = idList;
		document.list.typeList.value = typeList;
	}
	
	tstate = true;

	document.list.submit();
	return;
}	
function delList(idList1, naList1, tyList1){
	idList = idList1;
	nameList = naList1;	
	typeList = tyList1;
	return;
}
function lastStrDel(str, delStr){
	var lastStr = str.lastIndexOf(delStr);
	return str.substring(0, lastStr);				
}

// 부서 선택 시 유저 뽑아내기.
function userList(id, name, type){
	if(type != '') {
		idAll=id;
		selid = id;
		selname = name;
	} else {
		idAll='';
		selid = '';
		selname = '';
	}
	seltype = type;
	idUpper = false;
	userGroup = false;
}
function groupList(id, name, type){
	idAll=id;
	selid = id;
	selname = name;
	seltype = type;
	idUpper = false;
	userGroup = false;
}

function modSelect() {
	var height = screen.height; 
	var width = screen.width; 
	var leftpos = width / 2 - 235; 
	var toppos = height / 2 - 235; 

	if(seltype != "group"){
		alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.groupSelect")%>');
		return;
	}

	var urlname = "/totsys/common/web/report_dept/modifier.jsp?groupID="+selid;
	//post2= window.open(urlname, "post2","width=275, height=465, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + leftpos + ",top=" + toppos);
    post2= window.open(urlname, "post2","width=450, height=465, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + leftpos + ",top=" + toppos);
	post2.focus(); 
}

function deptComp(){
	if(document.group.groupName.value == null || document.group.groupName.value == ""){
		alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.groupName")%>');
		document.group.groupName.focus();
	}else if(document.list.idList.value=="")
	{
		alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.deptComp")%>');
		return;
	}
	else{

		document.group.deptIDs.value = document.list.idList.value;
		document.group.deptNames.value = document.list.nameList.value;
		document.group.deptTypes.value = document.list.typeList.value;

		var deptTemp = document.list.idList.value.split(",");
		var deptCounter = deptTemp.length;
		
		document.group.submit();
	}
}

function deptCancel(){
	window.close();
}

function openerdeptConfirm(){ //구성원으로 추가
		var gid = document.list.openeridList.value;
		var gname = document.list.openernameList.value;
		var gtype = document.list.openertypeList.value;

		var arrayID = gid.split(",");
		var arrayName = gname.split(",");
		var arrayType = gtype.split(",");

		var isChange = false;

		for(var i=0; i < arrayID.length; i++){
			selid = arrayID[i];
			selname = arrayName[i];
			seltype = arrayType[i];

			if(selid == '' ){
				alert("<%=Moumi.getMessageBundle().getString("moumi.message.popup.deptConfirm")%>");
			}else{
				id = selid;
				name = selname;
				type = seltype;
				if(	idList == '' ){
					document.list.idList.value = idList = id;
					idList=idList+"";
					document.list.typeList.value = typeList = type;
					typeList=typeList+"";

				}else{
					var isAdd = listAdd(idList, id, typeList, type);
					document.list.idList.value = idList;
					document.list.typeList.value = typeList;
				}

				isChange = true;
			}

		}

		if(isChange){
			document.list.submit();
		}
	}
</script>
</HEAD>

<BODY>
<form name="list" method="post"
	action="/servlet/kr.co.kihyun.beans.user.HttpDeptList"
	target="deptFrame"><input type="hidden" name="idList"> <input
	type="hidden" name="nameList"> <input type="hidden"
	name="typeList"><input type="hidden" name="openeridList">
<input type="hidden" name="openernameList"> <input type="hidden"
	name="openertypeList"></form>
	<!--//타이틀 -->
	<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
          <td bgcolor="728ab5" style="padding: 10 20 5 20"><strong><font color="#FFFFFF">제출기관지정</font></strong></td>
  </tr></table>
  <!--타이틀 //-->
  <!-- //본문 -->
<table border="0" cellspacing="0" cellpadding="0">
	<!-- 제목 -->
	<tr>
		<td colspan="3">
		 <table width="100%" height="26" border="0" cellpadding="0" cellspacing="0" style="padding-top:10px ; padding-bottom:10px">
              <tr> 
                <td width="300"><img src="/totsys/common/images/ico_3.gif"  border="0" align="absmiddle">&nbsp;<b><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.deptMap")%></b></td>
                <td  align="left" width="100" ></td>
                <td width="470"><img src="/totsys/common/images/ico_3.gif"  border="0" align="absmiddle">&nbsp;<b><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.submitDept")%></b></td>
              </tr>
            </table>
		
		
		</td>
	</tr>

	<!-- 분류,부서 선택 -->
	<tr>
		<td width="300"><!-- 분류 선택 아이프레임 -->
		<table border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td><iframe src="iframe/new_section_list.html" width="135"
					height="21" frameborder="0" scrolling="no"> </iframe></td>
			</tr>
		</table>
		<!-- 부서 선택 아이프레임 -->
		<table border="1px" class="kecttep_tdmenu" bordercolor="#e3e3e3"
			width="300" cellpadding="0" cellspacing="0">
			<tr>
				<td><iframe name="leftFrame" src="./iframe/group_list.jsp"
					width="300" height="329" frameborder="0"></iframe></td>
			</tr>
<!--			<tr>
				<td align="left" style="padding: 2px 3px;">
				<form name="searchForm" onsubmit="javascript: return false;">
				<table border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td style="font-size: 12px; font-family: 돋움, serif;"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.search")%>:</td>
						<td><input name="keyword" size="20" class="inputtxt"
							onkeydown="ProcKeyDown();" /></td>
						<td><a id="previousButton" class="simplebutton" href="#"
							onclick="previous();"
							onfocus="focusedButton = document.getElementById('previousButton');"
							onblur="focusedButton = null;"><span class="previous"><%=Moumi.getMessageBundle().getString("moumi.message.button_small.previous")%></span></a></td>
						<td><a id="nextButton" class="simplebutton" href="#"
							onclick="next();"
							onfocus="focusedButton = document.getElementById('nextButton');"
							onblur="focusedButton = null;"><span class="next"><%=Moumi.getMessageBundle().getString("moumi.message.button_small.next")%></span></a></td>
					</tr>
				</table>
				</form>
				</td>
			</tr>-->
		</table>
		</td>

		<!-- 추가,삭제 -->
		<td align="center">
		<table border="0" cellspacing="0" cellpadding="0" width="50">
			<!--추가-->
			<tr>
				<td height="35" style="padding-left: 10px; padding-right: 10px"><a
					href="javascript:deptConfirm();"><img
					src="./images/new_dept_add.gif"></a></td>
			</tr>
			<!--삭제-->
			<tr>
				<td height="35" style="padding-left: 10px; padding-right: 10px"><a
					href="javascript:deptDelete();"><img
					src="./images/new_dept_del.gif"></a></td>
			</tr>
			<!--구성원--/>
					<tr>
						<td style="padding-left:10px; padding-right:10px">
							<A href="javascript:modSelect();" border="0"><img src="./images/new_modifier.gif"></a>
						</td>
					</tr>
					-->
		</table>
		</td>

		<!-- 선택 된 아이프레임 -->
		<td width="470" style="padding-top: 20px;">
		<table border="1px" class="kecttep_tdmenu" bordercolor="#e3e3e3"
			width="470" cellpadding="0" cellspacing="0">
			<tr>
				<td><iframe name="deptFrame" src="./iframe/selected_list.jsp"
					width="470" height="330" frameborder="0"></iframe></td>
			</tr>
		</table>
		</td>
	</tr>

	<tr style="padding-top: 20px;">
		<td colspan="3">
		<form name="group" method="post"
			action="/servlet/kr.co.kihyun.beans.user.HttpUserGroup"><input
			type="hidden" name="deptIDs"> <input type="hidden"
			name="deptNames"> <input type="hidden" name="userIDs">
		<input type="hidden" name="userNames"> <input type="hidden"
			name="deptTypes"> <input type="hidden" name="userID"
			value="<%=usID%>">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
			<tr>
				<td style="width: 14"><img src="./images/ico_1.gif"></td>
				<td class="kecttep_title" style="padding-left: 5" align="left"
					width="355"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.group")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.name")%>
				: <input name="groupName" type="text" value='' size="30"
					maxlength="20" class="inputtxt"></td>
				<td style="width: 14" style="padding-left:13">&nbsp;</td>
				<td class="kecttep_title" style="padding-left: 5" align="left">&nbsp;</td>
			</tr>
			<tr>
				<td height="3"></td>
			</tr>
		</table>
		</form>
		</td>
	</tr>
</table>


<!-- 확인, 취소 버튼 -->
<table border=0 cellspacing=0 cellpadding=0 width="100%">
	<tr style="padding-top: 5px">
		<td align="center">
		<table width="200" border="0" cellpadding="0" cellspacing="0">
			<tr align="center">
				<td width="100"><a href="#" onclick="deptComp()"><img
					src="images/bt_enter.gif"></a></td>
				<td width="100"><a href="#" onClick="deptCancel()"><img
					src="images/bt_cancle3.gif"></a></td>
			</tr>
		</table>
		</td>
	</tr>
</table>
<!-- //본문 -->
</BODY>
</HTML>
