<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="${data._INCLUDE}/header.jsp"></jsp:include>
<script src="https://t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
<script>
$( function(){
    $( "#newForm" ).validate({
        rules: {
            centerName : {
                minlength : 2,
                maxlength : 100
            },
            staffId: {
                minlength : 4,
                maxlength : 20,
                idValid :  true,
                remote : { 
                    type : "POST",
                    url  : "/staff/duplicateIdCheck",
                    data : { 
                        staffId : function(){
                            return $( "input[name='staffId']" ).val();
                        }
                    }
                }
            },
            centerNumber : {
                phoneValid : true
            },
            staffPhoneNumber : {
                phoneValid : true
            },
            staffPw : {
                minlength : 8,
                maxlength : 15,
                passwordValid : true
            },
            staffPwConfirm : {
                equalTo: "#staffPw",
            },
            totalCapacity :{
                number:true
            },
            totalStaff :{
                number:true
            }
        },
        messages : {
            staffId : {
                remote : "이미 존재하는 아이디입니다"
            },
            staffPw : {
                minlength : "비밀번호를 확인하세요 (영문, 숫자, 특수문자를 혼합하여 8 ~ 15자 이내)",
                maxlength : "비밀번호를 확인하세요 (영문, 숫자, 특수문자를 혼합하여 8 ~ 15자 이내)"
            },
            staffPwConfirm : {
                equalTo: "비밀번호가 일치하지 않습니다.",
            }
        },
        onkeyup: function( element, event ) {
            $( element ).valid();
        },
        onfocusout: function (element) {
            $( element ).val( $.trim( $( element ).val() ) );
            $( element ).valid();
        },
        submitHandler: function(form) {
            $("#mainAddr").removeAttr("disabled");
            form.submit();
        }
    });
})
</script>
</head>
<body>
    <div class="wrapper">
        <jsp:include page="${data._INCLUDE}/sidebar.jsp"></jsp:include>
        
        <div class="main">
            <jsp:include page="${data._INCLUDE}/top.jsp"></jsp:include>

            <main class="content">
                <div class="container-fluid p-0">
                    <!-- 환자관리 : 신규환자 등록 START -->
                    <div class="row">
                        <div class="col-12 col-lg-6">
                            <h1 class="h3 mb-3">
                            생활치료센터 신규등록
                            </h1>
                        </div>
                        <div class="col-12 col-lg-6  text-right">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="javscript:;">Home</a></li>
                                    <li class="breadcrumb-item">생활치료센터 관리</li>
                                    <li class="breadcrumb-item active">생활치료센터 신규</li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12">
                            <div class="card">
                                <form action="./new/regist" method="post" id="newForm">
                                    <div class="card-body">
                                        <table class="table mobile-table">
                                            <colgroup>
                                                <col style="width:15%">
                                                <col style="width:35%">
                                                <col style="width:15%">
                                                <col style="width:35%">
                                            </colgroup>
                                            <tr>
                                                <th><span class="fix">*</span>생활치료센터명</th>
                                                <td>
                                                    <input type="text" class="form-control" name="centerName" required>
                                                </td>
                                                <th><span class="fix">*</span>지역</th>
                                                <td>
                                                    <select class="custom-select" name="locationCode">
                                                        <c:forEach var="i" items="${locationList}">
                                                            <option value="${i.locationCode}"><c:out value="${i.locationName}"/></option>
                                                        </c:forEach>
                                                    <!-- <option>1</option>
                                                    <option>2</option>
                                                    <option>3</option>
                                                    <option>4</option>
                                                    <option>5</option>
                                                    <option>6</option>
                                                    <option>7</option> -->
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <th><span class="fix">*</span>주소</th>
                                                <td colspan="3">
                                                    <div class="form-row">
                                                        <div class="col-lg-10"><input type="text" class="form-control" disabled id="mainAddr" name="centerAddress" required></div>
                                                        <div class="col-lg-2"><span class="btn btn-primary w100" onclick="juso();">주소찾기</span></div>
                                                        <div class="col-lg-10"><input type="text" class="form-control mt8" id="detailAddr" name="detailAddr" placeholder="상세주소" required></div>
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <th><span class="fix">*</span>전화번호</th>
                                                <td colspan="3">
                                                    <input type="text" class="form-control" name="centerNumber" placeholder="'-'를 제외한 숫자만 입력하세요" required onkeypress="onlyNumber()">
                                                </td>
                                            </tr>
                                            <tr>
                                                <th><span class="fix">*</span>수용인원(명)</th>
                                                <td>
                                                    <input type="text" class="form-control" name="totalCapacity" required>
                                                </td>
                                                <th><span class="fix">*</span>의료진수 (명)</th>
                                                <td>
                                                    <input type="text" class="form-control" name="totalStaff" required>
                                                </td>
                                            </tr>
                                            <tr>
                                                <th><span class="fix">*</span>담당자 아이디</th>
                                                <td>
                                                    <input type="text" class="form-control" name="staffId" autocomplete="off" maxlength="20" required>
                                                </td>
                                                <th><span class="fix">*</span>담당자 이름</th>
                                                <td>
                                                    <input type="text" class="form-control" name="staffName" required>
                                                </td>
                                            </tr>
                                            <tr>
                                                <th><span class="fix">*</span>담당자 전화번호</th>
                                                <td colspan="3">
                                                    <input type="text" class="form-control" name="staffPhoneNumber"  placeholder="'-'를 제외한 숫자만 입력하세요" required onkeypress="onlyNumber();">
                                                </td>
                                            </tr>
                                            <tr>
                                                <th><span class="fix">*</span>비밀번호</th>
                                                <td colspan="3">
                                                    <input type="password" class="form-control" name="staffPw" id="staffPw" placeholder="숫자, 영문, 특수문자 조합 8~15자 이내" maxlength="15" required>
                                                </td>
                                            </tr>
                                            <tr>
                                                <th><span class="fix">*</span>비밀번호 확인</th>
                                                <td colspan="3">
                                                    <input type="password" class="form-control" name="staffPwConfirm"  placeholder="비밀번호 확인을 위해 비밀번호를 한번 더 입력하세요." maxlength="15" required>
                                                </td>
                                            </tr>
                                        </table>
                                        <div class="row mt-3">
                                            <div class="col-12">
                                                <div class="text-right">
                                                    <button type="button" class="btn btn-outline-primary w100" onclick="history.back();">취소</button>
                                                    <button type="submit" class="btn btn-primary w100">등록</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <!-- 환자관리 : 신규환자 등록 END -->
                </div>
            </main>

            <jsp:include page="${data._INCLUDE}/footer.jsp"></jsp:include>
        </div>
    </div>
</body>
</html>