/**
 * Quick Comments for WordPress
 * Post comments quickly without leaving or refreshing the page.
 * @name quick-comments-0.6.1.min.js
 * @author wokamoto - http://dogmap.jp
 * @version 0.6.1
 * @date November 22, 2008
 * @copyright (c) 2008 wokamoto (dogmap.jp)
 * @license  Released under the GPL license (http://www.gnu.org/copyleft/gpl.html)
 * @requires jQuery v1.2.3 or later and jQuery.blockUI v2.08 or later and jQuery.ScrollTo V1.4 or later
 */
if(typeof jQuery!=="undefined"){jQuery((function(P){var G=P.extend({form:"form#commentform",list:"ol.commentlist:first",requireNameEmail:false,errMsgNameEmail:"Error: please fill the required fields (name, email).",errMsgCommentNone:"Error: please type a comment.",errMsgEmail:"Error: please enter a valid email address.",message:"wait...",message2:"loading...",loader:"ajax-loader.gif",messageCSS:{border:"1px solid #8C8C8C",font:"normal 12px Arial"},overlayCSS:{backgroundColor:"#FFF",opacity:"0.6"},effect:0,speed:"fast",update:"/wp-content/plugins/quick-comments/quick-comments.php",editReturn:"#edit-comment-%ID%",editOffset:-50,editButtonLabel:"Update Comment",editDisabled:{author:true,email:true,url:true}},quickCommentsL10n);var M=P.browser.msie;var A=M&&P.browser.version<"7.0";var B=P(G.form);var E={position:B.css("position")};var J=P(G.list);var I={zoom:J.css("zoom")};var F=B.attr("action");var N=G.update;var K='<div style="margin:0 auto;padding:0 1em 0;"><p style="margin:1.5em 0;white-space: nowrap;"><img src="'+G.loader+'" alt="loading" style="margin-right:.25em;" />%MESSAGE%</p></div>';var O=P("textarea[name^=comment]",B).val();O=(typeof O==="undefined"?"":O);var L=P("#submit",B).val();var D=function(){L=P("#submit",B).val();P.scrollTo(G.form,1000,{offset:G.editOffset});B.block({message:K.replace("%MESSAGE%",G.message2),css:G.messageCSS,overlayCSS:G.overlayCSS});var Q=N+"?json&comment_ID="+P(this).attr("id").replace(/^[^\d]+/,"");P.getJSON(Q,function(T){if(T.status){P("input",B).each(function(){if(this.type=="text"||this.type=="checkbox"){this.disabled=true}});var U=P("input[name^=author]",B),S=P("input[name^=email]",B),R=P("input[name^=url]",B);if(U.length>0){U.val(T.author)[0].disabled=G.editDisabled.author}if(S.length>0){S.val(T.email)[0].disabled=G.editDisabled.email}if(R.length>0){R.val(T.url)[0].disabled=G.editDisabled.url}P("textarea[name^=comment]",B).val(T.content);if(P("#comment_ID").length>0){P("#comment_ID").val(T.id)}else{B.append(P('<input type="hidden" id="comment_ID" name="comment_ID" value="'+T.id+'" />'))}if(P("#datetime").length>0){P("#datetime").val(T.datetime)}else{B.append(P('<input type="hidden" id="datetime" name="datetime" value="'+T.datetime+'" />'))}if(P("#update").length>0){P("#update").val("1")}else{B.append(P('<input type="hidden" id="update" name="update" value="1" />'))}}else{alert(T.message)}P("#submit",B).val(G.editButtonLabel);B.unblock()});return false};P("a.edit-comment",J).each(function(){P(this).unbind("click").click(D)});var C=function(T){B.unblock();if(A){P("legend",B).hide()}var S=(P("#comment_ID").length>0?G.editReturn.replace("%ID%",P("#comment_ID").val()):false);var V=(G.list).replace(/^.*[#\.]/,"").replace(/:.*$/,"");if(J.size()<=0){var R=(G.list).replace(/^([^#\.].*)[#\.].*$/,"$1");J=P("<"+R+" "+((/^#/).test(G.list)?"id":"class")+'="'+V+'"></'+R+">");P(G.form).prepend(J)}var Q=T.replace(/[\r\n\t]/g,"").replace(/^.*<body ?[^>]*>(.*)<\/body>.*$/i,"$1");var U=P(G.list,P(Q)).children();P("a.edit-comment",U).each(function(){P(this).unbind("click").click(D)});if(U.length>0){if(P("input#update",B).size()>0){J.animate({opacity:"hide"},G.speed,function(){P(this).empty().append(U).animate({opacity:"show"},G.speed,function(){if(M){J.css(I)}if(A){B.css(E);P("legend",B).show()}if(S!==false){P.scrollTo(S,1000,{offset:G.editOffset})}})})}else{switch(G.effect){case 1:U=P(P.extend(U.hide().get(),J.children().get()));J.empty().append(U).children(":hidden").slideDown(G.speed,function(){if(M){J.css(I)}if(A){B.css(E);P("legend",B).show()}if(S!==false){P.scrollTo(S,1000,{offset:G.editOffset})}});break;case 2:U=P(P.extend(U.hide().get(),J.children().get()));J.empty().append(U).children(":hidden").fadeIn(G.speed,function(){if(M){J.css(I)}if(A){B.css(E);P("legend",B).show()}if(S!==false){P.scrollTo(S,1000,{offset:G.editOffset})}});break;default:J.animate({opacity:"hide"},G.speed,function(){P(this).empty().append(U).animate({opacity:"show"},G.speed,function(){if(M){J.css(I)}if(A){B.css(E);P("legend",B).show()}if(S!==false){P.scrollTo(S,1000,{offset:G.editOffset})}})});break}}P("textarea[name^=comment]",B).val("")}else{alert(T.replace(/[\r\n\t]/g,"").replace(/^.*<body ?[^>]*>(.*)<\/body>.*$/i,"$1").replace(/<[^>]*>/,""))}P("#comment_ID").remove();P("#datetime").remove();P("#update").remove();P("#quick-comments").remove();P("#submit",B).val(L)};var H=function(R,Q,S){B.unblock();if(A){P("legend",B).hide()}alert(R.responseText.replace(/[\r\n\t]/g,"").replace(/^.*<p>(.*?)<\/p>.*$/i,"$1"));if(A){B.css(E);P("legend",B).show()}P("#submit",B).val(L)};B.submit(function(){if(P("#quick-comments").length<=0){P(this).append('<input type="hidden" name="quick-comments" id="quick-comments" value="1" />')}var T=P("input[name^=author]",P(this)).val();var R=P("input[name^=email]",P(this)).val();var Q=P("textarea[name^=comment]",P(this)).val();T=(typeof T==="undefined"?"":T);R=(typeof R==="undefined"?"":R);Q=(typeof Q==="undefined"?"":Q);if(G.requireNameEmail&&(T===""||R==="")){alert(G.errMsgNameEmail);return false}if(R!==""&&!(/^([a-z0-9+_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,6}$/).test(R)){alert(G.errMsgEmail);return false}if(Q===""||Q===O){alert(G.errMsgCommentNone);return false}P("input",P(this)).each(function(){this.disabled=false});var S=(P("input#update").length>0?N:F);var U=P("input, textarea",P(this)).serialize();P(this).block({message:K.replace("%MESSAGE%",G.message),css:G.messageCSS,overlayCSS:G.overlayCSS});P.ajax({type:"POST",cache:false,url:S,data:U,success:C,error:H});return false})})(jQuery))};
