window.addEvent("domready",function(){Forums.initialize()});var Forums={submitting:false,initialize:function(){when($("newThreadForm"),this.initNewThread.bind(this));when($("replyForm"),this.initNewReply.bind(this));window.onbeforeunload=function(){var a=$("post_content");if(!this.submitting&&a&&a.value){this.submitting=false;return"Your post has not yet been submitted. If you continue, your changes will be lost."}}.bind(this)},initNewThread:function(b){var a=new FormManager(b);a.required("post_title","post_content");a.addSubmitHandler(function(){Auth.required({message:"You must be logged in to add a new thread.",onAuthorize:function(){this.submitting=true;a.submitNow()}.bind(this)});return false}.bind(this));$("preview_button").addEvent("click",function(c){new Event(c).stop().preventDefault();a.validate(function(){new Element("input",{type:"hidden",name:"preview",value:true}).inject(b);this.submitting=true;a.submitNow()}.bind(this))}.bind(this));a.focus()},initNewReply:function(b){var a=new FormManager(b);a.required("post_content");a.addSubmitHandler(function(){Auth.required({message:"You must be logged in to reply to a thread.",onAuthorize:function(){var c=new LoadingStatus(b);c.loading("Adding your comment...");new Request.AjaxIO("addReply",{onSuccess:function(d){if(d.success){$("post_content").value="";$("reply_add").blur();var e=new Element("div",{html:d.html});Icons.addEvents(e);$("thread").adopt(e.childNodes)}else{a.showError("post_content","Whoops. A server error occured. Refresh the page and try again.")}c.doneLoading()}}).send($("commentid").value,$("post_content").value)}});return false});$("preview_button").addEvent("click",function(c){new Event(c).stop().preventDefault();a.validate(function(){this.submitting=true;a.submitNow()}.bind(this))}.bind(this));this.replyManager=a},delPost:function(b,a){var c,e;if(a){c=$("thread");e="Deleting thread..."}else{c=$("t"+b);e="Deleting comment..."}var d=new LoadingStatus(c);d.loading(e);new Request.AjaxIO("delPost",{onSuccess:function(f){d.doneLoading();c.destroy()}}).send(b);return false},inappropriate:function(b,c){var d=$("t"+c);var e=new LoadingStatus(d);e.loading("Flagging as inappropriate...");new Request.AjaxIO("flagInappropriate",{onSuccess:function(){new Element("span",{html:"flagged",styles:{color:"#999","font-style":"italic"}}).replaces(b);e.doneLoading()}}).send(c);return false},quote:function(b){var c=$("post_content");this.replyManager.clear(c);if(b){var a=$("t"+b).getElement(".quoteText").get("html");a=new Element("div").set("html",a).firstChild.nodeValue;c.value=c.value+a+"\n\n"}new Fx.Scroll(window).toElement("footer").chain(function(){this.setcursor(c,c.value.length,c.value.length)}.bind(this));return false},setcursor:function(c,b,a){if(c.setSelectionRange){c.focus();c.setSelectionRange(b,a)}else{if(c.createTextRange){range=c.createTextRange();range.collapse(true);range.moveEnd("character",a);range.moveStart("character",b);range.select()}}}};