﻿function addError(block, name, text) {
    var errBox =$("#err" + block) 
    if (errBox.find("span").length == 0)
        $("#comm" + block).fadeTo("fast", 0);
    if (document.getElementById(name + "Error")) {
        $("#" + name + "Error").html(text);
    }
    else {
        var errBox = $("#err" + block);
        if (errBox.find("span").length == 0)
            $("#comm" + block).fadeTo("fast", 0, function() { $(this).css("visibility", "hidden"); $(this).css("opacity", ""); });
        var newError = $("<span style='display:none' class='field-validation-error' id='" + name + "Error'>" + text + "</span>");
        errBox.find("span").each(function() {
            if (newError && this.id > name) {
                $(this).before(newError);
                newError.slideDown("fast");
                newError = null;
            }
        });
        if (newError) {
            errBox.append(newError);
            newError.slideDown("fast");
        }
    }
}


function showComments(block) {
    $("#comm" + block).css("opacity", "0");
    $("#comm" + block).css("visibility", "visible");
    $("#comm" + block).fadeTo("fast", 100, function() { $(this).css("opacity", ""); });
}

function removeError(block, name) {
    var errBox = $("#err" + block);
    var oldError = $("#" + name + "Error");
    if (oldError.length != 0) {
        oldError.slideUp("fast", function() {
            $(this).remove();
            if (errBox.find("span").length == 0)  showComments(block);
         });
    }
}

function removeErrors(block) { $("#err" + block).empty(); showComments(block); }
