<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$skin_url.'/style.css" media="screen">', 0);

if ($w == "" && isset($_POST['mb_id']) && $_POST['mb_id']) {
    $member['mb_id'] = $_POST['mb_id'];
    $readonly = "readonly";
}

if($header_skin)
	include_once('./header.php');

?>
<script src="<?php echo G5_JS_URL ?>/jquery.register_form.js"></script>
<script>var g5_captcha_url  = "<?php echo G5_CAPTCHA_URL; ?>";</script>
<script src="<?php echo G5_CAPTCHA_URL; ?>/kcaptcha.js"></script>
<?php if($config['cf_cert_use'] && ($config['cf_cert_ipin'] || $config['cf_cert_hp'])) { ?>
    <script src="<?php echo G5_JS_URL ?>/certify.js?v=<?php echo APMS_SVER; ?>"></script>
<?php } ?>

<form class="form-horizontal register-form" role="form" id="fregisterform" name="fregisterform" action="<?php echo $action_url ?>" onsubmit="return fregisterform_submit(this);" method="post" enctype="multipart/form-data" autocomplete="off">
	<input type="hidden" name="w" value="<?php echo $w ?>">
	<input type="hidden" name="url" value="<?php echo $urlencode ?>">
	<input type="hidden" name="pim" value="<?php echo $pim;?>">
    <?php if ($w == "") { ?>
    <div class="panel panel-default">
        <div class="panel-heading"><strong><i class="fa fa-check-square-o fa-lg"></i> 이용약관 및 개인정보처리방침안내</strong></div>
        <div class="panel-body">

			<div class="alert alert-info" style="margin-bottom:0; padding:10px 12px;">
				 <label style="font-weight:bold; font-size:1.05em; margin:0; cursor:pointer; display:block;">
					<input type="checkbox" id="chk_all" checked style="width:16px; height:16px; vertical-align:middle; margin:0 5px 0 0;"> <span style="vertical-align:middle;">전체 약관에 동의합니다.</span>
				 </label>
				 <div style="margin-top:4px; font-size:12px; color:#31708f;">
					이용약관 및 개인정보처리방침 동의를 포함합니다.
				 </div>
				 <div style="margin-top:8px; text-align:right;">
					<button type="button" id="btn_toggle_agreement_cards" class="btn btn-xs btn-default" data-toggle="collapse" data-target="#agreement_detail_cards" aria-expanded="false" aria-controls="agreement_detail_cards">
						약관 상세 보기 <i class="fa fa-chevron-down"></i>
					</button>
				 </div>
			</div>

			<div id="agreement_detail_cards" class="collapse" style="margin-top:10px;">
				<div style="margin-bottom:10px; border:1px solid #ddd; padding:10px; border-radius:4px; background:#fff;">
					<div style="margin-bottom:0;">
						<label style="font-weight:bold; cursor:pointer;" class="pull-left">
							<input type="checkbox" name="agree" value="1" id="agree11" class="agree_chk" checked style="width:16px; height:16px; vertical-align:middle; margin:0 5px 0 0;"> <span style="vertical-align:middle;">회원가입약관의 내용에 동의합니다.</span>
						</label>
						<button type="button" class="btn btn-xs btn-default pull-right" data-toggle="collapse" data-target="#provision_box" aria-expanded="false" aria-controls="provision_box">
							내용보기 <i class="fa fa-chevron-down"></i>
						</button>
						<div class="clearfix"></div>
					</div>
					<div id="provision_box" class="collapse" style="margin-top:10px; border-top:1px solid #eee; padding-top:10px;">
						<div style="height:180px; overflow:auto; padding:10px; background:#f9f9f9; font-size:12px;">
							<?php echo $provision; ?>
						</div>
					</div>
				</div>

				<div style="border:1px solid #ddd; padding:10px; border-radius:4px; background:#fff;">
					<div style="margin-bottom:0;">
						<label style="font-weight:bold; cursor:pointer;" class="pull-left">
							<input type="checkbox" name="agree2" value="1" id="agree21" class="agree_chk" checked style="width:16px; height:16px; vertical-align:middle; margin:0 5px 0 0;"> <span style="vertical-align:middle;">개인정보처리방침안내의 내용에 동의합니다.</span>
						</label>
						<button type="button" class="btn btn-xs btn-default pull-right" data-toggle="collapse" data-target="#privacy_box" aria-expanded="false" aria-controls="privacy_box">
							 내용보기 <i class="fa fa-chevron-down"></i>
						</button>
						 <div class="clearfix"></div>
					</div>
					<div id="privacy_box" class="collapse" style="margin-top:10px; border-top:1px solid #eee; padding-top:10px;">
						 <div style="height:180px; overflow:auto; padding:10px; background:#f9f9f9; font-size:12px;">
							<?php echo $privacy; ?>
						</div>
					</div>
				</div>
			</div>

        </div>
    </div>
    <script>
    $(function() {
        $("#chk_all").click(function() {
            if($(this).is(":checked")) {
                $(".agree_chk").prop("checked", true);
            } else {
                $(".agree_chk").prop("checked", false);
            }
        });
        $(".agree_chk").click(function() {
             if($(".agree_chk:checked").length == $(".agree_chk").length) {
                $("#chk_all").prop("checked", true);
            } else {
                $("#chk_all").prop("checked", false);
            }
        });

		// Toggle icon on collapse
        $('#provision_box, #privacy_box').on('show.bs.collapse', function () {
            $(this).parent().find(".fa-chevron-down").removeClass("fa-chevron-down").addClass("fa-chevron-up");
        }).on('hide.bs.collapse', function () {
            $(this).parent().find(".fa-chevron-up").removeClass("fa-chevron-up").addClass("fa-chevron-down");
        });

		// 약관 상세 카드 토글 버튼 아이콘/문구
		$('#agreement_detail_cards').on('show.bs.collapse', function () {
			$('#btn_toggle_agreement_cards').html('약관 상세 숨기기 <i class="fa fa-chevron-up"></i>');
		}).on('hide.bs.collapse', function () {
			$('#btn_toggle_agreement_cards').html('약관 상세 보기 <i class="fa fa-chevron-down"></i>');
		});
    });
    </script>
    <?php } else { ?>
	    <input type="hidden" name="agree" value="1">
	    <input type="hidden" name="agree2" value="1">
    <?php } ?>
	<input type="hidden" name="cert_type" value="<?php echo $member['mb_certify']; ?>">
	<input type="hidden" name="cert_no" value="">
	<?php if (isset($member['mb_sex'])) {  ?><input type="hidden" name="mb_sex" value="<?php echo $member['mb_sex'] ?>"><?php }  ?>
	<?php /* if (isset($member['mb_nick_date']) && $member['mb_nick_date'] > date("Y-m-d", G5_SERVER_TIME - ($config['cf_nick_modify'] * 86400))) { // 닉네임수정일이 지나지 않았다면  ?>
		<input type="hidden" name="mb_nick_default" value="<?php echo get_text($member['mb_nick']) ?>">
		<input type="hidden" name="mb_nick" value="<?php echo get_text($member['mb_nick']) ?>">
	<?php } */ ?>

	<div class="panel panel-default">
		<div class="panel-heading"><strong><i class="fa fa-star fa-lg"></i> 사이트 이용정보 입력</strong></div>
		<div class="panel-body">
		<?php
		// 안드로이드 앱에서 전달된 아이디 처리
		$is_android_app = false;
		$android_id = '';
		if ($w == '' && !empty($_POST['mb_id']) && strpos($_POST['mb_id'], 'VpNgueSt') === 0) {
			$is_android_app = true;
			$android_id = substr($_POST['mb_id'], 8); // 'VpNgueSt' 제거
			$member['mb_id'] = $android_id;
		}
		?>
			<div class="form-group has-feedback text-gap">
				<label class="col-sm-2 control-label" for="reg_mb_id"><b>아이디</b><strong class="sound_only">필수</strong><span class="text-primary small"> (필수)</span></label>
				<div class="col-sm-3">
				<input type="text" name="mb_id" value="<?php echo $member['mb_id'] ?>" id="reg_mb_id" <?php echo $required ?> <?php echo $readonly ?> class="form-control input-sm" minlength="3" maxLength="32" title="아이디" <?php echo $is_android_app ? 'readonly' : ''; ?>>
					<span class="fa fa-check form-control-feedback"></span>
				</div>
			<?php if ($w == '' && !$readonly && !$is_android_app) { ?>
			<div class="col-sm-2">
			<button type="button" id="btn_regenerate_id" class="btn btn-default btn-sm" onclick="regenerateId()" style="margin-top:0px;">
				<i class="fa fa-refresh"></i> 자동 생성
				</button>
				<input type="hidden" name="is_android_app" value="0">
			</div>
			<?php } else if ($is_android_app) { ?>
				<input type="hidden" name="is_android_app" value="1">
				<input type="hidden" name="android_original_id" value="<?php echo $_POST['mb_id']; ?>">
			<?php } ?>
		</div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-8 text-muted">
				<div id="msg_mb_id"></div>
				<?php if ($w == '' && !$is_android_app) { ?>
				<span id="id_info_msg"><i class="fa fa-info-circle"></i> '자동 생성' 버튼을 눌러 아이디를 생성하거나 직접 입력하세요.</span>
				<?php } else if (!$is_android_app) { ?>
				영문자, 숫자, _ 만 입력 가능. 최소 3자이상 입력하세요.
				<?php } ?>
			</div>
		</div>

		<div class="form-group has-feedback text-gap">
			<label class="col-sm-2 control-label" for="reg_mb_email"><b>E-mail</b><strong class="sound_only">필수</strong><span class="text-primary small"> (필수)</span></label>
			<div class="col-sm-3">
				<input type="hidden" name="old_email" value="<?php echo $member['mb_email'] ?>">
			<input type="text" name="mb_email" value="<?php echo isset($member['mb_email'])?$member['mb_email']:''; ?>" id="reg_mb_email" required class="form-control input-sm email" maxlength="100" title="E-mail" autocomplete="off" <?php echo ($w=='u') ? 'readonly' : ''; ?>>
				<span class="fa fa-envelope form-control-feedback"></span>
			</div>
			<div class="col-sm-4">
				<div id="msg_mb_email"></div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-8 text-muted">
				<?php if ($config['cf_use_email_certify']) {  ?>
					<?php if ($w=='') { echo '<span class="text-info-email"><i class="fa fa-info-circle"></i> E-mail 로 발송된 내용을 확인한 후 인증하셔야 회원가입이 완료됩니다.</span>'; }  ?>
					<?php if ($w=='u') { echo '<span class="text-info-email"><i class="fa fa-info-circle"></i> E-mail 주소를 변경하시면 다시 인증하셔야 합니다.</span>'; }  ?>
				<?php }  ?>
			</div>
		</div>

			<div class="form-group has-feedback text-gap">
				<label class="col-sm-2 control-label" for="reg_mb_password"><b>비밀번호</b><strong class="sound_only">필수</strong><?php if ($w == '') { ?><span class="text-primary small"> (필수)</span><?php } ?></label>
				<div class="col-sm-3">
				<input type="password" name="mb_password" id="reg_mb_password" <?php echo $required ?> class="form-control input-sm" minlength="3" maxLength="32" autocomplete="new-password">
				<span class="fa fa-lock form-control-feedback"></span>
				<div class="h15 hidden-lg hidden-md hidden-sm"></div>
			</div>
			<label class="col-sm-2 control-label" for="reg_mb_password_re"><b>비밀번호 확인</b><strong class="sound_only">필수</strong><?php if ($w == '') { ?><span class="text-primary small"> (필수)</span><?php } ?></label>
			<div class="col-sm-3">
				<input type="password" name="mb_password_re" id="reg_mb_password_re" <?php echo $required ?> class="form-control input-sm" minlength="3" maxLength="32" autocomplete="new-password">
					<span class="fa fa-check form-control-feedback"></span>
				</div>
			</div>
            <?php if ($w == 'u') { ?>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-8 text-muted">
                    <i class="fa fa-info-circle"></i> 비밀번호를 변경하지 않으려면 빈 칸으로 두세요.
                </div>
            </div>
            <?php } ?>
		</div>
	</div>

	<div class="panel panel-default">
		<div class="panel-heading"><strong><i class="fa fa-user fa-lg"></i> 개인정보 입력</strong></div>
		<div class="panel-body">
		<?php
		// 초기값 설정 (회원가입 시에는 공백으로 시작)
		if ($w == '' && !$is_android_app) {
			// 페이지 로드 시 아이디, 이름, 닉네임, 이메일은 공백으로 시작
			if (empty($member['mb_id'])) {
				$member['mb_id'] = '';
			}
			if (empty($member['mb_name'])) {
				$member['mb_name'] = '';
			}
			if (empty($member['mb_nick'])) {
				$member['mb_nick'] = '';
			}
			// E-mail도 항상 빈 상태로 시작
			$member['mb_email'] = '';
		}
		?>
			<div class="form-group has-feedback text-gap">
				<label class="col-sm-2 control-label" for="reg_mb_name"><b>이름</b><strong class="sound_only">필수</strong><span class="text-primary small"> (필수)</span></label>
				<div class="col-sm-3">
					<!-- Name Field -->
					<input type="text" id="reg_mb_name" name="mb_name" value="<?php echo get_text($member['mb_name']); ?>" required <?php echo $required ?> class="form-control input-sm" size="10">
					<span class="fa fa-check form-control-feedback"></span>
				</div>
				<?php if ($w == '') { ?>
				<div class="col-sm-2">
					<button type="button" id="btn_regenerate_name" class="btn btn-default btn-sm" onclick="regenerateName()" style="margin-top:0px;">
						<i class="fa fa-refresh"></i> 자동 생성
					</button>
				</div>
				<?php } ?>
			</div>
			<?php if ($w == '') { ?>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-8 text-muted">
					<span id="name_info_msg"><i class="fa fa-info-circle"></i> '자동 생성' 버튼을 눌러 이름을 생성하거나 직접 입력하세요.</span>
				</div>
			</div>
			<?php } ?>

			<?php // if ($req_nick) { ?>
				<div class="form-group has-feedback text-gap">
					<label class="col-sm-2 control-label" for="reg_mb_nick"><b>닉네임</b><span class="text-muted small"> (선택)</span></label>
					<div class="col-sm-3">
						<input type="hidden" name="mb_nick_default" value="<?php echo isset($member['mb_nick']) ? get_text($member['mb_nick']) : ''; ?>">
						<input type="text" name="mb_nick" value="<?php echo isset($member['mb_nick']) ? get_text($member['mb_nick']) : ''; ?>" id="reg_mb_nick" class="form-control input-sm nospace" size="10" maxLength="32" title="닉네임">
						<span class="fa fa-user form-control-feedback"></span>
					</div>
					<?php if ($w == '') { ?>
					<div class="col-sm-2">
						<button type="button" id="btn_regenerate_nick" class="btn btn-default btn-sm" onclick="regenerateNick()" style="margin-top:0px;">
							<i class="fa fa-refresh"></i> 자동 생성
						</button>
					</div>
					<?php } ?>
				</div>
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-8 text-muted">
						<div id="msg_mb_nick"></div>
						<?php if ($w == '') { ?>
						<span id="nick_info_msg"><i class="fa fa-info-circle"></i> '자동 생성' 버튼을 눌러 닉네임을 생성하거나 직접 입력하세요.</span>
						<?php } else { ?>
						공백없이 한글,영문,숫자만 입력 가능 (한글2자, 영문4자 이상)<br>
						<span style="color:#e65100;font-size:0.88em;">&#9888; 변경 후 기존 닉네임은 본인을 포함해 누구도 다시 사용할 수 없습니다. 신중히 결정해 주세요.</span>
						<?php } ?>
						<!-- NICK_POLICY_WARNING_PATCHED -->
					</div>
				</div>
			<?php // } ?>

			<?php if ($config['cf_use_homepage']) {  ?>
				<div class="form-group has-feedback">
					<label class="col-sm-2 control-label" for="reg_mb_homepage"><b>홈페이지</b><?php if ($config['cf_req_homepage']){ ?><strong class="sound_only">필수</strong><span class="text-primary small"> (필수)</span><?php } else { ?><span class="text-muted small"> (선택)</span><?php } ?></label>
					<div class="col-sm-5">
						<input type="text" name="mb_homepage" value="<?php echo get_text($member['mb_homepage']) ?>" id="reg_mb_homepage" <?php echo $config['cf_req_homepage']?"required":""; ?> class="form-control input-sm" size="70" maxlength="255">
						<span class="fa fa-home form-control-feedback"></span>
					</div>
				</div>
			<?php }  ?>

			<?php if ($config['cf_use_tel']) {  ?>
				<div class="form-group has-feedback">
					<label class="col-sm-2 control-label" for="reg_mb_tel"><b>전화번호</b><?php if ($config['cf_req_tel']) { ?><strong class="sound_only">필수</strong><span class="text-primary small"> (필수)</span><?php } else { ?><span class="text-muted small"> (선택)</span><?php } ?></label>
					<div class="col-sm-3">
						<input type="text" name="mb_tel" value="<?php echo get_text($member['mb_tel']) ?>" id="reg_mb_tel" <?php echo $config['cf_req_tel']?"required":""; ?> class="form-control input-sm" maxLength="32">
						<span class="fa fa-phone form-control-feedback"></span>
					</div>
				</div>
			<?php }  ?>

			<?php if ($w == 'u' && ($config['cf_use_hp'] || $config['cf_cert_hp'])) {  ?>
				<div class="form-group has-feedback">
					<label class="col-sm-2 control-label" for="reg_mb_hp"><b>휴대폰번호</b><?php if ($config['cf_req_hp']) { ?><strong class="sound_only">필수</strong><span class="text-primary small"> (필수)</span><?php } else { ?><span class="text-muted small"> (선택)</span><?php } ?></label>
					<div class="col-sm-5">
                        <div style="display: flex;">
                            <select name="mb_hp_nation" id="reg_mb_hp_nation" class="form-control input-sm" style="flex: 0 0 170px; margin-right: 5px; padding-right: 5px;">
                                <option value="">- 국가 선택 -</option>
                                <?php
                                global $countries, $country_local_names;
                                if(isset($countries) && is_array($countries)) {
                                    $user_nation = (isset($member['mb_hp_nation']) && $member['mb_hp_nation']) ? $member['mb_hp_nation'] : 'KOREA';
                                    foreach ($countries as $country => $code) {
                                        $selected = (strtolower($user_nation) == strtolower($country)) ? ' selected' : '';
                                        $display_name = $country;
                                        if (isset($country_local_names[$country])) {
                                            $display_name = $country . ' (' . $country_local_names[$country] . ')';
                                        }
                                        echo "<option value=\"$country\"$selected>$display_name ($code)</option>";
                                    }
                                }
                                ?>
                            </select>
                            <div style="position: relative; flex: 1;">
                                <input type="text" name="mb_hp" value="<?php echo get_text($member['mb_hp']) ?>" id="reg_mb_hp" <?php echo ($config['cf_req_hp'])?"required":""; ?> class="form-control input-sm" maxLength="32" style="width: 100%;">
                                <span class="fa fa-mobile form-control-feedback" style="top: 0; right: 0; height: 30px; line-height: 30px;"></span>
                            </div>
                        </div>
						<?php if ($config['cf_cert_use'] && $config['cf_cert_hp']) { ?>
							<input type="hidden" name="old_mb_hp" value="<?php echo get_text($member['mb_hp']) ?>">
						<?php } ?>
					</div>
				</div>
			<?php }  ?>

			<?php if ($w == 'u') { ?>
			<div class="form-group has-feedback">
				<label class="col-sm-2 control-label" for="reg_mb_sns_name"><b>메신저</b><span class="text-muted small"> (선택)</span></label>
				<div class="col-sm-5">
					<div style="display: flex;">
                        <input type="hidden" name="mb_sns_name_default" value="<?php echo isset($member['mb_sns_name']) ? get_text($member['mb_sns_name']) : ''; ?>">
						<select name="mb_sns_name" id="reg_mb_sns_name" class="form-control input-sm" style="flex: 0 0 170px; margin-right: 5px; padding-right: 5px;">
							<option value="">- 메신저 선택 -</option>
							<?php
                             if(isset($snslist) && is_array($snslist)) {
                                foreach ($snslist as $key => $val) {
                                    $selected = ($member['mb_sns_name'] == $key) ? 'selected' : '';
                                    echo '<option value="'.$key.'" '.$selected.'>'.$val.'</option>';
                                }
                            }
							?>
                            <option value="Other" <?php echo ($member['mb_sns_name'] == 'Other') ? 'selected' : ''; ?>>기타</option>
						</select>
                        <div style="position: relative; flex: 1;">
						    <input type="text" name="mb_sns_id" value="<?php echo isset($member['mb_sns_id']) ? get_text($member['mb_sns_id']) : ''; ?>" id="reg_mb_sns_id" class="form-control input-sm" placeholder="메신저 ID" maxlength="32" style="width: 100%;">
						    <span class="fa fa-comment form-control-feedback" style="top: 0; right: 0; height: 30px; line-height: 30px;"></span>
                        </div>
					</div>
				</div>
			</div>
			<?php } ?>

			<?php if ($config['cf_use_addr']) { ?>
				<div class="form-group has-feedback">
					<label class="col-sm-2 control-label"><b>주소</b><?php if ($config['cf_req_addr']) { ?><strong class="sound_only">필수</strong><span class="text-primary small"> (필수)</span><?php } else { ?><span class="text-muted small"> (선택)</span><?php } ?></label>
					<div class="col-sm-8">
						<label for="reg_mb_zip" class="sound_only">우편번호<?php echo $config['cf_req_addr']?'<strong class="sound_only"> 필수</strong>':''; ?></label>
						<label>
						<input type="text" name="mb_zip" value="<?php echo $member['mb_zip1'].$member['mb_zip2'] ?>" id="reg_mb_zip" <?php echo $config['cf_req_addr']?"required":""; ?> class="form-control input-sm" size="6" maxlength="6">
						</label>
						<label>
			                <button type="button" class="btn btn-black btn-sm win_zip_find" style="margin-top:0px;" onclick="win_zip('fregisterform', 'mb_zip', 'mb_addr1', 'mb_addr2', 'mb_addr3', 'mb_addr_jibeon');">주소 검색</button>
						</label>

						<div class="addr-line">
							<label class="sound_only" for="reg_mb_addr1">기본주소<?php echo $config['cf_req_addr']?'<strong class="sound_only"> 필수</strong>':''; ?></label>
							<input type="text" name="mb_addr1" value="<?php echo get_text($member['mb_addr1']) ?>" id="reg_mb_addr1" <?php echo $config['cf_req_addr']?"required":""; ?> class="form-control input-sm" size="50" placeholder="기본주소">
						</div>

						<div class="addr-line">
							<label class="sound_only" for="reg_mb_addr2">상세주소</label>
							<input type="text" name="mb_addr2" value="<?php echo get_text($member['mb_addr2']) ?>" id="reg_mb_addr2" class="form-control input-sm" size="50" placeholder="상세주소">
						</div>

						<label class="sound_only" for="reg_mb_addr3">참고항목</label>
						<input type="text" name="mb_addr3" value="<?php echo get_text($member['mb_addr3']) ?>" id="reg_mb_addr3" class="form-control input-sm" size="50" readonly="readonly" placeholder="참고항목">
						<input type="hidden" name="mb_addr_jibeon" value="<?php echo get_text($member['mb_addr_jibeon']); ?>">
					</div>
				</div>
			<?php }  ?>

		</div>
	</div>

	<div class="panel panel-default">
		<div class="panel-heading"><strong><i class="fa fa-cog fa-lg"></i> 기타 개인설정</strong></div>
		<div class="panel-body other-settings-visibility-scope">
			<style>
			.other-settings-visibility-scope > * { display: none; }
			.other-settings-visibility-scope > .other-settings-captcha-only { display: block; }
			</style>

			<?php if ($config['cf_use_signature']) {  ?>
				<div class="form-group">
					<label class="col-sm-2 control-label" for="reg_mb_signature"><b>서명</b><?php if ($config['cf_req_signature']){ ?><strong class="sound_only">필수</strong><?php } ?></label>
					<div class="col-sm-8">
						<textarea name="mb_signature" rows=5 id="reg_mb_signature" <?php echo $config['cf_req_signature']?"required":""; ?> class="form-control input-sm"><?php echo $member['mb_signature'] ?></textarea>
					</div>
				</div>
			<?php }  ?>

			<?php if ($config['cf_use_profile']) {  ?>
				<div class="form-group">
					<label class="col-sm-2 control-label" for="reg_mb_profile"><b>자기소개</b><?php if ($config['cf_req_profile']){ ?><strong class="sound_only">필수</strong><?php } ?></label>
					<div class="col-sm-8">
						<textarea name="mb_profile" rows=5 id="reg_mb_profile" <?php echo $config['cf_req_profile']?"required":""; ?> class="form-control input-sm"><?php echo $member['mb_profile'] ?></textarea>
					</div>
				</div>
			<?php }  ?>

			<?php if ($config['cf_use_member_icon'] && $member['mb_level'] >= $config['cf_icon_level']) {  ?>
				<div class="form-group">
					<label class="col-sm-2 control-label" for="reg_mb_profile"><b>회원아이콘</b></label>
					<div class="col-sm-8">
						<input type="file" name="mb_icon" id="reg_mb_icon">
						<?php if ($w == 'u' && file_exists($mb_icon_path)) {  ?>
							<label for="del_mb_icon" class="checkbox-inline">
								<img src="<?php echo $mb_icon_url ?>" alt="회원아이콘">
								<input type="checkbox" name="del_mb_icon" value="1" id="del_mb_icon"> 삭제
							</label>
						<?php }  ?>
						<span class="help-block">
							아이콘 크기는 가로 <?php echo $config['cf_member_icon_width'] ?>픽셀, 세로 <?php echo $config['cf_member_icon_height'] ?>픽셀 이하로 해주세요.
							gif, jpg, png만 가능하며 용량 <?php echo number_format($config['cf_member_icon_size']) ?>바이트 이하만 등록됩니다.
						</span>
					</div>
				</div>
			<?php }  ?>

            <?php if ($member['mb_level'] >= $config['cf_icon_level'] && $config['cf_member_img_size'] && $config['cf_member_img_width'] && $config['cf_member_img_height']) {  ?>
				<div class="form-group">
					<label class="col-sm-2 control-label" for="reg_mb_img"><b>회원이미지</b></label>
					<div class="col-sm-8">
		                <input type="file" name="mb_img" id="reg_mb_img" >
						<?php if ($w == 'u' && file_exists($mb_img_path)) {  ?>
						<img src="<?php echo $mb_img_url ?>" alt="회원이미지">
						<input type="checkbox" name="del_mb_img" value="1" id="del_mb_img">
						<label for="del_mb_img">삭제</label>
						<?php }  ?>
						<span class="help-block">
		                    이미지 크기는 가로 <?php echo $config['cf_member_img_width'] ?>픽셀, 세로 <?php echo $config['cf_member_img_height'] ?>픽셀 이하로 해주세요.
				            gif, jpg, png파일만 가능하며 용량 <?php echo number_format($config['cf_member_img_size']) ?>바이트 이하만 등록됩니다.
						</span>
					</div>
				</div>
			<?php }  ?>

			<?php
			//회원정보 수정인 경우 소셜 계정 출력
			if($config['cf_social_login_use'] && $w == 'u' && function_exists('social_member_provider_manage') ){
				social_member_provider_manage();
			}
			?>

			<div class="form-group">
				<label class="col-sm-2 control-label" for="reg_mb_mailling"><b>메일링서비스</b></label>
				<div class="col-sm-8">
					<div class="checkbox">
						<label>
							<input type="checkbox" name="mb_mailling" value="1" id="reg_mb_mailling" <?php echo ($w=='' || $member['mb_mailling'])?'checked':''; ?>>
							정보 메일을 받겠습니다.
						</label>
					</div>
					<div class="text-muted" style="font-size:12px; margin-top:5px; padding-left:20px;">
						<p style="margin:0;"><i class="fa fa-info-circle"></i> 사이트 공지사항, 이벤트, 프로모션 등의 정보를 이메일로 받습니다.</p>
						<p style="margin:0;">※ 회원가입 인증, 비밀번호 찾기 등 필수 메일은 체크 해제 시에도 발송됩니다.</p>
					</div>
				</div>
			</div>

			<?php if ($config['cf_use_hp']) {  ?>
				<div class="form-group">
					<label class="col-sm-2 control-label" for="reg_mb_sms"><b>SMS 수신여부</b></label>
					<div class="col-sm-8">
						<div class="checkbox">
							<label>
								<input type="checkbox" name="mb_sms" value="1" id="reg_mb_sms" <?php echo ($w=='' || $member['mb_sms'])?'checked':''; ?>>
								휴대폰 문자메시지를 받겠습니다.
							</label>
						</div>
					</div>
				</div>
			<?php }  ?>

			<?php if (isset($member['mb_open_date']) && $member['mb_open_date'] <= date("Y-m-d", G5_SERVER_TIME - ($config['cf_open_modify'] * 86400)) || empty($member['mb_open_date'])) { // 정보공개 수정일이 지났다면 수정가능  ?>
				<div class="form-group">
					<label class="col-sm-2 control-label" for="reg_mb_open"><b>정보공개</b></label>
					<div class="col-sm-8">
						<div class="checkbox">
							<label>
								<input type="hidden" name="mb_open_default" value="<?php echo $member['mb_open'] ?>">
								<input type="checkbox" name="mb_open" value="1" <?php echo ($member['mb_open'])?'checked':''; ?> id="reg_mb_open">
								다른분들이 나의 정보를 볼 수 있도록 합니다.
							</label>
						</div>
						<div class="text-muted" style="font-size:12px; margin-top:5px; padding-left:20px;">
							<p style="margin:0;"><i class="fa fa-info-circle"></i> 다른 회원이 나의 프로필 정보를 볼 수 있으며, 쪽지를 주고받을 수 있습니다.</p>
							<p style="margin:0;">※ 정보공개를 해제하시면 다른 회원으로부터 쪽지를 받을 수 없습니다.</p>
							<p style="margin:0;">※ 정보공개를 바꾸시면 앞으로 <?php echo (int)$config['cf_open_modify'] ?>일 이내에는 변경이 안됩니다.</p>
						</div>
					</div>
				</div>
			<?php } else {  ?>
				<div class="form-group">
					<label class="col-sm-2 control-label"><b>정보공개</b></label>
					<div class="col-sm-8">
						<div class="alert alert-warning" style="margin-bottom:0;">
							정보공개는 수정후 <?php echo (int)$config['cf_open_modify'] ?>일 이내, <?php echo date("Y년 m월 j일", isset($member['mb_open_date']) ? strtotime("{$member['mb_open_date']} 00:00:00")+$config['cf_open_modify']*86400:G5_SERVER_TIME+$config['cf_open_modify']*86400); ?> 까지는 변경이 안됩니다.<br>
							이렇게 하는 이유는 잦은 정보공개 수정으로 인하여 쪽지를 보낸 후 받지 않는 경우를 막기 위해서 입니다.
						</div>
						<input type="hidden" name="mb_open" value="<?php echo $member['mb_open'] ?>">
					</div>
				</div>
			<?php } ?>

			<?php if ($w == "" && $config['cf_use_recommend']) {  ?>
				<div class="form-group has-feedback">
					<label class="col-sm-2 control-label" for="reg_mb_recommend"><b>추천인아이디</b></label>
					<div class="col-sm-3">
						<input type="text" name="mb_recommend" id="reg_mb_recommend" class="form-control input-sm">
						<span class="fa fa-user form-control-feedback"></span>
					</div>
				</div>
			<?php }  ?>

			<div class="form-group other-settings-captcha-only">
				<label class="col-sm-2 control-label"><b>자동등록방지</b></label>
				<div class="col-sm-8">
					<style>
					.captcha_wrap { display: table; width: 100%; table-layout: fixed; }
					.captcha_cell { display: table-cell; vertical-align: middle; }
					.captcha_cell.img_cell { width: 45%; padding-right: 10px; }
					.captcha_cell.inp_cell { width: 55%; padding-left: 10px; }
					@media (max-width: 767px) {
						.captcha_wrap { display: block; }
						.captcha_cell { display: block; width: 100% !important; padding: 0 !important; }
						.captcha_cell.img_cell { margin-bottom: 10px; text-align: center; }
						.captcha_cell.img_cell img { max-width: 200px !important; display: inline-block; }
					}
					</style>

					<div style="background:#f9f9f9; padding:10px; border:1px solid #ddd; border-radius:4px;">
						<div class="captcha_wrap">
							<div class="captcha_cell img_cell">
								<img src="<?php echo G5_CAPTCHA_URL; ?>/img/dot.gif" alt="자동등록방지" id="captcha_img" class="img-responsive" style="width:100%; border:1px solid #ccc; border-radius:4px; max-width:180px;">
							</div>
							<div class="captcha_cell inp_cell">
								<div class="input-group">
									<input type="text" name="captcha_key" id="captcha_key" required class="form-control" placeholder="숫자 입력" style="text-align:center; letter-spacing:2px;">
									<span class="input-group-btn">
										<button type="button" id="captcha_reload" class="btn btn-default" title="새로고침"><i class="fa fa-refresh"></i></button>
										<button type="button" id="captcha_mp3" class="btn btn-default" title="음성듣기"><i class="fa fa-volume-up"></i></button>
									</span>
								</div>
							</div>
						</div>
						<div class="text-muted text-center" style="margin-top:5px; font-size:12px;">
							<i class="fa fa-info-circle"></i> 왼쪽의 글자를 순서대로 입력하세요.
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<style>
	#fregisterform > .text-center { margin:14px 0 10px !important; }
	</style>
	<div class="text-center" style="margin:14px 0 10px;">
		<button type="submit" id="btn_submit" class="btn btn-color" accesskey="s"><?php echo $w==''?'회원가입':'정보수정'; ?></button>
	</div>

</form>

<script>
$(function() {
	$("#reg_zip_find").css("display", "inline-block");

	<?php if($config['cf_cert_use'] && $config['cf_cert_ipin']) { ?>
	// 아이핀인증
	$("#win_ipin_cert").click(function(e) {
		if(!cert_confirm())
			return false;

		var url = "<?php echo G5_OKNAME_URL; ?>/ipin1.php";
		certify_win_open('kcb-ipin', url, e);
		return;
	});

	<?php } ?>
	<?php if($config['cf_cert_use'] && $config['cf_cert_hp']) { ?>
	// 휴대폰인증
	$("#win_hp_cert").click(function(e) {
		if(!cert_confirm())
			return false;

		<?php
		switch($config['cf_cert_hp']) {
			case 'kcb':
				$cert_url = G5_OKNAME_URL.'/hpcert1.php';
				$cert_type = 'kcb-hp';
				break;
			case 'kcp':
				$cert_url = G5_KCPCERT_URL.'/kcpcert_form.php';
				$cert_type = 'kcp-hp';
				break;
			case 'lg':
				$cert_url = G5_LGXPAY_URL.'/AuthOnlyReq.php';
				$cert_type = 'lg-hp';
				break;
			default:
				echo 'alert("기본환경설정에서 휴대폰 본인확인 설정을 해주십시오");';
				echo 'return false;';
				break;
		}
		?>

			certify_win_open("<?php echo $cert_type; ?>", "<?php echo $cert_url; ?>", e);
			return;
		});
		<?php } ?>

		// 실시간 중복 체크
		$("#reg_mb_id").on("keyup blur", function() {
            <?php if ($w == 'u') { ?>return;<?php } ?>
			if ($(this).val().length >= 3) {
				var result = reg_mb_id_check();
				if (result) {
					$("#msg_mb_id").html('<span style="color:red;">' + result + '</span>');
				} else {
					$("#msg_mb_id").html('<span style="color:green;">사용 가능한 아이디입니다.</span>');
				}
			}
		});

		$("#reg_mb_email").on("keyup blur", function() {
            <?php if ($w == 'u') { ?>return;<?php } ?>
			if ($(this).val().length >= 5) {
				var result = reg_mb_email_check();
				if (result) {
					$("#msg_mb_email").html('<span style="color:red;">' + result + '</span>');
				} else {
					$("#msg_mb_email").html('<span style="color:green;">사용 가능한 E-mail입니다.</span>');
				}
			}
		});

		$("#reg_mb_nick").on("keyup blur", function() {
			if ($(this).val().length >= 2) {
				var result = reg_mb_nick_check();
				if (result) {
					$("#msg_mb_nick").html('<span style="color:red;">' + result + '</span>');
				} else {
					$("#msg_mb_nick").html('<span style="color:green;">사용 가능한 닉네임입니다.</span>');
				}
			}
		});
	});

	// 아이디 재생성
	function regenerateId() {
		$.ajax({
			url: g5_bbs_url + '/ajax.regenerate_member.php',
			type: 'POST',
			data: { type: 'id' },
			dataType: 'json',
			success: function(data) {
				if (data.success) {
					$('#reg_mb_id').val(data.value);
					$("#msg_mb_id").html('<span style="color:green;">새로운 아이디가 생성되었습니다.</span>');
					// 버튼 텍스트와 안내 메시지 변경
					$('#btn_regenerate_id').html('<i class="fa fa-refresh"></i> 다시 생성');
					$('#id_info_msg').html('<i class="fa fa-info-circle"></i> 자동으로 생성된 아이디입니다. 원하시면 수정하거나 \'다시 생성\' 버튼을 누르세요.');
					// 중복 체크
					setTimeout(function() {
						$("#reg_mb_id").blur();
					}, 100);
				}
			}
		});
	}

	// 이름 재생성
	function regenerateName() {
		$.ajax({
			url: g5_bbs_url + '/ajax.regenerate_member.php',
			type: 'POST',
			data: { type: 'name' },
			dataType: 'json',
			success: function(data) {
				if (data.success) {
					$('#reg_mb_name').val(data.value);
					// 버튼 텍스트와 안내 메시지 변경
					$('#btn_regenerate_name').html('<i class="fa fa-refresh"></i> 다시 생성');
					$('#name_info_msg').html('<i class="fa fa-info-circle"></i> 자동으로 생성된 이름입니다. 원하시면 수정하거나 \'다시 생성\' 버튼을 누르세요.');
					// 닉네임도 함께 재생성
					regenerateNick();
				}
			}
		});
	}

	// 닉네임 재생성
	function regenerateNick() {
		var mb_name = $('#reg_mb_name').val();
		$.ajax({
			url: g5_bbs_url + '/ajax.regenerate_member.php',
			type: 'POST',
			data: { type: 'nick', mb_name: mb_name },
			dataType: 'json',
			success: function(data) {
				if (data.success) {
					$('#reg_mb_nick').val(data.value);
					// 버튼 텍스트와 안내 메시지 변경
					$('#btn_regenerate_nick').html('<i class="fa fa-refresh"></i> 다시 생성');
					$('#nick_info_msg').html('<i class="fa fa-info-circle"></i> 자동으로 생성된 닉네임입니다. 원하시면 수정하거나 \'다시 생성\' 버튼을 누르세요.');
					$("#msg_mb_nick").html('<span style="color:green;">새로운 닉네임이 생성되었습니다.</span>');
					// 중복 체크
					setTimeout(function() {
						$("#reg_mb_nick").blur();
					}, 100);
				}
			}
		});
	}

	// submit 최종 폼체크
	function fregisterform_submit(f)
	{
		// 회원아이디 검사
		if (f.w.value == "") {
            if (!f.agree.checked) {
                alert("회원가입약관의 내용에 동의하셔야 회원가입 하실 수 있습니다.");
                f.agree.focus();
                return false;
            }

            if (!f.agree2.checked) {
                alert("개인정보처리방침안내의 내용에 동의하셔야 회원가입 하실 수 있습니다.");
                f.agree2.focus();
                return false;
            }

			var msg = reg_mb_id_check();
			if (msg) {
				alert("아이디: " + msg);
				f.mb_id.select();
				return false;
			}
		}

		if (f.w.value == "") {
		if (f.mb_password.value.length < 3) {
			alert("비밀번호를 3글자 이상 입력하십시오.");
			f.mb_password.focus();
			return false;
		}
	}

	if (f.mb_password.value != f.mb_password_re.value) {
		alert("비밀번호가 같지 않습니다.");
		f.mb_password_re.focus();
		return false;
	}

	if (f.mb_password.value.length > 0) {
		if (f.mb_password_re.value.length < 3) {
			alert("비밀번호를 3글자 이상 입력하십시오.");
			f.mb_password_re.focus();
			return false;
		}
	}

	// 이름 검사
	if (f.w.value=="") {
		if (f.mb_name.value.length < 1) {
			alert("이름을 입력하십시오.");
			f.mb_name.focus();
			return false;
		}

		/*
		var pattern = /([^가-힣\x20])/i;
		if (pattern.test(f.mb_name.value)) {
			alert("이름은 한글로 입력하십시오.");
			f.mb_name.select();
			return false;
		}
		*/
	}

	<?php if($w == '' && $config['cf_cert_use'] && $config['cf_cert_req']) { ?>
	// 본인확인 체크
	if(f.cert_no.value=="") {
		alert("회원가입을 위해서는 본인확인을 해주셔야 합니다.");
		return false;
	}
	<?php } ?>

		// 닉네임 검사
		if ((f.w.value == "") || (f.w.value == "u" && f.mb_nick.defaultValue != f.mb_nick.value)) {
			var msg = reg_mb_nick_check();
			if (msg) {
				alert("닉네임: " + msg);
				f.reg_mb_nick.select();
				return false;
			}
		}

		// E-mail 검사
		if ((f.w.value == "") || (f.w.value == "u" && f.mb_email.defaultValue != f.mb_email.value)) {
			var msg = reg_mb_email_check();
			if (msg) {
				alert("E-mail: " + msg);
				f.reg_mb_email.select();
				return false;
			}
		}

	<?php if (($config['cf_use_hp'] || $config['cf_cert_hp']) && $config['cf_req_hp']) {  ?>
	// 휴대폰번호 체크
	var msg = reg_mb_hp_check();
	if (msg) {
		alert(msg);
		f.reg_mb_hp.select();
		return false;
	}
	<?php } ?>

	if (typeof f.mb_icon != "undefined") {
		if (f.mb_icon.value) {
			if (!f.mb_icon.value.toLowerCase().match(/.(gif|jpe?g|png)$/i)) {
				alert("회원아이콘이 이미지 파일이 아닙니다.");
				f.mb_icon.focus();
				return false;
			}
		}
	}

	if (typeof f.mb_img != "undefined") {
		if (f.mb_img.value) {
			if (!f.mb_img.value.toLowerCase().match(/.(gif|jpe?g|png)$/i)) {
				alert("회원이미지가 이미지 파일이 아닙니다.");
				f.mb_img.focus();
				return false;
			}
		}
	}

	if (typeof(f.mb_recommend) != "undefined" && f.mb_recommend.value) {
		if (f.mb_id.value == f.mb_recommend.value) {
			alert("본인을 추천할 수 없습니다.");
			f.mb_recommend.focus();
			return false;
		}

		var msg = reg_mb_recommend_check();
		if (msg) {
			alert(msg);
			f.mb_recommend.select();
			return false;
		}
	}

	<?php echo chk_captcha_js();  ?>

	document.getElementById("btn_submit").disabled = "disabled";

	return true;
}
</script>
