<?
$ci =& get_instance();

# 회원가입 셋팅 정보
$ci->load->model('web/m_member_setting');
$arr_member_setting = $ci->m_member_setting->member_setting_where_not_default_list();
$ci->load->model('web/m_site_info');
$site_info = $ci->m_site_info->site_info_select(1);

$arr_member_setting_list = array();
foreach ($arr_member_setting as $val) {
	$arr_member_setting_list[$val['idx']] = array('is_required' => $val['is_required'], 'item_field_name' => $val['item_field_name'], 'item_title' => $val['item_title'], 'is_use' => $val['is_use']);
}

# 세션저장
$SES_RANDOM_STATE = $this->session->userdata('RANDOM_STATE');
if ($SES_RANDOM_STATE == '') {
	$random_state = md5(microtime() . mt_rand());
	$this->session->set_userdata('RANDOM_STATE', $random_state);
	$SES_RANDOM_STATE = $this->session->userdata('RANDOM_STATE');
}

$SES_MEMBER_NAME = $this->session->userdata('C_Member_Name');
$SES_MEMBER_FIRST = $this->session->userdata('C_Member_First');
$SES_MEMBER_PASSWORD_CHANGE = $this->session->userdata('C_Member_Password_Change');
$SES_MEMBER_LOGIN = $this->session->userdata('C_Member_Login');
$SES_MEMBER_ID = $this->session->userdata('C_Member_Id');
$this->session->unset_userdata('C_Member_Login');
$this->session->unset_userdata('C_Member_First');
$this->session->unset_userdata('C_Member_Password_Change');

if ($SES_MEMBER_ID != '') { ?>


	<div id="passwd_check_layer" style="display:none;">
		<div class="popup_wrap">
			<div class="popupbox" style=" width:445px; ">
				<div class="popuptop trc">
					<h3 class="p_title">비밀번호 확인 </h3>
					<span class="btn-close"><a href="/m/member/login"><img
								src="/img/web/btn-close.png"></a></span>
				</div>
				<div class="popupbody">
					<div class="info_forms">
						<div class="form-group">
							<label for="exampleInputEmail1">비밀번호</label>
							<p>설정하신 비밀번호를 입력해주세요.</p>
							<input type="password" class="form-control" id="profile_password" name="profile_password"
								   style="width:97%; margin:10px 0;"
								   onkeypress="if( event.keyCode==13 ){check_password();}">
						</div>
						<div class="form-group">
							<label for="exampleInputEmail1">아이디/비밀번호 찾기</label>
							<p style="margin-bottom:10px;">설정하신 비번이 기억 안나시나요?</p>
							<p>
								<button type="button" class="btn btn-default br5"
										style="padding:7px 20px; font-size:16px; margin-right:10px;"
										onclick="commonLayerClose('passwd_check_layer');commonLayerOpen('find_id_layer');">
									아이디찾기
								</button>
								<button type="button" class="btn btn-default br5"
										style="padding:7px 20px; font-size:16px;"
										onclick="commonLayerClose('passwd_check_layer');commonLayerOpen('find_pwd_layer')">
									비밀번호 찾기
								</button>
							</p>
						</div>
						<div class="form-group bgt"
							 style="margin:40px 0 20px 0; display:block; text-align:center;padding-top: 20px;">
							<button type="button" class="btn btn-success br20"
									style="padding:7px 40px; font-size:16px; margin-right:10px"
									onclick="check_password();">확인
							</button>
							<button type="button" class="btn btn-default br20" style="padding:7px 40px; font-size:16px;"
									onclick="commonLayerClose('passwd_check_layer')">취소
							</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="mask"></div>
	</div>


	<? if ($SES_MEMBER_FIRST == 'Y') { ?>
		<div id="join_complete" style="display:block;">
			<div class="popup_wrap">
				<div class="popupbox trc" style=" width:445px; ">
					<div class="popuptop2">
						<span class="logo"><img src="/img/web/logo_sm.jpg" alt="logo"></span>
						<span style="float:right; padding-right:30px;">크리스천 기독 종합 포털</span>
					</div>
					<div class="popupimg">
						<img src="/img/web/popupimg.jpg">
						<div class="popuptxt">
							<span class="ft22 done">가입이 완료됐습니다.</span><br>
							<span style="padding-top: 5px; display: inline-block;">크리스천 놀이터 크로스맵에 자주 놀러 오실 거죠?</span>
						</div>
					</div>
					<div class="popupbody">

						<table class="body_table">
							<tr>
								<td class="bt_tit" style="padding-top:15px;">아이디</td>
								<td class="bt_txt" style="padding-top:15px;"><?= $SES_MEMBER_ID ?></td>
							</tr>
							<tr>
								<td class="bt_tit" style="padding-top:10px; padding-bottom:15px;">이름</td>
								<td class="bt_txt"
									style="padding-top:10px; padding-bottom:15px;"><?= $SES_MEMBER_NAME ?></td>
							</tr>
						</table>
						<div class="ft14" style="margin-top:20px;">닉네임 등 프로필 정보는 <span class="beachblue"
																					   style="text-decoration:underline;"><a
									href="javascript:commonLayerClose('join_complete');commonLayerOpen('passwd_check_layer')">내 정보관리</a></span>에서
							수정할 수 있어요.
						</div>
						<div class="form-group" style="margin:20px 0 30px; display:block; text-align:center">
							<button type="button" onclick="location.href='/'" class="btn btn-success br5"
									style="padding: 15px 40px;font-size: 16px; width: 100%;"><span
									class="current">시작하기 </span></button>
						</div>
					</div>
				</div>
			</div>
			<div class="mask"></div>
		</div>

	<? } ?>

	<? if ($SES_MEMBER_PASSWORD_CHANGE == 'Y') { ?>

		<div id="pw_3month_auto_change" style="display:block;">
			<div class="popup_wrap">
				<div class="popupbox" style=" width:445px; ">
					<div class="popuptop  trc">
						<h3 class="p_title">비밀번호 변경 안내</h3>
						<span class="btn-close"><a href="javascript:commonLayerClose('pw_3month_auto_change');"><img
									src="/img/web/btn-close.png"></a></span>
					</div>
					<div class="popupbody">
						<div class="bgb trc" style="padding:30px 0 20px;">
							<span class="ft14">회원님의 소중한 개인정보를 안전하게 보호하기 위해</span><br>
							<span class="ft24" style="margin-top: 5px;color: #606060;display: inline-block;">비밀번호 변경을 안내 드립니다.</span>
						</div>
						<div style="padding: 20px 0; width: 90%; margin: 0 auto;">
							비밀번호를 변경하신 지 <span class="beachblue">3개월이 지난 경우</span>
							에 비밀번호 <br>변경 안내를 드리고 있습니다.<br>
							<span style="padding:10px 0;display: block;">
					‘다음에 변경하기’ 버튼을 눌러 변경을 연기하시면 새로 로그인 접속하실 때 다시 안내해 드립니다.<br>
					</span>
							조금 불편하시더라도, <span class="beachblue">주기적으로 비밀번호를 변경하여 소중한 개인정보를 스스로 지켜주세요.</span>
						</div>
						<div class="info_forms">
							<div class="form-group">
								<input type="password" name="now_pwd" id="now_pwd" class="form-control"
									   placeholder="현재 비밀번호를 입력해주세요. " style="width:97%;">
							</div>
							<div class="form-group">
								<input type="password" name="new_member_pwd" id="new_member_pwd" class="form-control"
									   placeholder="새 비밀번호 (6~16 영문 대·소문자,숫자,특수문자)" style="width:97%; margin:10px 0">
							</div>
							<div class="form-group">
								<input type="password" name="new_re_member_pwd" id="new_re_member_pwd"
									   class="form-control" placeholder="새 비밀번호를 한번 더 입력해주세요. " style="width:97%;">
							</div>
						</div>
						<div class="form-group bgt"
							 style="margin:30px 0 30px 0; display:block; text-align:center; padding-top:30px;">
							<button type="button" class="btn btn-success br20" style="padding:7px 40px; font-size:16px"
									onclick="change_password()">변경하기
							</button>
							<button type="button" class="btn btn-default_bb br20"
									style="padding:7px 40px; font-size:16px"
									onclick="commonLayerClose('pw_3month_auto_change');">다음에 변경하기
							</button>
						</div>
					</div>
				</div>
			</div>
			<div class="mask1"></div>
		</div>

	<? } ?>

<? } else { ?>


	<form name="join_form" id="join_form" method="post" action="/m/member/member_join_proc"
		  enctype="multipart/form-data">
		<input type="hidden" name="social_id" id="social_id">
		<input type="hidden" name="is_mobile_auth" id="is_mobile_auth">
		<input type="hidden" name="mobile_CI" id="mobile_CI">
		<input type="hidden" name="email_check" id="email_check">
		<input type="hidden" name="member_gender" id="member_gender">
		<input type="hidden" name="is_under14" id="is_under14">
		<input type="hidden" name="is_use_id" id="is_use_id">
		<input type="hidden" name="member_name" id="member_name">
		<input type="hidden" name="sns_profile_img" id="sns_profile_img">
		<!-- 회원가입 step 2 -->
		<div id="member_join2_layer">


			<div class="account_header_fixed">
				<span class="header_tit">약관 동의</span><span class="fr" style="padding-right:20px; padding-top:3px;"><a
						href="/m/member/login"><img src="/img/mobile/img_close.gif"></a></span>
			</div>
			<div class="account_cont_fixed">
				<div class="popup_policy2">
					<h3>서비스 이용약관 동의 (필수) <span class="checks" style="float:right"><input type="checkbox" id="agree1"
																						 name="agree1" value="Y"><label
								for="agree1"></label></span></h3>
					<textarea rows="14"><?= $site_info['service'] ?>

			</textarea>
					<h3 style="margin-top:20px;">개인정보 취급방침 동의 (필수) <span class="checks" style="float:right"><input
								class="agree_on" type="checkbox" id="agree2" name="agree2" value="Y"><label
								for="agree2"></label></span></h3>
					<textarea rows="14"><?= $site_info['privacy'] ?>
			</textarea>
					</textarea>
					<h3 style="margin-top:20px;">개인정보 수집 및 이용 동의 (필수) <span class="checks" tyle="float:right"><input
								class="agree_on" type="checkbox" id="agree3" name="agree3" value="Y"><label
								for="agree3"></label></span></h3>
					<textarea rows="14"><?= $site_info['privacy_agreement'] ?>
			</textarea>

				</div>
				<p style="margin:10px 0; text-align: center;">'다음'버튼을 누르시면 본 정책에 모두 동의하는 것입니다.</p>
				<div class="account_btn">
					<span><a href="/m/member/login" class="btn btn-grey br5"
							 style="font-size: 17px;padding: 10px 0;width: 48%; margin-right:3%">뒤로가기</a></span>
					<span><a onclick="policy_agreement()" class="btn btn-success br5"
							 style="font-size: 17px;padding: 10px 0; width: 48%;">다음</a></span>
				</div>
			</div>

		</div>

		<!--// 회원가입 step 2 -->

		<!-- 회원가입 step 3 -->
		<div id="member_join3_layer" style="display:none;">


			<div class="account_header_fixed">
				<span class="header_tit">회원가입 1단계</span><span class="fr" style="padding-right:20px; padding-top:3px;"><a
						href="/m/member/login"><img src="/img/mobile/img_close.gif"></a></span>
			</div>
			<div class="account_cont_fixed">
				<p style="text-align:center; margin:60px 0 80px;; display:block; overflow:hidden;"><img
						src="/img/mobile/logo_cm.gif"></p>
				<div class="form-group">
					<label for="exampleInputEmail1">아이디 </label>
					<div class=" form_info"
						 style="position: absolute;top: 10px;left: 80px;line-height:18px;color:#a7a7a7; font-size:12px;">
						5~20자의 영문 대 소문자, 숫자와 (_),(-)만 사용 가능합니다
					</div>
					<input type="text" class="form-control" name="member_id" id="member_id"
						   placeholder="아이디를 입력해주세요.">
					<span style="position:absolute; right:0; bottom:8px;">
						<a onclick="member_overlap_check();" class="btn btn-default_bb br5">중복확인</a>
					</span>
				</div>
				<div class="form-group" style="margin-top:30px;">
					<label for="exampleInputEmail1">비밀번호 </label>
					<div class=" form_info"
						 style="position: absolute;top: 10px;left: 80px;line-height:18px;color:#a7a7a7; font-size:12px;">
						6~16자 영문 대 소문자, 숫자, 특수 문자를 사용하세요.
					</div>

					<input type="password" id="member_pwd" name="member_pwd" class="form-control mybutton_off"
						   placeholder="비밀번호를 입력해주세요(6자 이상)" onkeyup="member_pwd_check(this);" style="width:97%; ">

				</div>
				<div class="form-group">
					<input type="password" id="re_member_pwd" name="re_member_pwd" class="form-control mybutton_off"
						   placeholder="비밀번호를 한번 더 입력해주세요." onkeyup="member_pwd_check(this);" style="width:97%;">
				</div>
				<div class="form-group" style="margin-top:30px;">
					<label for="exampleInputEmail1">이름 </label>
					<input type="id" class="form-control mybutton_on" placeholder="이름을 입력해 주세요." style="width: 98%;">
				</div>
				<div class="form-group" style="border : 0px;">
					<div class="form_tit">성별</div>

					<button type="button" class="btn btn-default br5" id="gender_btn1"
							onclick="member_gender_select(1);"
							style="width:48%; margin-top:10px; margin-right:7px;padding:9px ">남자
					</button>
					<button type="button" class="btn btn-default br5" id="gender_btn2"
							onclick="member_gender_select(2);"
							style="width:48%; margin-top:10px; padding:9px ">여자
					</button>
				</div>
				<div class="form-group">
					<div class="form_tit">생년월일</div>
					<span class="slct">
			     <select id="birth_year" name="birth_year" onchange="birth_change()">
                           <option value="">출생연도 </option>
					 <? for ($i = 1920; $i <= date("Y"); $i++) { ?>
						 <option value="<?= $i ?>"><?= $i ?></option>
					 <? } ?>
                       </select>

			</span>
					<span class="slct">
			      <select id="birth_month" name="birth_month" onchange="birth_change()">
                           <option value="">월</option>
					  <? for ($i = 1; $i <= 12; $i++) { ?>
						  <option value="<?= sprintf("%02d", $i) ?>"><?= $i ?></option>
					  <? } ?>
                       </select>
			</span>
					<span class="slct">
			   <select id="birth_day" name="birth_day" onchange="birth_change()">
			                           <option value="">일</option>
				   <? for ($i = 1; $i <= 31; $i++) { ?>
					   <option value="<?= sprintf("%02d", $i) ?>">
			<?= $i ?></option>
				   <? } ?>

			                       </select>
			</span>
					<span class="slct" style="width:90px; margin-left:20px;">
				<select id="member_calendar" name="member_calendar" style="color:#fc5252; padding-left:30px">
					<option value="1">양력</option>
					<option value="2">음력</option>
				</select>
			</span>
				</div>


				<div class="account_btn" id="more14_form">
					<span><a href="/m/member/login" class="btn btn-grey br5"
							 style="font-size: 17px; padding: 10px 0; width: 48%; margin-right:3%">뒤로가기</a></span>
					<span><a onclick="member_join_next();" class="btn btn-success br5"
							 style="font-size: 17px; padding: 10px 0; width: 48%;">다음</a></span>
				</div>


				<div id="under14_form" style="display:none;">
					<div class="info_red" style="padding:10px 0 20px 10px;">만 14세 미만의 어린이는 보호자 동의가 필요합니다.</div>
					<div class="account_btn2" style="margin-bottom:20px;">
					<span><a class="btn btn-success br5"
							 style="font-size: 17px; padding: 10px 0; width: 100%; ">모바일폰 인증</a></span>
						<!--					<span><a href="" class="btn btn-success br5" style="font-size: 17px; padding: 10px 0; width: 49%; ">아이핀 인증</a></span>-->
					</div>


					<div class="form-group" style="margin-top:2px;">
						<input type="id" id="parent_name" name="parent_name" class="form-control mybutton_on"
							   placeholder="보호자 이름" style="width: 98%;">
					</div>

					<div class="form-group">
						<div class="form_tit">모바일폰</div>
						<span class="slct">
			    <select id="parent_mobile_company" name="parent_mobile_company">
			                               <option value="">선택 </option>
			                               <option value="SKT">SKT </option>
			                               <option value="KT">KT </option>
			                               <option value="LGU+">LGU+ </option>
			                           </select>
			</span>
						<input name="parent_mobile" id="parent_mobile" class="form-control mybutton_on"
							   placeholder="휴대폰 번호" style="width: 30%;">
						<span style="position:absolute; right:0; bottom:8px;"><a onclick="parent_mobile_auth()"
																				 class="btn btn-default_bb br10"
																				 style="padding:4px 26px">인증  </a></span>
					</div>

					<div class="info_red" style="padding:10px 0 10px 10px">인증비용은 크로스맵에서 부담합니다.</div>
					<div class="form-group">
						<input type="hidden" name="under14_member_name" id="under14_member_name"
							   class="form-control" placeholder="본인 이름" style="width:97%;">
						<input type="text" name="under14_member_email"
							   id="under14_member_email" placeholder="본인확인 이메일"
						>
						<button type="button" onclick="under14_email_overlap_check();" class="btn btn-default_bb br5"
								style="float:right">
							중복확인
						</button>


					</div>
					<div class="account_btn">
						<span><a class="btn btn-success br5" style="font-size: 17px; padding: 10px 0; width: 100%;"
								 onclick="under14_member_join()">가입하기</a></span>
					</div>
				</div>
			</div>

		</div>
		<!--// 회원가입 step 3 -->


		<!-- 회원가입 step 4 -->
		<div id="member_join4_layer" style="display:none;">
			<div class="account_header_fixed">
				<span class="header_tit">회원가입 2단계</span><span class="fr" style="padding-right:20px; padding-top:3px;"><a
						href="/m/member/login"><img src="/img/mobile/img_close.gif"></a></span>
			</div>
			<div class="account_cont_fixed">
				<div class="join_header">
					<span class="profile_add_photo">
						<input type="file" id="member_img" name="member_img" onchange="readURL(this)" style="display:none;" >
						<label for="member_img" style="background: url(&quot;/img/web/img_photo.png&quot;) center center / cover no-repeat;"></label>
						<span class="camera"><img src="/img/web/img_camera2.png"></span>
					</span>
					<span class="camera"><img src="/img/mobile/img_camera2.png"></a></span>
				</div>
				<div class="form-group" style="margin-top:20px; padding-right: 80px; box-sizing: border-box;">
					<label for="exampleInputEmail1">연락정보</label>
					<input id="email1" name="email1" type="email" class="form-control" placeholder="" style="width:25%; float:left;">
					<span style="float:left; padding: 10px 3px;">@</span>
					<input id="email2" name="email2" type="email" class="form-control" placeholder="" style="width:20%; float:left;">
					<span class="slct" style="width: 38%;">
						<!-- <select id="" name="" style="color:#fc5252; padding-left:0;" onchange="email_change(this.value);"> -->
						<select id="email3" name="email3" style="color:#fc5252; padding-left:0;">
                           <option value="naver.com">naver.com</option>
                           <option value="daum.net">daum.net</option>
                           <option value="nate.com">nate.com</option>
                           <option value="gmail.com">gmail.com</option>
                           <option value="etc" selected="selected">직접입력</option>
						</select>
						<span style="position:absolute; right:0; bottom:8px;"><a onclick="email_overlap_check();" class="btn btn-default_bb br10">중복확인</a></span>
					</span>
				</div>
				<div class="form-group" style="padding-right: 80px; box-sizing: border-box;">
					<div class="form_tit">모바일폰</div>
					<span class="slct" style="width:20%">
						<select id="country_phone_no" name="country_phone_no">
				   			<option value="+82">+82 </option>
						</select>
					</span>
					<select id="mobile1" name="mobile1" style="width:20%">
						<option value="">선택 </option>
						<option value="010">010 </option>
						<option value="011">011 </option>
						<option value="016">016 </option>
						<option value="017">017 </option>
						<option value="019">019 </option>
					</select>

					<img src="/img/mobile/img_bar.gif">
					<input  id="mobile2" name="mobile2" type="tel" class="form-control" placeholder="" style="width:17%"><img src="/img/mobile/img_bar.gif">
					<input  id="mobile3" name="mobile3" type="tel" class="form-control" placeholder=" " style="width:17%; text-align:center;">

					<span style="position:absolute; right:0; bottom:8px;"><a onclick="mobile_auth()" class="btn btn-default_bb br10">본인인증</a></span>
				</div>


				<div class="form-group">
					<label>추가정보 <span class="church">출석교회(선택)</span></label>
					<? if ($arr_member_setting_list[10]['is_use'] == 'Y') { ?>
						<input type="text" class="form-control" name="member_church" id="member_church"
							   placeholder="교회명" style="width:120px;">
					<? } ?>
					<? if ($arr_member_setting_list[11]['is_use'] == 'Y') { ?>
						<input type="text" class="form-control" id="etc1" name="etc1"
							   placeholder="<?= $arr_member_setting_list[11]['item_title'] ?>"
							   style="width:120px;">
					<? } ?>
					<? if ($arr_member_setting_list[12]['is_use'] == 'Y') { ?>
						<input type="text" class="form-control" id="etc2" name="etc2"
							   placeholder="<?= $arr_member_setting_list[12]['item_title'] ?>"
							   style="width:90px;">
					<? } ?>
				</div>

				<? for ($i = 13; $i < 15; $i++) {
					if ($arr_member_setting_list[$i]['item_title'] != '') {

						?>
						<div class="form-group">
							<label>추가정보 <span
									class="church"><?= $arr_member_setting_list[$i]['item_title'] ?></span></label>
							<? if ($arr_member_setting_list[$i]['is_use'] == 'Y') { ?>
								<input type="text" class="form-control"
									   name="<?= $arr_member_setting_list[$i]['item_field_name'] ?>"
									   id="<?= $arr_member_setting_list[$i]['item_field_name'] ?>"
									   placeholder="<?= $arr_member_setting_list[$i]['item_title'] ?>"
									   style="width:120px;">
							<? } ?>
						</div>
						<?
					}
				} ?>
				<div class="account_btn">
					<span><a onclick="commonLayerClose('member_join4_layer');commonLayerOpen('member_join3_layer');" class="btn btn-grey br5"
							 style="font-size: 17px;padding: 10px 0;width: 48%; margin-right:3%">뒤로가기</a></span>
					<span><a  onclick="member_join();return false;" class="btn btn-success br5" style="font-size: 17px;padding: 10px 0;width: 48%;">가입완료</a></span>
				</div>
			</div>

		</div>
		<!--// 회원가입 step 4 -->
	</form>


<? } ?>


<script>
	$(document).ready(function () {
		<? if($SES_MEMBER_LOGIN == 'Y') {?>
		commonLayerOpen('login_layer');
		<? }?>

	});

	$(".mask").on('click', function (event) {
		$(event.target).parent().hide();

	});

	function check_password() {
		if ($("#profile_password").val() == "") {
			alert("비밀번호를 입력해주세요.");
			return false;
		}

		var form_data = {
			"member_id": "<?=$SES_MEMBER_ID?>",
			"member_pwd": $("#profile_password").val()
		};
		$.ajax({
			url: '/web/member/password_check_proc',
			async: false,
			type: 'POST',
			dataType: 'JSON',
			data: form_data,
			success: function (rtnJson) {
				console.log(rtnJson);
				console.log(rtnJson.code);
				if (rtnJson.code == "0000") {
					location.href = "/web/mypage/member_edit";
				} else {
					alert(rtnJson.msg);
					return false;
				}
			},
			error: function (rtnJson) {
				alert('비밀번호 확인에 실패했습니다.');
				return false;
			}
		});
	}

	// 로그인
	function login_proc() {
		if ($("#login_member_id").val() == "") {
			alert("아이디를 입력해주세요.");
			return false;
		}
		if ($("#login_member_pwd").val() == "") {
			alert("아이디를 입력해주세요.");
			return false;
		}

		var save_login = 'N';
		if ($('input:checkbox[id="save_login"]').is(":checked") == true) {
			save_login = $('input:checkbox[id="save_login"]').val()
		}

		var form_data = {
			"member_id": $("#login_member_id").val(),
			"member_pwd": $("#login_member_pwd").val(),
			"save_login": save_login
		};
		$.ajax({
			url: '/web/member/login_proc',
			async: false,
			type: 'POST',
			dataType: 'JSON',
			data: form_data,
			success: function (rtnJson) {
				if (rtnJson.code == "0000") {
					if (rtnJson.msg != '') {
						alert(rtnJson.msg);
					}
					location.href = "<?=CROSSMAP_URL?>";

				} else {
					alert(rtnJson.msg);
					return false;
				}
			},
			error: function (rtnJson) {
				alert('로그인에 실패했습니다.');
				return false;
			}
		});
	}


	function join_reset() {
		if ($("#login_layer").css("display") == "block") {
			$("#login_layer").hide();
		}

		$('#join_form')[0].reset();
		$("#member_pwd").removeClass('mybutton_on');
		$("#member_pwd").removeClass('mybutton_off');
		$("#member_pwd").addClass('mybutton_off');
		$("#re_member_pwd").removeClass('mybutton_on');
		$("#re_member_pwd").removeClass('mybutton_off');
		$("#re_member_pwd").addClass('mybutton_off');

		$("#gender_btn1").removeClass('btn-default_bb');
		$("#gender_btn1").removeClass('btn-default');
		$("#gender_btn1").addClass('btn-default');

		$("#gender_btn2").removeClass('btn-default_bb');
		$("#gender_btn2").removeClass('btn-default');
		$("#gender_btn2").addClass('btn-default');


		$(".profile_add_photo label").css("background", "url('/img/web/img_photo.png') no-repeat center");
		$(".profile_add_photo label").css("background-size", "cover");
	}




	// 이용약관동의
	function policy_agreement() {
		if ($("#agree1").is(":checked") == false) {
			alert("서비스 이용약관 동의를 해주세요.");
			return false;
		}

		if ($("#agree2").is(":checked") == false) {
			alert("개인정보 취급방침 동의를 해주세요.");
			return false;
		}

		if ($("#agree3").is(":checked") == false) {
			alert("개인정보 수집 및 이용 동의를 해주세요.");
			return false;
		}

		if ($("#social_id").val() != '') {
			$("#crossmap_join").hide();

			var form_data = {
				"social_id": $("#social_id").val()
			};
			$.ajax({
				url: '/web/comm/social_member_info',
				sync: false,
				type: 'POST',
				dataType: 'json',
				data: form_data,
				success: function (rtn_json) {
					if (rtn_json.result_code != '0000') {
						alert("sns 계정연동에 실패했습니다.");
						$("#social_id").val('');
						return false;
					} else {
						$("#member_name").val(rtn_json.result_data.name);
						if (rtn_json.result_data.profile_img != '') {
							$(".profile_add_photo label").css("background", "url('" + rtn_json.result_data.profile_img + "') no-repeat center");
							$(".profile_add_photo label").css("background-size", "cover");
							$("#sns_profile_img").val(rtn_json.result_data.profile_img);
						}
					}
				},
				error: function (rtnHtml) {
					return false;
				}
			});

		}
		$("#member_join2_layer").hide();
		$("#member_join3_layer").show();

	}


	// 아이디 중복체크
	function member_overlap_check() {
		var member_id = $("#member_id").val();
		if (member_id == "") {
			alert("아이디를 입력해주세요.");
			return false;
		}
		if (member_id_valid_check(member_id) == false) {
			alert("아이디는 5~20자의 영문 대 소문자, 숫자와 (_),(-)만 사용 가능합니다.");
			return false;
		}

		var form_data = {
			"member_id": member_id
		};
		$.ajax({
			url: '/web/member/member_id_check_proc',
			sync: false,
			type: 'POST',
			dataType: 'json',
			data: form_data,
			success: function (rtn_json) {
				if (rtn_json.result_code != '0000') {
					alert("사용할수없는 아이디입니다.");
					$("#member_id").val('');
					$("#is_use_id").val('N');

					return false;
				} else {
					alert("사용가능한 아이디입니다.");
					$("#is_use_id").val('Y');
					return false;
				}
			},
			error: function (rtnHtml) {
				$("#is_use_id").val('N');
				return false;

			}
		});
	}

	// 비밀번호 체크
	function member_pwd_check(t) {
		var id = t.id;
		var val = t.value;

		$("#" + id).removeClass('mybutton_off');
		if (member_pwd_valid_check(val) == false) {
			$("#" + id).addClass('mybutton_off');
		} else {
			$("#" + id).addClass('mybutton_on');
		}
	}

	// 성별체크
	function member_gender_select(val) {
		var member_gender = $("#member_gender").val();

		$("#gender_btn" + member_gender).removeClass('btn-default_bb');
		$("#gender_btn" + member_gender).addClass('btn-default');

		$("#member_gender").val(val);
		$("#gender_btn" + val).addClass('btn-default_bb');
	}

	// 만14세 체크
	function birth_change() {
		var birth_year = $("#birth_year").val();
		var birth_month = $("#birth_month").val();
		var birth_day = $("#birth_day").val();

		if (birth_year != '' && birth_month != '' && birth_day != '') {
			var date = new Date();
			var year = date.getFullYear();
			var month = (date.getMonth() + 1);
			var day = date.getDate();
			if (month < 10) month = '0' + month;
			if (day < 10) day = '0' + day;
			var today = year + month + day;
			var birth = birth_year + birth_month + birth_day;

			var result = parseInt(today) - parseInt(birth) - 150000;
			if (parseInt(result) < 0) { // 14세미만
				$("#under14_form").show();
				$("#more14_form").hide();
				$("#is_under14").val('Y');
			} else {
				$("#under14_form").hide();
				$("#more14_form").show();
				$("#is_under14").val('N');
			}
		}
	}

	// 프로필이미지 등록
	function readURL(input) {
		if (input.files && input.files[0]) {
			var reader = new FileReader();
			reader.onload = function (e) {
				$(".profile_add_photo label").css("background", "url('" + e.target.result + "') no-repeat center");
				$(".profile_add_photo label").css("background-size", "cover");
				$("#sns_profile_img").val('');
			}
			reader.readAsDataURL(input.files[0]);
		}
	}

	// 이메일선택
	function email_change(val) {
		$("#email2").val(val);
	}

	$(document).ready(function() {
		$("#email3").change(function() {
			var email3 = $(this).val();
			if(email3 == "etc") {
				$("input[name='email2']").val('');
				$("input[name='email2']").attr('readonly', false);
			} else {
				$("input[name='email2']").val(email3);
				$("input[name='email2']").attr('readonly', true);
			}
		});
	});

	// 14세 미만
	// 이메일 중복체크
	function under14_email_overlap_check() {
		$("#email_check").val('N');
		var email = $("#under14_member_email").val();
		if (checkEmail(email) == false) {
			alert("이메일을 확인해주세요.");
			return false;
		}

		var form_data = {
			"email": email
		};
		$.ajax({
			url: '/web/member/member_email_check_proc',
			async: false,
			type: 'POST',
			dataType: 'JSON',
			data: form_data,
			success: function (rtnJson) {
				if (rtnJson.result_code != "0000") {
					alert("사용할수 없는 이메일입니다.");
					return false;
				} else {
					alert("사용가능한 이메일입니다.");
					$("#email_check").val('Y');
					return false;
				}
			},
			error: function (rtnJson) {
				alert('이메일 중복확인을 실패했습니다.');
				return false;
			}
		});

	}


	// 이메일 중복체크
	function email_overlap_check() {
		$("#email_check").val('N');
		var email = $("#email1").val() + '@' + $("#email2").val();
		if (checkEmail(email) == false) {
			alert("이메일을 확인해주세요.");
			return false;
		}

		var form_data = {
			"email": email
		};
		$.ajax({
			url: '/web/member/member_email_check_proc',
			async: false,
			type: 'POST',
			dataType: 'JSON',
			data: form_data,
			success: function (rtnJson) {
				if (rtnJson.result_code != "0000") {
					alert("사용할수 없는 이메일입니다.");
					return false;
				} else {
					alert("사용가능한 이메일입니다.");
					$("#email_check").val('Y');
					return false;


				}
			},
			error: function (rtnJson) {
				alert('이메일 중복확인을 실패했습니다.');
				return false;
			}
		});

	}

	// 휴대폰 인증
	function mobile_auth() {
		var mobile = $("#mobile1").val() + $("#mobile2").val() + $("#mobile3").val();
		if (checkMobile(mobile) == false) {
			alert("휴대폰번호를 확인해주세요.");
			return false;
		}
		window.open("/m/common/kmc_mobile_auth?mobile=" + mobile + "&type=member_join1");
	}

	// 보호자 모바일 인증
	function parent_mobile_auth() {
		if ($("#parent_mobile_company").val() == "") {
			alert("통신사를 선택해주세요. 입력해주세요.");
			return false;
		}

		var mobile = $("#parent_mobile").val();
		if (checkMobile(mobile) == false) {
			alert("휴대폰번호를 확인해주세요.");
			return false;
		}


		window.open("/m/common/kmc_mobile_auth?mobile=" + mobile + "&type=member_join2");
		// $('#kmc_mobile_auth')[0].contentWindow.kmc_window_open(mobile, 'member_join2');

	}


	function member_join_next() {
		if ($("#social_id").val() == "") {
			if ($("#member_id").val() == "") {
				alert("아이디를 입력해주세요.");
				return false;
			}

			if ($("#is_use_id").val() != "Y") {
				alert("아이디 중복확인을 해주세요.");
				return false;
			}


			if ($("#member_pwd").val() == "") {
				alert("비밀번호를 입력해주세요.");
				return false;
			}

			if ($("#re_member_pwd").val() == "") {
				alert("비밀번호를 확인을 입력해주세요.");
				return false;
			}

			if ($("#member_pwd").val() != $("#re_member_pwd").val()) {
				alert("비밀번호를 확인을 입력해주세요.");
				return false;
			}
		}

		if ($("#member_gender").val() == "") {
			alert("성별을 선택해주세요.");
			return false;
		}

		if ($("#birth_year").val() == "") {
			alert("출생연도를 선택해주세요.");
			return false;
		}

		if ($("#birth_month").val() == "") {
			alert("출생월을 선택해주세요.");
			return false;
		}

		if ($("#birth_day").val() == "") {
			alert("출생일을 선택해주세요.");
			return false;
		}

		if ($("#member_calendar").val() == "") {
			alert("양력/음력을 선택해주세요.");
			return false;
		}


		commonLayerClose('member_join3_layer');
		commonLayerOpen('member_join4_layer');
	}


	// 회원체크
	function member_join() {

		if ($("#social_id").val() == "") {
			if ($("#member_id").val() == "") {
				alert("아이디를 입력해주세요.");
				commonLayerClose('member_join4_layer');
				commonLayerOpen('member_join3_layer');
				return false;
			}

			if ($("#is_use_id").val() != "Y") {
				alert("아이디 중복확인을 해주세요.");
				commonLayerClose('member_join4_layer');
				commonLayerOpen('member_join3_layer');
				return false;
			}

			if ($("#member_pwd").val() == "") {
				alert("비밀번호를 입력해주세요.");
				commonLayerClose('member_join4_layer');
				commonLayerOpen('member_join3_layer');
				return false;
			}

			if ($("#re_member_pwd").val() == "") {
				alert("비밀번호를 확인을 입력해주세요.");
				commonLayerClose('member_join4_layer');
				commonLayerOpen('member_join3_layer');
				return false;
			}

			if ($("#member_pwd").val() != $("#re_member_pwd").val()) {
				alert("비밀번호를 확인을 입력해주세요.");
				commonLayerClose('member_join4_layer');
				commonLayerOpen('member_join3_layer');
				return false;
			}
		}

		if ($("#member_name").val() == "") {
			alert("이름을 입력해주세요.");
			commonLayerClose('member_join4_layer');
			commonLayerOpen('member_join3_layer');
			return false;
		}

		if ($("#member_gender").val() == "") {
			alert("성별을 선택해주세요.");
			commonLayerClose('member_join4_layer');
			commonLayerOpen('member_join3_layer');
			return false;
		}

		if ($("#birth_year").val() == "") {
			alert("출생연도를 선택해주세요.");
			commonLayerClose('member_join4_layer');
			commonLayerOpen('member_join3_layer');
			return false;
		}

		if ($("#birth_month").val() == "") {
			alert("출생월을 선택해주세요.");
			commonLayerClose('member_join4_layer');
			commonLayerOpen('member_join3_layer');
			return false;
		}

		if ($("#birth_day").val() == "") {
			alert("출생일을 선택해주세요.");
			commonLayerClose('member_join4_layer');
			commonLayerOpen('member_join3_layer');
			return false;
		}

		if ($("#member_calendar").val() == "") {
			alert("양력/음력을 선택해주세요.");
			commonLayerClose('member_join4_layer');
			commonLayerOpen('member_join3_layer');
			return false;
		}

		var email = $("#email1").val() + '@' + $("#email2").val();
		if (checkEmail(email) == false) {
			alert("이메일을 확인해주세요.");
			return false;
		}

		if ($("#email_check").val() != 'Y') {
			alert("이메일 중복확인해주세요.");
			return false;
		}


		var mobile = $("#mobile1").val() + $("#mobile2").val() + $("#mobile3").val();
		if (checkMobile(mobile) == false) {
			alert("휴대폰번호를 확인해주세요.");
			return false;
		}

		if ($("#is_mobile_auth").val() != "Y") {
			alert("휴대폰 본인인증을 해주세요.");
			return false;
		}

		if ($("#mobile_CI").val() == "") {
			alert("휴대폰 본인인증을 해주세요.");
			return false;
		}

		if ($("#member_name").val() == "") {
			alert("휴대폰 본인인증한 이름이 없습니다.");
			return false;
		}


		<?
		if($arr_member_setting_list[9]['is_required'] == 'Y'){
		?>
		if ($("#member_img").val() == "") {
			alert("프로필을 등록해주세요.");
			return false;
		}
		<?
		}

		for($i = 10;$i <= 15;$i++) {
		if($arr_member_setting_list[$i]['is_required'] == 'Y'){
		?>
		if ($("#<?=$arr_member_setting_list[$i]['item_field_name']?>").val() == '') {
			alert("<?=$arr_member_setting_list[$i]['item_title']?>을 입력해주세요.");
			return false;
		}
		<?
		}
		}

		?>
		$('#join_form').submit();

	}


	// 14세 미만 회원가입
	function under14_member_join() {
		if ($("#is_under14").val() == 'N') {
			alert("잘못된 경로로 가입을 하셨습니다.");
			join_reset();

			commonLayerClose('member_join3_layer');
			commonLayerOpen('member_join2_layer');
			return false;
		}
		if ($("#social_id").val() == "") {
			if ($("#member_id").val() == "") {
				alert("아이디를 입력해주세요.");
				return false;
			}

			if ($("#is_use_id").val() != "Y") {
				alert("아이디 중복확인을 해주세요.");
				return false;
			}

			if ($("#member_pwd").val() == "") {
				alert("비밀번호를 입력해주세요.");
				return false;
			}

			if ($("#re_member_pwd").val() == "") {
				alert("비밀번호를 확인을 입력해주세요.");
				return false;
			}

			if ($("#member_pwd").val() != $("#re_member_pwd").val()) {
				alert("비밀번호를 확인을 입력해주세요.");
				return false;
			}
		}


		if ($("#member_gender").val() == "") {
			alert("성별을 선택해주세요.");
			return false;
		}

		if ($("#birth_year").val() == "") {
			alert("출생연도를 선택해주세요.");
			return false;
		}

		if ($("#birth_month").val() == "") {
			alert("출생월을 선택해주세요.");
			return false;
		}

		if ($("#birth_day").val() == "") {
			alert("출생일을 선택해주세요.");
			return false;
		}

		if ($("#member_calendar").val() == "") {
			alert("양력/음력을 선택해주세요.");
			return false;
		}

		if ($("#parent_name").val() == "") {
			alert("보호자 이름을 입력해주세요.");
			return false;
		}

		if ($("#parent_mobile_company").val() == "") {
			alert("통신사를 선택해주세요. 입력해주세요.");
			return false;
		}

		var mobile = $("#parent_mobile").val();
		if (checkMobile(mobile) == false) {
			alert("휴대폰번호를 확인해주세요.");
			return false;
		}

		if ($("#is_mobile_auth").val() != "Y") {
			alert("휴대폰 본인인증을 해주세요.");
			return false;
		}

		if ($("#mobile_CI").val() == "") {
			alert("휴대폰 본인인증을 해주세요.");
			return false;
		}

		if ($("#member_name").val() == "") {
			alert("이름을 입력해주세요.");
			return false;
		}

		var under14_member_email = $("#under14_member_email").val();
		if (checkEmail(under14_member_email) == false) {
			alert("이메일을 확인해주세요.");
			return false;
		}

		if ($("#email_check").val() != 'Y') {
			alert("이메일 중복확인해주세요.");
			return false;
		}

		$("#under14_member_name").val($("#member_name").val());
		$('#join_form').submit();

	}


	// This is called with the results from from FB.getLoginStatus().
	function statusChangeCallback(response) {
		if (response.status === 'connected') {
			FB.api('/me', function (response) {
				if (response.id != '') {
					var form_data = {
						"id": response.id,
						"name": response.name
					};
					$.ajax({
						url: '/web/share/facebook_login_proc',
						async: false,
						type: 'POST',
						dataType: 'JSON',
						data: form_data,
						success: function (rtnJson) {
							if (rtnJson.code == "0000") {
								window.location.reload();
							} else {
								alert("페이스북 로그인에 실패했습니다.");
								return false;
							}

						},
						error: function (rtnJson) {
							return false;
						}
					});
				}


			});
		}
	}

	function checkLoginState() {
		window.FB.login(function (response) {
			console.log(response);
			if (response.status === 'connected') {
				statusChangeCallback(response);
			}
		});
	}


	window.fbAsyncInit = function () {
		FB.init({
			appId: '961578337335000',
			cookie: true,  // enable cookies to allow the server to access
			xfbml: true,  // parse social plugins on this page
			version: 'v2.8' // use graph api version 2.8
		});
	};
	// Load the SDK asynchronously
	(function (d, s, id) {
		var js, fjs = d.getElementsByTagName(s)[0];
		if (d.getElementById(id)) return;
		js = d.createElement(s);
		js.id = id;
		js.src = "https://connect.facebook.net/en_US/sdk.js";
		fjs.parentNode.insertBefore(js, fjs);
	}(document, 'script', 'facebook-jssdk'));


</script>
