$(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 joinCompanyParams = {
            // 관리자정보
            loginId: $("#userId").val(),
            password: $("#password").val(),
            name: $("#name").val(),
            phone: _.replace($("#phone").val(), /\-/g, ''),
            birth: _.replace($("#birth").val(), /\-/g, ''),
            gender: $("#gender option:selected").val(),

            // 기업정보
            companyGbn: $("#companyGbn option:selected").val(),
            companyNm: $("#companyNm").val(),
            saupjaNo: _.replace($("#saupjaNo").val(), /\-/g, ''),
            ownerName: $("#ownerName").val(),
            telNo: _.replace($("#telNo").val(), /\-/g, ''),
            faxNo: _.replace($("#faxNo").val(), /\-/g, ''),
            companySiteUrl: $("#companySiteUrl").val(),
            addrM: $("#addrM").val(),
            addrD: $("#addrD").val(),
        };

        var joinAble = userService.joinCompanyCheckAll(joinCompanyParams);
        if (joinAble) {
            userService.joinCompanyRequest(joinCompanyParams);
        }

    })

    $('#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);
    });

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

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



