﻿///////////////////////
// Display functions //
///////////////////////

// Hide all 'views' then show selected 'view'
function showView(strID)
{
    hideDiv('ViewA');
    hideDiv('ViewB');

    showDiv(strID);
}

// Hide all 'lists' then show selected 'list'
function showList(strID)
{
    hideDiv('SBList1');
    hideDiv('SBList2');

    showDiv(strID);
}

// Show content
function showDiv(strID)
{
    $('#' + strID).show();
    //animatedcollapse.show(strID)
}

// Hide content
function hideDiv(strID)
{
    $('#' + strID).hide();
    //animatedcollapse.hide(strID)
}

// Show/hide any Div
function toggleContent(strID)
{
    $('#' + strID).toggle();
    //animatedcollapse.toggle(strID)
}

// Shows or hides the specified object depending on the boolean 'value'
function setVisible(object, value)
{
    if (value)
        $(object).show();
    else
        $(object).hide();
}


///////////////////////
// Utility functions //
///////////////////////

// Return a random number
function random(X)
{
    return Math.floor(X * (Math.random() % 1));
}

// Return a random number between MIN and MAX values
function randomBetween(MinV, MaxV)
{
    return MinV + random(MaxV - MinV + 1);
}

function unescapeHTML(html)
{
    var htmlNode = document.createElement("DIV");
    htmlNode.innerHTML = html;
    if (htmlNode.innerText)
    {
        theExp = new RegExp("&apos;", "g");
        return htmlNode.innerText.replace(theExp, "'"); // IE
    }
    return htmlNode.textContent; //Ff
}


////////////////////
// AJAX functions //
////////////////////

// Load more 'News' items
function MoreNews(url, type)
{
    var more = $('.MoreNews').attr("alt").split('_')[1];
    $.ajax(
            {
                type: "POST",
                url: url,
                data:
                    {
                        type: type,
                        from: more
                    },
                dataType: "html",
                success: function (result)
                {
                    $('.NewsTab_' + type).html(result);
                    var count = (parseInt(more) + 5);
                    $('.MoreNews').attr("alt", 'More_' + count);
                },
                error: function (xhr, ajaxOptions, thrownError)
                {
                }
            });
}

// This function accepts the tab that was clicked on, its status and the AJAX action to call
function SaveActiveTab(tab, status, url)
{
    $.ajax(
            {
                type: "POST",
                url: url,
                data:
                    {
                        active_tab: tab,
                        active_tab_status: status
                    },
                dataType: "html",
                success: function (result)
                {
                },
                error: function (xhr, ajaxOptions, thrownError)
                {
                }
            });
}
