CommentSubmitForm=Class.create();CommentSubmitForm.prototype={form:null,a:null,initialize:function(a){this.form=$(a);this.commentReply=$$("a.comment_reply");this.commentReplyTo=$$("a.comment_replyToComment");this.commentMod=$$("a.comment_mod");this.edit=$$("a.comment_edit");this.showIgnoredLink=$$("a.comment_ignore");Event.observe($("button_submit"),"click",this.onSubmit.bindAsEventListener(this));this.commentReply.each(function(b){Event.observe(b,"click",this.showReplyBox.bindAsEventListener(this))}.bind(this));this.commentReplyTo.each(function(b){Event.observe(b,"click",this.showReplyBox.bindAsEventListener(this))}.bind(this));this.commentMod.each(function(b){Event.observe(b,"click",this.showEditBox.bindAsEventListener(this))}.bind(this));this.edit.each(function(b){Event.observe(b,"click",this.showEditBox.bindAsEventListener(this))}.bind(this));this.showIgnoredLink.each(function(b){Event.observe(b,"click",this.showIgnoredComment.bindAsEventListener(this))}.bind(this));if($("hidden_commentId").value>0){$("div_authorRow").hide();$("div_excerptRow").hide();$("h_commentHeader").innerHTML="Edit a previous comment";$("div_replyForm").show()}},showTagName:function(a){alert(Event.element(a).id)},showError:function(b,d){var c=this.form[b];var a=c.up().down(".error");if(a){a.update(d);a.show()}},resetErrors:function(){this.form.getElementsBySelector(".error").invoke("hide")},showReplyBox:function(b){var a=Event.element(b).id;if(!$("wmd_input").visible()){$("wmd_input").show()}if(!$("div_excerptRow").visible()){$("div_excerptRow").show()}this.updateOriginalUserName(a);this.updateCommentText(a);$("hidden_replyToId").value=(a);if($("hidden_commentId").value>0){this.clearForm();$("h_commentHeader").innerHTML="Add a new comment";$("hidden_replyToId").value="r_"+$("hidden_resourceId").value;$("button_submit").value="Post"}$("div_replyForm").show();$("wmd_input").focus()},showReplyBoxWithQuote:function(c){var a=Event.element(c).id;if($("hidden_commentId").value>0){this.clearForm()}if($("div_excerptRow").visible()){$("div_excerptRow").hide()}this.updateOriginalUserName(a);this.getQuotedComment(a);$("hidden_replyToId").value=0;var b=$("comment_body_"+a.replace("c_","")).innerHTML;$("div_replyForm").show();$("text_area").focus()},getQuotedComment:function(a){new Ajax.Request("/commentajax/updatequotedcomment/",{method:"get",onCreate:function(b){$("text_area").value="[Loading quote...]"},parameters:{id:a},onSuccess:function(c){var b=c.responseText||"[No username available]";$("text_area").value=b},onFailure:function(){alert("Something went wrong...")}})},clearForm:function(){$("hidden_commentId").value="";$("text_area").innerHTML="";$("hidden_commentId").value="";$("div_authorRow").show();$("div_excerptRow").show()},hideReplyBox:function(a){Event.stop(a);$("div_replyForm").hide()},updateOriginalUserName:function(a){new Ajax.Request("/commentajax/updatereplyusername/",{method:"get",parameters:{id:a},onSuccess:function(c){var b=c.responseText||"[No username available]";$("link_originalUserName").innerHTML=b},onFailure:function(){alert("Something went wrong...")}})},updateCommentText:function(a){new Ajax.Request("/commentajax/updatereplycomment/",{method:"get",parameters:{id:a},onSuccess:function(c){var b=c.responseText||"[No excerpt avaiable]";$("p_commentText").innerHTML=b},onFailure:function(){alert("Something went wrong...")}})},updatePreview:function(){var a=$("text_area").value},showEditBox:function(a){Event.stop(a);window.location.href=Event.element(a).href},showIgnoredComment:function(b){var a=Event.element(b).id;$("div_ignoredComment_"+a).hide();Effect.Appear("comment_"+a)},onSubmit:function(b){Event.stop(b);var a={parameters:this.form.serialize(),method:this.form.method,onSuccess:this.onFormSuccess.bind(this)};this.saveLastComment();this.resetErrors();new Ajax.Request(this.form.action,a)},onFormSuccess:function(c){if(c.responseText=="invalid user"){window.location.href="/account/login/?timeout=true"}var a=c.responseText.evalJSON(true);var b=$H(a.errors);if(b.size()>0){this.form.down(".error").show();b.each(function(d){this.showError(d.key,d.value)}.bind(this))}else{$("button_submit").disable();this.form.submit()}},include:function(jsFile){new Ajax.Request(jsFile,{method:"get",asynchronous:false,onSuccess:function(transport){eval(transport.responseText)},onFailure:function(){alert("Failure including file: "+jsFile)}})},saveLastComment:function(){var b=$("hidden_userId").value;var c=$("wmd_input").value;if(b>0&&c!=""){var a={parameters:{id:b,text:c},method:"post",onSuccess:function(){}};new Ajax.Request("/commentajax/savelastcomment/",a)}}};
