// Copyright Zikula Foundation 2010 - license GNU/LGPLv3 (or at your option, any later version).
Zikula.define("Categories");Zikula.Categories.InitEditView=function(){if($("category_attributes_add")){Zikula.Categories.Attributes.Init()}Zikula.Categories.Collapse.Init()};$(document).observe("dom:loaded",Zikula.Categories.InitEditView);Zikula.define("Categories.Collapse");Zikula.Categories.Collapse.Init=function(){$$(".categories_collapse_control").invoke("observe","click",Zikula.Categories.Collapse.Click).invoke("addClassName","z-toggle-link").each(function(b){var a=b.up("legend").next(".categories_collapse_details");if(a&&a.visible()){a.removeClassName("z-toggle-link-open").hide()}})};Zikula.Categories.Collapse.Click=function(b){b.preventDefault();var c=b.findElement(".categories_collapse_control"),a=c.up("legend").next(".categories_collapse_details");if(a.visible()){Element.removeClassName.delay(0.9,a,"z-toggle-link-open")}else{a.addClassName("z-toggle-link-open")}Zikula.switchdisplaystate(a)};Zikula.define("Categories.Attributes");Zikula.Categories.Attributes.Init=function(){$("category_attributes_add").observe("click",Zikula.Categories.Attributes.Add);$$(".category_attributes_remove").invoke("observe","click",Zikula.Categories.Attributes.Remove)};Zikula.Categories.Attributes.Add=function(a){a.preventDefault();var j=a.element();if($("new_attribute_name").getValue().empty()||$("new_attribute_value").getValue().empty()){return false}var e=j.up("td"),i=e.up("tr"),k=i.up("table"),l=k.insertRow(i.rowIndex+1);var d=l.insertCell(0),h=new Element("input",{name:"attribute_name[]",value:$("new_attribute_name").getValue()});$("new_attribute_name").clear();d.appendChild(h);var c=l.insertCell(1),g=new Element("input",{name:"attribute_value[]",value:$("new_attribute_value").getValue()});$("new_attribute_value").clear();c.appendChild(g);var b=l.insertCell(2),f=new Element("input",{type:"image",src:"images/icons/extrasmall/edit_remove.png"}).observe("click",Zikula.Categories.Attributes.Remove);b.appendChild(f);$("new_attribute_name").focus();return true};Zikula.Categories.Attributes.Remove=function(b){b.preventDefault();var d=b.element(),c=d.up("tr"),a=c.up("table");a.deleteRow(c.rowIndex);return true};