"undefined"==typeof XWiki&&(XWiki={});
XWiki.Blog={blogToolsValues:{show:{title:"This blog post is not visible to other users. Make it visible",imageSrc:"/xwiki/resources/icons/silk/lock_open.png?cache-version\x3d1759477984000",imageAlt:"show",comment:"Made%20entry%20visible"},hide:{title:"Hide this blog post from other users",imageSrc:"/xwiki/resources/icons/silk/lock.png?cache-version\x3d1759477984000",imageAlt:"hide",comment:"Hidden%20entry"},loading:{title:"Loading...",imageSrc:"/xwiki/resources/icons/xwiki/spinner.gif?cache-version\x3d1759477984000",imageAlt:"loading"}},
initialize:function(){XWiki.Blog.addBehaviorToBlogTools()},addBehaviorToBlogTools:function(){$$(".blog-tool-hide").each(function(a){a.blogCallback=XWiki.Blog.makeEntryInvisible.bindAsEventListener(a)});$$(".blog-tool-show").each(function(a){a.blogCallback=XWiki.Blog.makeEntryVisible.bindAsEventListener(a)});$$(".blog-tool-show, .blog-tool-hide").each(function(a){a.href=a.href.replace(/&xredirect=.*?(&|$)/,"\x26ajax\x3d1$1");Event.observe(a,"click",XWiki.Blog.linkDisabler.bindAsEventListener(a));Event.observe(a,
"click",a.blogCallback)});var b=$("blog_AddCategoryButton");b&&Event.observe(b,"click",XWiki.Blog.createBlogCategory.bindAsEventListener(b.form))},makeEntryInvisible:function(b){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(a){a.request.options.onSuccess(a)},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(b){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(a){a.request.options.onSuccess(a)},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 b=XWiki.Blog.getEntry(this);b&&XWiki.Blog.setEntryVisibility(b,!0);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(a){a.previous(".warningmessage").hide()})},
onEntryMadeInvisible:function(){var b=XWiki.Blog.getEntry(this);b&&!b.hasClassName("single-article")&&XWiki.Blog.setEntryVisibility(b,!1);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(a){if(a.previous(".warningmessage"))a.previous(".warningmessage").show();else{var d=document.createElement("div").addClassName("warningmessage"),
c=document.createElement("span").addClassName("messagetype");c.appendChild(document.createTextNode("Warning: "));d.appendChild(c);d.appendChild(document.createTextNode("This blog post is hidden."));a.up().insertBefore(d,a)}})},updateShowHideButton:function(b,a){b.title=a.title;b.down("img").src=a.imageSrc;b.down("img").alt=a.alt;b.href=b.href.replace(/&comment=(.*?)(&|$)/,"\x26comment\x3d"+a.comment+"$2");b.href.match(/_hidden=1/)?b.href=b.href.replace(/_hidden=1/,"_hidden\x3d0"):b.href=b.href.replace(/_hidden=0/,
"_hidden\x3d1")},getEntry:function(b){return b.up(".hentry")},setEntryVisibility:function(b,a){a?b.removeClassName("hidden-article"):b.addClassName("hidden-article")},setToolLoadingStatus:function(b,a){b.title=a.title;b.down("img").src=a.imageSrc;b.down("img").alt=a.alt},linkDisabler:function(b){Event.stop(b)},createBlogCategory:function(){var b=this.newCategoryName.value,a=encodeURI(b.replace(/'/g,"").replace(/"/g,"")),d=encodeURI(b),c=this.newCategoryParent.value,f=encodeURI(c.substring(0,c.indexOf("."))),
k=encodeURI(c);new Ajax.Request("/xwiki/bin/save/Blog/__name__?ajax\x3d1\x26template\x3dBlog.CategoryTemplate\x26form_token\x3d1xvDXCpZXD6oBSk3QhPBpg".replace(/__name__/g,a)+"\x26parent\x3d"+k+"\x26title\x3d"+d+"\x26Blog.CategoryClass_0_name\x3d"+d,{method:"get",onSuccess:XWiki.Blog.updateCategoryTree.bindAsEventListener(this,b,c,f),on1223:function(h){h.request.options.onSuccess(h)},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(b,a,d,c){b=(b=$("blog_category_"+d))?b.up():$("blog_category_container");d=b.down("ul");d||(d=document.createElement("ul"),b.appendChild(d));var f=d.childElements(),k=!1,h="blog_category_"+c+"."+a,m=document.createElement("li"),e=document.createElement("label");e.id=h;m.appendChild(e);var g=document.createElement("input");g.type="checkbox";g.checked=
"checked";g.name="Blog.BlogPostClass_0_category";g.value=c+"."+a;e.appendChild(g);e.appendChild(document.createTextNode(" "+a));e=document.createElement("option");e.id=h+"_option";e.value=c+"."+a;g=0;for(c=b;c&&c!=$("blog_category_container");)g++,c=c.up("li");e.appendChild(document.createTextNode("\x26nbsp;".unescapeHTML().times(2*g)+a));a=$("blog_category_selectBox");for(c=0;c<f.size();++c)if(f[c].down("label").id>h){d.insertBefore(m,f[c]);f=$(f[c].down("label").id+"_option");a.insertBefore(e,f);
k=!0;break}if(!k){d.appendChild(m);c=b;for(var l;!l&&c;)l=c.next("li"),c=c.up("li");l?a.insertBefore(e,$(l.down("label").id+"_option")):a.appendChild(e)}}};function publishEntry(b,a,d){new Ajax.Request("/xwiki/bin/view/Blog/__name__".replace(/__name__/g,b)+"?entryName\x3d"+a,{method:"get",onSuccess:function(){alert("done");d.parentNode.removeChild(d)}});return!1}document.observe("dom:loaded",XWiki.Blog.initialize);