if(typeof (XWiki)=="undefined"){XWiki=new Object()
}if(typeof (XWiki.viewers)=="undefined"){XWiki.viewers=new Object()
}XWiki.viewers.Comments=Class.create({xcommentSelector:".xwikicomment",initialize:function(){if($("commentscontent")){this.startup()
}if($("Commentstab")){this.container=$("Commentspane");
this.generatorTemplate="commentsinline.vm"
}else{if($$(".main.layoutsubsection").size()>0&&$$(".main.layoutsubsection").first().down("#commentscontent")){this.container=$$(".main.layoutsubsection").first();
this.generatorTemplate="comments.vm"
}}this.addTabLoadListener()
},startup:function(){if($("commentform")){this.form=$("commentform").up("form")
}else{this.form=undefined
}this.loadIDs();
this.addDeleteListener();
this.addReplyListener();
this.addSubmitListener();
this.addCancelListener()
},loadIDs:function(){$$(this.xcommentSelector).each(function(B){var A=B.id;
B._x_number=A.substring(A.lastIndexOf("_")+1)-0
})
},addDeleteListener:function(){$$(this.xcommentSelector).each(function(A){A=A.down("a.delete");
if(!A){return 
}A.observe("click",function(B){A.blur();
B.stop();
if(A.disabled){return 
}else{new XWiki.widgets.ConfirmedAjaxRequest(A.href+(Prototype.Browser.Opera?"":"&ajax=1"),{onCreate:function(){A.disabled=true
},onSuccess:function(){var C=A.up(this.xcommentSelector);
if(this.form&&this.form.descendantOf(C.next(".commentthread"))){this.resetForm()
}C.replace(this.createNotification("Deleted comment."));
this.updateCount()
}.bind(this),onComplete:function(){A.disabled=false
}},{confirmationText:"Are you sure you want to remove this comment?",progressMessageText:"Deleting...",successMessageText:"Comment deleted",failureMessageText:"Failed to delete comment: "})
}}.bindAsEventListener(this))
}.bind(this))
},addReplyListener:function(){if(this.form){$$(this.xcommentSelector).each(function(A){A=A.down("a.commentreply");
if(!A){return 
}A.observe("click",function(B){A.blur();
B.stop();
if(this.form.up(".commentthread")){this.form.up(".commentthread").previous(this.xcommentSelector).down("a.commentreply").show()
}A.up(this.xcommentSelector).next(".commentthread").insert({top:this.form});
this.form["XWiki.XWikiComments_replyto"].value=A.up(this.xcommentSelector)._x_number;
this.form["XWiki.XWikiComments_comment"].value="";
this.form["XWiki.XWikiComments_comment"].focus();
A.hide()
}.bindAsEventListener(this))
}.bind(this))
}else{$$(this.xcommentSelector+" a.commentreply").each(function(A){A.hide()
})
}},addSubmitListener:function(){if(this.form){this.form.down("input[type='submit']").observe("click",function(A){A.stop();
if(this.form["XWiki.XWikiComments_comment"].value!=""){var B=new Hash(this.form.serialize(true));
B.set("xredirect",window.docviewurl+"?xpage=xpart&vm="+this.generatorTemplate);
B.unset("action_cancel");
this.form._x_notification=new XWiki.widgets.Notification("Sending comment...","inprogress");
this.form.disable();
this.restartNeeded=false;
new Ajax.Request(this.form.action,{method:"post",parameters:B,onSuccess:function(){this.restartNeeded=true;
this.form._x_notification.replace(new XWiki.widgets.Notification("Comment posted","done"))
}.bind(this),onFailure:function(C){var D=C.statusText;
if(C.statusText==""||C.status==12031){D="Server not responding"
}this.form._x_notification.replace(new XWiki.widgets.Notification("Failed to post comment:"+D,"error"))
}.bind(this),on0:function(C){C.request.options.onFailure(C)
},onComplete:function(C){if(this.restartNeeded){this.container.update(C.responseText);
document.fire("xwiki:docextra:loaded",{id:"Comments",element:this.container});
this.updateCount()
}else{this.form.enable()
}}.bind(this)})
}}.bindAsEventListener(this))
}},addCancelListener:function(){if(this.form){this.initialLocation=new Element("span",{className:"hidden"});
$("_comments").insert(this.initialLocation);
this.form.down("input[name='action_cancel']").observe("click",this.resetForm.bindAsEventListener(this))
}},resetForm:function(A){if(this.form.up(".commentthread")){if(A){A.stop()
}this.form.up(".commentthread").previous(this.xcommentSelector).down("a.commentreply").show();
this.initialLocation.insert({after:this.form})
}this.form["XWiki.XWikiComments_replyto"].value="";
this.form["XWiki.XWikiComments_comment"].value=""
},updateCount:function(){if($("Commentstab")&&$("Commentstab").down(".itemcount")){$("Commentstab").down(".itemcount").update("(__number__)".replace("__number__",$$(this.xcommentSelector).size()))
}if($("commentsshortcut")&&$("commentsshortcut").down(".itemcount")){$("commentsshortcut").down(".itemcount").update("(__number__)".replace("__number__",$$(this.xcommentSelector).size()))
}},addTabLoadListener:function(A){var B=function(C){if(C.memo.id=="Comments"){this.startup()
}}.bindAsEventListener(this);
document.observe("xwiki:docextra:loaded",B)
},createNotification:function(A){var B=new Element("div",{"class":"notification"});
B.update(A);
return B
}});
document.observe("xwiki:dom:loaded",function(){new XWiki.viewers.Comments()
});