﻿
    var method = null; 
    var imgButton = null;
    var div = null;
    var headingDiv = null;
    var _sortByMatchDate = false;
    // Get round matches and update round container
    function ShowRound(e, roundId) {
        
        method = "r";
        //Get reference to the image button that needs to be toggled
        imgButton = e;
        //Get reference to the round container where the return HTML should be populated
        div = getObj("r" + roundId);
        
        headingDiv = getObj("rh" + roundId);
        
        //alert("r " + roundId + " - " + div.innerHTML);
        //If we have no data for this round then get round matches via AJAX
        if (div.innerHTML.length < 10) {

            TheFA.Portal.WebServices.Competitions.AjaxGet.RoundDetails(roundId, _sortByMatchDate, GetComplete);
        }
        else {
            ToggleSection(imgButton, div);
        }

    }

    //Update relevant container
    function GetComplete(html, context, methodName) {
        
       //Update results container
        div.innerHTML = html;
        //Show or hide results container
        ToggleSection(imgButton, div);
    }

    
    //Toggle container and change toggle img.
    function ToggleSection(img, container) {

        if (container.style.display == "block") {
           // Effect.SlideUp(container);
           container.style.display = "none";
            img.src = "/images/thefa/openIcon.gif";
        }
        else {
            //Effect.SlideDown(container);
            container.style.display = "block";
            img.src = "/images/thefa/closeIcon.gif";
        }
        
        //If we are expanding a round div then change the heading class to reflect open state
        if (method == "r") {
            //alert(headingDiv + " c: " + headingDiv.className + " d: " + div.style.display);
            if (container.style.display == "block") {
                headingDiv.className = "RoundHeadingOpen";
            }
            else {
                headingDiv.className = "RoundHeading";
            }
        }
        
    }

    // Get match details and update match container
    function ShowMatch(e, matchId, archiveId) {

        //If no archive id then set to 0
        if (archiveId == undefined)
            archiveId = 0;
        method = "m";
        //Get reference to the image button that needs to be toggled
        imgButton = e;
        //Get reference to the match container where the return HTML should be populated
        div = getObj("m" + matchId);

        //alert("m " + matchId + " - " + div.innerHTML);
        //If we have no data for this match then match detail via AJAX
        if (div.innerHTML.length < 10) {
            TheFA.Portal.WebServices.Competitions.AjaxGet.MatchDetails(matchId, archiveId, GetComplete);
        }
        else {
            ToggleSection(imgButton, div);
        }
    }

    function ShowFixtureDetail(e, fixtureId) {
        //Get reference to the image button that needs to be toggled
        img = e;
        //Get reference to the fixture container to toggle
        container = getObj("f" + fixtureId);
        
        if (container.style.display == "block") {
            container.style.display = "none";
            img.src = "/images/thefa/openIcon.gif";
        }
        else {
            container.style.display = "block";
            img.src = "/images/thefa/closeIcon.gif";
        }
    }




   


