function pageLoad()
{
    $('body').activity(false); //use pageload to reset after updatepanel refresh

    if ($('#successLabel').text() === '')
    {
        $('#successDiv').hide();
    }

    if ($('#errorLabel').text() === '')
    {
        $('#errorDiv').hide();
    }
}

$(document).ready(function ()
{
    $('tr.GRow, tr.GARow').hover(
        function () { $(this).addClass('trHover'); },
        function () { $(this).removeClass('trHover'); }
    );

    var $form = $('#aspnetForm');
    var $inputs = $('#aspnetForm input');

    $inputs.filter(':submit').hover(
	    function () { $(this).addClass('ui-state-hover'); },
	    function () { $(this).removeClass('ui-state-hover'); }
    );

    $inputs.filter('.date').datepicker(
        { changeYear: true, changeMonth: true, dateFormat: 'm/dd/yy', yearRange: 'c-2:c+2', defaultDate: new Date() }
    );

    $inputs.filter(':text, :password').focus(function () { this.select(); }).hover(
	    function () { $(this).addClass('txtHover'); },
	    function () { $(this).removeClass('txtHover'); }
    );

    $inputs.filter('.phone').mask("(999) 999-9999");

    $form.submit(function ()
    {
        if ($form.data('beenSubmitted') === 'true')
        {
            return false;
        }
        else
        {
            $form.data('beenSubmitted', 'true');

            if ($form.data('isValid') !== 'false')
            {
                if (typeof (Page_ClientValidate) === 'function')
                {
                    if (Page_IsValid)
                    {
                        $('#successDiv').hide();
                        $('#errorDiv').hide();
                        $('body').activity();
                    }
                    else
                    {
                        $form.data('beenSubmitted', 'false');
                    }
                }
                else
                {
                    $('#successDiv').hide();
                    $('#errorDiv').hide();
                    $('body').activity();
                }
            }

            return true;
        }
    });

    $('#aspnetForm a').click(function ()
    {
        var $this = $(this);
        var href = $this.attr('href');
        var className = $this.attr('class');
        var clickEvent = $this.attr('onclick');
        var showActivity = true;

        if ($this.attr('data-busy') === 'false')
        {
            showActivity = false;
        }
        else if (className === 'srCellC' || className === 'srCellT')
        {
            showActivity = false;
        }
        else if ($this.attr('target') === '_blank')
        {
            showActivity = false;
        }
        else if (href === undefined || href === '')
        {
            showActivity = false;
        }
        else if (href && (href.indexOf('#') !== -1 || href.indexOf('javascript') !== -1 || href.indexOf('xlsx') !== -1 || href.indexOf('pdf') !== -1 || href.indexOf('mailto') !== -1))
        {
            showActivity = false;
        }
        else if (clickEvent !== undefined) //or if we have an onclick
        {
            showActivity = false;
        }

        if (showActivity)
        {
            $('body').activity();
        }
    });

    $(window).bind("load", function ()
    {
        var footerHeight = 0;
        var footerTop = 0;
        var $footer = $("#footer");
        positionFooter();

        function positionFooter()
        {
            footerHeight = $footer.height();
            footerTop = ($(window).scrollTop() + $(window).height() - footerHeight) + "px";

            if (($(document.body).height() + footerHeight) < $(window).height())
            {
                $footer.css({ position: "absolute", top: footerTop });
            }
            else
            {
                $footer.css({ position: "static" });
            }
        }

        $(window).scroll(positionFooter).resize(positionFooter);
    });
});
