﻿var SimpleRoller = {
    _currentItem: 0,
    _itemLength: 0,
    _matchEntites: null,
    option: {
        rollerTag: '',
        childTag: 'li'
    },
    _getElement: function() {
        var opt = this.option;
        //        if (this._matchEntites == null)
        //            return document.getElementById(opt.rollerTag).getElementsByTagName(opt.childTag);

        return $("#" + opt.rollerTag).find(opt.childTag);
    },
    _show: function(n) {
        var o = this._getElement();
        var currentIndex = 0;
        o.each(function(index) {
            this.style.display = (index == n) ? 'block' : 'none';
            if (index == n) {
                currentIndex = index;
            }
        });

        this._currentItem = currentIndex;
    },
    moveNext: function() {
        var n = (this._currentItem == this._itemLength) ? 0 : this._currentItem + 1;
        this._show(n);
    },
    movePrev: function() {
        var n = (this._currentItem == 0) ? this._itemLength : this._currentItem - 1;
        this._show(n);
    },
    init: function() {
        this._itemLength = this._getElement().length - 1;
        this._show(0);
    }
}

function InitLatestLeagueMatch(imgServer, siteRoot, IsAuthenticated, IdentityName, leagueNo, ruleFlag) {
    var oLeagueManageScript = new LeagueManageScript();
        
    oLeagueManageScript.GetSelectedLeagueMatch(leagueNo, ruleFlag, function(result) {
        try {
            CallBackLeagueMatch(result, imgServer, siteRoot, IsAuthenticated, IdentityName);
        }
        catch (e) {
            alert(e);
        }
    });

}

function CallBackLeagueMatch(result, imgServer, siteRoot, isAuthenticated, identityName) {

    var dvLatestMatch = $("#dvLatestMatch");

    if (result.MatchEntities.length < 1) {
        $("#dvLatestsEmpty").css("display", "block");
        dvLatestMatch.css("display", "none");
        return;
    }

    $.get("../Javascript/Template/tmpl_LatestMatch.html", function(html) {

        var tmpl = parseTemplate(html, { oMatch: result,
            ImgServer: imgServer,
            SiteRoot: siteRoot,
            IsAuthenticated: isAuthenticated,
            IdentityName: identityName
        });

        dvLatestMatch.html(tmpl);

        if (result.MatchEntities.length > 1) {
            SimpleRoller._matchEntites = result.MatchEntities;

            SimpleRoller.option = {
                rollerTag: 'dvLatestMatch',
                childTag: 'div[MatchNo]'
            };

            SimpleRoller.init();

            $('#dvRoller').css("display", "block");
        }
    });
}

function InitGameList(Multi1, Multi2, Multi3, imgServer, siteRoot, IsAuthenticated, IdentityName, PageSize) {    
    var oIndexScript = new IndexScript();
    oIndexScript.GetGameList(function(result) {

        var oGameList = result;

        var innerHTML = "";

        for (var i = 0; i < oGameList.GameListEntities.length; i++) {

            var GameListEntitiy = oGameList.GameListEntities[i];

            var oOption = document.createElement("option");
            oOption.value = GameListEntitiy.GameNo;

            var options = new Option(GameListEntitiy.GameName, GameListEntitiy.GameNo);
            document.getElementById("ddlGameList").options[i] = options;
        }

        document.getElementById("ddlGameList").options.selectedIndex = 0;

        //GetGameRankingList(Multi1, Multi2, Multi3, imgServer, siteRoot, IsAuthenticated, IdentityName, PageSize);
    });
}

function GetGameRankingList(Multi1, Multi2, Multi3, imgServer, siteRoot, isAuthenticated, identityName, PageSize) {

    //[$("ctl00_MasterHolder_ddlnationality").selectedIndex]
    if (oMplogSSO)
        oMplogSSO.CloseActionLayer();
        
    var selectedValue = document.getElementById("ddlGameList").options[document.getElementById("ddlGameList").options.selectedIndex].value;

    document.getElementById("GameRankingList").innerHTML = Loading(imgServer);

    var oIndexScript = new IndexScript();
    oIndexScript.GetGameRankingList(selectedValue, PageSize, function(result) {
        var GameRanking = result;
        
        if (GameRanking.GameRankingListEntities != null && GameRanking.GameRankingListEntities.length > 0) {

            $.get(siteRoot + "/JavaScript/Template/tmpl_GameRankingList.html", function(html) {
                var tmpl = parseTemplate(html, { Header_1: Multi1,
                    Header_2: Multi2,
                    Header_3: Multi3,
                    ImgServer: imgServer,
                    SiteRoot: siteRoot,
                    IsAuthenticated: isAuthenticated,
                    IdentityName: identityName,
                    oGameRankingList: GameRanking
                });

                $("#GameRankingList").html(tmpl);
            });
        }
        else {
            getMultiLangNoData("GameRankingList");
        }
    });
}

function WinPercent(Win, Loss) {

    var returnValue = "";
    var cal = 0;
    var sum = Win + Loss;

    if (sum == 0)
        returnValue = 0;
    else
        returnValue = Math.round((Win / sum)*10000);

    return ValidatePercent(returnValue);
}

function ValidatePercent(Number) {

    var returnValue = "";

    if ((Number + "").length > 2) {

        Number = Number + "";
        //alert((Number + "").length - 2);
        returnValue = Number.substring(0, Number.length - 2) + "." + Number.substring(Number.length - 2, Number.length);
    }
    else {
        if ((Number + "").length == 2) {
            returnValue = "0." + Number;
        }
        else if ((Number + "").length == 1) {
            returnValue = "0.0" + Number;
        }
    }

    return returnValue + "%";
}

function MinusRankPreRank(Rank, PreRank) {

    return PreRank - Rank;
}

function ValidateNumber(Number) {

    Number = Number + "";
    var returnValue = "";

    if (Number.length == 1) returnValue = "0" + Number;
    else returnValue = Number;

    return returnValue;
}

function ValidateRankingNumber(Number, imgServer) {

    return imgServer + "/rank/rank" + ValidateNumber(Number) + ".gif";
}

function ValidateRankingUpDown(Rank, PreRank) {

    var returnValue = "";

    if (PreRank == 0) {
          returnValue = "rank_new";
    }
    else {
        if (PreRank - Rank == 0)
            returnValue = "rank_eq";
        else if (PreRank - Rank > 0)
            returnValue = "rank_up";
        else
            returnValue = "rank_down";
    }
    
    return returnValue;
}

function ValidateRankingUpDownImagePath(ValidateRankingUpDown, imgServer) {

    var returnValue = "";

    returnValue = imgServer + "/rank/" + ValidateRankingUpDown + ".gif";

    return returnValue;
}



if (typeof (LG_Index) == 'undefined')
    LG_Index = {};

LG_Index.Ranking = function(imgServer) {
    this.imgServer = imgServer;
}

LG_Index.Ranking.prototype = {
    InitializeMenu: function(imgServer) { },

    OnMouseOverTopMenu: function(SelectObject, imgServer) {

        if ($("#menuGameFirst")[0].style.visibility != null)
            $("#menuGameFirst")[0].style.visibility = "hidden";

        if ($("#menuLeagueFirst")[0].style.visibility != null)
            $("#menuLeagueFirst")[0].style.visibility = "hidden";

        if ($("#menuDatesFirst")[0].style.visibility != null)
            $("#menuDatesFirst")[0].style.visibility = "hidden";

        var oLeagueManageScript = new LeagueManageScript();

        if (SelectObject.id == "menuGame") {
            oLeagueManageScript.InitializeGameSubMenu(imgServer, function(result) {
                var oMenuGameFirst = $("#menuGameFirst")[0];
                oMenuGameFirst.innerHTML = result;
            });
        }

        if ((SelectObject.id != "menuPlayNow") && (SelectObject.id != "menuSponsored")) {
            if ($("#" + SelectObject.id + "First")[0].style.visibility != null)
                $("#" + SelectObject.id + "First")[0].style.visibility = "visible";
        }

        SelectObject.style.cursor = "pointer";
    },

    OnMouseOutTopMenu: function(SelectObject) { },

    OnClickMenu: function(SelectObject) {
        if ((SelectObject.id == "menuPlayNow")) {
            $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnSelectedMenu").val(SelectObject.id);

            __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$btnSelectedMenuChange', '');
        }
        else if (SelectObject.id == "menuSponsored") {
            __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$btnSelectedMenuSponsored', '');
        }

    },

    //FirstMenu
    OnMouseOverFirstMenu: function(SelectObject) {

        if (SelectObject.style.visibility != null)
            SelectObject.style.visibility = "visible";

        SelectObject.style.cursor = "pointer";
    },

    OnMouseOutFirstMenu: function(SelectObject) {
        if ($("#menuGameFirst")[0].style.visibility != null)
            $("#menuGameFirst")[0].style.visibility = "hidden";

        if ($("#menuLeagueFirst")[0].style.visibility != null)
            $("#menuLeagueFirst")[0].style.visibility = "hidden";

        if ($("#menuDatesFirst")[0].style.visibility != null)
            $("#menuDatesFirst")[0].style.visibility = "hidden";
    },

    // FirstMenuGame
    OnMouseOverFirstMenuGame: function(SelectObject) {
        //alert('a');
        SelectObject.style.cursor = "pointer";
    },

    OnMouseOutFirstMenuGame: function(SelectObject) {
        SelectObject.style.cursor = "pointer";
    },

    OnClickFirstMenuGame: function(SelectObject) {
        if ((SelectObject.id.indexOf("menuGameFirst") >= 0)) {
            $('#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnSelectedMenu').val(SelectObject.getAttribute("GameNo"));

            __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$btnSelectedMenuChangeGame', '');
        }

    },

    OnClickFirstMenuGameProgressbar: function(SelectObject) {
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_LG_Index_Ranking_MainCtrl_Game1_hdnSelectedIndex").val(SelectObject);
        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$LG_Index_Ranking_MainCtrl_Game1$btnGetList', '');

    },

    // FirstMenuLeague
    OnMouseOverFirstMenuLeague: function(SelectObject) {
        SelectObject.style.cursor = "pointer";

        if ($("#menuLeague01Second")[0].style.visibility != null)
            $("#menuLeague01Second")[0].style.visibility = "visible";

    },

    OnMouseOverSecondMenuLeague: function(SelectObject, imgServer) {
        SelectObject.style.cursor = "pointer";
        
        var oLeagueManageScript = new LeagueManageScript();

        oLeagueManageScript.InitializeLeagueListbyNation(7, imgServer, function(result) {
            $("#menuLeague02Second").html(result);
        });

        if ($("#menuLeague02Second")[0].style.visibility != null)
            $("#menuLeague02Second")[0].style.visibility = "visible";

    },

    OnMouseOver3thMenuLeague: function(SelectObject, imgServer) {
        SelectObject.style.cursor = "pointer";
        
        var oLeagueManageScript = new LeagueManageScript();

        oLeagueManageScript.InitializeLeagueListLeagueGroupsExbyGroupsEx(imgServer, function(result) {
            $("#menuLeague02_3th").html(result);
        });

        if ($("#menuLeague02_3th")[0].style.visibility != null)
            $("#menuLeague02_3th")[0].style.visibility = "visible";

    },

    OnMouseOver4thMenuLeague: function(SelectObject, imgServer) {
        SelectObject.style.cursor = "pointer";

        var oLeagueManageScript = new LeagueManageScript();

        oLeagueManageScript.InitializeLeagueListLeagueSponsoredbySponsored(imgServer, function(result) {
            $("#menuLeague02_4th").html(result);
        });
        //}

        if ($("#menuLeague02_4th")[0].style.visibility != null)
            $("#menuLeague02_4th")[0].style.visibility = "visible";

    },

    OnMouseOver6thMenuLeague: function(SelectObject, imgServer) {

        SelectObject.style.cursor = "hand";

        var oLeagueManageScript = new LeagueManageScript();

        oLeagueManageScript.InitializeLeagueListbyNationEx(9, imgServer, function(result) {
            $("#menuLeague02_6th")[0].innerHTML = result;
        });

        if ($("#menuLeague02_6th")[0].style.visibility != null)
            $("#menuLeague02_6th")[0].style.visibility = "visible";
    },

    OnMouseOutFirstMenuLeague: function(SelectObject) {
        SelectObject.style.cursor = "arrow";

        if ($("#menuLeague01Second")[0].style.visibility != null)
            $("#menuLeague01Second")[0].style.visibility = "hidden";
    },

    OnMouseOutSecondMenuLeague: function(SelectObject) {
        SelectObject.style.cursor = "arrow";

        if ($("#menuLeague02Second")[0].style.visibility != null)
            $("#menuLeague02Second")[0].style.visibility = "hidden";
    },

    OnMouseOut3thMenuLeague: function(SelectObject) {
        SelectObject.style.cursor = "arrow";

        if ($("#menuLeague02_3th")[0].style.visibility != null)
            $("#menuLeague02_3th")[0].style.visibility = "hidden";
    },

    OnMouseOut4thMenuLeague: function(SelectObject) {
        SelectObject.style.cursor = "arrow";

        if ($("#menuLeague02_4th")[0].style.visibility != null)
            $("#menuLeague02_4th")[0].style.visibility = "hidden";
    },

    OnMouseOut6thMenuLeague: function(SelectObject) {
        SelectObject.style.cursor = "arrow";

        if ($("#menuLeague02_6th")[0].style.visibility != null)
            $("#menuLeague02_6th")[0].style.visibility = "hidden";
    },

    //MenuLeagueSecond
    OnMouseOverMenuLeagueSecond: function(SelectObject) {

        if ($("#menuLeagueFirst")[0].style.visibility != null)
            $("#menuLeagueFirst")[0].style.visibility = "visible";

        if (SelectObject.style.visibility != null)
            SelectObject.style.visibility = "visible";
    },

    OnMouseOutMenuLeagueSecond: function(SelectObject) {

        if ($("#menuLeagueFirst")[0].style.visibility != null)
            $("#menuLeagueFirst")[0].style.visibility = "hidden";

        if (SelectObject.style.visibility != null)
            SelectObject.style.visibility = "hidden";
    },

    OnMouseOverMenuLeagueSecondEntity: function(SelectObject) {
        SelectObject.style.cursor = "pointer";
    },

    OnMouseOutMenuLeagueSecondEntity: function(SelectObject) {
        SelectObject.style.cursor = "arrow";
    },

    OnClickMenuLeagueSecondEntity: function(SelectObject) {

        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnSelectedMenu").val("monthly");
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnLeagueMonthlyStart").val(SelectObject.getAttribute("date").split('|')[0]);
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnLeagueMonthlyEnd").val(SelectObject.getAttribute("date").split('|')[1]);

        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$btnSelectedMenuLeagueMonthly', '');
    },

    OnClickMenuLeagueSecondEntityProgressbar: function(SeletedIndex) {

        //ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_LG_Index_Ranking_MainCtrl_Game1_hdnSelectedIndex
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_LG_Index_Ranking_MainCtrl_League1_hdnSelectedIndex").val(SeletedIndex);
        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$LG_Index_Ranking_MainCtrl_League1$btnGetList', '');
    },

    OnClickMenuLeague3thEntity: function(SelectNationNo) {
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnSelectedMenu").val("Preliminary");
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnNationNo").val(SelectNationNo);

        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$btnSelectedMenuLeagueMonthly', '');
    },

    OnClickMenuLeague3thEntityProgressbar: function(SeletedIndex) {

    $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_LG_Index_Ranking_MainCtrl_League1_hdnSelectedIndex").val(SeletedIndex);
        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$LG_Index_Ranking_MainCtrl_League1$btnGetList', '');
    },

    OnClickMenuLeague4thEntity: function(SelectGroupsNo) {
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnSelectedMenu").val("Groups");
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnLeagueGroupNo").val(SelectGroupsNo);

        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$btnSelectedMenuLeagueMonthly', '');
    },

    OnClickMenuLeague5thEntity: function(SelectGroupsNo) {
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnSelectedMenu").val("Sponsored");
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnLeagueGroupNo").val(SelectGroupsNo);

        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$btnSelectedMenuLeagueMonthly', '');
    },

    OnClickMenuLeague6thEntity: function(SelectNationNo) {

        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnSelectedMenu").val("Pan");
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnNationNo").val(SelectNationNo);
        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$btnSelectedMenuLeagueMonthly', '');
    },

    OnClickMenuLeague6thEntityProgressbar: function(SeletedIndex) {

        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_LG_Index_Ranking_MainCtrl_League1_hdnSelectedIndex").val(SeletedIndex);
        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$LG_Index_Ranking_MainCtrl_League1$btnGetList', '');
    },

    OnClickAutoCalender: function(AddMonth) {
        var day = new Date();
        var y = day.getYear();
        if (y < 2000) y = y + 1900;
        var mon = day.getMonth() + 1;
        var date = day.getDate();

        $('#CalenderRight').val(y + "-" + mon + "-" + date);

        if (AddMonth > -12) {
            AddMonth = Math.abs(AddMonth);
            if (mon > AddMonth) {
                mon = (mon - AddMonth);
            }
            else if (mon <= AddMonth) {
                y = y - 1;
                mon = (12 + mon) - AddMonth;
            }
        }
        else if (AddMonth == -12) {
            y = y - 1;
        }

        $('#CalenderLeft').val(y + "-" + mon + "-" + date);
    },

    OnClickCalender: function(obj, IsLeft) {
        var oCalenderLeft = "";

        if (IsLeft) {
            oCalenderLeft = $('#CalenderLeft')[0];
            displayCalendar(oCalenderLeft, 'yyyy-mm-dd', obj);
        }
        else {
            oCalenderLeft = $('#CalenderRight')[0];
            displayCalendar(oCalenderLeft, 'yyyy-mm-dd', obj);
        }

        var oCalender = $('#calendarDiv')[0];
        oCalender.onmouseover = this.OnMouseOverCalender;
    },

    OnMouseOverCalender: function() {
        //        if ($('menuDatesFirst').style.visibility != null)
        //              $("menuDatesFirst").style.visibility = "visible";
    },

    OnClickDate: function() {
        var oCalenderLeft = $('#CalenderLeft')[0];
        var oCalenderRight = $('#CalenderRight')[0];

        if (oCalenderLeft.value == "") {
            //CallMsg('검색 시작일자가 입력되지 않았습니다.');
            getMultiLang("JS_10001_27", MLCallMsg);
            return;
        }

        if (oCalenderRight.value == "") {
            //CallMsg('검색 종료일자가 입력되지 않았습니다.');
            getMultiLang("JS_10001_28", MLCallMsg);
            return;
        }

        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnDateStart").val(oCalenderLeft.value);
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_hdnDateEnd").val(oCalenderRight.value);
        
        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$btnSeletedDate', '')
    },

    OnClickMenuDateEntityProgressbar: function(SeletedIndex) {
        //alert(SeletedIndex);
        $("#ctl00_MasterHolder_LG_Index_Ranking_MainCtrl1_LG_Index_Ranking_MainCtrl_Dates1_hdnSelectedIndexDate").val(SeletedIndex);
        //alert(SeletedIndex);
        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_MainCtrl1$LG_Index_Ranking_MainCtrl_Dates1$btnSelectedDate', '');
    },

    OnClickGroupProgressbar: function(SeletedIndex) {
        //alert(SeletedIndex);
        $("#ctl00_MasterHolder_LG_Index_Ranking_Groups1_hdnSelectedIndex").val(SeletedIndex);
        //alert(SeletedIndex);
        __doPostBack('ctl00$MasterHolder$LG_Index_Ranking_Groups1$btnGetList', '');
    }
}

LG_Index.JoinLeague = function() {}

LG_Index.JoinLeague.prototype = {
    ClickJoinLeague: function(IsLogin, GameNo, LeagueNo, MemberNo, imgServer, IP, hash, NationNo, MemberID, TeamMode) {
        this.ClickJoinLeague(IsLogin, GameNo, LeagueNo, MemberNo, imgServer, IP, hash, NationNo, MemberID, TeamMode, "ctl00$MasterHolder$btnJoinLeague");
    },

    ClickJoinLeague: function(IsLogin, GameNo, LeagueNo, MemberNo, imgServer, IP, hash, NationNo, MemberID, TeamMode, btnID) {
        //alert(IsLogin);
        //alert(TeamMode);

        if (IsLogin == "True") {
            this.InitializeView(GameNo, imgServer, LeagueNo, MemberNo, IP, hash, NationNo, MemberID, TeamMode);
        }
        else {
            //CallMsgMove();
            __doPostBack(btnID, '');
        }

    },

    InitializeView: function(gameNo, imgServer, leagueNo, memberNo, userIP, hash, nationNo, memberID, teamMode) {

        var divJoinLeague = $("#divJoinLeague")[0];

        CloseDiv();

        //alert(divJoinLeague.style.display);
        if (teamMode == 2) {
            try {
                LeagueManageScript.GetLeagueEntryInfomation(gameNo, leagueNo, memberNo, teamMode, function(result) {
                    var url = "/wcgzone/javascript/template/tmpl_LeagueEntryInfomation.html";

                    $.get(url, function(html) {
                        var tmpl = parseTemplate(html, { GameNo: gameNo,
                            ImgServer: imgServer,
                            LeagueNo: leagueNo,
                            Hash: hash,
                            MemberNo: memberNo,
                            MemberID: memberID,
                            TeamID: result.TeamID,
                            EntryID: result.EntryID,
                            TeamMode: teamMode
                        });

                        $(divJoinLeague).html(tmpl);

                        OpenDiv(divJoinLeague.id);

                    });
                });
            }
            catch (ex) {
                return false;
            }

        }
        else if (teamMode == 1) {
            LeagueManageScript.GetGamOnEntrynoEntryid(gameNo, leagueNo, memberNo, function(result) {
                //1	WarCraft®III: Frozen Throne™  
                //2	StarCraft®: Brood War™  
                //3	FIFA Soccer 06
                //4	Half Life - Counter Strike
                //5	FIFA Soccer 07
                //6	Age of Empires III
                //7	Age of Empires III : The War Chiefs
                //8	Carom3D
                //9	Command & Conquer 3
                //10	FIFA Soccer 08
                //11	DOTA (Defense of the Ancients)
                //12	CALL OF DUTY®4   ?????
                //13	Fantasy Masters     ??????
                //14	PLAY HOLD'EM        ?????
                //15	Age of Empires III:The Asian Dynasties
                //16	Command & Conquer 3:KANE'S WRATH
                //17	Red Stone       ?????

                // 리그가 닫혀 있는 경우
                if (result == "|||error|DB_10001|26") {
                    clearMsg();

                    CallMsg("The registration is closed for this league. Please try another league.");
                }
                //국적이 다름
                else if (result == "|||error|DB_10001|37") {
                    clearMsg();

                    CallMsg("This league is not for your nation.");
                }
                //리그에 가입하지 않은 경우
                else if (result == "|||error|DB_10001|27") {
                    var url = "/wcgzone/javascript/template/tmpl_GamOnEntry.html";

                    $.get(url, function(html) {
                        var tmpl = parseTemplate(html, { GameNo: gameNo,
                            ImgServer: imgServer,
                            LeagueNo: leagueNo,
                            Hash: hash,
                            MemberNo: memberNo,
                            MemberID: memberID,
                            IP: userIP,
                            NationNo: nationNo
                        });

                        $(divJoinLeague).html(tmpl);

                        OpenDiv(divJoinLeague.id);

                    });

                }
                //리그에 가입한 경우
                else {
                    var oXMLDom = GetXMLDocument(result, "NewDataSet");

                    for (var i = 0; i < oXMLDom.childNodes.length; i++) {
                        if (oXMLDom.childNodes[i].nodeName == "Table") {
                            var oTable = oXMLDom.childNodes.item(i);

                            for (var j = 0; j < oTable.childNodes.length; j++) {
                                if (oTable.childNodes[j].nodeName == "entryno") {
                                    var url = "/wcgzone/javascript/template/tmpl_LeagueEntryInfomation.html";

                                    $.get(url, function(html) {
                                        var tmpl = parseTemplate(html, { GameNo: gameNo,
                                            ImgServer: imgServer,
                                            LeagueNo: leagueNo,
                                            Hash: hash,
                                            MemberNo: memberNo,
                                            MemberID: memberID,
                                            TeamID: "",
                                            EntryID: oTable.getElementsByTagName("entryid")[0].firstChild.nodeValue,
                                            TeamMode: teamMode
                                        });

                                        $(divJoinLeague).html(tmpl);

                                        OpenDiv(divJoinLeague.id);
                                    });

                                    return;
                                }

                            }

                        }

                    }

                }
            });
        }
    },

    Close: function() {
        clearMsg();
    },

    RegisterLeague: function(gameNo, leagueNo, memberNo, entryID, userIP, imgServer, hash, nationNo, steamID, memberID, loginID) {
        
        CloseDiv();

        if ((entryID == "") || (entryID.length < 3) || (entryID.length > 20)) {
            CallMsg("Entry ID contains invalid characters.");
            return;
        }

        for (var i = 0; i < entryID.length; i++) {
            //alert(valueStr);
            var code = entryID.charAt(i);
            if (!((code >= 'a' && code <= 'z') || (code >= 'A' && code <= 'Z') || (code >= '0' && code <= '9') || (code == '_') || (code == '-') || (code == '[') || (code == ']') || (code == '(') || (code == ')'))) {
                //						alert( "Member ID contains invalid characters." );
                clearMsg();

                CallMsg("Entry ID contains invalid characters.");
                return;
            }
        }

        var url = "/wcgzone/javascript/template/tmpl_LeagueEntryInfomation.html";

        if (typeof (steamID) == "undefined") {
            if (gameNo != "8") {
                LeagueManageScript.RegisterLeague(gameNo, leagueNo, memberNo, entryID, userIP, function(result) {
                    if (result == "") {
                        $.get(url, function(html) {
                            var divJoinLeague = document.getElementById("divJoinLeague");

                            var tmpl = parseTemplate(html, { GameNo: gameNo,
                                ImgServer: imgServer,
                                LeagueNo: leagueNo,
                                Hash: hash,
                                MemberNo: memberNo,
                                MemberID: memberID,
                                TeamID: "",
                                EntryID: entryID,
                                TeamMode: "1"
                            });

                            $(divJoinLeague).html(tmpl);
                            OpenDiv(divJoinLeague.id);
                        });
                    }
                    else if (result == "|||error|DB_10001|37") {
                        CallMsg("You are not from one of the participating nation(s).");
                    }
                });
            }
            else {
                var _loginID = document.getElementById(loginID).value;

                LeagueManageScript.AuthrityCarom3D(leagueNo, _loginID, entryID, memberID, nationNo, function(result) {
                    if (result == 0) {
                        CallMsg("Invalid ID/password combination.");
                    }
                    else if (result == 1) {
                        LeagueManageScript.RegisterLeague(gameNo, leagueNo, memberNo, _loginID, userIP, function(result) {
                            $.get(url, function(html) {
                                var divJoinLeague = document.getElementById("divJoinLeague");

                                var tmpl = parseTemplate(html, { GameNo: gameNo,
                                    ImgServer: imgServer,
                                    LeagueNo: leagueNo,
                                    Hash: hash,
                                    MemberNo: memberNo,
                                    MemberID: memberID,
                                    TeamID: "",
                                    LoginID: _loginID,
                                    TeamMode: "1"
                                });

                                $(divJoinLeague).html(tmpl);
                                OpenDiv(divJoinLeague.id);
                            });
                        });

                    }
                    else if (result == 2) {
                        CallMsg("That Carom3D ID is already registered for WCGZONE league.");
                    }
                    else if (result == 3) {
                        CallMsg("You have already registered for WCGZONE league.");
                    }
                    else {
                        var divJoinLeague = $("#divJoinLeague");
                        divJoinLeague.removeClass();
                        divJoinLeague.attr({ "style": "",
                            "width": "",
                            "height": ""
                        });

                        divJoinLeague.appendTo("<h3>CAROM3D Server is not working now.</h3>").html();
                        divJoinLeague.appendTo(result);
                        divJoinLeague.find("img").attr({ 'src': imgServer + "/btn/btn_delete.gif",
                            'onclick': "CloseDiv();"
                        });
                        
                        OpenDiv(divJoinLeague[0].id);

                        //CallMsg("CAROM3D Server is not working now." + result);
                    }
                });
            }
        }
        else {
            steamID = steamID + document.getElementById("txtJoinID1").value + ":" + document.getElementById("txtJoinID2").value + ":" + document.getElementById("txtJoinID3").value;

            LeagueManageScript.RegisterLeagueCS(gameNo, leagueNo, memberNo, entryID, userIP, steamID, function(result) {                
                $.get(url, function(html) {
                    var divJoinLeague = document.getElementById("divJoinLeague");

                    var tmpl = parseTemplate(html, { GameNo: gameNo,
                        ImgServer: imgServer,
                        LeagueNo: leagueNo,
                        Hash: hash,
                        MemberNo: memberNo,
                        MemberID: memberID,
                        TeamID: "",
                        EntryID: entryID,
                        TeamMode: "1"
                    });

                    $(divJoinLeague).html(tmpl);
                    OpenDiv(divJoinLeague.id);
                });
            });
        }
    },
    RunGame: function(GameNo, LeagueNo, LanguageNo, WCGZoneID, hash, MemberID) {
        try {
            var oWCGZone = document.getElementById("WCGZone");

            oWCGZone.SetParamEx(MemberID, hash, GameNo, LeagueNo, LanguageNo);
            oWCGZone.SetAddress('update.wcgzone.com', '5999');
            oWCGZone.Update();
        }
        catch (e) {
            alert("Failed to start GamOn.\nAllow intallation of ActiveX control or click GamOn Start after refreshing the page.");
        }
    }
}
