<?
$member_img			= $result['member_img'];
$member_name 		= $result['member_name'];
$member_id 			= $result['member_id'];
$member_nickname	= $result['member_nickname'];
$member_intro	 	= $result['member_intro'];
$member_birth 		= $result['member_birth'];
$member_calendar	= $result['member_calendar'];
$member_gender 		= $result['member_gender'];
$country_phone_no 	= $result['country_phone_no'];
$member_mobile 		= $result['member_mobile'];
$member_email 		= $result['member_email'];
$is_agree_sms 		= $result['is_agree_sms'];

$is_agree_mail 		= $result['is_agree_mail'];
$is_agree_info_open	= $result['is_agree_info_open'];
$member_edit_church	= $result['member_church'];
$etc1				= $result['etc1'];
$etc2				= $result['etc2'];
$mobile_CI			= $result['mobile_CI'];
$sns_type			= $result['sns_type'];
$is_under14			= $result['is_under14'];
$is_nickname = 'N';
if($member_nickname!='') 	$is_nickname = 'Y';
if($member_img == '') {
	$member_img = '/img/web/img_photo.png';
}
$member_id  = mb_substr($member_id, 0, 4).'****';

$member_birth1 = ''; $member_birth2 = ''; $member_birth3 = '';
if($member_birth!='') {
	$arr_birth = explode("-", $member_birth);
	$member_birth1 =  $arr_birth[0];
	$member_birth2 =  (int)$arr_birth[1];
	$member_birth3 =  (int)$arr_birth[2];
}

$member_calendar_txt = '';
if($member_calendar == 1) {
	$member_calendar_txt = '양력';
} if($member_calendar == 2) {
	$member_calendar_txt = '음력';
}

$member_gender_txt = '';
if($member_gender == 1) {
	$member_gender_txt = '남성';
} if($member_gender == 2) {
	$member_gender_txt = '여성';
}

$member_email_txt = '';
$member_mobile  = mb_substr($member_mobile, 1, 4).'***-***'.mb_substr($member_mobile, 12, 1);
if($member_email!='') {
	$arr_email = explode("@", $member_email);

	$email1 = mb_substr($arr_email[0], 0, 2).'******';
	$arr_email2 = explode(".", $arr_email[1]);
	$email2 = mb_substr($arr_email[1], 0, 1).'*******'.str_replace($arr_email2[0], '', $arr_email[1]);
	$member_email_txt = $email1.'@'.$email2;

}

$SES_MEMBER_ID              = $this->session->userdata('C_Member_Id');
?>







<form class="profile_forms2" id="input_form" name="input_form" action="/web/mypage/member_edit_proc" method="post"  enctype="multipart/form-data">
	<input type="hidden" name="is_nickname" id="is_nickname" value="<?=$is_nickname?>">
	<input type="hidden" name="is_mobile_auth_email" id="is_mobile_auth_email" value="N">
	<input type="hidden" name="org_profile_img" id="org_profile_img" value="<?=$member_img?>">

	<div class="mypage_top">
		<a href="/m/mypage/qna_add" class="pens"><img src="/img/mobile/penicon.png"></a>
		<div class="mypage_logo"><a href="/m"><img src="/img/mobile/logo_cm.jpg" alt="logo"></a>
		</div>
		<div class="mypage_title"><a href="/m/mypage/req_password">마이페이지</a>
		</div>
		<div class="mypage_menu"><a href=""><img src="/img/mobile/menu_list.gif" alt="menu"></a>
		</div>
	</div>
	<div class="account_header">
		<span class="header_tit"><a href="javascript:window.history.back(-1)"><img src="/img/mobile/arrow_account.gif"></a>프로필 수정</span>
		<span  class="fr save" style="padding-right:20px; padding-top:3px;"><a  onclick="member_edit_proc()" style="cursor:pointer">저장 </a></span>
	</div>
	<div class="account_cont account_cont_wrap">
		<div class="join_header">
			<span class="photo"><a href=""><img id="profile" style="max-width:77px;max-height:77px;" src="<?=$member_img?>"></a></span>
			<input type="file" id="member_img" name="member_img" style="position:absolute; top:0; left:-9999px;" onChange="readURL1(this)" />
			<label for="member_img"><div class="btn btn-default br15" style="color:black">사진 변경</div></label>
		</div>
		<div class="form-group"  style="margin-top:20px;">
			<label for="exampleInputEmail1">기본정보</label>
			<div class=" form_info" style="position: absolute;top: 10px;left: 100px;line-height:18px;color:#a7a7a7; font-size:13px;">이름변경은 PC버전에서만 가능합니다.</div>
			<span class="fixed"><?=$member_name?></span>
		</div>
		<div class="form-group">
			<div class="form_tit">아이디</div><div class=" form_info" style="position: absolute;top: 10px;left: 100px;line-height:18px;color:#a7a7a7; font-size:13px;">아이디는 변경이 불가합니다.</div>
			<span class="fixed"><?=$member_id?></span>
		</div>
		<div class="form-group">
			<div class="form_tit" style="height: 35px;">닉네임<div class=" form_info" style="position: absolute;top: 10px;left: 100px;line-height:18px;color:#a7a7a7; font-size:13px;">5~20자 이내 한글,영문,특수문자</div></div>
			<input type="id" class="form-control" placeholder="닉네임을 입력해 주세요." name="member_nickname" id="member_nickname" value="<?=$member_nickname?>">
			<span style="position:absolute; right:0; bottom:8px;"><a  href="javascript:nickname_overlab_check()"  class="btn btn-default_bb br10">중복확인</a></span>
		</div>
		<div class="form-group">
			<input type="text" name="member_intro" id="member_intro" value="<?=$member_intro?>" class="form-control" placeholder="한 줄 메세지 (20자이내)">
		</div>
		<div class="form-group">
			<div class="form_tit">성별</div>
			<span class="fixed" style="padding-left: 45%;"><?=$member_gender_txt?></span>
		</div>
		<div class="form-group">
			<div class="form_tit">생년월일</div>
			<span class="fixed" style="padding-left:60px;"><?=$member_birth1?><span style="color:#b7b7b7"> 년</span></span>
			<span class="fixed" style="padding-left:40px;"><?=$member_birth2?><span style="color:#b7b7b7"> 월</span></span>
			<span class="fixed" style="padding-left:40px;"><?=$member_birth3?><span style="color:#b7b7b7"> 일</span></span>
			<span class="fixed" style="padding-left:40px;"><span style="color:#b7b7b7"> <?=$member_calendar_txt?></span></span>
		</div>
		<div class="form-group"  style="margin-top:10px;">
			<label for="exampleInputEmail1">연락처</label>
			<div class="form_tit" style="height: 35px;">이메일<div class=" form_info" style="position: absolute;top: 10px;left: 70px; color:#a7a7a7; font-size:13px;">아이디, 비밀번호 찾기 등 본인확인이 필요한 경우 사용할 이메일 주소입니다.</div></div>
			<span class="fixed" id="member_email_txt" class="member_email_txt"><?=$member_email_txt?></span>


			<span style="position:absolute; right:0; bottom:8px;"><a  href="javascript:email_reset();commonLayerOpen('email_check_layer');" class="btn btn-default_bb br10">변경</a></span>
		</div>

		<div class="form-group" id="email_check_layer" style="display:none;margin-top:10px;">
			<div id="email_change_layer1">
				<div class="form-group2">
					<input type="text" name="now_email" id="now_email" style="width:400px;border:1px solid" class="form-control" placeholder="현재 이메일 주소 확인" >
				</div>
				<p class="red" id="email_check_error" style="display:none;padding-top:10px;">본인 확인 이메일을 정확하게 입력해 주세요.</p>
				<div style="margin-top:10px;">
					<? if($is_under14!='Y') {?><div class="form_tit" style="height: 10px;">휴대전화 인증으로도 이메일 수정이 가능합니다. <span class="b_login"><a href="javascript:member_email_mobile_auth()">휴대전화인증</a></span></div><?}?>
					<div class="form_wrap" style="border-bottom:0 !important">
						<div  class="form-group" style="margin:20px 0; display:block; text-align:center; border-bottom:0">
							<button type="button" class="btn btn-success br20" style="padding:7px 30px; font-size:16px" onclick="email_check();"><span class="current">확인</span></button>
							<button type="button" class="btn btn-default_bb br20" style="padding:7px 30px; font-size:16px; margin-left:5px " onclick="commonLayerClose('email_check_layer');">취소</button>
						</div>
					</div>
				</div>
			</div>
			<div id="email_change_layer2" style="display:none">
				<div class="form-group2">
					<input type="text" name="change_email" id="change_email" style="width:400px;border:1px solid" class="form-control" placeholder="변경할 이메일 주소" onkeypress="if( event.keyCode==13 ){email_edit();}">
				</div>
				<div style="margin-top:10px;">
					<div class="form_wrap" style="border-bottom:0 !important">
						<div  class="form-group" style="margin:20px 0; display:block; text-align:center; border-bottom:0">
							<button type="button" class="btn btn-success br20" style="padding:7px 30px; font-size:16px" onclick="email_edit();"><span class="current">변경</span></button>
							<button type="button" class="btn btn-default_bb br20" style="padding:7px 30px; font-size:16px; margin-left:5px " onclick="commonLayerClose('email_check_layer');">취소</button>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="form-group">
			<div class="form_tit" style="height: 45px;">모바일폰<div class=" form_info" style="position: absolute;top: 10px;left: 70px;line-height:15px;color:#a7a7a7; font-size:13px;">아이디, 비밀번호 찾기 등 본인확인이 필요한 경우 등에 크로스맵으로부터 알림을 받을 때 사용할 휴대전화입니다.</div></div>
			<span class="fixed" id="member_edit_text"><?=$country_phone_no?> <?=$member_mobile?></span>
			<? if($is_under14!='Y') {?><button type="button" class="btn btn-default_bb br10 fr"  onclick="commonLayerOpen('mobile_edit_layer');">변경</button><?}?>
		</div>
		<div id="mobile_edit_layer" class="form-group" style="display:none;margin-top:0px;">
			<div style="margin:0px 0 10px; height:30px">
								<span class="slct" style="width:50px;  margin-top:-2px;  height:30px;   margin-right:3px;">
									<select id="country_phone_no" name="country_phone_no" style=" height:30px;width:50px;">
										<option value="+82">+82 </option>
									</select>
								</span>
				<input type="text" name="member_edit_mobile" id="member_edit_mobile" class="form-control" placeholder="변경할 휴대전화번호 입력" style="width:58%; height:30px;  padding:0 2%;   border: 1px solid #adadad; border-radius:5px;">
				<span style="position:absolute;right:0px;top:8px;"><a type="button" class="btn btn-default_bb br10"  onclick="member_edit_mobile_auth();">인증<span class="caret"></span></a></span>
			</div>
			<div class="form_wrap" style="border-bottom:0 !important">
				<div class="form-group" style="margin:20px 0; display:block; text-align:center; border-bottom:0">
					<button type="button" class="btn btn-success br20" style="padding:7px 30px; font-size:16px"><span class="current">변경완료</span></button>
					<button type="button" onclick="javascript:commonLayerClose('mobile_edit_layer');" class="btn btn-default_bb br20" style="padding:7px 30px; font-size:16px; margin-left:5px ">취소</button>
				</div>
			</div>
		</div>
		<div class="form-group"  style="margin-top:10px;">
			<label for="exampleInputEmail1"> 수신동의</label>
			<div class="form_tit">이메일알림 수신동의 <span style="padding-left:20px;"><input value="Y"  name="is_agree_sms" id="is_agree_sms" type="checkbox" <? if($is_agree_sms=='Y') { echo 'checked';}?>>  이벤트 알림 등 (본인인증 제외) </span></span></div>
		</div>
		<div class="form-group">
			<div class="form_tit">SMS알림 수신동의 <span style="padding-left:30px;"><input value="Y"  name="is_agree_mail" id="is_agree_mail" type="checkbox" <? if($is_agree_mail=='Y') { echo 'checked';}?>> SMS알림 등 (본인인증 제외)</span></span></div>
		</div>
		<div class="form-group">
			<div class="form_tit">정보공개 동의 <span style="padding-left:55px;"><input value="Y" name="is_agree_info_open" id="is_agree_info_open" type="checkbox" <? if($is_agree_info_open=='Y') { echo 'checked';}?> > 정보를 공개합니다.</span></span></div>
		</div>
		<div style="margin-top:30px; text-align:center;">
			<span style=""><a href="/m/member/secession" class="btn btn-default_bb br3" style="padding:10px 10px; font-size:16px; margin-bottom:10px;">회원탈퇴 </a></span>
			<span style=""><a target="_blank" href="/m/rules/privacy" class="btn btn-default_bb br3" style="padding:10px 10px; font-size:16px; margin-bottom:10px; margin-left:5px;">개인정보 취급방침</a>
				<a target="_blank" href="/m/rules/service"  class="btn btn-default_bb br3" style="padding:10px 10px; font-size:16px; margin-bottom:10px; margin-left:5px;">이용약관 </a></span>
		</div>
		<div class="form-group"  style="margin-top:10px;">
			<label for="exampleInputEmail1">추가정보 (선택사항)</label>
			<div class="form_tit" style="height: 20px;">출석교회</div>
		</div>
		<div class="form-group"  style="border-bottom:0;">
			<input type="text" name="member_edit_church" id="member_edit_church" value="<?=$member_edit_church?>" placeholder="교회명"  style="width:30%; border-bottom:1px solid #ccc;margin-right:1%;">
			<input type="text" name="member_edit_etc1" id="member_edit_etc1" value="<?=$etc1?>" placeholder="지역(동)"  style="width:30%; border-bottom:1px solid #ccc;margin-right:1%;">
			<input type="text" name="member_edit_etc2" id="member_edit_etc2" value="<?=$etc2?>" placeholder="담임목사" style="width:30%; border-bottom:1px solid #ccc;">

		</div>
		<? 	if($sns_type=='') {?>
		<div class="form-group"  style="margin-top:10px;">
			<label for="exampleInputEmail1">비밀번호 변경</label>
			<div class="form-group">
				<input type="password" name="member_edit_password" id="member_edit_password" class="form-control" placeholder="현재 비밀번호" onkeydown="inputSendit();">
			</div>
			<div class="form-group">
				<div class="form_tit" style="height: 20px;">새 비밀번호<div class=" form_info" style="position: absolute;top: 10px;left: 100px;line-height:18px;color:#a7a7a7; font-size:13px;">6~16자 영문 대 소문자,숫자,특수문자를 사용하세요</div></div>
				<input type="password" name="member_edit_new_password" id="member_edit_new_password" class="form-control" placeholder="새로운 비밀번호 " style="margin-top:15px;" onkeydown="inputSendit();">
			</div>
			<div class="form-group">
				<input type="password" name="member_edit_new_password_re" id="member_edit_new_password_re" class="form-control" placeholder="새로운 비밀번호 재입력" onkeydown="inputSendit();">
			</div>
		</div>
		<?	}?>
		<div class="form_wrap" style="border-bottom:0 !important">
			<div  class="form-group" style="margin:20px 0; display:block; text-align:center; border-bottom:0">
				<button type="button" onclick="member_edit_proc()" class="btn btn-success br20" style="padding:7px 30px; font-size:16px"><span class="current">저장하기</span></button>
				<button type="button" onclick="window.location='/m/mypage'" class="btn btn-default_bb br20" style="padding:7px 30px; font-size:16px; margin-left:5px ">취소하기</button>
			</div>
		</div>
	</div>
	</div>
</form>

	<script src="js/jquery-1.11.3.min.js"></script>
	<script>
		$( document ).ready( function() {
			var jbOffseter = $( '.mypage_top' ).offset();
			$( window ).scroll( function() {
				if ( $( document ).scrollTop() > jbOffseter.top ) {
					$( '.mypage_top' ).addClass( 'fix' );
				}
				else {
					$( '.mypage_top' ).removeClass( 'fix' );
				}
			});
		} );
	//var topEle = $('#member_leave_btn');
	//topEle.on('click', function() {
	//	var popH = $(this).offset().top;
	//	commonLayerOpen('member_leave_step1_layer');
	//	$('#member_leave_step1_layer').css('top', popH+'px');
	//
	//});
	//
	//

	var topEle = $('#member_leave_btn');
	var delay = 100;
	topEle.on('click', function() {
		commonLayerOpen('member_leave_step1_layer');
		//$('html').stop().animate({scrollTop: 0}, delay);
	});


	function onchange_nickname(){
		$("#is_nickname").val('N');
	}



	// 프로필이미지 등록
	function readURL1(input) {
		if (input.files && input.files[0]) {
			var reader = new FileReader();
			reader.onload = function (e) {
				$("#profile").attr("src",e.target.result);
			}
			reader.readAsDataURL(input.files[0]);
		}
	}

	// 프로필삭제
	function profile_delete() {
		$("#profile").css("background","url('/img/web/img_photo.png') no-repeat center");
		$("#profile").css("background-size","cover");
		$("#member_img").val("");
		$("#org_profile_img").val("");

	}

	// 닉네임 중복확인
	function nickname_overlab_check(){
		if($("#member_nickname").val()==""){
			alert("닉네임을 입력해주세요.");
			return false;
		}

		if($("#member_nickname").val().length < 5 || $("#member_nickname").val().length > 20 ) {
			alert("닉네임은 5~20자 이내 한글,영문,특수문자만 가능합니다.");
			return false;
		}

		if(checkNumber($("#member_nickname").val())==true) {
			alert("닉네임은 5~20자 이내 한글,영문,특수문자만 가능합니다.");
			return false;
		}

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


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


	// 이메일 reset
	function email_reset(){
		$("#email_check_error").hide();
		$("#now_email").val('');
		$("#change_email").val('');
		$("#email_change_layer1").show();
		$("#email_change_layer2").hide();
		$("#is_mobile_auth_email").val('N');
	}

	// 현재 이메일 체크
	function email_check(){
		$("#email_check_error").hide();
		var email = $("#now_email").val();
		if(checkEmail(email)==false) {
			alert("이메일을 확인해주세요.");
			return false;
		}

		var form_data = {
			"email"     : email
		};
		$.ajax({
			url: '/web/member/member_my_email_check_proc',
			async: false,
			type: 'POST',
			dataType: 'JSON',
			data: form_data,
			success: function (rtnJson) {
				if (rtnJson.result_code != "0000") {
					$("#email_check_error").show();
					$("#is_mobile_auth_email").val('N');

					return false;
				} else {
					$("#email_change_layer2").show();
					$("#email_change_layer1").hide();
					$("#is_mobile_auth_email").val('Y');
					$("#now_email").val('');

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

	}


	// 휴대폰 인증
		function member_email_mobile_auth(){
			window.open("/m/common/kmc_mobile_auth?mobile=&type=email_check");
			//$('#kmc_mobile_auth')[0].contentWindow.kmc_window_open('', 'email_check');
		}

		function member_edit_mobile_auth(){
			var mobile = $("#member_edit_mobile").val();
			if(checkMobile(mobile)==false){
				alert("휴대폰번호를 확인해주세요.");
				return false;
			}
			window.open("/m/common/kmc_mobile_auth?mobile="+mobile+"&type=member_edit");
			//$('#kmc_mobile_auth')[0].contentWindow.kmc_window_open(mobile, 'member_edit');
		}



		function email_edit(){
		if($("#is_mobile_auth_email")=="N") {
			alert("이메일 인증에 실패했습니다.");
			return false;
		}

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

		console.log(email);
		var form_data = {
			"email"     : email
		};
		$.ajax({
			url: '/web/member/member_email_edit_proc',
			async: false,
			type: 'POST',
			dataType: 'JSON',
			data: form_data,
			success: function (rtnJson) {
				if (rtnJson.code == "0000") {
					alert("이메일이 변경되었습니다.");
					commonLayerClose('email_check_layer');
					$("#change_email").val('');
					$("#member_email_txt").html(rtnJson.data);
					$("#member_email_txt").html(rtnJson.data);
					return false;
				} else {
					alert("이메일이 변경이 실패되었습니다.");
					return false;
				}
			},
			error: function (rtnJson) {
				alert('이메일이 변경이 실패되었습니다.');
				return false;
			}
		});
	}


	function member_edit_proc(){
		if($("#member_nickname").val()!=""){
			if($("#is_nickname").val()=='N') {
				alert("닉네임 중복확인을 해주세요.");
				return false;
			}
		}

		if($("#member_edit_new_password").val()!="" || $("#member_edit_password").val()!="") {
			if($("#member_edit_password").val()=="") {
				alert("현재 비밀번호를 입력해주세요.");
				$("#member_edit_password").focus();
				return false;
			}
			if(member_pwd_valid_check($("#member_edit_new_password").val())==false) {
				alert("새로운 비밀번호를 6~16자 영문 대 소문자,숫자,특수문자로 입력해주세요.");
				$("#member_edit_new_password").focus();
				return false;
			}
			if($("#member_edit_password").val() == $("#member_edit_new_password").val()) {
				alert("현재 비밀번호와 새로운 비밀번호가 같습니다.");
				$("#member_edit_new_password").focus();
				return false;
			}
			if($("#member_edit_new_password_re").val()=="") {
				alert("새로운 비밀번호를 재입력해주세요.");
				$("#member_edit_new_password_re").focus();
				return false;
			}
			if($("#member_edit_new_password").val() != $("#member_edit_new_password_re").val()) {
				alert("재입력하신 새로운 비밀번호가 일치하지 않습니다.");
				$("#member_edit_new_password_re").focus();
				return false;
			}
		}



		$("#input_form").submit();


	}


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

		var form_data = {
			"member_pwd"     : $("#member_leave_chk_pwd").val()
		};
		$.ajax({
			url: '/web/member/member_pwd_check_proc',
			async: false,
			type: 'POST',
			dataType: 'JSON',
			data: form_data,
			success: function (rtnJson) {
				if (rtnJson.code == "0000") {
					commonLayerClose('member_leave_step1_layer');
					commonLayerOpen('member_leave_step2_layer');
					return false;
				} else {
					alert("비밀번호를 확인해주세요.");
					return false;
				}
			},
			error: function (rtnJson) {
				alert('비밀번호를 확인해주세요.');
				return false;
			}
		});
	}


	function member_leave_step3(){
		if($("#member_leave_agree").is(":checked")==false){
			alert("계정삭제 안내사항에 동의 해주세요.");
			return false;
		}
		commonLayerClose('member_leave_step2_layer');
		commonLayerOpen('member_leave_step3_layer');

	}

	function member_leave_proc(){
		if($("#member_leave_chk_pwd").val()==""){
			alert("잘못된 접근입니다.");
			location.href='/web/mypage/member_edit';
			return false;
		}

		if($("#member_leave_agree").is(":checked")==false){
			alert("잘못된 접근입니다.");
			location.href='/web/mypage/member_edit';
			return false;
		}

		var form_data = {
			"member_pwd"     : $("#member_leave_chk_pwd").val()
		};
		$.ajax({
			url: '/web/member/member_leave_proc',
			async: false,
			type: 'POST',
			dataType: 'JSON',
			data: form_data,
			success: function (rtnJson) {
				if (rtnJson.code == "0000") {
					commonLayerClose('member_leave_step3_layer');
					commonLayerOpen('member_leave_step4_layer');
					return false;
				} else {
					alert("탈퇴에 실패했습니다.");
					return false;
				}
			},
			error: function (rtnJson) {
				alert('탈퇴에 실패했습니다.');
				return false;
			}
		});
	}


	function inputSendit() {
		if (event.keyCode == 13) {
			member_edit_proc();
		}
	}

</script>
