<%@ page language="java" contentType="text/html; charset=utf-8"%>

<%@page import="com.eactive.eai.rms.common.datasource.DataSourceType"%>
<%@page import="com.eactive.eai.rms.common.datasource.DataSourceTypeManager"%>
<%@page import="com.eactive.eai.common.util.SystemUtil"%>
<%@page import="com.eactive.eai.rms.env.EmsConfig"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/include/localemessage.jsp" %>
<c:set var="themeColor" value="<%=System.getProperty(\"theme.color\")%>" scope="session" />

<%
	String sysMode = (String)System.getProperty("eai.systemmode");
	String sysModeName = "";
	/* System.out.println("##### SERVER_TYPE ====>"+sysMode); */
	if( sysMode == null ) {
		sysMode = "";
	}
	if (sysMode.equals("T")) {
		sysModeName = "테스트";
	} else if (sysMode.equals("D")){
		sysModeName = "개발";
	}else {
		sysModeName = "";
	}

	String systemModeTitle = SystemUtil.getSystemModeTitle();
	String drmode = System.getProperty(EmsConfig.DR_MODE);
	if ("Y".equals(drmode)) {
		systemModeTitle = "[DR] ";
	}
%>

<%
	String resultMsg = (String)session.getAttribute("resultMsg");
	session.removeAttribute("resultMsg");
	session.removeAttribute("SSO_ID");
	request.removeAttribute("SSO_ID");


	if( resultMsg == null ) {
		resultMsg = "";
	}
%>

<script src="js/jquery-1.12.1.min.js"></script>
<!-- <script src="js/popper.js"></script> -->
<script src="js/bootstrap.min.js"></script>

<link rel="stylesheet" href="css/login-style.css">
<link rel="stylesheet" href="css/login-fontawesome_all.css">

<html>
<head>
	<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
	<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
	<META HTTP-EQUIV="Cache-control" CONTENT="no-cache">
	<link rel="icon"
		  href="<c:url value="/img/ic_eai_favi_${themeColor}.png"/>"
		  type="image/ico" sizes="16x16" />
	<title><%=systemModeTitle%><%=localeMessage.getString("screen.title")%></title>
	<%-- <jsp:include page="/jsp/common/include/css.jsp"/> --%>
	<jsp:include page="/jsp/common/include/script.jsp"/>
	<script type="text/javascript">
		if( self.name == 'mainFrame' || self.name == 'leftFrame' || self.name == 'topFrame') {
			parent.window.location.href='<c:url value="/"/>';
		}

		function fncPreMain() {
			if ($("input[name=userId]").val() ==null || $("input[name=userId]").val().length == 0 ){
				alert("<%= localeMessage.getString("login.checkid") %>");
				$("input[name=userId]").trigger("focus");
				return;
			}
			if ($("input[name=password]").val() ==null || $("input[name=password]").val().length == 0 ){
				alert("<%= localeMessage.getString("login.checkpwd1") %>");
				$("input[name=password]").trigger("focus");
				return;
			}
			if ($("select[name=serviceType]").val() ==null|| $("select[name=serviceType]").val().length == 0 ){
				alert("<%= localeMessage.getString("login.checkservicetype") %>");
				$("select[name=serviceType]").trigger("focus");
				return;
			}
			sessionStorage["serviceType"]= $("select[name=serviceType]").val();
			$("#loginForm").submit();
		}
		function changePwd(){
			if ($("input[name=userId]").val() == null || $("input[name=userId]").val().length == 0 ){
				alert("<%= localeMessage.getString("login.checkid") %>");
				$("input[name=userId]").trigger("focus");
				return;
			}
			if ($("input[name=password]").val() == null || $("input[name=password]").val().trim().length == 0 ){
				alert("<%= localeMessage.getString("login.checkpwd1") %>");
				$("input[name=password]").trigger("focus");
				return;
			}
			if ($("input[name=password]").length == 0){
				alert("<%= localeMessage.getString("login.checkpwd2") %>");
				return ;
			}
			if ($("input[name=changePassword]").length == 0){
				alert("<%= localeMessage.getString("login.checkpwd3") %>");
				return ;
			}
			if ($("input[name=confirmPassword]").val() != $("input[name=changePassword]").val()){
				alert("<%= localeMessage.getString("login.checkpwd4") %>");
				return ;
			}
			if ($("input[name=userId]").val() == $("input[name=changePassword]").val()){
				alert("<%= localeMessage.getString("login.checkpwd5") %>");
				return ;
			}

			//if (idCheck.checked){
			//		setCookie("key",id);
			//}
			<%--   $("form").attr("action","<c:url value="/changePassword.do"/>");
              //$("form").action = "<%=request.getContextPath()%>/changePassword.do";
              --%>
			$("form").submit();
		}

		function openPwdChgWindow() {
			
			<%
				if(sysMode.equals("T") || sysMode.equals("D")) {
			%>			
			    windowOpen("http://ssodev.kbankwithu.com:7010", "PopupWindow", 1024, 768);			    
			<%
				} else {
			%>    
			    windowOpen("https://ssoap.kbankwithu.com/nls3/clientLogin.jsp", "PopupWindow", 1024, 768);
			<%
				}
			%>			
		}
		
		$(document).ready(function() {
			$("input[name=userId]").keydown(function(event){
				if ( event.which == 13 ) {
					fncPreMain();
				}
			});
			$("input[name=password]").keydown(function(event){
				if ( event.which == 13 ) {
					fncPreMain();
				}
			});
			$("input[name=changePassword]").keydown(function(event){
				if ( event.which == 13 ) {
					changePwd();
				}
			});
			$("input[name=confirmPassword]").keydown(function(event){
				if ( event.which == 13 ) {
					changePwd();
				}
			});
			$("select[name=serviceType]").change(function(){
				fncPreMain();
			});

			$("#btn_login").click(function(){
				fncPreMain();
			});
			$("#changePwd").click(function(){
				changePwd();
			});


		});
	</script>
</head>
<body>

<div class="container mt-5">
	<div class="row justify-content-left mb-3">
		<div class="col-md-12 text-center">
			<img style="width: 20%;opacity: 0.4;" src='<c:url value="/img/logo_eactive.png"/>'/>
		</div>
	</div>
	<div class="row justify-content-center">
		<div class="col-md-8 text-center">
			<h1 style="vertical-align: middle !important" class="h1"><span class="text-danger">e</span><span class="text-info">Link Monitoring Admin</span></h1>
		</div>
	</div>
	<div class="row justify-content-center">
		<div class="col-md-7 col-lg-5">
			<div class="login-wrap p-4 p-md-5">
				<div class="icon text-danger d-flex align-items-center justify-content-center">
					<img style="width: 40px;" src='<c:url value="/img/login/user.png"/>'/>
				</div>
				<h3 class="text-center mb-4">Log In</h3>
				<form name="form" id="loginForm" action="<c:url value="/login.do"/>" method="post">
					<div class="form-group">
						<input type="text" name="userId" class="form-control rounded-left" placeholder="Id" required>
					</div>
					<div class="form-group d-flex">
						<input type="password" name="password" class="form-control rounded-left" placeholder="Password" required>
					</div>
					<div class="form-group">
						<select  name="serviceType" class="form-control rounded-left" placeholder="system" required>
							<%
								for (DataSourceType dt : DataSourceTypeManager.getDynamicDataSourceTypes()){
							%>
							<option value="<%=dt.getName()%>"><%=dt.getText()%></option>
							<%
								}
							%>
						</select>
					</div>
					<div class="form-group">
						<input type="button" id ="btn_login" class="form-control btn btn-primary rounded submit px-3" value="Login">
					</div>
					<div style="text-align: right !important;" class="form-group">
						<a style="font-size: 12px !important;" href="#pwdChgSsoModal" onclick="openPwdChgWindow()" >Password Change</a>
						 <!-- <a style="font-size: 12px !important;" href="#pwdChgModal" data-toggle="modal" >Password Change</a> -->
					</div>
					<p style="color:red;"><%=resultMsg %></p>
				</form>
			</div>
		</div>
	</div>
</div>


<%-- <div class="modal fade" id="pwdChgModal" tabindex="-1" role="dialog" aria-labelledby="pwdChgModalLabel" aria-hidden="true">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="pwdChgModalLabel">Password 설정</h5>
				<button class="close" type="button" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">X</span>
				</button>
			</div>
			<form name="form" id="modalLoginForm" action="<c:url value="/changePassword.do"/>" method="post">
				<div class="modal-body">
					<div class="form-group d-flex">
						<input type="text" name="userId" class="form-control rounded-left" placeholder="User Id" required>
					</div>
					<div class="form-group d-flex">
						<input type="password" name="password" class="form-control rounded-left" placeholder="<%= localeMessage.getString("login.placeholderCurrentPassword") %>" required>
					</div>
					<p><%= localeMessage.getString("login.toChangePasswordMessage") %></p>
					<div class="form-group d-flex">
						<input type="password" name="changePassword" class="form-control rounded-left" placeholder="<%= localeMessage.getString("login.placeholderChangePassword") %>" required>
					</div>
					<div class="form-group d-flex">
						<input type="password" name="confirmPassword" class="form-control rounded-left" placeholder="<%= localeMessage.getString("login.placeholderConfirmationPassword") %>" required>
					</div>
				</div>
				<div class="modal-footer">
					<input type="button" id ="changePwd" class="form-control btn btn-primary rounded submit px-3" value="변경">
				</div>
			</form>
		</div>
	</div>
</div> --%>
</body>

</html>

