﻿var FirstLoad = false; var currentStage; var ajaxAction = 1; $(document).ready(function() { FirstLoad = true; $.historyInit(StageChanged); AttachSelectStageEvent(); AttachGroupMatchsLink() }); function StageChanged(num) { try { if (FirstLoad) { GetCurrentStage() } var groupId = 1; if (!FirstLoad) { if (ajaxAction == 1 && num.toString().charAt(1) != "@") { if (num) { currentNum = num } else { currentNum = currentStage } OnStageClick(currentNum, 0) } else if (ajaxAction == 2) { if (num) { groupId = num.toString().split("@")[1].toString() } OnGroupMatchClick(groupId) } else if (ajaxAction == 1 && num.toString().charAt(1) == "@") { groupId = num.toString().split("@")[1].toString(); OnGroupMatchClick(groupId) } } if (FirstLoad && num != '') { if (num.toString().charAt(1) == "@") { stage = num.toString().charAt(0); groupId = num.toString().split("@")[1].toString(); OnStageClick(stage, groupId) } else { stage = num.toString().charAt(0); OnStageClick(stage, 0) } } FirstLoad = false } catch (err) { } } function GetCurrentStage() { $("div.ARArrange ul li a").each(function(i) { if ($(this).attr("class") == "selected") { currentStage = $(this).attr("stageId") } }) } function OnStageClick(obj, groupId) { OnClickEvent($("div.ARArrange ul li a[stageId=" + obj + "]"), groupId); $("div.ARArrange ul li a").removeClass("selected"); $("div.ARArrange ul li a[stageId=" + obj + "]").addClass("selected") } function OnGroupMatchClick(obj) { OnClickEvent($("a.ToGroupMatches[GroupId=" + obj + "]"), 0); ajaxAction = 1 } function AttachSelectStageEvent() { $("div.ARArrange ul li a").attr("rel", "history"); $("div.ARArrange ul li a").each(function(i) { $(this).attr("href", "#" + $(this).attr("stageId")) }); $("div.ARArrange ul li a").click(function() { if ($(this).attr("class") != "selected") { ajaxAction = 1; $("div.ARArrange ul li a").removeClass("selected"); $(this).addClass("selected"); if ($(this).attr("rel") == "history") { var hash = this.href; hash = hash.replace(/^.*#/, ''); $.historyLoad(hash) } } }) } function AttachGroupMatchsLink() { $("a.ToGroupMatches").attr("rel", "history"); stageId = $("div.ARArrange ul li a[class=selected]").attr("stageId"); $("a.ToGroupMatches").each(function(i) { $(this).attr("href", "#" + stageId + "@" + $(this).attr("GroupId")) }); $("a.ToGroupMatches").click(function() { if ($(this).attr("rel") == "history") { ajaxAction = 2; var hash2 = this.href; hash2 = hash2.replace(/^.*#/, ''); $.historyLoad(hash2) } }) } function OnClickEvent(obj, gId) { var ChampId = $(obj).attr("champId"); var RoundId = $(obj).attr("roundId"); var StageType = $(obj).attr("stageType"); var StageId = $(obj).attr("stageId"); var IsGroupMatches = $(obj).attr("IsGroupMatches"); var GroupId = $(obj).attr("GroupId"); var GroupName = $(obj).attr("groupName"); var AllParameters = "ChampId=" + ChampId + "&RoundId=" + RoundId + "&StageType=" + StageType + "&StageId=" + StageId + "&IsGroupMatches=" + IsGroupMatches + "&GroupId=" + GroupId + "&GroupName=" + GroupName; LoadChampDetailsAccordingToStage("AjaxPages/OtherChamps.aspx", AllParameters, gId) } function LoadChampDetailsAccordingToStage(PageUrl, QString, gId) { try { $("#OtherChampsContainer").html("<img class='loading' src='images/loading.gif' />"); $.post(PageUrl, QStrToJson(QString), function(data) { $("#OtherChampsContainer").html(data.OtherChamp); AttachGroupMatchsLink(); if (gId != 0) { OnGroupMatchClick(gId) } return false }, "json") } catch (err) { } }
