<%
/**
 * <pre>
 * @Class Name : initPasswordForm.jsp
 * 
 * @Description : 비밀번호 초기화
 * 
 * 
 * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
 *
 * </pre>
 *
 * @ ------------    --------    ---------------------------
 * @ 수정일                     수정자             수정내용
 * @ ------------    --------    ---------------------------
 * @ 2021. 7. 12.    JSYOO       최초 생성
 *
 * 
 * @author 이씨플라자 * DIGITALSHIP JSYOO
 * @since 2021. 7. 12.
 * @version 1.0
 *
 */
 %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script>
$(document).ready(function() {
	var previousPage ="${loginVO.previousPage}";
	if(previousPage == "alreadySignUpPopup")
	{
		document.getElementById("cancle").setAttribute("onClick", "fn_cancle()");
	}else
	{
		document.getElementById("cancle").setAttribute("onClick", "fn_closeLayerPopup()");
	}
		
});
function goFindPw(){
    
    var data = $("form[name=initPw]").serialize();
    var regExp = /^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$/i;
    if($("#initPw [name=email]").val() == "")
   	{
    	$("#initPw [name=email]").focus();
     	alert("이메일을 입력해주세요.");
        return false;     	
   	}
    if(!regExp.test($("#initPw [name=email]").val()))
   	{
    	$("#initPw [name=email]").focus();
     	alert("이메일을 다시 확인해주세요. (예: example@mail.com)");
     	return false;
   	}
    	$.ajax({
            url : "${pageContext.request.contextPath}/member/initPassword.ajax",
            type : "POST",
            data : data,
            success : function(result){
                if(result == "success")
               	{
                	alert("입력하신 이메일로 임시 비밀번호가 발송되었습니다. 메일을 확인해주세요.");
                	var previousPage ="${loginVO.previousPage}";
                    if(previousPage == "alreadySignUpPopup")
                    {
                        document.initPw.action="${pageContext.request.contextPath}/member/selectAlreadySignUpMobilePopup.do";
                        fn_layerPopFormSubmit("initPw",false);
                    }else{
                    	fn_closeLayerPopup();
                    }
                    
               	}
                else if(result == "fail")
               	{
	               alert("일치하는 정보가 없습니다. 다시 확인해주세요.");
               	}
                
                },error : function(){
                alert("이메일 발송에 실패하였습니다.");
            }
        })
    
}
function fn_cancle()
{
    document.initPw.action="${pageContext.request.contextPath}/member/selectAlreadySignUpMobilePopup.do";
    fn_layerPopFormSubmit("initPw",false);
}
</script>
</head>
<body>
<form id="initPw" name="initPw" method="post">
    <input type="hidden" id="mbInfoId" name="mbInfoId" value="${loginVO.mbInfoId }">
    <input type="hidden" id="nameTemp" name="nameTemp" value="${loginVO.nameTemp }">
    <input type="hidden" id="emailTemp" name="emailTemp" value="${loginVO.emailTemp }">
    <input type="hidden" id="mobileNo" name="mobileNo" value="${loginVO.mobileNo }">
    <input type="hidden" id="previousPage" name="previousPage" value="${loginVO.previousPage}">
    <div class="pop-find">
        <div class="row Title">
            <p>내 정보</p>
            <h3>비밀번호 찾기</h3>
        </div>
        <div class="inner">
            <div class="row Text">
                <p>이메일 정보가 확인되면 해당 메일로<br><span>임시비밀번호</span>를 보내드립니다.</p>
            </div>
            <div class="row find">
                <p><input type="text" name="email" placeholder="example@mail.com" class="find-input" onKeypress="javascript:if(event.keyCode==13) {goFindPw();}"/></p>
                <p class="text">-  임시 비밀번호가 발급된 후 [마이페이지 &gt; 회원정보관리 &gt; 내 정보]에서 비밀번호를 수정해주세요.</p>
            </div>
            <div class="row btn-box">
                <button type="button" class="btn btn-color" onclick="goFindPw();">확인</button>
                <button type="button" class="btn btn-gray close" id="cancle">취소</button> 
            </div>
            <button type="button" class="find-close" onclick="fn_closeLayerPopup();"></button>
        </div>
        <div class="Bg"></div>
    </div>
</form>
</body>
</html>