<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" session="true" %>
<%@ page import="kcg.faics.sec.LoginUserVO"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<% 
	LoginUserVO userVO = (LoginUserVO) session.getAttribute("userVO");
%>
<script type="text/javaScript" defer="defer">
	$(document).ready(function(){
		$.ajaxSetup({
			cache: false
		});
		
		$(window).resize(function(){
			var modalBack = $('#modalBack');
				modalBack.css({
					'width' : $(window).outerWidth(),
					'height' : $(window).outerHeight()
				});
		});
		
		// ContextMenu 방지 코드
		$(document).contextmenu(function(){
			return false;
		});
		
		// FancyBox 기본 설정
		$.extend($.fancybox.defaults, {
		    closeClick: true
		});
		
		// Jquery 달력 기본 설정
		$.datepicker.setDefaults({
			dateFormat: "yy-mm-dd",
			changeMonth: true,
			changeYear: true
		})
	});
	
	function showPwMenu(){
		$('#pwMenu').show();
		
		var modalBack = $('#modalBack');
		if (modalBack.length == 0) {
			modalBack = $('<div>')
			.show()
			.attr('id', 'modalBack')
			.css({
				//'background-color' : 'rgba(0,0,0 ,0.5)',
				'display' : 'none',
				'position' : 'absolute',
				'width' : $(window).outerWidth(),
				'height' : $(window).outerHeight(),
				'overflow' : 'hidden',
				'top' : '0px'
			});
			$('body').append(modalBack);
		}
		modalBack.show();
		
		
	}
	function hidePwMenu(){
		$('#pwMenu').hide();
		$('#modalBack').hide();
	}
	
	/* pagination 페이지 링크 function */
	function fn_changePw() {
		var form = document.forms['pwForm'];
		var npasswd = form.npasswd.value;
		var num = npasswd.search(/[0-9]/g);
		var eng = npasswd.search(/[a-z]/ig);
		var spe = npasswd.search(/['~!@@#$%^&*|₩₩₩'₩";:₩/?]/gi);
		if (form.checkPwd.value == 'N') {
			alert('변경 비밀번호가 일치하지 않습니다.');
			return false;
		}else if((npasswd.length < 8) || (npasswd.length > 20) || (num <0) || (eng < 0) || (spe < 0)){
			alert("8~20자 영문, 숫자, 특수문자를 사용하세요.");
			return false;
		} else {
			$.ajax({
				'url': '/member/changePw.json',
				'type': 'post',
				'data': $(form).serialize(),
				'dataType': 'json', 
				'success': function(result){
					if (result.match == false) {
						alert('현재 비밀번호가 일치하지 않습니다.');
					} else if (result.result != '1') {
						alert('에러가 발생하였습니다. 다시 시도하세요.');
					} else {
						alert('비밀번호가 변경되었습니다.');
						form.passwd.value = "";
						form.npasswd.value = "";
						form.re_npasswd.value = "";
						hidePwMenu();
					}
				}
			});
		}
	}
	
	var Member = {
			checkPWD : function(_str){
				var form = document.forms['pwForm'];
				var passwd = form.npasswd.value;
				if(passwd == _str){
					$('#pwd_desc').html("<spring:message code="member.msg.match"/>");
					$('#pwd_desc').css('color', '#00f');
					form.checkPwd.value = 'Y'; 
				}else{
					$('#pwd_desc').html("<spring:message code="member.msg.dismatch"/>");
					$('#pwd_desc').css('color', '#f00');
					form.checkPwd.value = 'N'; 
				}
			}
		}
</script>

<c:if test="${not empty userVO}">
	<div class="header_user">		
		<div class="top-gnb">		
			<ul id="menu1">
			<c:forEach items="${topSubMenuList}" var="item">
				<li><a href="<c:url value="${item.uri}" />" target="${item.windowTarget}"><c:out value="${item.name}" /></a></li>
			</c:forEach>
				<%-- <c:if test="${userVO.isAdmin == true}">
				<li><a href="/admin/faMemberList.do"><spring:message code="menu.admin" /></a></li>
				</c:if>
				<li><a class="title_menu" href="/admin/faMemberCmmnList.do"><spring:message code="menu.member" /></a></li>
				<li><a href="/admin/faMemberCmmnList.do">*<spring:message code="menu.member.common" /></a></li>
				<li><a href="/fa/memberManagePersonnel.do">*<spring:message code="menu.member.manage" /></a></li>
				<li><a href="/fa/exmemberList.do">*<spring:message code="menu.admin.exmember" /></a></li>
				<li><a href="/bbs/list.do?id=notice"><spring:message code="menu.notice" /></a></li>
				<li><a href="/bbs/list.do?id=bbs"><spring:message code="menu.bbs" /></a></li>
				<li><a href="#manual"><spring:message code="menu.manual" /></a></li>
				<li><a href="/sitemap.do"><spring:message code="menu.sitemap" /></a></li>
				<li><a href="/qna.do" target="_blank"><spring:message code="menu.qna" /></a></li> --%>
			</ul>
			<ul class="gnb-menu-right">
				<li class="logout"><a href="<c:url value='/j_spring_security_logout'/>"><spring:message code="login.msg.logout" /></a></li>
				<li><span>[<c:out value="${userVO.name}" /><spring:message code="login.msg.nim" /> <spring:message code="login.msg.welcom" /> ]</span></li>				
				<li><a href="javascript:showPwMenu();">비밀번호 변경</a></li>
				<c:if test="${userVO.type eq 2}">
					<li><a href="/member/cmmnView.do">회원정보</a></li>
				</c:if>
			</ul>
		</div>
	</div>
	
	<div class="logo">
		<h1><a href="<spring:message code="Url.MPSS" />" target="_blank"><img src="/images/new/mpss_01.jpg" alt="국민안전처"></a></h1>		
		<h1><a href="/"><img src="/images/cmmn/kcg.png" alt="사이버외사정보시스템"></a></h1>
	</div>
	
	<div id="menu2" class="header-gnb">
		<ul class="gnb-menu">
		<c:forEach items="${mainMenuList}" var="main">
			<li>
				<a href="#" style="cursor:default;"><c:out value="${main.name}" /></a>
				<div class="submenu">
					<ul>
            <c:choose>
              <c:when test="${fn:length(main.subMenu) > 0}">
                <c:forEach items="${main.subMenu}" var="sub">
                  <li><a href="<c:url value="${sub.uri}" />"><c:out value="${sub.name}" /></a></li>
                </c:forEach>
              </c:when>
              <c:otherwise>
                  <li><a href="<c:url value="${main.uri}" />"><c:out value="${main.name}" /></a></li>
              </c:otherwise>
            </c:choose>
					</ul>
				</div>				
			</li>	
		</c:forEach>
		<!-- 추가 -->
			<li>
				<a href="#" style="cursor:default;" title="국제해양정보시스템">국제해양정보</a>
				<div class="submenu" style="display: none;">
					<ul>
						<li><a href="#" title="국제해양정보시스템" onclick="submitFrmSSO();">국제해양정보</a></li>
					</ul>
				</div>
			</li>
		</ul>	
		<div class="all-menu">
			<a href="#" class="all-menu-view all-view-hiden"><img src="/images/cmmn/all-btn.png" alt="전체메뉴 보기" title="<spring:message code="menu.togglebtn.descript" />"></a>
		</div>
		<div id="menuBg" class="submenu_bg submenubg on"></div>				
	</div>
	
	<script type="text/javascript">
	//네비게이션
	    $(document).ready(function () {
	    	$(".all-menu").click(function () {
	            $(".submenu, #menuBg").toggle();
	            
	            $(".gnb-menu").mouseleave(function () {
	                $(".submenu, #menuBg").show();
	            });
	        });
	        $(".gnb-menu").mouseenter(function () {
	            $(".submenu, #menuBg").show();
	        });
	        $(".gnb-menu").mouseleave(function () {
	            $(".submenu, #menuBg").hide();
	        });
	    });   
	</script>		
	
	<div id="pwMenu">	
		<div class="dimBg"></div>
		<div class="mini_window" id="mini_window_ModifyWindow">  
			<div class="password-pop">
				<h3>비밀번호 변경</h3>
				<form name="pwForm">
				<input name=checkPwd type="hidden" value="N">
				<table class="tbl_add border-style">
					<tr>
						<th>아이디</th>
						<td><c:out value="${userVO.userid}" /></td>
					</tr>
					<tr>
						<th>현재 비밀번호</th>
						<td class="w-256"><input name="passwd" type="password" value=""></td>
					</tr>
					<tr>
						<th>변경 비밀번호</th>
						<td class="w-256"><input name="npasswd" type="password" value="">	  </td>
					</tr>
					<tr>
						<th>변경 비밀번호 확인</th>
						<td class="w-256"><input name="re_npasswd" onkeyup="Member.checkPWD(this.value)" type="password" value="">	</td>
					</tr>
					<tr>
						<td colspan="2">8~20자 영문, 숫자, 특수문자를 사용하세요.</th>
					</tr>							
				</table>
				</form>
				<div class="boardviewinfo">
					<ul class="right btn-style">
		   			   	<li>
		   			   		<a href="javascript:fn_changePw();"><spring:message code="button.modify" /></a>
			            </li>
			   			<li>
			   				<a href="javascript:hidePwMenu();"><spring:message code="button.changeLater" /></a>
			            </li>
			   			<li>
			   				<a href="javascript:hidePwMenu();"><spring:message code="button.close" /></a>
			            </li>
					</ul>	
				</div>
		  	</div>
		</div>
	</div>
</c:if>
<!-- //상단메뉴 -->

<%-- 
		<ul>
			<li><a href="/bbs/list.do?id=fa_info_rpt">1외사정보 보고</a></li>
			<li><a href="/bbs/list.do?id=fa_arrest_rpt">2외사수사</a></li>
			<li><a href="#fa_info_report">3외사사범검거보고</a></li>
			<li><a href="/susa/incident/list.do">4내사사건 현황</a></li>
			<li><a href="/susa/promot/list.do">5공작 추진현황</a></li>
			<li><a href="/bbs/list.do?id=fa_target">6외사대상목표</a></li>
			<li><a href="/equip/status.do">7외사장비</a></li>
			<li><a href="/equip/status.do">8외사장비현황</a></li>
			<li><a href="/equip/useStateList.do">9사용실적</a></li>
			<li><a href="/equip/cyberEquipList.do">10사이버 외사장비</a></li>
			<li><a href="/bbs/list.do?id=data">11자료실</a></li>
	
			<!-- left menu -->
			<li><a class="title_menu" href="/report/myList.do">12<spring:message code="menu.report" /></a></li>
			<li><a class="sub_menu" href="/report/add.do">13<spring:message code="menu.report.write" /></a></li>
			<!-- 외사경찰 -->
			<li><a class="sub_menu" href="/report/waitList.do">14 <spring:message code="menu.report.list" /></a></li>
			<!-- /외사경찰 -->
			<!-- 일반경찰 -->
				<!-- 
				<li>
					<a class="sub_menu" href="/report/report_wait_list">* 실적조회</a>
				</li>
				-->
			<!-- /일반경찰 -->
			<!-- auth_search -->
			<li><a class="sub_menu" href="/report/search.do">15<spring:message code="menu.report.search" /></a></li>
			<!-- /auth_search -->
			<!-- auth_statistics -->
			<li><a class="sub_menu" href="/report/statistics.do">16 <spring:message code="menu.report.statistics" /></a></li>
			<!-- /auth_statistics -->
			<!-- auth_manage or 관리자 -->
			<li><a class="sub_menu" href="/report/presentList.do">17 <spring:message code="menu.report.manage" /></a></li>
			<!-- /auth_manage or 관리자 -->
			<li><a class="title_menu" href="/stats/fs/board_list?id=stat_bbs">18<spring:message code="menu.stat" /></a></li>
			<li><a class="title_menu" href="/admin/faMemberCmmnList.do">19<spring:message code="menu.member" /></a></li>
			<li>
				<a class="sub_menu" href="/admin/faMemberCmmnList.do">20 <spring:message code="menu.member.common" /></a>
			</li>
			<li>
				<a class="sub_menu" href="/fa/memberManagePersonnel.do">21<spring:message code="menu.member.manage" /></a>
			</li>
			<!-- 관리자 전용 -->
			<li>
				<a class="sub_menu" href="/fa/exmemberList.do">22 <spring:message code="menu.admin.exmember" /></a>
			</li>
			<!-- /관리자 전용 -->
			<!-- /외사경찰 -->
			<!-- 외국어선 단속시스템 -->
			<!-- 외사경찰에게는 관리자만, 일반경찰은 그냥 보임 -->
			<li><a class="title_menu" href="/bbs/list.do?id=guard_info&category=arrest">23<spring:message code="menu.guard_info" /></a></li>
			<li>
				<a class="sub_menu" href="/bbs/list.do?id=guard_info&category=arrest">24 <spring:message code="menu.guard_info.arrest" /></a>
			</li>
			<li>
				<a class="sub_menu" href="/bbs/list.do?id=guard_info&category=info">25<spring:message code="menu.guard_info.stat" /></a>
			</li>
			<li>
				<a class="sub_menu" href="/bbs/list.do?id=guard_info&category=info">2 <spring:message code="menu.guard_info.info" /></a>
			</li>
			<!-- 일반경찰 전용 
			<li>
				<a class="sub_menu" href="/bbs/board_list?id=guard_info&category=data">* 자료실</a>
			</li>
			 일반경찰 전용 -->
		</ul>	
		<!-- /외사경찰에게는 관리자만, 일반경찰은 그냥 보임 -->
		<!-- /외국어선 단속시스템 --> --%>


