var Comments=new Class({initialize:function(A){this.options={className:"",user:false};if(A!=undefined){this.options.className=A.className||this.options.className;this.options.user=A.user||this.options.user}$$("."+this.options.className+" form").each(function(C){var D=C.getAttributeNode("id").nodeValue;var B=new FormValidator(D,{submit:false,errorLabel:"error-label"});if(!this.options.user){B.addRoule("username_"+D,"empty","");B.addRoule("password_"+D,"empty","")}B.addRoule("text_"+D,"empty","");$(D).addEvents({submit:function(E){E.stop();this.add(D,B)}.bind(this),keyup:function(E){if(E.control&&E.code==13){this.add(D,B)}}.bind(this)})}.bind(this));$$(".comments_reply_open").each(function(C){var D=C.get("href").replace(/.+reply\_id=(\d+).+/,"$1");var B=new Fx.Reveal("comments_form_reply_"+D);C.addEvent("click",function(E){E.stop();B.toggle()})});$$(".comments_edit_open").each(function(C){var D=C.get("href").replace(/.+edit\_id=(\d+).+/,"$1");var B=new Fx.Reveal("comments_form_edit_"+D);C.addEvent("click",function(E){E.stop();B.toggle()})});$$(".comments_del").each(function(B){B.addEvent("click",this.del.bindWithEvent(this,B))}.bind(this))},add:function(B,A){if(A.validate()){$(B).getElement("input[type=submit]").set("disabled",true);new Ajax("/inc/ajax.php",{method:"post",data:B,response:function(C){if(!C.error){$$(".content-comments .msg").destroy();if(!this.options.user){$$(".content-comments .username",".content-comments .password",".content-comments .lnk").destroy()}if(C.comments!=undefined){this.create(C);$(B).getElement("textarea").set("value","")}else{$("text_"+C.comment_id).set("html",C.comment_text);new Fx.Reveal("comments_form_edit_"+C.comment_id).toggle();msg(C.done,"done")}}else{msg(C.error,"error")}$(B).getElement("input[type=submit]").set("disabled",false)}.bind(this)}).request()}},del:function(B,A){B.stop();if(confirm(lng.confirm_comments_del)){new Ajax("/inc/ajax.php",{method:"post",data:getParams(A.get("href")),response:function(C){$("comment_"+C.comment_id).destroy();if($("comments_list").getChildren().length==0){new Element("div",{"class":"msg"}).set("text",lng.msg_comments_empty).inject("comments_list")}msg(C.done,"done")}}).request()}},create:function(G){var F=new Element("div",{id:"comment_"+G.comments.comment_id,"class":"item "+G.comments.shift_style});var K=new Element("ul",{"class":"userline"}).inject(F);var I=new Element("li",{"class":"author"}).set("html",G.comments.comment_author).inject(K);var H=new Element("li",{"class":"date"}).set("text",G.comments.date_add).inject(K);var E=new Element("li",{"class":"link"}).inject(K);new Element("a",{href:"#comment-"+G.comments.comment_id,title:lng.l_constant_link}).set("text","#"+G.comments.comment_id).inject(E);var L=new Element("div",{"class":"body"}).inject(F);var B=new Element("div",{"class":"body-wrap"}).inject(L);var C=new Element("div",{"class":"photo"}).inject(B);var A=new Element("a",{href:G.comments.user_path}).inject(C);new Element("img",{src:G.comments.avatar.mini_path,alt:G.comments.comment_author_edit}).inject(A);var D=new Element("div",{id:"comments_text_"+G.comments.comment_id,"class":"text",styles:{display:"block"}}).set("html",G.comments.comment_text.replace(/&quot;/g,'"')).inject(B);new Element("div",{"class":"empty"}).inject(B);var J=new Element("ul",{"class":"userline m little"}).inject(F);new Element("div",{"class":"empty"}).inject(F);if(G.comments.to_id>0){if(G.comments.last_comment_id>0){F.inject("comment_"+G.comments.last_comment_id,"after")}else{F.inject("comment_"+G.comments.to_id,"after")}new Fx.Reveal("comments_form_reply_"+G.comments.to_id).toggle()}else{F.inject("comments_list")}L.highlight("#00529b")}});
