﻿function GetBaseUrl() {
    return $("#BaseUrlHiddenField").val();
}

function StripResponse(response) {
    response = response.substring(response.indexOf('<div id="JQueryPage"'));
    response = response.replace('</form></body></html>', '');
    return response;
}

function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }

    return IsNumber;
}

function AutoCompleteClubTextBox(TextBoxControlId, status, ControlWidth) {
    $().ready(function() {

        $("#" + TextBoxControlId).flushCache();
        
        if (status != '') {
            var fullpath = GetBaseUrl() + '/Infomat/Pages/ClubsAutoComplete.aspx?status=' + status;
        }
        else {
            var fullpath = GetBaseUrl() + '/Infomat/Pages/ClubsAutoComplete.aspx';
        }

        $.get(fullpath, function(response) {
            var dataArray = response.split("||");

            $("#" + TextBoxControlId).autocomplete(dataArray, {
                matchContains: true,
                minChars: 2,
                mustMatch: false,
                width: ControlWidth,
                max: 50
            });
        });
    });
}

function ShowResults(divControlNameToShow) {
    var currentDate = new Date();
    var dummy = currentDate.getTime();

    $("div#" + divControlNameToShow).html("<img class=\"loadingImage\" src=\"" + GetBaseUrl() + "/infomat/images/ajax-loader.gif\" alt=\"Loading...\" /> Veuillez patienter. Chargement des données...").show();

    $.get(GetBaseUrl() + "/infomat/Pages/Competition_results.aspx?dummy=" + dummy, function(response) {
        $("div#" + divControlNameToShow).html(StripResponse(response)).show();
    });
}

function ShowRankings(divControlNameToShow) {
    var currentDate = new Date();
    var dummy = currentDate.getTime();

    $("div#" + divControlNameToShow).html("<img class=\"loadingImage\" src=\"" + GetBaseUrl() + "/infomat/images/ajax-loader.gif\" alt=\"Loading...\" /> Veuillez patienter. Chargement des données...").show();

    $.get(GetBaseUrl() + "/infomat/Pages/Competition_rankings.aspx?show=normal&dummy=" + dummy, function(response) {
        $("div#" + divControlNameToShow).html(StripResponse(response)).show();
    });
}

function ShowRankingsReserve(divControlNameToShow) {
    var currentDate = new Date();
    var dummy = currentDate.getTime();

    $("div#" + divControlNameToShow).html("<img class=\"loadingImage\" src=\"" + GetBaseUrl() + "/infomat/images/ajax-loader.gif\" alt=\"Loading...\" /> De klassementen worden opgehaald").show();

    $.get(GetBaseUrl() + "/infomat/Pages/Competition_rankings.aspx?show=reserve&dummy=" + dummy, function(response) {
        $("div#" + divControlNameToShow).html(StripResponse(response)).show();
    });
}

function SetMemberDetailTabs() {
    var tabContainers = $('div.tabs > div');
    tabContainers.hide().filter(':first').show();

    $('div.tabs ul.tabNavigation a').click(function() {
        tabContainers.hide();
        tabContainers.filter(this.hash).show();
        $('div.tabs ul.tabNavigation a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();
}
