﻿var EventBannerHandler =
{
    itemMaxCount: 0, //모든 아이템 숫자
    itemStatus: 0,
    beforeStatus: 0,
    isOver: false,
    isMoving: true,
    SetCurrentBanner: function(no) {
        this.itemStatus = no;
        this.SetSignal(this.itemStatus);
        this.FadeinBanner(this.itemStatus, this.beforeStatus);
        this.beforeStatus = this.itemStatus; //과거의 것을 갱신시켜줌
    },

    FadeinBanner: function(after, before) {
        $("[id^=eventBanner]").each(
            function(i) {
                if (after == i) {
                    $(this).css("z-index", "10").css("display", "none").fadeIn(500);
                }
                else if (before == i) {
                    $(this).css("z-index", "9").css("display", "").fadeIn(1);
                }
                else {
                    $(this).css("z-index", "1").css("display", "").fadeIn(1);
                }
                $(this).hover(function() { this.isOver = true; }, function() { this.isOver = false; });
            }
        );

    },

    SetSignal: function(no) {
        $("[id^=eventBtn]").each(
            function(i) {
                if (no == i) {
                    $(this).attr("class", "eventNum_on");
                }
                else {
                    $(this).attr("class", "eventNum_off");
                }
            }
        );       
    }
}

var LoginFunction = {
    DoLogin: function() {
        if (document.forms[0].chkSave.checked == true) {

            CookieHelper.SetCookie("chkSave", "Y", 100);
            CookieHelper.SetCookie("memberID", $("#username").val(), 100);
        }
        else {
            CookieHelper.SetCookie("chkSave", "", 0);
            CookieHelper.SetCookie("memberID", "", 0);
        }

        if ($("#username").attr("value") === '') {
            alert("아이디를 입력해주세요");

        }
        else if ($("#password").attr("value") === '') {
            alert("패스워드를 입력해주세요");
            return false;
        }
        else {

            if (document.forms[0].chkSecure.checked) {
                document.forms[0].action = "https://secure.howlingsword.co.kr/Login";
            }
            else {
                document.forms[0].action = "http://secure.howlingsword.co.kr/Login";
            }
            document.forms[0].submit();

//            var sMsg = "Hello, world";
//            window.setTimeout("alert(" + sMsg + ")", 1000);

        }
    }
}

function SetCommunityPanel(result) {
    $("#btnComm1").attr("src", $("#btnComm1").attr("src").replace((result == 1 ? "off" : "on"), (result == 1 ? "on" : "off")));
    $("#btnComm2").attr("src", $("#btnComm2").attr("src").replace((result == 2 ? "off" : "on"), (result == 2 ? "on" : "off")));
    $("#btnComm3").attr("src", $("#btnComm3").attr("src").replace((result == 3 ? "off" : "on"), (result == 3 ? "on" : "off")));
    switch (result) {
        case 2:
            PanelControl.SetPanelVisible("Community", "PlayKnowhow");
            break;
        case 3:
            PanelControl.SetPanelVisible("Community", "ArtGallery");
            break;
        case 1:
        default:
            PanelControl.SetPanelVisible("Community", "MediaBoard");
            break;
    }
}

$(document).ready(
    function() {

        //$("input:#username").focus();
        $("#username").keypress(
            function(e) {
                if (e.keyCode == 13) { $("#password").focus(); }

            }
        );
        $("#password").keypress(
                function(e) {
                    if (e.keyCode == 13) { return LoginFunction.DoLogin(); }
                }
        );

        $("#username").focus(function(e) {
            if ($.trim($("#username").val()) === "아이디입력") {
                $("#username").val("");
            }
        });

        $("#password").focus(function(e) {
            if ($.trim($("#username").val()) === "패스워드입력") {
                $("#username").val("");
            }
        });

        setTimeout(
            function() {

                var ckuid = CookieHelper.GetCookie('memberID');
                var cksave = CookieHelper.GetCookie('chkSave');
                try {

                    if (cksave) {
                        document.forms[0].chkSave.checked = true;
                        $("#username").val(ckuid);

                    }
                    else {
                        document.forms[0].chkSave.checked = false;
                    }
                }
                catch (e) { }
            }
        , 100);


        // ------------------ 쿠폰 ------------------2010/01/04------- //        
        function PopSearch() {
            if ($("input:#hdIsLogin").val() == "False") {
                alert("로그인을 하신 후 이용 가능 합니다.");
                return;
            }
            $("div:#divSearch").show();
        }


        $("img:#btnPopCbt2Result").click(function() {
            //PopSearch();
            //alert("2010년 2월 중 오픈베타 예정입니다.");
        });

        //        $("img:#btnPopCouponRegister").click(function() {
        //            if ($("input:#hdIsLogin").val() == "False") {
        //                alert("로그인을 하신 후 이용 가능 합니다.");
        //                return;
        //            }

        //            if (mem_hdReslutCD.val() == "200" || mem_hdReslutCD.val() == "100") {
        //                alert("이미 2차테스터에 당첨되셨습니다.");
        //                return;
        //            }

        //            mem_divRegister.show();
        //            mem_txtCoupon.focus();
        //            mem_txtCoupon.val("");
        //        });
    }
);