﻿var FindIdPw = {

    IdValidate: function () {

        var frm = document.frmMain;

        if (!NTO.isCheckInput(frm.txtNameFindID.value)) {
            alert("이름을 입력해 주시기 바랍니다.");
            frm.txtNameFindID.value = '';
            frm.txtNameFindID.focus();
            return false;
        }


        if (!NTO.isCheckInput(frm.txtJuminNo1FindID.value) || !NTO.isCheckInput(frm.txtJuminNo2FindID.value)) {
            alert("주민등록번호를  입력해 주시기 바랍니다.");
            frm.txtJuminNo1FindID.focus();
            return false;
        }

        if (!NTO.isCheckResidentNo(frm.txtJuminNo1FindID.value, frm.txtJuminNo2FindID.value)) {
            alert("올바른 주민등록번호가 아닙니다. 다시 입력해 주시기 바랍니다.");
            frm.txtJuminNo1FindID.focus();
            frm.txtJuminNo1FindID.value = '';
            frm.txtJuminNo2FindID.value = '';
            return false;
        }
    },

    PwValidate: function () {

        var frm = document.frmMain;

        if (!NTO.isCheckInput(frm.txtIDFindPW.value)) {
            alert("아이디를 입력해 주시기 바랍니다.");
            frm.txtIDFindPW.value = '';
            frm.txtIDFindPW.focus();
            return false;
        }

        if (!NTO.isCheckInput(frm.txtNameFindPW.value)) {
            alert("이름을 입력해 주시기 바랍니다.");
            frm.txtNameFindPW.value = '';
            frm.txtNameFindPW.focus();
            return false;
        }


        if (!NTO.isCheckInput(frm.txtJuminNo1FindPW.value) || !NTO.isCheckInput(frm.txtJuminNo2FindPW.value)) {
            alert("주민등록번호를  입력해 주시기 바랍니다.");
            frm.txtJuminNo1FindPW.focus();
            return false;
        }

        if (!NTO.isCheckResidentNo(frm.txtJuminNo1FindPW.value, frm.txtJuminNo2FindPW.value)) {
            alert("올바른 주민등록번호가 아닙니다. 다시 입력해 주시기 바랍니다.");
            frm.txtJuminNo1FindPW.focus();
            frm.txtJuminNo1FindPW.value = '';
            frm.txtJuminNo2FindPW.value = '';
            return false;
        }
    }
}


var Login = {

    Validate: function () {

        var frm = document.frmMain;

        if (!NTO.isCheckInput(frm.txtID.value)) {
            alert('아이디를 입력해 주시기 바랍니다.');
            frm.txtID.value = "";
            frm.txtID.focus();
            return false;
        }
        if (!NTO.isCheckInput(frm.txtPW.value)) {
            alert('비밀번호를 입력해 주시기 바랍니다.');
            frm.txtPW.value = "";
            frm.txtPW.focus();
            return false;
        }
    }

}

var _UserMode = true;
var _RegistMode = true;

var permitID = /^[a-zA-Z0-9]{4,12}$/;
var permit = /^[a-zA-Z0-9]{4,12}$/;
var permit2 = /[0-9]/;
var permit3 = /[a-zA-Z]/;

var Join = {

    CheckID: function (str) {
        if (!permit.test(str)) {
            return false;
        } else {
            return true;
        }
    },

    CheckIDPW: function (str) {
        if (!permit.test(str)) {
            return false;
        } else {
            return true;
        }
    },

    GoMail: function () {
        var ddlEmailDomain = document.getElementById("ddlEmailDomain");
        var txtEmailDomain = document.getElementById("txtEmailDomain");
        if (ddlEmailDomain.value == 'etc') {
            txtEmailDomain.style.display = '';
            txtEmailDomain.value = '';
            txtEmailDomain.readOnly = false;
            txtEmailDomain.focus();
        }
        else {
            txtEmailDomain.style.display = 'none';
            txtEmailDomain.value = ddlEmailDomain.value;
        }
    },

    PhoneCode: function (value) {
        if (value == "") {
            frm.txtPhone1.value = "";
            frm.txtPhone2.value = "";

        }
        else {
            frm.txtPhone1.focus();
        }
    },

    GoJob: function () {
        var ddlJob = document.getElementById("ddlJob");
        if (ddlJob.value == '대학생' || ddlJob.value == '대학원생') {
            divCollege.style.display = '';
            document.frmMain.txtCollege.value = '';
            document.frmMain.txtMajor.value = '';
            document.frmMain.txtCollege.focus();
        }
        else {
            divCollege.style.display = 'none';
            document.frmMain.txtCollege.value = '';
            document.frmMain.txtMajor.value = '';
        }
    },


    Validate: function () {

        var isRegist = true;

        var frm = document.frmMain;

        if (_UserMode) {
            if (_RegistMode) {
                //  아이디
                if (Join.CheckID(frm.txtID.value) == false) {
                    alert("아이디는 4자리에서 12자리로 된 영,숫자로만 신청이 가능합니다.");
                    return false;
                }
            }
        }

        if (_UserMode) {
            //  비밀번호
            if (!NTO.isValidateEmpty(frmMain.txtPW, "비밀번호를 입력하십시오.")) return false;

            if (Join.CheckIDPW(frm.txtPW.value) == false) {
                alert("비밀번호는 영,숫자 4자에서 12자 이내 입니다.");
                frm.txtPW.focus();
                return false;
            }
        }


        //        if (fnCheckPassContinue('', frmMain.txtPW.value) == false) {
        //            alert('비밀번호는 연속된 4자 이상의 글자는 사용하실 수 없습니다.');
        //            frmMain.txtPW.focus();
        //            return false;
        //        }

        //        if (fnCheckPassSame(frmMain.txtPW.value) == false) {
        //            alert('비밀번호는 동일한 글자를 4자 이상 연속하여 사용하실 수 없습니다.');
        //            frmMain.txtPW.focus();
        //            return false;
        //        }

        //        if (frmMain.txtPW.value.indexOf(frmMain.txtID.value.substring(0, 4)) != -1) {
        //            alert('비밀번호는 ID와 4자 이상 중복될 경우 사용하실 수 없습니다.');
        //            frmMain.txtID.focus();
        //            return false;
        //        }

        //        if (fnCheckPassContinue(frmMain.hidUserSN.value.substring(0, 6), frmMain.txtPW.value) == false || fnCheckPassContinue(frmMain.hidUserSN.value.substring(6, 13), frmMain.txtPW.value) == false) {
        //            alert('비밀번호는 주민등록번호 앞, 뒷자리와 4자리 이상 중복될 경우 사용하실 수 없습니다.');
        //            frmMain.txtPW.focus();
        //            return false;
        //        }

        if (_UserMode) {
            if (_RegistMode) {
                if (!NTO.isValidateEmpty(frmMain.txtPWConfirm, "비밀번호 확인을 입력하십시오.")) return false;

                if (frm.txtPW.value != frm.txtPWConfirm.value) {
                    alert('비밀번호와 비밀번호 확인이 다릅니다.');
                    frm.txtPW.value = "";
                    frm.txtPWConfirm.value = "";
                    frm.txtPW.focus();
                    return false;
                }
            }
            else {
                if (frm.txtPWNew.value != frm.txtPWNewConfirm.value) {
                    alert('비밀번호와 비밀번호 확인이 다릅니다.');
                    frm.txtPWNew.value = "";
                    frm.txtPWNewConfirm.value = "";
                    frm.txtPWNew.focus();
                    return false;
                }

            }
        }





        //  이메일
        if (!NTO.isCheckInput(frm.txtEmailID.value)) {
            alert("이메일주소를 입력해 주시기 바랍니다.");
            frm.txtEmailID.value = '';
            frm.txtEmailID.focus();
            return false;
        }

        if (!NTO.isCheckMail(frmMain.txtEmailID.value + "@" + frmMain.txtEmailDomain.value)) {
            alert("입력하신 이메일 주소 형식이 올바르지 않습니다.");
            frm.txtEmailID.value = '';
            frm.txtEmailDomain.value = '';
            return false;
        }

        //  우편번호
        if (!NTO.isCheckInput(frm.txtZipCode1.value) || !NTO.isCheckInput(frm.txtZipCode2.value)) {
            alert("우편번호 찾기를 클릭하여 주소를 선택해 주시기 바랍니다.");
            return false;
        }

        //  상세주소
        if (!NTO.isCheckInput(frm.txtAddress.value) || !NTO.isCheckInput(frm.txtAddressDetail.value)) {
            alert("주소를 입력해 주시기 바랍니다.");
            frm.txtAddressDetail.value = '';
            frm.txtAddressDetail.focus();
            return false;
        }

        //  핸드폰
        if (frm.cboHPCode.selectedIndex == 0) {
            alert("전화번호 국번을 선택해 주시기 바랍니다.");
            frm.cboHPCode.focus();
            return false;
        }

        if (!NTO.isCheckInput(frm.txtHP1.value) || !NTO.isNumeric(frm.txtHP1.value)) {
            alert("올바른 핸드폰 번호를 입력해 주시기 바랍니다. ");
            frm.txtHP1.focus();
            return false;
        }

        if (!NTO.isCheckInput(frm.txtHP2.value) || !NTO.isNumeric(frm.txtHP2.value)) {
            alert("올바른 핸드폰 번호를 입력해 주시기 바랍니다. ");
            frm.txtHP2.focus();
            return false;
        }

        //  전화번호
        if (frm.cboPhoneCode.selectedIndex == 0) {
            alert("전화번호 국번을 선택해 주시기 바랍니다.");
            frm.cboPhoneCode.focus();
            return false;
        }

        if (!NTO.isCheckInput(frm.txtPhone1.value) || !NTO.isNumeric(frm.txtPhone1.value)) {
            alert("올바른 전화번호를 입력해 주시기 바랍니다. ");
            frm.txtPhone1.focus();
            return false;
        }
        if (!NTO.isCheckInput(frm.txtPhone2.value) || !NTO.isNumeric(frm.txtPhone2.value)) {
            alert("올바른 전화번호를 입력해 주시기 바랍니다. ");
            frm.txtPhone2.focus();
            return false;
        }

        //  직업
        if (frm.ddlJob.selectedIndex == 0) {
            alert("직업을 선택해 주시기 바랍니다.");
            frm.ddlJob.focus();
            return false;
        }

        if (frm.ddlJob.selectedIndex == 1 || frm.ddlJob.selectedIndex == 2) {
            if (!NTO.isCheckInput(frm.txtCollege.value)) {
                alert("학교명을 입력해 주시기 바랍니다.");
                frm.txtCollege.value = '';
                frm.txtCollege.focus();
                return false;
            }
            if (!NTO.isCheckInput(frm.txtMajor.value)) {
                alert("학과(학부)를 입력해 주시기 바랍니다.");
                frm.txtMajor.value = '';
                frm.txtMajor.focus();
                return false;
            }

        }




        //  참여여부
        var isCheck = false;

        for (var i = 0; i < document.frmMain.rdoHistory.length; i++) {
            if (document.frmMain.rdoHistory[i].checked) {
                isCheck = true;
                break;
            }
        }

        if (!isCheck) {
            alert("참여여부 항목을 선택해주십시오.");
            return false;
        }

        //  공모전 알게된 경로
        isCheck = false;
        for (var i = 0; i < document.frmMain.rdoRoute.length; i++) {
            if (document.frmMain.rdoRoute[i].checked) {
                isCheck = true;
                break;
            }
        }

        if (!isCheck) {
            alert("공모전 알게된 경로를 선택해주십시오.");
            return false;
        }

        if (frm.rdoRoute9.checked) {
            if (!NTO.isCheckInput(frm.txtRouteContent.value)) {
                alert("공모전을 알게된 경로 기타내용을 입력해 주십시오.");
                frm.txtRouteContent.focus();
                return false;
            }
        }


        isCheck = false;
        for (var i = 0; i < document.frmMain.rdoReason.length; i++) {
            if (document.frmMain.rdoReason[i].checked) {
                isCheck = true;
                break;
            }
        }

        if (!isCheck) {
            alert("홈페이지 가입이유를 선택해 주십시오.");
            return false;
        }

        //  홈페이지 가입이유
        if (frm.rdoReason3.checked) {
            if (!NTO.isCheckInput(frm.txtReason.value)) {
                alert("홈페이지 가입이유의 기타내용을 입력해 주십시오.");
                frm.txtReason.focus();
                return false;
            }
        }



        if (isRegist) {
            isRegist = false;
            //            frmMain.target = "";
            //            frmMain.action = "./Regist.aspx";
        }
        else {
            alert("처리중입니다. 잠시만 기다려 주십시오.");
            return false;
        }


    }
}

var Secession = {
    Validate : function(){
        isCheck = false;
        for (var i = 0; i < document.frmMain.rdoReason.length; i++) {
            if (document.frmMain.rdoReason[i].checked) {
                isCheck = true;
                break;
            }
        }

        if (!isCheck) {
            alert("탈퇴 이유를 선택해 주십시오.");
            return false;
        }
    }
}
var n = false;
var Event = {
   
    CommentClick: function () {   
        if (n) return;
        $('#txtContent').val("");
        n = true;

    },

    ScrabCopy: function () {

        var contentsIn = '<div style="display:none;">쟈뎅 제 3회 까페모리 컵 공모전</div>' +
        '<div style="width:1px; height:1px;overflow: hidden;">쟈뎅 제 3회 까페모리 컵 공모전</div>' +
        '<table width="590" border="0" cellspacing="0" cellpadding="0">' +
			'<tr> ' +
				'<td><a href="http://www.cafemoriidea.co.kr/Event/Scrab/List.aspx" target="_blank"><img src="http://www.cafemoriidea.co.kr/Image/evt_i01_.jpg" border="0" alt="제3회쟈뎅까페모리컵공모전" width="590" height="267" /></a></td>' +
			'</tr>' +
            '<tr> ' +
				'<td><a href="http://www.cafemoriidea.co.kr/Overview/Outline.aspx" target="_blank"><img src="http://www.cafemoriidea.co.kr/Image/evt_i02_.jpg" border="0" alt="제3회쟈뎅까페모리컵공모전" width="590" height="716" /></a></td>' +
			'</tr>' +
		'</table>';

        window.clipboardData.setData('Text', contentsIn);
        alert("글 내용이 클립보드에 복사되었습니다. \n이벤트 내용을 올리고자 하는 게시판에서, 게시글 작성 시 html 모드로 체크하시고, \nCtrl + V 하셔서 붙여넣기 하세요! ");
    },

    EvaluationValidate: function () {
        var frm = document.frmMain;
        var str = document.getElementById("txtContent").value
        if (!NTO.isCheckInput(str)) {
            alert("내용을 입력하세요");
            return false;
        }

        var intLimit = 200;

        if (NTO.ContentLimit(intLimit, str)) {
            alert("입력하신 글자수가 " + intLimit + "자가 넘어\n\n더 이상 내용을 입력할 수 없습니다.");
            return false;
        }
    },

    ScrabValidate: function () {
        var frm = document.frmMain;
        var str = document.getElementById("txtContent").value
        if (!NTO.isCheckInput(str)) {
            alert("내용을 입력하세요");
            return false;
        }

        var intLimit = 200;

        if (NTO.ContentLimit(intLimit, str)) {
            alert("입력하신 글자수가 " + intLimit + "자가 넘어\n\n더 이상 내용을 입력할 수 없습니다.");
            return false;
        }

    }

}

var _Org = true;

var Apply =
{
    CategoryClick: function (intCategory) {

        if (intCategory == 3 || intCategory == 4) {
            _Org = false;
            document.all.OrgFile.style.display = "none";

        }
        else {
            _Org = true;
            document.all.OrgFile.style.display = "";
        }

    },
    Validate: function () {

        var frm = document.frmMain;

        if (!NTO.isCheckInput(frm.txtTitle.value)) {
            alert("작품명을 입력해 주시기 바랍니다.");
            frm.txtTitle.focus();
            return false;
        }

        if (_Org) {
            if (NTO.isCheckInput(frm.FileUploadSingleContainer_arrFilePath.value) && !NTO.isCheckInput(frm.FileUploadSingleContainer2_arrFilePath2.value)) {
                alert("이미지 파일을 업로드해 주시기 바랍니다.");
                return false;
            }
        }


        if (!NTO.isCheckInput(frm.FileUploadSingleContainer2_arrFilePath2.value)) {
            alert("이미지 파일을 업로드해 주시기 바랍니다.");
            return false;
        }


        if (!NTO.isCheckInput(frm.txtContent.value)) {
            alert("작품설명을 입력해 주시기 바랍니다.");
            frm.txtContent.focus();
            return false;
        }
    }
}
