$(window).load(function () {
    ResizeContainer();
});

$(document).ready(function() {
    var nav = window.location.pathname;
    $('ul[id^="ni"] li[^="link"] a[href$="' + nav + '"] ').addClass('activeLink');

    if (nav === "/") {
        $('ul[id^="ni"] li[^="link"] a[href$="' + nav + '"] ').css({ 'background': 'url("/images/home-purple.png") no-repeat scroll -4px -5px transparent' });
    }
    else {
        $('#ni61 li[^="link"] a[href$="' + nav + '"] ').addClass('activeLink');
        $('#ni61 li[^="link"] a[href$="' + nav + '"] ').next('ul').addClass('activeLink');
        $('#ni61 li[^="link"] a[href$="' + nav + '"] ').parent().parent().addClass('activeLink');
        $('#ni61 li[^="link"] a[href$="' + nav + '"] ').parent().parent().prev().addClass('activeLink');
    }

    if (navigator.platform == "MacIntel") {
        $('.searchBox').css({ 'height': '20px', 'width': '220px' });
    }
    
    $("img[title]:gt(1)").tooltip({

        // use div.tooltip as our tooltip
        tip: '.tooltip',

        // use the fade effect instead of the default
        effect: 'fade',

        // make fadeOutSpeed similar to the browser's default
        fadeOutSpeed: 100,

        // the time before the tooltip is shown
        predelay: 400,

        // tweak the position
        position: "bottom right",
        offset: [-50, -80]
    });
});

function SetActiveLink(id)
{
    $('#' + id + ' a').addClass('activeLink');
}

function ResizeContainer()
{  
    var difference = 0;
    
    $('div[id^="mod"]').each(function()
    {
        var currentDifference = parseInt($(this).height() - $(this).css('min-height').replace('px', ''));
        
        if(currentDifference > difference)
        {
            difference = currentDifference;
        }
    });
    
    $('#container').height($('#container').height() + difference);
}

function ResizeModule(name, type)
{
    if(type == 'Form')
    {
        if (typeof(Page_Validators) != 'undefined') 
        {
            if(!Page_IsValid)
            {
                if(!$('.' + name).parent().attr('style'))
                {
                    var offset = 10; 
                    var numberOfValidators = $('span[id*="RequiredFieldValidator"]').length;
                
                    $('.' + name).parent().height($('.' + name).parent().height() + (offset * numberOfValidators));
                    ResizeContainer();
                }
            }
        }
   }
   else
   {
       var spaceBetweenContainer = 10;
       var newHeight = parseInt($(name).height()) + parseInt($(name).css('top').replace('px', '')) + spaceBetweenContainer;
       $('#container').height(newHeight);
   }
}

function ClearInputText(selector)
{
    $(selector).val('');
}

function SetCursorToEndOfText(textControlID)
{
    var text = document.getElementById(textControlID);
    
    if (text != null && text.value.length > 0)
    {
        if (text.createTextRange)
        {
            var fieldRange = text.createTextRange();
            fieldRange.moveStart('character', text.value.length);
            fieldRange.collapse();
            fieldRange.select();
        }
    }
}

String.prototype.endsWith = function(a){ return this.substr(this.length - a.length) === a; }
String.prototype.startsWith = function(a){ return this.substr(0, a.length) === a; }
String.prototype.trim = function(){ return this.replace(/^\s*/, '').replace(/\s*$/, ''); }
String.prototype.trimEnd = function(){ return this.replace(/\s+$/, ""); }
String.prototype.trimStart = function(){ return this.replace(/^\s+/, ""); }

function ShowFullImage(imageSelector)
{
    $(imageSelector).fadeIn(500);
}

function HideFullImage(imageSelector)
{
    $(imageSelector).hide();
}
