/*
	jQuery Form Validators v0.3
	License: http://validator.codeplex.com/license
*/
function validate(B) {
    var A = true; 
    $("*[validate=" + B + "]").each(function(C, D) {
        if (check(D)) {
            $(D).highlight();
            if (A) { $(D).focus() }
            A = false
        }
        else {
            $(D).unhighlight()
        }
    });
    return A
}

function revalidate() {
    if (!check(this)) {
        $(this).unhighlight()
    }
    else {
        $(this).highlight()
    }
}

function check(C) {
    var A = $(C);
    var B = A.find("input:radio, input:checkbox").size();
    if (A.attr("disabled") || B > 0 && B == A.find("input:radio:disabled, input:checkbox:disabled").size())
        { return "" }

    if (A.val() == "" && A.find("input:radio:checked, input:checkbox:checked").size() == 0)
    { return A.attr("requiredField") ? "requiredField" : "" }

    if (A.attr("regular") && A.attr("validExpress") && !new RegExp(A.attr("validExpress"), "m").test(A.val()))
    { return "regular" }

    if (A.attr("regular") && A.attr("invalidExpress") && new RegExp(A.attr("invalidExpress"), "m").test(A.val()))
    { return "regular" }

    if (A.attr("compare") && $("#" + A.attr("compareTo")).val() != A.val())
    { return "compare" }

    if (A.attr("custom") && !new Function(A.attr("customFn")).call(C))
    { return "custom" }

    if (A.attr("invalid") && A.val() == A.attr("invalidVal"))
    { return "invalid" } 
}

function showAlert() {
  var A = $(this);
  var C = A.position().top + A.height() + 4;
  var B = A.position().left + Math.max(A.width() - 260, 0);

  A.parent().children(".alertbox").remove();
  A.parent().append("<div class='alertbox' style='top:" + C + " px; left:" + B + " px; z-index:1500; white-space:nowrap;'>" + A.attr(check(this)) + "</div>")
}

function hideAlert() {
    $(this).parent().children(".alertbox").remove()
  }

function customAlert(InputID, sMessage, sImagePath) {
  $(".ui-dialog").css("overflow", "visible");
  var A = $("#" + InputID);
  var C = A.position().top;
  var B = A.position().left + Math.max(A.width()  + 18, 0);
  A.addClass("highlight").blur(hideAlert).change(revalidate);
  A.parent().children(".alertbox").remove();
  A.parent().append("<div class='alertbox' style='top:" + C + "px; left:" + B + "px; z-index: 6000 !important; white-space:nowrap;'><img src='" + sImagePath + "/Callout_Arrow.gif' class='calloutArrow'/><span style='vertical-align:top;position:relative;left:-10px;'>" + sMessage + "</span></div>");
}


(function(A) {
    A.fn.highlight = function() { this.addClass("highlight").focus(showAlert).blur(hideAlert).change(revalidate) }
})

(jQuery);
(function(A) {
    A.fn.unhighlight = function() { this.removeClass("highlight").unbind("focus", showAlert).unbind("blur", hideAlert).parent().children(".alertbox").remove() }
})
(jQuery);