
/*
    Calls the Rsults service to get all of the results for an event and all of it's past events
*/

var _constResultsUrl = "http://" + _RESTDomain + "/Results/ResultsHandler.ashx";
var proxyUrl = "/NonAcm/Proxy.ashx";

function resultsData()
{
    this.eventId;
    this.categories;
    this.outputElementId;
    this.currentYear;
    this.getResults = function()
                        {
                            me = this;
                             var postBodyValue = "";
                            postBodyValue = "<request>";
                            postBodyValue += "<eventId>" + this.eventId + "</eventId>";
                            postBodyValue += "<functionName>get</functionName>";
                            postBodyValue += "<destinationUrl>" + _constResultsUrl + "</destinationUrl>";
                            postBodyValue += "<urlReferer>" + encodeURIComponent(location.href) + "</urlReferer>";
                            postBodyValue += "</request>";
                            
                            //Make the ajax call
                             ShowWait(true,this.outputElementId);
                            var requestCall = new Ajax.Request(proxyUrl
                                                            ,
                                                                {
                                                                    method: "POST",
                                                                    contentType: "text/xml",
                                                                    postBody: postBodyValue,
                                                                    onSuccess: function(req)
                                                                                {
                                                                                        document.getElementById(me.outputElementId).innerHTML = req.responseText;
                                                                                        
                                                                         },
                                                                         onFailure: function()
                                                                                {
                                                                                    alert('Failed');
                                                                                },
                                                                         onComplete: function()
                                                                                {
                                                                                    //alert('Completed');
                                                                                    ShowWait(false, me.outputElementId);
                                                                                    showResultsContainer('divResultsContainer_' + me.currentYear, 'lnkResultsButton_' + me.currentYear);
                                                                                }       
                                                             }
                                                 );
                        }
}
//Show the content for the selected event
function showResultsContainer(containerId, button)
{
    if (($(containerId) != null) & ($(button) != null))
    {
	    if ($(containerId).className == "goAwayDiv")
	    {
		    $(containerId).className = "resultsContainer";

		    $(button).className = "collapseButtonLink";
	    }
	    else
	    {
		    $(containerId).className = "goAwayDiv";
		    $(button).className = "expandButtonLink";
	    }
	}
}