(function($, window, undefined){ var toggleFormAndLink = function(type) { return function() { $("#create-" + type + "-form") .find("input[type='text']").val("").end() .find("input[type='checkbox']").removeAttr("checked").end() .find("> .edit-mode").val(0).end() .find("> fieldset > legend").text("Create new " + type).end() .clearModelErrors() .toggle(); $("#" + type + "-select").toggle(); return false; } }; var addNewCheckbox = function($table, name, value, text, cellsPerRow) { var $row = $table.find("tr:last"); if ($row.find("td").length === cellsPerRow) { $row = $(""); $table.append($row); } var $cell = $("").append($("").attr({ type: "checkbox", name: name, value: value, id: name + "_" + value, checked: "checked" })).append($("