﻿Sys.Application.add_load(LoadShows);

function LoadShows()
{
    ShowsService.LoadYearDropDown(LoadYearDropDownSucceeded, FailedCallback);
    ShowsService.LoadShows('-1', LoadShowsSucceeded, FailedCallback);  
}

function LoadYearDropDownSucceeded(result)
{
    var sShows = $("#sShows");
    $("#sShows option[value='1']").remove(); 
    var i = 0;
    var message = new Array();
    for(var item in result)
    {   
        var key = i;
        var value = result[item];
        $('#sShows').append($("<option></option>").attr("value",key).text(value));
        i++;
    }
}

// This is the callback function called if the
// Web service succeeded. It accepts the result
// object, the user context, and the method name as
// parameters.
function LoadShowsSucceeded(result)
{
    var divContent = $("#ShowsContent");
    divContent.empty(); //Clear div so we don't keep appending news.
    if (result.length > 0)
    {
        var htmlString = "<table cellspacing='0' cellpadding='0' class='tblShows'><tr class='trShowHeader'><td>Date</td><td>Location</td><td>Venue</td><td>With</td><td>Notes</td></tr>";
        var i = 0;
        //        var message = new Array();
        for(var item in result)
        {
	        if (i %2 == 0)
                htmlString += "<tr class='trShowContent'>";
            else
                htmlString += "<tr class='trShowContentAlt'>";
                
            htmlString += "<td>" + result[item].ShowDateString + "</td>";
            htmlString += "<td>" + result[item].Location + "</td>";
            htmlString += "<td>" + result[item].Venue + "</td>";
            if (result[item].Support == "")
                htmlString += "<td>" + "&nbsp" + "</td>";
            else
                htmlString += "<td>" + result[item].Support + "</td>";
            if (result[item].Notes == "")
                htmlString += "<td>" + "&nbsp" + "</td>";
            else
                htmlString += "<td>" + result[item].Notes + "</td>";
            htmlString += "</tr>";
            i++;
        }
        htmlString += "</table>";
        divContent.append(htmlString);
    }
    else
    {
        divContent.append("Red Sparowes does not have any shows for the selected time period.");
    }
}

// This is the callback function called if the
// Web service failed. It accepts the error object
// as a parameter.
function FailedCallback(error)
{
    // Display the error.    
    //var RsltElem = 
    //    document.getElementById("Results");
    //RsltElem.innerHTML = 
    //    "Service Error: " + error.get_message();
}

function sShows_onchange()
{
    var year = $("#sShows :selected").text();
    if (year == "Upcoming")
        year = "-1";
    //ShowsService.LoadShows($("#sShows :selected").text(), LoadShowsSucceeded, FailedCallback);    
    ShowsService.LoadShows(year, LoadShowsSucceeded, FailedCallback);    
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();