var g_SeasonID = 0;
var g_SportID = 0;
var g_PriceTypeID = 0;
var g_LeagueDataID = 0;
var g_EventLeagueID = 0;
var g_LeagueID = 0;
var g_SkillID = 0;
var g_DayID = 0;
var g_Deposit = 0;
var g_DepositAmount = 0;
var g_DepositDetails = '';
var g_Players = '';

function RegisterAjaxFunction( URL, ElementID ) {
    $("#Loading").slideDown("fast");
    $.get( URL, function(data) {
        $("#" + ElementID).html(data);
        $("#Loading").slideUp("fast", function() {
            $("#" + ElementID).slideDown( "normal" );
        } );
    } );
}

function SubmitForm( ) {
    if (g_PriceTypeID == 1) $("#RequestPlayers" ).val( $("#PlayerRequest" ).val() );
    document.register.submit();
}
function GetNextSection( Action, Div ){
    var url = 'a.php?Action='+Action+'&SeasonID='+g_SeasonID+'&SportID='+g_SportID+'&LeagueID='+g_LeagueID+'&PriceTypeID='+g_PriceTypeID+'&DayID='+g_DayID+'&SkillID='+g_SkillID+'&EventLeagueID='+g_EventLeagueID+'&r=';
    RegisterAjaxFunction( url, Div );
}
function GetRegistrations( ) {
    $("#AddToCart").slideUp( "normal" );
    $("#PlayersName").slideUp( "normal" );
    $("#Players").slideUp( "normal" );
    $("#DepositName").slideUp( "normal" );
    $("#Skill").slideUp( "normal" );
    $("#SkillName").slideUp( "normal" );
    $("#DayName").slideUp( "normal" );
    $("#Price").slideUp( "normal" );
    $("#LeagueName").slideUp( "normal" );
    $("#Leagues").slideUp( "normal" );
    $("#SeasonName").slideUp( "normal" );
    $("#Seasons").slideUp( "normal" );
    $("#EventName").slideUp( "normal" );
    $("#Events").slideUp( "normal" );
    $("#RegistrationName").slideUp( "normal" );
    GetNextSection( "GetRegistrations","Registrations" );
}
function SelectRegistration( Type, Name, ShowNextSection ) {
    $("#Registrations").slideUp( "normal", function( data ) {
        $("#RegistrationName").html( "<p>Registration Type: " + Name + "</p>" );
        $("#RegistrationName").slideDown( "normal", function (data) {
            if (Type == "league") {
                if (ShowNextSection == 1) GetNextSection( "GetSeasons","Seasons" );
            } else {
                if (ShowNextSection == 1) GetNextSection( "GetEvents","Events" );
            }
        } );
    } );
}
function GetEvents( ) {
    $("#AddToCart").slideUp( "normal" );
    $("#PlayersName").slideUp( "normal" );
    $("#Players").slideUp( "normal" );
    $("#DepositName").slideUp( "normal" );
    $("#Skill").slideUp( "normal" );
    $("#SkillName").slideUp( "normal" );
    $("#DayName").slideUp( "normal" );
    $("#Price").slideUp( "normal" );
    $("#LeagueName").slideUp( "normal" );
    $("#Leagues").slideUp( "normal" );
    $("#SeasonName").slideUp( "normal" );
    $("#Seasons").slideUp( "normal" );
    GetNextSection( "GetSeasons","Seasons" );
}

function ShowEventInformation( EventID ) {
	$("#EventInformation").html("<table width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr valign=\"middle\"><td align=\"center\"><img src=\"/images/ajax-loader_bar2.gif\" /></td></tr></table>" );
	$("#EventInformation").dialog("open");
	var url = "a.php?Action=GetEventInformation&EventLeagueID=" + EventID;
    RegisterAjaxFunction( url, "EventInformation" );
}

function SelectEvent( EventID, EventName, PriceTypeID, PriceTypeName ) {
    document.getElementById( "EventLeagueID" ).value = EventID;
    document.getElementById( "LeagueDataID" ).value  = 0;
    document.getElementById( "PriceTypeID" ).value = PriceTypeID;
    g_EventLeagueID = EventID;
    g_LeagueDataID  = 0;
	g_PriceTypeID   = PriceTypeID;

	$("#Events").slideUp( "normal", function( data ) {
        $("#EventName").html( "<p>Event: " + EventName + " (" + PriceTypeName + ")</p>" );
        $("#EventName").slideDown( "normal", function (data) {
            GetNextSection( "GetPlayers","Players" );
        } );
    } );
}

function GetSeasons( ) {
    $("#AddToCart").slideUp( "normal" );
    $("#PlayersName").slideUp( "normal" );
    $("#Players").slideUp( "normal" );
    $("#DepositName").slideUp( "normal" );
    $("#Skill").slideUp( "normal" );
    $("#SkillName").slideUp( "normal" );
    $("#DayName").slideUp( "normal" );
    $("#Price").slideUp( "normal" );
    $("#LeagueName").slideUp( "normal" );
    $("#Leagues").slideUp( "normal" );
    $("#SeasonName").slideUp( "normal" );
    $("#Seasons").slideUp( "normal" );
    GetNextSection( "GetSeasons","Seasons" );
}
function SelectSeason( SeasonID, SeasonName ) {
    document.getElementById( "SeasonID" ).value = SeasonID;
    g_SeasonID = SeasonID;

	$("#Seasons").slideUp( "normal", function( data ) {
        $("#SeasonName").html( "<p><a href='javascript:void(0);' onclick='GetSeasons();'>Season</a>: " + SeasonName + "</p>" );
        $("#SeasonName").slideDown( "normal", function (data) {
            GetNextSection( "GetLeagues","Leagues" );
        } );
    } );
}

function DefaultLeague( SeasonID, SeasonName, SportID ) {
    $("#RegistrationName").html( "<p>Registration Type: League</p>" );
    $("#RegistrationName").slideDown( "normal" );
    document.getElementById( "SeasonID" ).value = SeasonID;
    g_SeasonID = SeasonID;
    $("#SeasonName").html( "<p><a href='javascript:void(0);' onclick='GetSeasons();'>Season</a>: " + SeasonName + "</p>" );
    $("#SeasonName").slideDown( "normal" );
    g_SportID = SportID;
    GetNextSection( "GetLeagues","Leagues" );
}

function GetLeagues( ) {
    $("#AddToCart").slideUp( "normal" );
    $("#PlayersName").slideUp( "normal" );
    $("#Players").slideUp( "normal" );
    $("#DepositName").slideUp( "normal" );
    $("#Skill").slideUp( "normal" );
    $("#SkillName").slideUp( "normal" );
    $("#DayName").slideUp( "normal" );
    $("#Price").slideUp( "normal" );
    $("#LeagueName").slideUp( "normal" );
    $("#Leagues").slideUp( "normal" );
    GetNextSection( "GetLeagues","Leagues" );
}
function SelectLeague( LeagueID, LeagueName, PriceTypeID, PriceTypeName ) {
    document.getElementById( "LeagueID" ).value      = LeagueID;
    document.getElementById( "PriceTypeID" ).value   = PriceTypeID;
    document.getElementById( "EventLeagueID" ).value = 0;
    g_LeagueID      = LeagueID;
    g_PriceTypeID   = PriceTypeID;
    g_EventLeagueID = 0;

    $("#Leagues").slideUp( "normal", function( data ) {
        $("#LeagueName").html( "<p><a href='javascript:void(0);' onclick='GetLeagues();'>League</a>: " + LeagueName + " (" + PriceTypeName + ")</p>" );
        $("#LeagueName").slideDown( "normal", function (data) {
            GetNextSection( "GetSkillDay","Skill" );
        } );
    } );
}
function GetSkillDay( ) {
    $("#AddToCart").slideUp( "normal" );
    $("#PlayersName").slideUp( "normal" );
    $("#Players").slideUp( "normal" );
    $("#DepositName").slideUp( "normal" );
    $("#SkillName").slideUp( "normal" );
    $("#DayName").slideUp( "normal" );
    $("#Price").slideUp( "normal" );
    GetNextSection( "GetSkillDay","Skill" );
}
function SelectSkillDay( SkillID, SkillName, DayID, DayName, Price, LeagueDataID ) {
    document.getElementById( "SkillID" ).value      = SkillID;
    document.getElementById( "DayID" ).value        = DayID;
    document.getElementById( "LeagueDataID" ).value = LeagueDataID;
    g_SkillID      = SkillID;
    g_DayID        = DayID;
    g_LeagueDataID = LeagueDataID;

    $("#Skill").slideUp( "normal", function( data ) {
        $("#SkillName").html( "<p><a href='javascript:void(0);' onclick='GetSkillDay();'>Skill</a>: " + SkillName + "</p>" );
        $("#DayName").html( "<p>Day: " + DayName + "</p>" );
        if (g_Deposit > 0) $("#Price").html( "<p>Price: $" + Price + g_DepositDetails + "</p>" );
        else $("#Price").html( "<p>Price: $" + Price + "</p>" );
        $("#SkillName").slideDown( "normal", function (data) {
            $("#DayName").slideDown( "normal", function (data) {
                $("#Price").slideDown( "normal", function (data) {
					if (g_PriceTypeID == 1) GetNextSection( "GetPlayers","Players" );
					else GetNextSection( "GetSummary","AddToCart" );
                } );
            } );
        } );
    } );
}

function GetPlayers() {
    $("#AddToCart").slideUp( "normal" );
    $("#PlayersName").slideUp( "normal" );
    $("#Players").slideUp( "normal" );
    GetNextSection( "GetPlayers","Players" );
}

function SelectLeagueFromSportsOffered( SeasonID, SeasonName, SportID, SportName, LeagueID, LeagueName, SkillID, SkillName, DayID, DayName, PriceTypeID, PriceTypeName, Price, LeagueDataID ) {
    document.getElementById( "SeasonID" ).value      = SeasonID;
    document.getElementById( "LeagueID" ).value      = LeagueID;
    document.getElementById( "PriceTypeID" ).value   = PriceTypeID;
    document.getElementById( "EventLeagueID" ).value = 0;
    document.getElementById( "SkillID" ).value       = SkillID;
    document.getElementById( "DayID" ).value         = DayID;
    document.getElementById( "LeagueDataID" ).value  = LeagueDataID;
    g_SeasonID     = SeasonID;
    g_SportID      = SportID;
    g_LeagueID     = LeagueID;
    g_SkillID      = SkillID;
    g_DayID        = DayID;
    g_PriceTypeID  = PriceTypeID;
    g_LeagueDataID = LeagueDataID;

    $("#RegistrationName").html( "<p>Registration Type: League</p>" );
    $("#SeasonName").html( "<p><a href='javascript:void(0);' onclick='GetSeasons();'>Season</a>: " + SeasonName + "</p>" );
    $("#LeagueName").html( "<p><a href='javascript:void(0);' onclick='GetLeagues();'>League</a>: " + LeagueName + " (" + PriceTypeName + ")</p>" );
    $("#SkillName").html( "<p><a href='javascript:void(0);' onclick='GetSkillDay();'>Skill</a>: " + SkillName + "</p>" );
    $("#DayName").html( "<p>Day: " + DayName + "</p>" );
    $("#Price").html( "<p>Price: $" + Price + "</p>" );

    $("#RegistrationName").slideDown( "normal", function (data) {
        $("#SeasonName").slideDown( "normal", function (data) {
            $("#LeagueName").slideDown( "normal", function (data) {
                $("#SkillName").slideDown( "normal", function (data) {
                    $("#DayName").slideDown( "normal", function (data) {
                        $("#Price").slideDown( "normal", function (data) {
                            if (g_PriceTypeID == 1) GetNextSection( "GetPlayers","Players" );
                            else GetNextSection( "GetSummary","AddToCart" );
                        } );
                    } );
                } );
            } );
        } );
    } );

    //$("#RegistrationName").html( "<p>Registration Type: League</p>" );
    //$("#RegistrationName").slideDown( "normal" );
    //document.getElementById( "SeasonID" ).value = SeasonID;
    //g_SeasonID = SeasonID;
    //$("#SeasonName").html( "<p><a href='javascript:void(0);' onclick='GetSeasons();'>Season</a>: " + SeasonName + "</p>" );
    //$("#SeasonName").slideDown( "normal" );
    //g_SportID = SportID;
    //GetNextSection( "GetLeagues","Leagues" );
}

function SelectPlayers(  ) {
    document.getElementById( "RequestPlayers" ).value = document.getElementById( "PlayerRequest" ).value;
    $("#Players").slideUp( "normal", function( data ) {
        $("#PlayersName").html( "<p><a href='javascript:void(0);' onclick='GetPlayers();'>Players/Notes</a>: " + document.getElementById( "RequestPlayers" ).value + "</p>" );
        $("#PlayersName").slideDown( "normal", function (data) {
			GetNextSection( "GetSummary","AddToCart" );
        } );
    } );
}

function ShowDeposit( ) {
    if (g_DepositAmount > 0) $("#example").dialog("open");
}
function SetDepositDetails( DepositDescription, DepositAmount ) {
    $("#example").html( "Equipment is available for this league:<br /><br />Equipment Item: " + DepositDescription + "<br />Deposit Amount: $" + DepositAmount + "<br /><br />Would you like to add this equipment deposit to your registration?" );
    g_Deposit = 0;
    g_DepositDescription = DepositDescription;
    g_DepositAmount = DepositAmount;
}
function AcceptDeposit( ) {
    g_Deposit = 1;
    g_DepositDetails = '$' + g_DepositAmount + ' (' + g_DepositDescription + ')';
    document.getElementById( "PayDeposit" ).value = g_Deposit;
    $("#DepositName").html( "<a href='javascript:void(0);' onclick='ShowDeposit();'>Deposit</a>: " + g_DepositDetails + "</p>" );
    $("#DepositName").slideDown( "normal" );
}
function DeclineDeposit() {
    g_Deposit = 0;
    g_DepositDetails = '';
    document.getElementById( "PayDeposit" ).value = g_Deposit;
    $("#DepositName").html( "<a href='javascript:void(0);' onclick='ShowDeposit();'>Deposit</a>: <i>Declined</i></p>" );
    $("#DepositName").slideDown( "normal" );
}
function ToggleDeposit( DepositDetails ) {
    if (g_Deposit == 0) { 
        g_Deposit = 1;
        g_DepositDetails = ' + '+DepositDetails;
    } else {
        g_Deposit = 0;
        g_DepositDetails = '';
    }
    
}
function ToggleSport( SportID ) {
    $(".registration_sporthead").css("background","#fff");
    $("#Sport" + SportID + "_Header").css("background","#fff url(/images/gradient_e0_40.png) repeat-x");
    $(".registration_sport").slideUp("normal");
    $("#Sport" + SportID ).slideDown("normal");
}
