﻿// Verify that the sys object exists
try
{
    if (Sys) {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(processValidationErrors);
}
}catch(err){}

function CloseWindow() {
    window.open('', '_self', '');
    window.close();
}

// This is a jQuery event that fires when all of the html document
// elements are ready for use.
$(document).ready(function() {
        processValidationErrors();
});

// This method wraps the jQuery propertychange event for the
// span.validation-error validator controls for applying the field
// highlighting css class.
function processValidationErrors()
{
    $("span.validation-error")
    .bind("DOMAttrModified propertychange", function(e) {
        // Exit early if IE because it throws this event lots more  
        if (e.originalEvent.propertyName && e.originalEvent.propertyName != "isvalid") return;

        var controlToValidate = $("#" + this.controltovalidate);
        var validators = controlToValidate.attr("Validators");
        if (validators == null) return;

        var isValid = true;
        $(validators).each(function() {
            if (this.isvalid !== true) {
                isValid = false;
            }
        });

        if (isValid) {
            controlToValidate.removeClass("validatorCalloutHighlight");
        } else {
            controlToValidate.addClass("validatorCalloutHighlight");
        }
    });
}
