$(document).ready(function() {
    $(".form-reset-button").live("click", function() {
        var specialForm = $(this).parents("form:first");
        $("input", specialForm).each(function() {
            if ($(this).attr("name"))
                $(this).val("");
        });
    });

    $(".form-send-button").live("click", function() {
        try {
            var mailRc = $(this).attr("rc");

            var specialForm = $(this).parents("form:first");
            var errMsg = "";
            var processedObj = {};
            $("input, select, textarea", specialForm).each(function() {
                var name = $(this).attr("name");
                if (!name)
                    return;

                if ($(this).attr("required") != "true")
                    return;

                var jEl = $(this);

                var val = jEl.val();

                var type = jEl.attr("type");

                if (type == "radio") {
                    if (!processedObj[name]) {
                        processedObj[name] = true;
                        var radioChecked = $("input[name=" + name + "]:checked", specialForm);
                        if (radioChecked.length == 0)
                            errMsg += jEl.attr("Label") + ", ";
                    }
                }
                else if ((typeof val == "undefined" || (typeof val == "string" && $.trim(val).length == 0)))
                    errMsg += jEl.attr("Label") + ", ";
            });

            if (errMsg.length > 0)
                throw new Error("Es wurde nicht alle Pflichtfelder ausgefüllt: " + errMsg.substring(0, errMsg.length - 2));
            return true;

        }
        catch (e) {
            alert(e.description || e);
        }
        return false;
    });
});