﻿
    //a 값은 value 이다.
    function CHK(a) {  
        var yr1;
        var mon1;
        var day1;

        a = a.replace("-","");
        a = a.replace("-","");

        if (a.length==8) {  
            document.frm["year"].value = a.substring(0,4);
            document.frm["month"].value = a.substring(4,6)*1;
            document.frm["day"].value = a.substring(6,8)*1;

            if (checkDate(document.frm["year"],document.frm["month"],document.frm["day"],"",true)) {
                //alert("트루");
                if (a==1)
                    document.frm.sDate2.focus();
            
                    return true;
            }
            else {
            }

        }
        else {
            alert("일자 입력이 잘못되었습니다.)");				 
        }
        return false;
    }

    function _next() {
        if (document.frm.sDate1.value.length==8)
            document.frm.sDate2.focus();
    }  

    // 등록된 주민등록번호인지 검사
    function CheckRegNo(reg1, reg2) {
        var strRegNo1 = reg1.value;
        var strRegNo2 = reg2.value;

        if (id_no_chk(reg1, reg2) == false) {
            alert("귀하께서 입력하신 주민등록번호는 정상적인 체계가 아닙니다.");
            return false;
            //return;
        }

        window.open('lib/regcheck.asp?RegNo=' + strRegNo1 + '&RegNo2=' + strRegNo2 + '&BrandName=', 'regcheck', 'width=330,height=300,resizable=1,scrollbars=0');
        return true;
        //return
    }

    function id_no_chk(obj1, obj2) {
        // CheckSum 체크
        if (chksumID(obj1, obj2) == false)
            return false;

        // 생성기로 만든게 아닌가 생년월일과 남녀필드 체크
        if (ValidRegNo(obj1, obj2) == false)
            return false;

        // YYMMDD가 맞는지 확인한다.
        if (ValidRegNo2(obj1) == false)
            return false;
    }

    function ValidRegNo(obj1, obj2) {
        strReg1 = obj1.value;
        strReg2 = obj2.value;
        sGender = strReg2.substring(0, 1);
        sYear = strReg1.substring(0, 2);

        // 두번째 단락 첫번째 숫자는 4보다 클 수 없다.
        if (sGender > 4) {
            return false;
        }

        // 2000년도 이전은 남자는 1, 여자는 2
        // 2000년도 이후는 남자는 3, 여자는 4
        if (sYear != '00') {
            if ((sGender != '1') && (sGender != '2')) {
                return false;
            }
        }

        return true;
    }

    // YYMMDD가 맞는지 확인한다.
    function ValidRegNo2(obj1) {
        strReg1 = obj1.value;

        a = new String(strReg1);

        if (a == '') return false;
        if (a.length != 6) return false;

        intYear = parseInt(a.substring(0, 2), 10);
        intMonth = parseInt(a.substring(2, 4), 10);
        intDay = parseInt(a.substring(4, 6), 10);

        if (intMonth < 0 || intMonth > 12) {
            return false;
        }

        switch (intMonth) {
            case 2:
                if (intDay < 0 || intDay > 29) {
                    return false;
                    breake;
                }
            case 4:
                if (intDay < 0 || intDay > 30) {
                    return false;
                    breake;
                }
            case 6:
                if (intDay < 0 || intDay > 30) {
                    return false;
                    breake;
                }
            case 9:
                if (intDay < 0 || intDay > 30) {
                    return false;
                    breake;
                }
            case 11:
                if (intDay < 0 || intDay > 30) {
                    return false;
                    breake;
                }
            default:
                if (intDay < 0 || intDay > 31) {
                    return false;
                    breake;
                }
        }

        return true;
    }

    function chksumID(obj1, obj2) {
        str1 = obj1.value;
        str2 = obj2.value;
        var li_lastid, li_mod, li_minus, li_last;
        var value0, value1, value2, value3, value4, value5, value6;
        var value7, value8, value9, value10, value11, value12;

        if (IsInteger(str1) && IsInteger(str2)) {
            li_lastid = parseFloat(str2.substring(6, 7));
            value0 = parseFloat(str1.substring(0, 1)) * 2;
            value1 = parseFloat(str1.substring(1, 2)) * 3;
            value2 = parseFloat(str1.substring(2, 3)) * 4;
            value3 = parseFloat(str1.substring(3, 4)) * 5;
            value4 = parseFloat(str1.substring(4, 5)) * 6;
            value5 = parseFloat(str1.substring(5, 6)) * 7;
            value6 = parseFloat(str2.substring(0, 1)) * 8;
            value7 = parseFloat(str2.substring(1, 2)) * 9;
            value8 = parseFloat(str2.substring(2, 3)) * 2;
            value9 = parseFloat(str2.substring(3, 4)) * 3;
            value10 = parseFloat(str2.substring(4, 5)) * 4;
            value11 = parseFloat(str2.substring(5, 6)) * 5;
            value12 = 0;

            value12 = value0 + value1 + value2 + value3 + value4 + value5 + value6 + value7 + value8 + value9 + value10 + value11 + value12;

            li_mod = value12 % 11;
            li_minus = 11 - li_mod;
            li_last = li_minus % 10;
            if (li_last != li_lastid) {

                return false;
            } else
                return true;
        } else

            return false;
    }

    // 주어진 문자열이 숫자로만 이루어져있는지 검사한다.
    function IsInteger(st) {
        if (!IsEmpty(st)) {
            for (j = 0; j < st.length; j++)
                if (((st.substring(j, j + 1) < "0") || (st.substring(j, j + 1) > "9")))
                return false;
        }
        else
            return false;

        return true;
    }

    // 주어진 문자열이 비어있는지 검사한다.
    function IsEmpty(toCheck) {
        var chkstr = toCheck + "";
        var is_Space = true;

        if ((chkstr == "") || (chkstr == null))
            return false;

        for (j = 0; is_Space && j < chkstr.length; j++) {
            if (chkstr.substring(j, j + 1) != " ")
                is_Space = false;
        }

        return is_Space;
    }

    //리스트팝업 띄우기
    function _popList(a, b, c) {
        //  this 값
        //  b 는 찾는 코드값이다.
        //  c 는 몇번째 인자인지 찾기위한 insa8 값이다.
        var check_id;
        var buff;
        var mul;
        if (tInsa3.rows.length > 2) {
            //배열이므로 c 값으로 찾아야 한다.
            mul = 1;
            for (i = 0; i < tInsa3.rows.length - 1; i++) {
                if (document.all["insa8"][i].value == c) {
                    c = i;
                    break;
                }
            }
        }
        else {
            //배열이 아니므로 그냥 넘기면 된다.
            mul = 0;
        }
        buff = "../codeList/List.asp?ret=" + a.name + "&srch=" + b + "&okz=" + mul + "&ary=" + c;
        window.open(buff, "", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,copyhistory=0,left=250, top=250, width=225,height=250");
    }


    //팝업 띄우기
    function _popList2(a, b, c) {
        //  a - 게시판 번호
        //  b - 이미지 번호

        var buff;

        if (a > '' && b > '') {
            if (confirm("파일을 삭제합니까?")) {

                buff = "/common/popup/delImage.asp?num=" + a + "&typ=" + b + "&imagePath=" + c;
                window.open(buff, "", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,copyhistory=0,left=240, top=240, width=50,height=10");
            }
        }
    }

    function _limit(a, b) {
        if (a.value.length >= parseInt(b)) {
            alert(b + "자 이상 넣을수 없습니다.");
            a.value = a.value.substring(0, parseInt(b) - 1);
            a.focus();
        }
    }
    //리스트팝업 띄우기


    //체크박스 자동 체크하기
    function _checkBoxz(f) {
        var chk;
        if (f.chk0.checked == true) {
            chk = true;
        }
        else {
            chk = false;
        }

        if (f.chk) {
            if (f.chk.length > 1) {
                for (i = 0; i < f.chk.length; i++) {
                    f.chk[i].checked = chk;
                }
            }
            else {
                f.chk.checked = chk;
            }
        }
    }
    /*
    mustbe(0,n-1)
    L=0;U=n-1
    mustbe(L,U)
    loop
    mustbe(L,U)
    if L>U	
    {L>U && mustbe(L,U)}
    {... is not in the array}
    p=-1;break;

    mustbe(L,U) && L<=U
    m=(L+U)/2
    mustbe(L,U) && L<=m<=U
    case 
    x[m] < t :
    mustbe(L,U) && cantbe(0,m)
    mustbe(m+1,U)
    L=m+1
    mustbe(L,U)
    x[m] = t :
    x[m]=t
    p=m;
    break;
    x[m] > t :
    mustbe(L,U) && cantbe(m,n-1)
    mustbe(0,m-1)
    u=m-1
    mustbe(L,U)
    mustbe(L,U)
    */
    function _biSearch(Arr, srchWord) {
        var bgn, endz, result;

        bgn = 0;
        endz = Arr.length - 1;

        while (true) {
            if (bgn > endz) {
                result = -1;
                break;
            }
            else {
                result = parseInt((bgn + endz) / 2)
                if (Arr[result] == srchWord) {
                    break;
                }
                else if (Arr[result] < srchWord) {
                    bgn = result + 1;
                }
                else if (Arr[result] > srchWord) {
                    endz = result - 1;
                }
            }
        }
        return result;
    }



    function _jump(a, b, c) {
        document.jump.num.value = a;
        document.jump.tNum.value = b;
        document.jump.ITYPE.value = c;
        document.jump.action = "1main.asp";
        document.jump.submit();
    }

    //체크박스 일괄 처리...a - 체크박스명,원하는 상태(true or false)
    function _checkBtn(a, b) {
        if (a) {
            if (a.length > 1) {
                for (i = 0; i < a.length; i++) {
                    a[i].checked = b;
                }
            }
            else {
                a.checked = b;
            }
        }
    }

    //검색을 위해 제약 단어를 변경한다.
    function _forSearch1(a) {
        a = a.replace("+", "%20")
        a = a.replace("/", "%2F")
        a = a.replace("?", "%3F")
        a = a.replace("%", "%25")
        a = a.replace("#", "%23")
        a = a.replace("&", "%26")
        return a;
    }
