var Comment=new Class({initialize:function(){this.mNewCommentBox=$("NewCommentBox");this.mAddCommentButton=$("AddComment");this.mSubmitButton=addcomment_submit;addcomment_addcomment.addEvent("onValid",this.updateComments.bind(this));this.mAddCommentButton.addEvent("click",this.showNewCommentBox.bindWithEvent(this));this.makeLinksActive()},makeLinksActive:function(a){$ES(".CommentAnswer a",a).each(function(b){b.addEvent("click",this.answerComment.bindWithEvent(this,[b]))}.bind(this));$ES(".CommentChildrenLink",a).each(function(b){b.addEvent("click",this.getChildren.bindWithEvent(this,[b]))}.bind(this))},answerComment:function(a,c){new Event(a).stop();var b=c.getProperty("id").match(/CommentAnswer(\d+)/)[1];addcomment_id_parent_comment.setValue(b);this.showNewCommentBox(a)},getChildren:function(b,c){new Event(b).stop();var a=c.getProperty("id").match(/CommentChildren_(\d+)_([0-9a-z_]+)_(\d+)/i);c.removeEvents("click");c.addEvent("click",function(d){d.stop()}.bindWithEvent());$(c).addClass("CommentLoadInfo");new Json.Remote("/ajax/afComments/GetCommentsByParent/",{onComplete:this.putChildren.bind(this)}).send({id:a[1],level:a[3],type:a[2]})},putChildren:function(b){new Element("div").setHTML(b.html).setProperty("id","CommentChildren_"+b.id_parent_comment).injectAfter($("CommentTable_"+b.id_parent_comment));this.makeLinksActive($("CommentChildren_"+b.id_parent_comment));var a=$("CommentChildren_"+b.id_parent_comment+"_"+b.type+"_"+b.level);$(a).removeEvents("click");$(a).addEvent("click",this.toggleChildren.bindWithEvent(this,[$(a)]));$(a).removeClass("CommentLoadInfo");$(a).addClass("CommentChildrenLinkOpen")},toggleChildren:function(c,f,d){new Event(c).stop();var a=f.getProperty("id").match(/CommentChildren_(\d+)_([0-9a-z_]+)_(\d+)/i);f.removeEvents("click");var b="close";var e="none";if("close"==d){b="open";e="block";f.addClass("CommentChildrenLinkOpen")}else{f.removeClass("CommentChildrenLinkOpen")}$("CommentChildren_"+a[1]).setStyle("display",e);f.addEvent("click",this.toggleChildren.bindWithEvent(this,[f,b]))},showNewCommentBox:function(a){new Event(a).stop();this.mAddCommentButton.getParent().setStyle("display","none");this.mNewCommentBox.setStyle("display","block");location.href="#NewCommentBox"},hideNewCommentBox:function(){var b=addcomment_table_name.getValue();var c=addcomment_id_record.getValue();var a=addcomment_nick.getValue();addcomment_addcomment.clear();addcomment_nick.setValue(a);addcomment_table_name.setValue(b);addcomment_id_record.setValue(c)},updateComments:function(){this.hideNewCommentBox();addcomment_addcomment.showSuccessBox("<strong>Udało się!</strong><br/>Komentarz został dodany.")}});window.addEvent("domready",function(){new Comment()});
