﻿

    function IsInt(Source) {
        if(isNaN(Source)) {
            return false;
        }

        if(Source.indexOf(".") >= 0 || Source.indexOf(" ") >= 0 || Source.indexOf("-") >= 0) {
            return false;
        }

        return true;
    }




    
    function IsEmailAddress(Source) {

        if(Source.length <= 0 || Source.indexOf("@") < 0 || Source.indexOf(".") < 0 || Source.indexOf(" ") >= 0) {
            return false;

        }
    
        if(Source.indexOf("@") != Source.lastIndexOf("@")) {
            return false;
            
        }
    
        return true;

    }





    function IsPhoneNumber(Source, Kind) {

        if(Source.length <= 0) {
            return false;
        }


        var RegexObj = "";

        switch(Kind.toUpperCase()) {

            case "MOBILE" :
                RegexObj = /^01(?:0|1|[6-9])-(?:\d{3}|\d{4})-\d{4}$/i;
                break;

            case "GENERAL" :
                RegexObj = /^0(?:2|31|32|33|41|42|43|51|52|53|54|55|61|62|63|64|70)-(?:\d{3}|\d{4})-\d{4}$/i;
                break;

            default :
                return false;
                break;

        }


        if (!RegexObj.test(Source)) {
            return false;
        }

        return true;

    }





    function IsZipCode(Source) {

        if(Source.length <= 0) {
            return false;
        }


        var RegexObj = /\d{3}-\d{3}$/i;;

        if (!RegexObj.test(Source)) {
            return false;
        }

        return true;

    }





    function IsEmpty(Source) {

        var Count;
        var StringLength = Source.length;

        for (Count = 0; Count < StringLength; Count++) {
           if ( Source.substring(Count, Count+1) != ' ' ) {
               return false;
           }
        }
   
        return true;
    }



 
    
    function IsDate(Source) {


        var Nalsu_Arr = new Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);


        var Data_Arr = new Array("","","");

        var Year, Month, Day
        var Count, Store_Locate = 0;
        var Buff = "", Dsr_Char;
        var StringLength = Source.length;

        for(Count = 0; Count < StringLength; Count++) {
      
            Dsr_Char = Source.substring(Count, Count + 1);
         
            if( (Dsr_Char == "/") || (Dsr_Char == "-") ) {
                if(Store_Locate > 1) {
                    return false;
                }
                Data_Arr[Store_Locate] = Buff;
                Buff = "";
                Store_Locate++;
            } else if(Dsr_Char >= "0" && Dsr_Char <= "9") {
                Buff += Dsr_Char;
            } else {
                return false;
            }
        }
        Data_Arr[Store_Locate] = Buff;


        for(Count = 0; Count < 3; Count++) {
            if(Data_Arr[Count].isNaN) {
                return false;
            }
        }   
      
        Year  = Data_Arr[0] * 1;
        Month = Data_Arr[1] * 1;
        Day   = Data_Arr[2] * 1;
      

        if((Year < 2000 || Year > 2100) || (Month  < 1 || Month > 12)) {
            return false;
        }
        if(Month == 2) {
            if( ((Year % 4) == 0 && (Year % 100) != 0) || (Year % 400) == 0 ) {
                Nalsu_Arr[2] = 29;
            }
        }  

        if(Day < 1 || Day > Nalsu_Arr[Month]) {
            return false;
        }

        return true
    }





    function IsDate1(Source) {


        var Nalsu_Arr = new Array(0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31);


        var Data_Arr = new Array("","","");

        var Year, Month, Day
        var Count, Store_Locate = 0;
        var Buff = "", Dsr_Char;
        var StringLength = Source.length;

        for(Count = 0; Count < StringLength; Count++) {
      
            Dsr_Char = Source.substring(Count, Count + 1);
         
            if( (Dsr_Char == "/") || (Dsr_Char == "-") ) {
                if(Store_Locate > 1) {
                    return false;
                }
                Data_Arr[Store_Locate] = Buff;
                Buff = "";
                Store_Locate++;
            } else if(Dsr_Char >= "0" && Dsr_Char <= "9") {
                Buff += Dsr_Char;
            } else {
                return false;
            }
        }
        Data_Arr[Store_Locate] = Buff;


        for(Count = 0; Count < 3; Count++) {
            if(Data_Arr[Count].isNaN) {
                return false;
            }
        }   
      
        Year  = Data_Arr[0] * 1;
        Month = Data_Arr[1] * 1;
        Day   = Data_Arr[2] * 1;
      

        if((Year < 1900 || Year > 2100) || (Month  < 1 || Month > 12)) {
            return false;
        }

        if(Day < 1 || Day > Nalsu_Arr[Month]) {
            return false;
        }

        return true
    }





    function StrLength(Source) {

        var Count, Total_Byte;
        var StringLength = Source.length;

        Total_Byte = 0;
        for(Count = 0; Count < StringLength; Count++) {

            if(Source.charCodeAt(Count) >= 128) {
                Total_Byte += 2;
            } else {
                Total_Byte += 1;
            }
        }
        return Total_Byte;
    }


    
    
    
    function MessageOutput(Message, ActionType, ActionValue) {
    
        if(Message.length > 0) {
            alert(Message);
        }

        switch(ActionType.toUpperCase()) {
        
            case "CLOSE" :
                top.close();
                break;
        
            case "FOCUS" :
                document.FormInput.elements[ActionValue].focus();
                break;
        
            case "MOVE" :
                self.location.href = ActionValue;
                break;

            case "MOVEBACK" :
                history.back();
                break;

        }

    }



    

    function GenerateOverFlowMessage(ItemName, UsedByte, MaxByte) {
    
        return ("[" + ItemName + "]" + " 항목의 입력 용량이, 허용 용량을 넘었습니다.\n입력 용량:" + UsedByte + "Byte , 허용 용량:" + MaxByte + "Byte\n(영문 1자 = 1Byte, 한글 1자 = 2Byte)");
    
    }





    function CheckRequireAndOverflow(Source, CheckKind, MaxByte, ItemName, ActionType, ActionValue) {
    
        var Length = StrLength(Source);

        CheckKind = CheckKind.toUpperCase();


        if(CheckKind == "R" || CheckKind == "RM") {

            if(IsEmpty(Source) || Length <= 0) {
                MessageOutput( ("[" + ItemName + "]" + " 항목을 입력하세요."), ActionType, ActionValue );
                return "R";
            }
        }        


        if(CheckKind == "M" || CheckKind == "RM") {

            if(Length > MaxByte) {
                MessageOutput(GenerateOverFlowMessage(ItemName, Length, MaxByte), ActionType, ActionValue);
                return "M";
            }
        }        

        return "";
    
    }




    function DocumentReload() {

        self.location.href = self.location.href;

    }





    function FindZipCode(FormName, ZipCodeName, AddressName, UrlRoot) {

        OpenWindow((UrlRoot + "Etc/ZipCode/FindZipCode.aspx?Form=" + escape(FormName) + "&ZipCode=" + escape(ZipCodeName) + "&Address=" + escape(AddressName)), "FINDZIPCODE");

    }





    function ReadNotice(TargetSerialNo, UrlRoot) {

        OpenWindow((UrlRoot + "Bbs/_Base/Receive/Read.aspx?ContentCode=BbsReceive_NoticeForBbs&Locate=NEW&SerialNo=" + escape(TargetSerialNo)), "NOTICE");

    }





    function GetAgaOrgInfo(TargetSerialNo, UrlRoot) {

        OpenWindow((UrlRoot + "AgaOrg/GetInfo.aspx?SerialNo=" + escape(TargetSerialNo)), "AGAORGINFO");

    }





    function OpenWindow(ActionValue, Target) {

        var DsrDate = new Date();
        var Width, Height;

        switch(Target.toUpperCase()) {

            case "SPECIALEVENT" :
                Width  = 656;
                Height = 570;
                window.open(ActionValue, Date.parse(DsrDate), "width=" + Width + ",height=" + Height + ",left=" + (((screen.width - Width) / 2) - 1) + ", top=" + (((screen.height - Height) / 2) - 100) + ", toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
                break;

            case "FINDZIPCODE" :
                Width  = 495;
                Height = 350;
                window.open(ActionValue, Date.parse(DsrDate), "width=" + Width + ",height=" + Height + ",left=" + (((screen.width - Width) / 2) - 1) + ", top=" + (((screen.height - Height) / 2) - 100) + ", toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
                break;

            case "NOTICE"   :
            case "SHOPNEWS" :
            case "AGASTORY" :
                Width  = 716;
                Height = 600;
                window.open(ActionValue, Date.parse(DsrDate), "width=" + Width + ",height=" + Height + ",left=" + (((screen.width - Width) / 2) - 1) + ", top=" + (((screen.height - Height) / 2) - 100) + ", toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
                break;

            case "AGAORGINFO" :
                Width  = 495;
                Height = 600;
                window.open(ActionValue, Date.parse(DsrDate), "width=" + Width + ",height=" + Height + ",left=" + (((screen.width - Width) / 2) - 1) + ", top=" + (((screen.height - Height) / 2) - 100) + ", toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
                break;

            case "GMI" :
                Width  = 495;
                Height = 300;
                window.open(ActionValue, Date.parse(DsrDate), "width=" + Width + ",height=" + Height + ",left=" + (((screen.width - Width) / 2) - 1) + ", top=" + (((screen.height - Height) / 2) - 100) + ", toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
                break;

            case "ANGELEDU" :
                Width  = 497;
                Height = 515;
                window.open(ActionValue, Date.parse(DsrDate), "width=" + Width + ",height=" + Height + ",left=" + (((screen.width - Width) / 2) - 1) + ", top=" + (((screen.height - Height) / 2) - 100) + ", toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
                break;

            case "GUIDEGOODS" :
                Width  = 732;
                Height = 460;
                window.open(ActionValue, Date.parse(DsrDate), "width=" + Width + ",height=" + Height + ",left=" + (((screen.width - Width) / 2) - 1) + ", top=" + (((screen.height - Height) / 2) - 100) + ", toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
                break;

            case "GUIDEDATE" :
                Width  = 496;
                Height = 425;
                window.open(ActionValue, Date.parse(DsrDate), "width=" + Width + ",height=" + Height + ",left=" + (((screen.width - Width) / 2) - 1) + ", top=" + (((screen.height - Height) / 2) - 100) + ", toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
                break;

        }

    }





    function OptionSelect(Target, SelectedValue) {

        var ItemLength = Target.length;
        var LoopCount, SelectIndex = -1;

        for(LoopCount = 0; LoopCount < ItemLength ; LoopCount++) {
            if(Target[LoopCount].value == SelectedValue) {
                SelectIndex = LoopCount;
                break;
            }
        }

        if(SelectIndex >= 0) Target.selectedIndex = SelectIndex;

        return SelectIndex;

    }





// 탭 보드 영역 처리 시작

    /*
        탭 보드 영역에 포함된 구성 단락을 아래와 같이 미리 정의하여 전달 하여야 함

        var BoardGroup = new Array("Board1", "Board2");

        <table id="Board1" style="display:none">
            <tr>
                <td><a href="javascript:BoardChange(BoardGroup, 'Board1');">탭1</a></td>
                <td>탭2</td>
            </tr>
        </table>
        <table id="Board2" style="display:none">
            <tr>
                <td>탭1</td>
                <td><a href="javascript:BoardChange(BoardGroup, 'Board2');">탭2</a></td>
            </tr>
        </table>
    */
    function BoardChange(BoardGroup, Target) {

        var ItemLength = BoardGroup.length;
        var LoopCount;

        for(LoopCount = 0; LoopCount < ItemLength ; LoopCount++) {
            if(BoardGroup[LoopCount] == Target)
                document.getElementById(BoardGroup[LoopCount]).style.display = "block";
            else
                document.getElementById(BoardGroup[LoopCount]).style.display = "none";
        }

    }
// 탭 보드 영역 처리 끝





// 메뉴 처리 시작
    MainMenuIndex = "";
    function ToggleMainMenu(ActionKind, Target) {

        if(typeof(MainMenuIndex).toUpperCase() == "UNDEFINED" || MainMenuIndex == null) 

            ToggleMenu(ActionKind, Target, "");
        else
            ToggleMenu(ActionKind, Target, MainMenuIndex);

    }





    function ToggleMenu(ActionKind, Target, SelectedMenuIndex) {

        if(Target.id == SelectedMenuIndex) return;

        switch(ActionKind.toUpperCase()) {

            case "IN" :
                Target.src = "/Img/Com/Menu/" + Target.id + "_ov.gif";

                break;

            case "OUT" :
                Target.src = "/Img/Com/Menu/" + Target.id + ".gif";

                break;

        }

    }





    function SetLeftMenuIndex(Source) {

        if(Source.length <= 0) return;

        var TargetArr = Source.split("_");
        var MenuDepth = TargetArr.length;
        var Target    = "", ClassName = "";

        for(var LoopCount = 0; LoopCount < MenuDepth; LoopCount++) {
            if(LoopCount > 0) Target += "_";
            Target += TargetArr[LoopCount];

            if(LoopCount == 0)
                ClassName = "LeftMenuMainItemAct";
            else
                ClassName = "LeftMenuSubItemAct";

            self.document.getElementById(Target).className = ClassName;

        }

    }
// 메뉴 처리 끝





// 기초 인증 시작
    function BindAuthQuestionBasic() {

        var Today    = new Date()

        var Number1  = 10;
        var Number2  = (Today.getMilliseconds() % 9) + 1;
        var Operator = (Today.getSeconds() % 2) == 1 ? " + " : " - ";

        return (Number1 + Operator + Number2 + " =");

    }
// 기초 인증 끝

