Comments={TOP_COMMENTS_CONTAINER:"commentsContainer",APPROVED_COMMENTS_CONTAINER:"commentList",UNAPPROVED_COMMENTS_CONTAINER:"unapprovedComments",RESPOND_FORM:"commentRespond",FILTERING_ELEMENT:"voteFilter",REUSABLE_ELEMENTS_CONTAINER:"reusableElements",VOTES_LIMIT:-5,resourceId:null,postingUrl:null,votingUrl:null,commentsManagementUrl:null,params:{},topContainer:null,container:null,replyForm:null,commentReplyRel:null,payForUnban:false,setParam:function(a,b){this.params[a]=b
},respond:function(a){if(message=this.checkBan()){if(this.payForUnban){if(confirm(message)){window.location.href="/abuse/index/unban"}return}else{alert(message);return}}if(oldLocation=this.replyForm.up("li")){oldLocation.down(".respond").show()}var b=this.replyForm.down("textarea").value="";a.element().hide();a.element().up("li").down(".content").insert(this.replyForm);this.replyForm.focusFirstElement();
this.commentReplyRel=a.element().readAttribute("rel")},vote:function(c){if(message=this.checkBan()){if(this.payForUnban){if(confirm(message)){window.location.href="/abuse/index/unban"}return}else{alert(message);return}}var b=c.element();var a=b.className.replace("vote ","").strip();var d={resourceId:this.resourceId,commentId:b.readAttribute("rel"),type:a};Object.extend(d,this.params);new Ajax.Request(this.votingUrl,{method:"post",parameters:Object.toQueryString(d),overlayer:{id:this.container},onSuccess:function(f){if(!parseInt(f.responseText)){return
}var g=b.adjacent("span").first();var e=parseInt(g.innerHTML);e+=(a=="pozitive"?1:-1);g.update((e>0?"+":"")+e).className=(e<0?"negativs":"pozitivs");if(e<this.VOTES_LIMIT&&!b.up("li").hasClassName("inappropiate")){b.up("li").addClassName("inappropiate")}}.bind(this)})},sendResponse:function(a){if(!this.replyForm.findFirstElement().value.strip().length){return}try{var b=Paginators.get("Comments").getCurrentPage()
}catch(c){var b=1}$("infoBox").hide();var d=this.replyForm.serialize(true);d.resourceId=this.resourceId;d.rel=this.commentReplyRel;d.page=b;Object.extend(d,this.params);new Ajax.Request(this.postingUrl,{method:"post",parameters:Object.toQueryString(d),overlayer:{id:this.overlayElement},onSuccess:function(e){$(this.REUSABLE_ELEMENTS_CONTAINER).insert(this.replyForm);$(this.container).update(e.responseText.evalJSON().results)
}.bind(this)})},sendComment:function(b){if(message=this.checkBan()){if(this.payForUnban){if(confirm(message)){window.location.href="/abuse/index/unban"}return}else{alert(message);return}}var a=b.element().up("form");if(!a.comment.value.strip().length){return}$("infoBox").hide();var c=a.serialize(true);c.resourceId=this.resourceId;Object.extend(c,this.params);new Ajax.Request(this.postingUrl,{method:"post",parameters:Object.toQueryString(c),overlayer:{id:this.overlayElement},onSuccess:function(d){$(this.container).update(d.responseText.evalJSON().results);
a.comment.value=""}.bind(this)})},cancelCommentResponse:function(a){a.element().up("li").down(".respond").show();$(this.REUSABLE_ELEMENTS_CONTAINER).insert(a.element().up("form"));this.commentReplyRel=null},showComment:function(a){a.element().up("li").toggleClassName("inappropiate")},approveComment:function(a){var b={resourceId:this.resourceId,commentId:a.findElement("a").readAttribute("rel"),task:"approve"};
Object.extend(b,this.params);new Ajax.Request(this.commentsManagementUrl,{method:"get",parameters:Object.toQueryString(b),overlayer:{id:this.overlayElement},onSuccess:function(d){var c=d.responseText;if(c.length){c=c.evalJSON();if(!Object.isUndefined(c.results)){$(this.container).update(c.results)}}this.removeUnapprovedComment(a,true)}.bind(this)})},deleteComment:function(a){var b={resourceId:this.resourceId,commentId:a.findElement("a").readAttribute("rel"),task:"delete"};
Object.extend(b,this.params);new Ajax.Request(this.commentsManagementUrl,{method:"get",parameters:Object.toQueryString(b),overlayer:{id:this.overlayElement},onSuccess:function(c){this.removeUnapprovedComment(a,true)}.bind(this)})},removeUnapprovedComment:function(a,c){var b=a.element().up("ol");if(b.childElements().size()==1&&c){b.up("div").hide()}a.element().up("li").remove()},setFilter:function(a){var c=Paginators.get("Comments");
var b=c.getParameters();b.set("resourceId",this.resourceId);b.set("properties",this.properties);b.set(this.FILTERING_ELEMENT,a.element().value);c.refresh(b)},checkBan:function(){var a=$("commentsBan").innerHTML;if(a){a=$("banMessage").innerHTML;if(/\|[0-9]+/.match(a)){a=a.replace(/\|[0-9]+/,"");this.payForUnban=true}}return a},attachListeners:function(a,b){this.container=(a||this.APPROVED_COMMENTS_CONTAINER);
this.unapprovedContainer=(b||this.UNAPPROVED_COMMENTS_CONTAINER);if(!$(this.container)){return}this.overlayElement=($(this.TOP_COMMENTS_CONTAINER)?this.TOP_COMMENTS_CONTAINER:this.container);$(document).delegate("click",{"a#sendComment span":this.sendComment.bindAsEventListener(this),"a.respond":this.respond.bindAsEventListener(this),"a.vote":this.vote.bindAsEventListener(this),"a.btnReply span":this.sendResponse.bindAsEventListener(this),"a.btnCancel span":this.cancelCommentResponse.bindAsEventListener(this),"a.btnApprove span":this.approveComment.bindAsEventListener(this),"a.btnDelete span":this.deleteComment.bindAsEventListener(this),"a.showComment":this.showComment});
if($(this.FILTERING_ELEMENT)){$(this.FILTERING_ELEMENT).observe("change",this.setFilter.bindAsEventListener(this))}this.replyForm=$(this.RESPOND_FORM)}};
