﻿

    function UserNameCheck() {

        var Source, Result;

        Source = document.FormInput.UserName.value;
        Result = CheckRequireAndOverflow(Source, "RM", UserNameSize, "이름", "FOCUS", "UserName");

        if(Result != "") {
            return false;
        }

        return true;

    }





    function JuminNoCheck() {

        var Source, Result;

        Source = document.FormInput.JuminNo.value;
        Result = CheckRequireAndOverflow(Source, "M", JuminNoSize, "후원자 주민등록번호", "FOCUS", "JuminNo");

        if(Result != "") {
            return false;
        }


        return true;

    }





    function ContactInfoCheck() {

        var Source, Result;

        Source = document.FormInput.ContactInfo.value;
        Result = CheckRequireAndOverflow(Source, "RM", ContactInfoSize, "연락처", "FOCUS", "ContactInfo");

        if(Result != "") {
            return false;
        }

        return true;

    }





    function EmailAddressCheck() {

        var Target = document.FormInput;
        var Source = Target.EmailAddress.value;
        var Result;


        Result = CheckRequireAndOverflow(Source, "RM", EmailAddressSize, "이메일주소", "FOCUS", "EmailAddress");
        if(Result != "") {
            return false
        }

        if(!IsEmailAddress(Source)) {
            MessageOutput("올바른 [이메일주소]를 입력하세요.", "FOCUS", "EmailAddress");
            return false;
        }

        return true;

    }





    function AddressCheck() {

        var Target      = document.FormInput;
        var ZipCode     = Target.ZipCode.value;
        var AddressMain = Target.AddressMain.value;
        var AddressSub  = Target.AddressSub.value;
        var Result;


        if(IsEmpty(ZipCode+AddressMain+AddressSub)) {
            MessageOutput("[주소]를 입력하세요.", "", "");
            return false;
        }

        Result = CheckRequireAndOverflow(ZipCode,     "RM", ZipCodeSize,     "우편번호", "", "");
        if(Result != "") return false;

        if(!IsZipCode(ZipCode)) {
            MessageOutput("올바른 [우편번호]를 입력하세요.", "", "");
            return false;
        }


        Result = CheckRequireAndOverflow(AddressMain, "RM", AddressMainSize, "주소",     "", "");
        if(Result != "") return false;

        Result = CheckRequireAndOverflow(AddressSub,  "RM", AddressSubSize,  "주소",     "FOCUS", "AddressSub");
        if(Result != "") return false;

        return true;

    }





    function ContributionCheck() {

        var Source, Result;

        Source = document.FormInput.Contribution.value;
        Result = CheckRequireAndOverflow(Source, "RM", ContributionSize, "후원금액", "FOCUS", "Contribution");

        if(Result != "") {
            return false;
        }

        return true;

    }





    function AccountInfoCheck() {

        var Source, Result;

        Source = document.FormInput.ConAccountNo.value;
        Result = CheckRequireAndOverflow(Source, "M", AccountNoSize, "계좌번호", "FOCUS", "ConAccountNo");

        if(Result != "") {
            return false;
        }


        Source = document.FormInput.ConUserName.value;
        Result = CheckRequireAndOverflow(Source, "M", UserNameSize, "예금주 이름", "FOCUS", "ConUserName");

        if(Result != "") {
            return false;
        }


        Source = document.FormInput.ConJuminNo.value;
        Result = CheckRequireAndOverflow(Source, "M", JuminNoSize, "예금주 주민등록번호", "FOCUS", "ConJuminNo");

        if(Result != "") {
            return false;
        }


        return true;

    }





    function DonationDataCheck() {

        var Source;

        Source = document.FormInput.DonationTarget
        if(Source.selectedIndex <= 0) {
            alert("[후원대상] 항목을 선택하세요");
            Source.focus();
            return false;

        }

        Source = document.FormInput.DonationKind
        if(Source.selectedIndex <= 0) {
            alert("[후원기간] 항목을 선택하세요");
            Source.focus();
            return false;

        }
//        if(Source.selectedIndex != 2) return ContributionCheck();

        Source = document.FormInput.DonationWay
        if(Source.selectedIndex <= 0) {
            alert("[후원방식] 항목을 선택하세요");
            Source.focus();
            return false;

        }

        if(!ContributionCheck()) return false;

        if(Source.selectedIndex != 2) return true;


        return AccountInfoCheck();

    }





    function CommentCheck() {

        var Source, Result;

        Source = document.FormInput.Comment.value;
        Result = CheckRequireAndOverflow(Source, "M", CommentSize, "코멘트", "FOCUS", "Comment");

        if(Result != "") {
            return false;
        }

        return true;

    }





    function AuthAnswerCheck() {

        var Source, Result;

        Source = document.FormInput.AuthAnswer.value;
        Result = CheckRequireAndOverflow(Source, "RM", AuthAnswerSize, "인증답변", "FOCUS", "AuthAnswer");

        if(Result != "") {
            return false;
        }

        if( !IsInt(Source) ) {
            MessageOutput("[인증답변] 항목은 숫자만 입력 가능 합니다.", "FOCUS", "AuthAnswer");
            return false;
        }

        return true;

    }





    function InputDataCheck(AuthUseFlag) {

        if( !UserNameCheck()     || !JuminNoCheck() || !ContactInfoCheck() || !EmailAddressCheck() || !AddressCheck() ||
            !DonationDataCheck() || !CommentCheck() ) {
            return false;
        }

        if(AuthUseFlag) {
            if(!AuthAnswerCheck()) {
                return false;
            }

        }


        var ConfirmMessage = "입력하신 연락처 : " + document.FormInput.ContactInfo.value + "\n\n입력 사항이 맞으시면 [확인] 버튼을 눌러 주세요";

        if(confirm(ConfirmMessage)) {
            return true;
        }
        else {
            document.FormInput.ContactInfo.focus();
            return false;
        }

    }





    function BindAuthQuestion() {

        if(!AuthUseFlag) return;

        var ReturnValue = BindAuthQuestionBasic();

        document.FormInput.AuthQuestion.value                 = ReturnValue;
        document.getElementById('AuthQuestionText').innerText = ReturnValue;

    }





    function EraseAddress() {

        if(!confirm("[주소] 지우기 확인")) return;

        var Target = document.FormInput;


        Target.ZipCode.value        = "";
        Target.AddressMain.value    = "";
        Target.AddressSub.value     = "";

    }





    function ShowHideAccountInfo(Action) {

        document.getElementById("AreaConBankName").style.display  = Action;
        document.getElementById("AreaConAccountNo").style.display = Action;
        document.getElementById("AreaConUserName").style.display  = Action;
        document.getElementById("AreaConJuminNo").style.display   = Action;

    }





    function DonationKindChange() {

        var DonationKindObj = document.getElementById("DonationKind");
        var DonationWayObj  = document.getElementById("DonationWay");


        if(DonationKindObj.selectedIndex != 2) {
            DonationWayObj.selectedIndex = 1;
            DonationWayObj.style.display = "none";
            ShowHideAccountInfo("none");

        } else {
            DonationWayObj.selectedIndex = 0;
            DonationWayObj.style.display = "inline";

        }

    }




    function DonationWayChange() {

        var DonationWayObj  = document.getElementById("DonationWay");


        if(DonationWayObj.selectedIndex != 2) {
            ShowHideAccountInfo("none");

        } else {
            ShowHideAccountInfo("block");

        }

    }

