/* ver. 1.2 */
var meCommentThread=(function(){var g={};var h=null;var i=null;var j=null;var k={};function getLoc(l){if(k[l]===undefined)loadLocalizations();if(k[l]===undefined)return l;return k[l]}function sendCommand(b,c,d){var e=h+"?"+i+"="+b;var f=function(a){d.call(this,a)};$.ajax({"url":e,"data":c,"async":true,"cache":false,"type":"POST","dataType":"json","success":f})}function loadLocalizations(){var b=h+"?"+i+"="+"getLocalizations";$.ajax({"url":b,"async":false,"timeout":3,"cache":true,"type":"POST","dataType":"json","success":(function(a){k=a.loc})})}function showPreview(b){var c={"tid":b.tid,"pid":b.pid,"title":$("#message-input-title-"+b.tid+"-"+b.pid).val(),"author":$("#message-input-author-"+b.tid+"-"+b.pid).val(),"message":$("#message-input-content-"+b.tid+"-"+b.pid).val()};toggleEditorLoadIndicator(b.tid,b.pid,true);sendCommand("getMessagePreview",c,function(a){$("#message-preview-"+b.tid+"-"+b.pid).html(a.html);toggleEditorLoadIndicator(b.tid,b.pid,false)})}function sendMessage(b){var c={"tid":b.tid,"pid":b.pid,"title":$("#message-input-title-"+b.tid+"-"+b.pid).val(),"author":$("#message-input-author-"+b.tid+"-"+b.pid).val(),"message":$("#message-input-content-"+b.tid+"-"+b.pid).val(),"sourceurl":window.location.toString()};toggleEditorLoadIndicator(b.tid,b.pid,true);sendCommand("addMessage",c,function(a){toggleEditorLoadIndicator(b.tid,b.pid,false);if(a.error!==undefined){$("#message-error-"+b.tid+"-"+b.pid).html(a.error);return}if(j!==null)setCookie("author",c.author,2592000,j);$("#thread-tree-"+b.tid).html(a.html);clearEditor(b.tid,b.pid);if(a.visible){$("#message-node-"+a.mid).addClass("message-node-new");scrollToElement("#message-node-"+a.mid)}else if(a.notice){$("#message-playground-"+b.pid).html(a.notice);scrollToElement("#message-node-"+b.pid)}})}function setCookie(a,b,c,d){var e=new Date();if(c===undefined||c===null)c=2592000;e.setTime(e.getTime()+Math.floor(c*1000));if(d===undefined||d===null)d="/";var f="meCommentThread["+escape(a)+"]="+escape(b)+";"+" expires="+e.toGMTString()+"; path="+escape(d);document.cookie=f}function scrollToElement(a){var b=($(a).offset()).top-50;if(b>0)window.scrollTo(0,b)}function clearEditor(a,b){$("#message-input-title-"+a+"-"+b).val("");$("#message-input-author-"+a+"-"+b).val("");$("#message-input-content-"+a+"-"+b).val("");$("#message-preview-"+a+"-"+b).html("")}function hookEditorButtons(a,b){$("#message-preview-btn-"+a+"-"+b).click(function(){showPreview({"tid":a,"pid":b})});$("#message-send-btn-"+a+"-"+b).click(function(){sendMessage({"tid":a,"pid":b})});$("#message-cancel-btn-"+a+"-"+b).click(function(){$("#message-playground-"+b).html("<!-- -->")});$("#message-fmtbtn-bold-"+a+"-"+b).click(function(){formatMessage(a,b,"b")});$("#message-fmtbtn-italic-"+a+"-"+b).click(function(){formatMessage(a,b,"i")});$("#message-fmtbtn-underline-"+a+"-"+b).click(function(){formatMessage(a,b,"u")});$("#message-fmtbtn-quote-"+a+"-"+b).click(function(){formatMessage(a,b,"quote")})}function formatMessage(a,b,c){var d=getSelectedText(a,b);d="<"+c+">"+d+"</"+c+">";replaceSelectedText(a,b,d)}function getSelectedText(a,b){var c=$("#message-input-content-"+a+"-"+b).get(0);if(document.selection){c.focus();return(document.selection.createRange()).text}else{return c.value.substring(c.selectionStart,c.selectionEnd)}}function replaceSelectedText(a,b,c){var d=$("#message-input-content-"+a+"-"+b).get(0);if(document.selection){d.focus();(document.selection.createRange()).text=c}else{var e=d.value;d.value=e.substring(0,d.selectionStart)+c+e.substring(d.selectionEnd)}}function toggleEditorLoadIndicator(a,b,c){$("#editor-load-indicator-"+a+"-"+b).css("visibility",c?"visible":"hidden")}function toggleMessageLoadIndicator(a,b,c){$("#message-load-indicator-"+a+"-"+b).css("visibility",c?"visible":"hidden")}g.deleteMessage=function(b){if(!confirm(getLoc("delete_confirm")))return;var c={"tid":b.tid,"id":b.id};toggleMessageLoadIndicator(b.tid,b.id,true);sendCommand("deleteMessage",c,function(a){toggleMessageLoadIndicator(b.tid,b.id,false);$("#thread-tree-"+b.tid).html(a.html)})};g.rebuildMessage=function(b){var c={"tid":b.tid,"id":b.id};toggleMessageLoadIndicator(b.tid,b.id,true);sendCommand("rebuildMessage",c,function(a){toggleMessageLoadIndicator(b.tid,b.id,false);$("#thread-tree-"+b.tid).html(a.html)})};g.publishMessage=function(b){var c={"tid":b.tid,"id":b.id};toggleMessageLoadIndicator(b.tid,b.id,true);sendCommand("publishMessage",c,function(a){toggleMessageLoadIndicator(b.tid,b.id,false);$("#thread-tree-"+b.tid).html(a.html)})};g.unpublishMessage=function(b){var c={"tid":b.tid,"id":b.id};toggleMessageLoadIndicator(b.tid,b.id,true);sendCommand("unpublishMessage",c,function(a){toggleMessageLoadIndicator(b.tid,b.id,false);$("#thread-tree-"+b.tid).html(a.html)})};g.getMessageEditor=function(b){var c={"tid":b.tid,"pid":b.pid,"quote":!!b.quote};$(".message-playground").html("<!-- -->");toggleMessageLoadIndicator(b.tid,b.pid,true);sendCommand("getMessageEditor",c,function(a){toggleMessageLoadIndicator(b.tid,b.pid,false);$("#message-playground-"+b.pid).html(a.html);hookEditorButtons(b.tid,b.pid);if($("#message-input-author-"+b.tid+"-"+b.pid).val()==="")$("#message-input-author-"+b.tid+"-"+b.pid).get(0).focus();else $("#message-input-content-"+b.tid+"-"+b.pid).get(0).focus()})};g.initEditor=function(a){hookEditorButtons(a,0)};g.init=function(a){h=a.commandProxy;i=a.commandParamName;j=a.cookiePath};return g})();

