<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<link rel="stylesheet" href="/publish/css/mem.css">

<script src="/publish/js/content.js"></script>
<script src="/js/RSA/rsa.js"></script>
<script src="/js/RSA/jsbn.js"></script>
<script src="/js/RSA/prng4.js"></script>
<script src="/js/RSA/rng.js"></script>

<script type="text/javascript">

  $(document).ready(function () {
    getId(document.loginForm2);

    <c:if test="${headerLoginResult ne 'N'}">
      headerLoginResult("<c:out value='${headerLoginResult}'/>");
    </c:if>
  });

  function getId(form) {
    if (getCookie("ncms_saveid") !== "") {
      form.checkId.checked = (form.id_text2.value = getCookie("ncms_saveid"));
    }
  }

  function showCredentials() {
    $("#credentials_frame").show();
    $("#verification_frame").hide();
  }

  function showVerification() {
    $("#subText").show();
    $("#badge").show();
    $("#credentials_frame").hide();
    $("#verification_frame").show();
  }

  function setEncrypted() {
    const id = $("#id_text2").val();
    const password = $("#password_text2").val();

    const rsa = new RSAKey();
    rsa.setPublic($("#RSAModulus2").val(), $("#RSAExponent2").val());

    document.loginForm2.id.value = rsa.encrypt(id.toLowerCase());
    document.loginForm2.password.value = rsa.encrypt(password);
  }

  function headerLoginResult(headerLoginResult) {
    if (headerLoginResult === 'secure') {
      const userId = $("#userId").val();

      document.loginForm2.id_text2.value = "<c:out value='${id_secure}'/>";
      document.loginForm2.password_text2.value = "<c:out value='${pw_secure}'/>";
      setEncrypted();
      showVerification();
      callMemberCertPhoneList(userId);
    } else {
      showCredentials();
      showCredentialsError(headerLoginResult);
	  if (headerLoginResult.indexOf("5회 이상 로그인에 실패") === 0) {
		$("#credentials_frame .mem_btn5")
			.prop("disabled", true)
			.addClass("disabled");
	  }
    }
  }

</script>

<div class="inner">
  <form:form id="loginForm2" name="loginForm2" method="post">

    <input type="hidden" name="beforeUrl" value="<c:out value='/web/user/login/login.do'/>"/>
    <input type="hidden" name="userSe" value="USR"/>

    <input type="hidden" id="RSAModulus2" value="${RSAModulus}"/>
    <input type="hidden" id="RSAExponent2" value="${RSAExponent}"/>

    <input type="hidden" id="id" name="id"/>
    <input type="hidden" id="password" name="password"/>

    <input type="hidden" name="goEventPay" value="${goEventPay}"/>

    <input type="hidden" id="hp" name="hp"/>
    <input type="hidden" id="num" name="num"/>
    <input type="hidden" id="msgId" name="msgId"/>


    <div class="send_top">
      <div class="mypage_content current">
        <div class="heading">
          <h2>로그인</h2>
        </div>

        <div class="mem_cont_in widthS login_wrap security_login">
          <div class="input_list">
            <p class="welcome">
              <span>문자온</span>에 오신것을 환영합니다.<br>
              <span class="c_222 fwMd">로그인</span>해주세요.
              <span id="subText" class="sub_text" style="display:none;">
                안전한 서비스 이용을 위해 등록된 휴대폰번호로 인증을 진행해주세요.
              </span>
            </p>
            <div id="badge" class="badge yellow" style="display:none;">
              <i>!</i>
              보안 강화를 위해&nbsp;모든 계정에 2차 인증(보안로그인)이 상시 적용됩니다.
            </div>
            <%@ include file="include/credentials.jspf" %>
            <%@ include file="include/verification.jspf" %>
          </div>
        </div>

      </div>
    </div>

  </form:form>

	<form name="kmcPhoneResetForm" method="post" action="#">
		<input type="hidden" name="tr_cert" value=""/>
		<input type="hidden" name="tr_url" value=""/>
		<input type="hidden" name="tr_add" value="N"/>
		<input type="hidden" name="tr_ver" value="V2"/>
	</form>


  <%-- SMS 인증번호 발송용 --%>
  <form name="checkForm"
        id="checkForm"
        method="post"
        action="#">

    <input type="hidden" name="searchNm" value=""/>
    <input type="hidden" id="userId" name="userId" value="${id_secure}"/>
    <input type="hidden" name="callTo" value=""/>
    <input type="hidden" name="receive" value=""/>
	<input type="hidden" name="securityLogin" value="Y"/>

  </form>


  <%-- 기업회원 처리용 --%>
  <form name="cmpChangeForm"
        id="cmpChangeForm"
        method="post"
        action="#">

    <input type="hidden" name="mberId" value=""/>

  </form>

</div>
