$(document).ready(function () {
    $("#userId").keyup(function () {
        userService.clearIdDuplicate();
    })
    $("#password").keyup(function () {
        userService.comparePasswordEquality($("#password").val(), $("#passwordConfirm").val());
    })
    $("#passwordConfirm").keyup(function () {
        userService.comparePasswordEquality($("#password").val(), $("#passwordConfirm").val());
    })
    $("#userIdDuplicateCheckBtn").click(function () {
        var userId = $("#userId").val();
        if (userService.checkLoginId(userId)) {
            userService.idDuplicateCheckRequest(userId);
        }
    })
    $("#joinBtn").click(function () {
        var joinParams = {
            loginId: $("#userId").val(),
            password: $("#password").val(),
            // email: $("#email").val(),
            name: $("#name").val(),
            phone: _.replace($("#phone").val(), /\-/g, ''),
            birth: _.replace($("#birth").val(), /\-/g, ''),
            gender: $("#gender option:selected").val()
        };

        var joinAble = userService.joinCheckAll(joinParams);
        if (joinAble) {
            userService.joinRequest(joinParams);
        }

    })
    $("#cancelBtn").click(function () {
        location.href = "/";
    })

    $('#authRequestBtn').click(function () {
        var phone = _.replace($("#phone").val(), /\-/g, '');
        var checkPhone = userService.checkPhone(phone);
        if (checkPhone) {
            userService.ajaxSmsSend(phone,function(){});
        }
    });

    $('#authCheckBtn').click(function () {
        var scb = function () {
            $('#joinAuthOk').show();
            $('#joinAuthNo').hide();
        };
        var ecb = function() {
            $('#joinAuthOk').hide();
            $('#joinAuthNo').show();
        };
        var phone = _.replace($("#phone").val(), /\-/g, '');
        userService.ajaxSmsCheck($('#phoneAuthKey').val(), phone, scb, ecb);
    });

    $('.terms').click(function () {
        $('#termsBack').show();
        $('#termsFront').show();
    });
    $('#termsCloseBtn').click(function () {
        $('#termsBack').hide();
        $('#termsFront').hide();
    });
});
