$(window).load(function () {
    ResizeContainer();
});

$(document).ready(function() {
    var nav = window.location.pathname;
    $('ul[id^="ni"] li[^="link"] a[href$="' + nav + '"] ').addClass('activeLink');
});

function SetActiveLink(id)
{
    $('#' + id + ' a').addClass('activeLink');
}

function ResizeContainer()
{  
    var maxHeight = parseInt($('#container').height());
    
    $('#container').children().each(function()
    {
        var currentHeight = parseInt($(this).offset().top) + parseInt($(this).outerHeight());
        if(currentHeight > maxHeight) maxHeight = currentHeight;
    });

    $('#container').height(maxHeight + 150);
}

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();
}

// On page load items
$(document).ready(function () {
	// Removes border on last li item in top nav
	$("#ni61 li").last().css("border-right", "0px");
	
	// Brings the footer outside of container
	var footer = $("#tb4").remove();
	$(footer).appendTo("body").addClass("footer");
	
	// Removes divider on last link on the side nav
	$("#ourProductsBox ul li").last().css("background", "none");
	
});
