﻿$(document).ready(function() {
    FixValidatorPositions('');

    //add a handler for panel postbacks to ensure jquery is reapplied to refreshed elements.
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
});

//Add an inner span to all validators so that they sit correctly.
function FixValidatorPositions(rootClass) {
    $(rootClass + ' span.errormessage').each(function() {
        if ($(this).parent().hasClass('errormessage') == false && $(this).attr('id').length > 0) {
            $(this).wrapInner('<span class="errormessage"></span>');
        }

    });

}

function UpdateValidatorPositions() {

}

function EndRequestHandler(sender, args) {
    if (args.get_error() == undefined) {
        FixValidatorPositions('');

        //reset document heights dependent on content length changes.
        $('.leftNavFooterCell').css('height', '');

        //reset column heights (in main.js).
        SetLeftNavSpace();
        SetMinDocHeight();
    }
}

/// replaces the default client validation for buttons on the registration form.
/// resizes the page after running validation to account for the increased length
/// coming from the validators displaying.
function ValidateAndSetPageLength() {
    
    if (Page_ClientValidate()) {
        return true;
    } else {
        SetLeftNavSpace();
        return false;
    }
}

