/* Copyright (C) 2007 - 2010 YOOtheme GmbH, YOOtheme License (http://www.yootheme.com/license) */

Zoo.Comment=new Class({initialize:function(a){this.setOptions({url:"index.php?option=com_zoo&controller=comment",id:"edit-comment-editor"},a);this.form=$("comments-default");this.form.getElementsBySelector("tr.comment-row").each(function(b){this.attachEvents(b)}.bind(this))},attachEvents:function(a){a.getElement(".actions-links .edit").addEvent("click",function(c){(new Event(c)).stop();this.editEvent(a)}.bind(this));a.getElement(".actions-links .reply").addEvent("click",function(c){(new Event(c)).stop();
this.replyEvent(a)}.bind(this));a.getElement(".actions-links .delete a").addEvent("click",function(c){(new Event(c)).stop();this.stateEvent(a,"remove")}.bind(this));var b=a.getElement(".actions-links .approve a"),d=a.getElement(".actions-links .unapprove a"),e=a.getElement(".actions-links .spam a"),g=a.getElement(".actions-links .no-spam a");b&&b.addEvent("click",function(c){(new Event(c)).stop();this.stateEvent(a,"approve")}.bind(this));d&&d.addEvent("click",function(c){(new Event(c)).stop();this.stateEvent(a,
"unapprove")}.bind(this));e&&e.addEvent("click",function(c){(new Event(c)).stop();this.stateEvent(a,"spam")}.bind(this));g&&g.addEvent("click",function(c){(new Event(c)).stop();this.stateEvent(a,"approve")}.bind(this))},editEvent:function(a){var b=this,d=a.getElement("input[name^=cid]").getProperty("value");(new Ajax(b.options.url,{method:"post",data:"task=edit&format=raw&cid="+d,onComplete:function(e){b.removeEditor();b.insertEditor(a,e);a.setStyle("display","none");b.form.removeEvents();b.form.addEvents({save:function(g,
c){if(Json.evaluate(c,true))Message.show(c);else{var f=(new Element("table")).setHTML(c).getElement("tr");b.removeEditor();b.attachEvents(f);g.replaceWith(f);b.stripe()}},cancel:function(){b.removeEditor()}})}})).request()},replyEvent:function(a){var b=this,d=a.getElement("input[name^=cid]").getProperty("value");(new Ajax(b.options.url,{method:"post",data:"task=reply&format=raw&cid="+d,onComplete:function(e){b.removeEditor();b.insertEditor(a,e);b.form.removeEvents();b.form.addEvents({save:function(g,
c){if(Json.evaluate(c,true))Message.show(c);else{var f=(new Element("table")).setHTML(c).getElement("tr");b.removeEditor();b.attachEvents(f);f.injectAfter(g);b.stripe()}},cancel:function(){b.removeEditor()}})}})).request()},stateEvent:function(a,b){var d=a.getElement("input[name^=cid]").getProperty("value");(new Element("input",{type:"hidden",name:"cid",value:d})).injectInside(this.form);this.form.getElement("input[name=task]").setProperty("value",b);this.form.submit()},insertEditor:function(a,b){var d=
this,e=(new Element("tr",{id:this.options.id})).injectAfter(a);(new Element("td",{colspan:"4"})).setHTML(b).injectInside(e);e.getElement(".content textarea").focus();e.getElement(".actions .save").addEvent("click",function(g){(new Event(g)).stop();var c=new Hash;d.form.getElementsBySelector("input, textarea").each(function(f){var h=f.name,i=f.getValue();i===false||!h||f.disabled||c.set(h,i)});(new Ajax(d.options.url,{method:"post",data:c.merge({task:"save",format:"raw"}).obj,onComplete:function(f){d.form.fireEvent("save",
[a,f])}})).request()});e.getElement(".actions .cancel").addEvent("click",function(g){(new Event(g)).stop();d.form.fireEvent("cancel")})},removeEditor:function(){var a=$(this.options.id);if(a){a.getPrevious().setStyle("display","");a.remove()}},stripe:function(){$$("table.stripe tbody tr").each(function(a,b){a.removeClass("even");a.removeClass("odd");a.addClass(b%2?"even":"odd")})}});Zoo.Comment.implement(new Events,new Options); 
