﻿// Utility functions

// Browser detection (start)
var isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;
var NS4 = (document.layers) ? true : false;
var IEmac = ((document.all) && (isMac)) ? true : false;
var IE4plus = (document.all) ? true : false;
var IE4 = ((document.all) && (navigator.appVersion.indexOf("MSIE 4.") != -1)) ? true : false;
var IE5 = ((document.all) && (navigator.appVersion.indexOf("MSIE 5.") != -1)) ? true : false;
var IE6 = ((document.all) && (navigator.appVersion.indexOf("MSIE 6.") != -1)) ? true : false;
var IE7 = ((document.all) && (navigator.appVersion.indexOf("MSIE 7.") != -1)) ? true : false;
var IE8 = ((document.all) && (navigator.appVersion.indexOf("MSIE 8.") != -1)) ? true : false;
var IE9 = ((document.all) && (navigator.appVersion.indexOf("MSIE 9.") != -1)) ? true : false;
var ver4 = (NS4 || IE4plus) ? true : false;
var NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape') != -1) ? true : false;
var IE = (IEmac || IE4plus || IE4 || IE5 || IE6 || IE7 || IE8 || IE9) ? true : false;
// Browser detection (end)

// Body onload utility (supports multiple onload functions) (start)
var gSafeOnload = new Array();

function safeAddOnLoad(f)
{
    if (IEmac && IE4)
    {
        // IE 4.5 blows out on testing window.onload    
        window.onload = safeOnload;
        gSafeOnload[gSafeOnload.length] = f;
    }

    else if (window.onload)
    {
        if (window.onload != safeOnload)
        {
            gSafeOnload[0] = window.onload;
            window.onload = safeOnload;
        }
        gSafeOnload[gSafeOnload.length] = f;
    }

    else
    {
        window.onload = f;
    }
}

function safeOnload()
{
    for (var i = 0; i < gSafeOnload.length; i++)
    {
        gSafeOnload[i]();
    }
}
// Body onload utility (supports multiple onload functions) (end)

// The terms of the Community Edition of Sitefinity requires a "powered
// by Sitefinity" logo to be displayed in the footer of every page. We've
// done this, but in IE7 and below, an *additional* logo is displayed (not
// visible in FF or Safari, nor IE8 when not in compatiblity mode). Hide this
// logo!
function hideDefaultSitefinityLogo()
{
    var telerikLogo = document.getElementById('ctl00_sitefinityLogo');

    if (telerikLogo)
    {
        telerikLogo.style['display'] = 'none';
    }
}

/// <summary>
///     Returns true if a particular string is null or empty.
/// </summary>
/// <param name="theString" type="String Data Type">
///     The string to be checked.
/// </param>
function stringIsNullOrEmpty(theString)
{
    return !theString || theString == '';
}

/* Execute on js load: */
safeAddOnLoad(hideDefaultSitefinityLogo);