<!doctype html>
<html lang="ko">

<head>
    <meta charset="utf-8">
    <meta name="naver-site-verification" content="894ba0807460988349b1e131377b26966e347fc1" />
    <meta name="google-site-verification" content="CitaOJM4btglyBtNxZFYymBBzh3g7Pb9PxKl9YF8jDg" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="viewport"
        content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta property="fb:app_id" content="961578337335000" />
    <meta property="og:type" content="website" />
    <meta property="og:url" content="<?php echo BASE_URL ?>/user/register" />
    <meta property="og:title" content="크로스맵 (회원가입) - 기독교 종합 포털" />
    <meta property="og:description" content="크로스맵은 일상 속에서 은혜를 구하는 크리스천을 위한 기독교 종합 포털사이트입니다." />
    <meta property="og:image" content="https://crossmap.co.kr" />
    <meta name="description" content="크로스맵은 일상 속에서 은혜를 구하는 크리스천을 위한 기독교 종합 포털사이트입니다.">
    <meta name="keywords" content="크로스맵 회원가입">
    <title>크로스맵 (로그인) - 기독교 종합 포털</title>
    <link rel="shortcut icon" href="<?php echo THEME_FOLDER; ?>/img/shortcut_icon.png">
    <link rel="apple-touch-icon" href="<?php echo THEME_FOLDER; ?>/img/shortcut_icon.png">
    <link rel="apple-touch-startup-image" href="<?php echo THEME_FOLDER; ?>/img/shortcut_icon.png">
    <link rel="shortcut icon" href="<?php echo THEME_FOLDER; ?>/img/favicon.ico" type="image/x-icon" />

    <!-- css -->
    <link rel="stylesheet" href="<?php echo THEME_FOLDER; ?>/css/main.css">
    <link rel="stylesheet" href="<?php echo THEME_FOLDER; ?>/css/popup.css">
    <!-- Font -->
    <link href="https://fonts.googleapis.com/css?family=Nanum+Gothic" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Nanum+Myeongjo" rel="stylesheet">
    <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

    <script src="<?php echo THEME_FOLDER; ?>/js/jquery-3.3.1.min.js"></script>
    <script src="<?php echo THEME_FOLDER; ?>/js/common.js"></script>
    <script src="<?php echo THEME_FOLDER; ?>/js/jquery.vticker.min.js"></script>
    <style>
    .cm-register-step,
    .cm-register-loading {
        display: none
    }

    .cm-register-step.step-0 {
        display: block
    }


    @keyframes spinner {
        to {
            transform: rotate(360deg);
        }
    }

    .spinner:before {
        content: '';
        box-sizing: border-box;
        position: absolute;
        top: 50%;
        left: 50%;
        width: 100px;
        height: 100px;
        margin-top: -10px;
        margin-left: -10px;
        border-radius: 50%;
        border: 2px solid #ccc;
        border-top-color: #000;
        animation: spinner .6s linear infinite;
    }
    </style>
</head>

<body>
    <iframe id="kmc_mobile_auth" src="/user/mobile_auth"
        style="width:0px;height:0px;position:absolute; top:0; left:-9999px;"></iframe>
    <iframe id="m_kmc_mobile_auth" src="/user/mobile_auth"
        style="width:0px;height:0px;position:absolute; top:0; left:-9999px;"></iframe>
    <?php $this->load->view('templates/register/register-select') ?>
    <?php $this->load->view('templates/register/register-terms') ?>
    <?php $this->load->view('templates/register/register-form') ?>
    <?php $this->load->view('templates/register/register-confirm') ?>

    <div class="cm-register-loading">
    </div>

    <script>
    $(function() {
        $('#email_select').on('change', function(each) {
            $('#email2').val($(this).val());
        })
        $('.cm-register-loading').addClass('spinner');
        var isUserNameChecked = false;
        var isEmailChecked = false;
        var checkForward = [
            function() {
                return true;
            },
            function() {
                if ($("#agree1").is(":checked") == false) {
                    alert("서비스 이용약관 동의를 해주세요.");
                    return false;
                }
                if ($("#agree2").is(":checked") == false) {
                    alert("개인정보 취급방침 동의를 해주세요.");
                    return false;
                }
                if ($("#agree3").is(":checked") == false) {
                    alert("개인정보 수집 및 이용 동의를 해주세요.");
                    return false;
                }
                return true;
            },
            function() {
                if ($("#member_id").val() == "") {
                    alert("아이디를 입력해주세요.");
                    return false;
                }
                var regexp = /^[a-zA-Z0-9_-]{5,20}$/;
                if (!regexp.test($("#member_id").val())) {
                    alert("아이디는 5~20자의 영문 대 소문자, 숫자와 (_),(-)만 사용 가능합니다.");
                    return false;
                }

                if (!isUserNameChecked) {
                    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;
                }
                return true;
            },
            function() {
                return true;
            }
        ]
        $('.cm-register-nav-next').on('click', function() {
            var step = 0;
            for (var i = 0; i < 4; i++) {
                if ($(this).closest('.cm-register-step').hasClass('step-' + i)) {
                    step = i;
                    break;
                }
            }
            if (checkForward[step]()) {
                $('.cm-register-step').hide();
                $('.cm-register-step.step-' + (step + 1)).length ?
                    $('.cm-register-step.step-' + (step + 1)).show() : function() {
                        $('.cm-register-loading').show();                        
                        var params = {
                            'userName': $('.step-2').find('input[name=member_id]').val(),
                            'password': $('.step-2').find('input[name=member_pwd]').val(),
                            'gender' : $("#member_gender").val() == "1" ? 'M' : 'F',
                            'birthday': $("#birth_year").val()+'-'+$("#birth_month").val()+'-'+$("#birth_day").val(),
                            'birth_cal': $("#member_calendar").val() == '1' ? 'S':'M',
                            'email' : $('.step-3').find('#email1').val()+'@'+$('.step-3').find('#email2').val(),
                            'e1':$.trim($('.step-3').find('#email1').val()),
                            'e2':$.trim($('.step-3').find('#email2').val()),
                            'mobile':$('#country_phone_no').val()+' '+$('#mobile1').val()+'-'+$('#mobile2').val()+'-'+$('#mobile3').val(),
                            'm1':$.trim($('#mobile1').val()), 
                            'm2':$.trim($('#mobile2').val()), 
                            'm3':$.trim($('#mobile3').val()), 
                            'church':$('#member_church').val()+' ^ '+$('#etc1').val()+' ^ '+$('#etc2').val()
                        }
                        if(!params.e1 || !params.e2) {
                            $('.cm-register-loading').hide();   
                            $('.cm-register-step.step-' + step).show();                     
                            alert('이메일을 입력해주세요');                            
                            return false;
                        }else if(!params.m1 || !params.m2 || !params.m3) {
                            $('.cm-register-loading').hide();   
                            $('.cm-register-step.step-' + step).show();                    
                            alert('모바일폰 번호를 입력해주세요');                            
                            return false;
                        } 
                        $.post('/user/submit', params, function(res) {
                            if (res.code == 200) {
                                alert('회원가입이 완료되었습니다. 홈페이지로 이동합니다.');
                                location.href="/";
                            } else {
                                alert('서버 요청중 오류가 발생했습니다. 잠시후 다시 시도해주세요.');
                            }
                        }, 'json');
                    }();
            }
        })
        $('.cm-register-nav-prev').on('click', function() {
            $('.cm-register-step').hide();
            var step = 0;
            for (var i = 0; i < 5; i++) {
                if ($(this).closest('.cm-register-step').hasClass('step-' + i)) {
                    step = i;
                    break;
                }
            }
            $('.cm-register-step.step-' + (step - 1)).show();
        });
        $('#agree').on('click', function() {
            $('#agree1,#agree2,#agree3').attr('checked', this.checked);
        });
        $('#agree1,#agree2,#agree3').on('click', function() {
            var agreeAll = -2;
            $('#agree1,#agree2,#agree3').each(function(i, el) {
                if ($(el).get(0).checked) agreeAll++;
            })
            $('#agree').get(0).checked = agreeAll > 0;
        });

        $('.cm-verify-username').on('click', function() {
            isUserNameChecked = false;
            var userName = $('.cm-register-step.step-2').get(0).member_id.value;
            if (!userName) {
                alert("아이디를 입력해주세요.");
                return false;
            }
            var regexp = /^[a-zA-Z0-9_-]{5,20}$/;
            if (!regexp.test(userName)) {
                alert("아이디는 5~20자의 영문 대 소문자, 숫자와 (_),(-)만 사용 가능합니다.");
                return false;
            }
            $.get('/user/check_username/' + userName, function(res) {
                if (res.code == 200) {
                    alert('사용가능한 아이디입니다.');
                    isUserNameChecked = true;
                } else {
                    alert('사용할수없는 아이디입니다.')
                }
            })
        }).prev().on('change', function() {
            isUserNameChecked = false;
        });

        $('.cm-verify-email').on('click', function(e) {
            isEmailChecked = false;
            var email1 = $('.cm-register-step.step-3').find('#email1').val();
            var email2 = $('.cm-register-step.step-3').find('#email2').val();
            if (!email1 || !email2) {
                alert("이메일 주소를 입력해주세요.");
                return false;
            }
            $.post('/user/check_email', {
                email: email1 + '@' + email2
            }, function(res) {
                if (res.code == 200) {
                    alert('사용가능한 이메일입니다.');
                    isEmailChecked = true;
                } else {
                    alert('사용할수없는 이메일입니다.')
                }
            })
        });

        $('.cm-gender-select').on('click', function() {
            $('.cm-gender-select').removeClass('btn-default_bb');
            $(this).addClass('btn-default_bb');
            $("#member_gender").val($(this).attr('id').replace('gender_', ''));
        })
    });

    // 만14세 체크
    function birth_change() {
        return true;
        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 mobile_auth(event) {
        event.preventDefault();
        var mobile = $("#mobile1").val() + $("#mobile2").val() + $("#mobile3").val();
        if (checkMobile(mobile) == false) {
            alert("휴대폰번호를 확인해주세요.");
            return false;
        }
        //스마트폰일 때 실행 될 스크립트
        if (navigator.userAgent.match(
                /Mobile|iP(hone|od)|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/
            )) {
            // $('#m_kmc_mobile_auth')[0].contentWindow.kmc_window_open(mobile, 'member_join1');
            window.open("/m/common/kmc_mobile_auth?mobile=" + mobile + "&type=member_join1");
        } else {
            $('#kmc_mobile_auth')[0].contentWindow.kmc_window_open(mobile, 'member_join1');
        }
    }

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

        var mobile = $("#parent_mobile").val();
        if (checkMobile(mobile) == false) {
            alert("휴대폰번호를 확인해주세요.");
            return false;
        }
        if (navigator.userAgent.match(
                /Mobile|iP(hone|od)|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/
            )) {
            // $('#m_kmc_mobile_auth')[0].contentWindow.kmc_window_open(mobile, 'member_join1');
            window.open("/m/common/kmc_mobile_auth?mobile=" + mobile + "&type=member_join2");
        } else {
            $('#kmc_mobile_auth')[0].contentWindow.kmc_window_open(mobile, 'member_join2');
        }
    }
    </script>

</body>

</html>