if(typeof (XWiki)=="undefined"){XWiki=new Object()}XWiki.Blog={blogToolsValues:{show:{title:"This blog post is not visible to other users. Make it visible",imageSrc:"/xwiki/resources/icons/silk/lock_open.gif",imageAlt:"show",comment:"Made%20entry%20visible"},hide:{title:"Hide this blog post from other users",imageSrc:"/xwiki/resources/icons/silk/lock.gif",imageAlt:"hide",comment:"Hidden%20entry"},loading:{title:"Loading...",imageSrc:"/xwiki/resources/icons/xwiki/spinner.gif",imageAlt:"loading"}},initialize:function(){XWiki.Blog.addBehaviorToBlogTools()},addBehaviorToBlogTools:function(){$$(".blog-tool-hide").each(function(B){B.blogCallback=XWiki.Blog.makeEntryInvisible.bindAsEventListener(B)});$$(".blog-tool-show").each(function(B){B.blogCallback=XWiki.Blog.makeEntryVisible.bindAsEventListener(B)});$$(".blog-tool-show, .blog-tool-hide").each(function(B){B.href=B.href.replace(/&xredirect=.*?(&|$)/,"&ajax=1$1");Event.observe(B,"click",XWiki.Blog.linkDisabler.bindAsEventListener(B));Event.observe(B,"click",B.blogCallback)});var A=$("blog_AddCategoryButton");if(A){Event.observe(A,"click",XWiki.Blog.createBlogCategory.bindAsEventListener(A.form))}},makeEntryInvisible:function(A){Event.stopObserving(this,"click",this.blogCallback);XWiki.Blog.setToolLoadingStatus(this,XWiki.Blog.blogToolsValues.loading);new Ajax.Request(this.href,{method:"get",onSuccess:XWiki.Blog.onEntryMadeInvisible.bind(this),on1223:function(B){B.request.options.onSuccess(B)},on403:function(){alert("You are not allowed to perform this action")},on401:function(){alert("You have been logged out, please login")},onFailure:function(){alert("Failed to change blog post visibility")}})},makeEntryVisible:function(A){Event.stopObserving(this,"click",this.blogCallback);XWiki.Blog.setToolLoadingStatus(this,XWiki.Blog.blogToolsValues.loading);new Ajax.Request(this.href,{method:"get",onSuccess:XWiki.Blog.onEntryMadeVisible.bind(this),on1223:function(B){B.request.options.onSuccess(B)},on403:function(){alert("You are not allowed to perform this action")},on401:function(){alert("You have been logged out, please login")},onFailure:function(){alert("Failed to change blog post visibility")}})},onEntryMadeVisible:function(){var A=XWiki.Blog.getEntry(this);if(A){XWiki.Blog.setEntryVisibility(A,true)}XWiki.Blog.updateShowHideButton(this,XWiki.Blog.blogToolsValues.hide);this.blogCallback=XWiki.Blog.makeEntryInvisible.bindAsEventListener(this);Event.observe(this,"click",this.blogCallback);$$(".entry-content").each(function(B){B.previous(".warningmessage").hide()})},onEntryMadeInvisible:function(){var A=XWiki.Blog.getEntry(this);if(A&&!A.hasClassName("single-article")){XWiki.Blog.setEntryVisibility(A,false)}XWiki.Blog.updateShowHideButton(this,XWiki.Blog.blogToolsValues.show);this.blogCallback=XWiki.Blog.makeEntryVisible.bindAsEventListener(this);Event.observe(this,"click",this.blogCallback);$$(".entry-content").each(function(C){if(C.previous(".warningmessage")){C.previous(".warningmessage").show()}else{var D=document.createElement("div").addClassName("warningmessage");var B=document.createElement("span").addClassName("messagetype");B.appendChild(document.createTextNode("Warning: "));D.appendChild(B);D.appendChild(document.createTextNode("This blog post is hidden."));C.up().insertBefore(D,C)}})},updateShowHideButton:function(A,B){A.title=B.title;A.down("img").src=B.imageSrc;A.down("img").alt=B.alt;A.href=A.href.replace(/&comment=(.*?)(&|$)/,"&comment="+B.comment+"$2");if(A.href.match(/_hidden=1/)){A.href=A.href.replace(/_hidden=1/,"_hidden=0")}else{A.href=A.href.replace(/_hidden=0/,"_hidden=1")}},getEntry:function(A){return A.up(".hentry")},setEntryVisibility:function(A,B){if(B){A.removeClassName("hidden-article")}else{A.addClassName("hidden-article")}},setToolLoadingStatus:function(A,B){A.title=B.title;A.down("img").src=B.imageSrc;A.down("img").alt=B.alt},linkDisabler:function(A){Event.stop(A)},createBlogCategory:function(){var A=this.newCategoryName.value;var F=encodeURI(A.replace(/'/g,"").replace(/"/g,""));var E=encodeURI(A);var B=this.newCategoryParent.value;var D=encodeURI(B.substring(0,B.indexOf(".")));var C=encodeURI(B);new Ajax.Request("/xwiki/bin/save/Blog/__name__?ajax=1&template=Blog.CategoryTemplate".replace(/__name__/g,F)+"&parent="+C+"&title="+E+"&Blog.CategoryClass_0_name="+E,{method:"get",onSuccess:XWiki.Blog.updateCategoryTree.bindAsEventListener(this,A,B,D),on1223:function(G){G.request.options.onSuccess(G)},on409:function(){alert("This category already exists")},on403:function(){alert("You are not allowed to perform this action")},on401:function(){alert("You have been logged out, please login")},onFailure:function(){alert("Failed to add category")}})},updateCategoryTree:function(O,S,H,N){var D=$("blog_category_"+H);if(!D){D=$("blog_category_container")}else{D=D.up()}var M=D.down("ul");if(!M){M=document.createElement("ul");D.appendChild(M)}var C=M.childElements();var I=false;var Q="blog_category_"+N+"."+S;var J=document.createElement("li");var G=document.createElement("label");G.id=Q;J.appendChild(G);var L=document.createElement("input");L.type="checkbox";L.checked="checked";L.name="Blog.BlogPostClass_0_category";L.value=N+"."+S;G.appendChild(L);G.appendChild(document.createTextNode(" "+S));var K=document.createElement("option");K.id=Q+"_option";K.value=N+"."+S;var R=0;var F=D;while(F&&F!=$("blog_category_container")){R++;F=F.up("li")}K.appendChild(document.createTextNode("&nbsp;".unescapeHTML().times(2*R)+S));var B=$("blog_category_selectBox");for(var P=0;P<C.size();++P){if(C[P].down("label").id>Q){M.insertBefore(J,C[P]);var E=$(C[P].down("label").id+"_option");B.insertBefore(K,E);I=true;break}}if(!I){M.appendChild(J);var F=D;var A;while(!A&&F){A=F.next("li");F=F.up("li")}if(A){B.insertBefore(K,$(A.down("label").id+"_option"))}else{B.appendChild(K)}}}};function publishEntry(C,A,B){new Ajax.Request("/xwiki/bin/view/Blog/__name__".replace(/__name__/g,C)+"?entryName="+A,{method:"get",onSuccess:function(){alert("done");B.parentNode.removeChild(B)}});return false}document.observe("dom:loaded",XWiki.Blog.initialize)