!function(){var e=tinymce.each;tinymce.create("tinymce.plugins.TemplatePlugin",{init:function(t,a){var n=this;n.editor=t,t.addCommand("mceTemplate",(function(e){t.windowManager.open({file:a+"/template.htm",width:t.getParam("template_popup_width",750),height:t.getParam("template_popup_height",600),inline:1},{plugin_url:a})})),t.addCommand("mceInsertTemplate",n._insertTemplate,n),t.addButton("template",{title:"template.desc",cmd:"mceTemplate"}),t.onPreProcess.add((function(t,a){var l=t.dom;e(l.select("div",a.node),(function(a){l.hasClass(a,"mceTmpl")&&(e(l.select("*",a),(function(e){l.hasClass(e,t.getParam("template_mdate_classes","mdate").replace(/\s+/g,"|"))&&(e.innerHTML=n._getDateTime(new Date,t.getParam("template_mdate_format",t.getLang("template.mdate_format"))))})),n._replaceVals(a))}))}))},getInfo:function(){return{longname:"Template plugin",author:"Moxiecode Systems AB",authorurl:"http://www.moxiecode.com",infourl:"http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/template",version:tinymce.majorVersion+"."+tinymce.minorVersion}},_insertTemplate:function(t,a){var l,r,m=this,i=m.editor,c=i.dom,o=i.selection.getContent();function p(e,t){return new RegExp("\\b"+t+"\\b","g").test(e.className)}l=a.content,e(m.editor.getParam("template_replace_values"),(function(e,t){"function"!=typeof e&&(l=l.replace(new RegExp("\\{\\$"+t+"\\}","g"),e))})),r=c.create("div",null,l),n=c.select(".mceTmpl",r),n&&n.length>0&&(r=c.create("div",null)).appendChild(n[0].cloneNode(!0)),e(c.select("*",r),(function(e){p(e,i.getParam("template_cdate_classes","cdate").replace(/\s+/g,"|"))&&(e.innerHTML=m._getDateTime(new Date,i.getParam("template_cdate_format",i.getLang("template.cdate_format")))),p(e,i.getParam("template_mdate_classes","mdate").replace(/\s+/g,"|"))&&(e.innerHTML=m._getDateTime(new Date,i.getParam("template_mdate_format",i.getLang("template.mdate_format")))),p(e,i.getParam("template_selected_content_classes","selcontent").replace(/\s+/g,"|"))&&(e.innerHTML=o)})),m._replaceVals(r),i.execCommand("mceInsertContent",!1,r.innerHTML),i.addVisual()},_replaceVals:function(t){var a=this.editor.dom,n=this.editor.getParam("template_replace_values");e(a.select("*",t),(function(t){e(n,(function(e,l){a.hasClass(t,l)&&"function"==typeof n[l]&&n[l](t)}))}))},_getDateTime:function(e,t){if(!t)return"";function a(e,t){var a;if((e=""+e).length<t)for(a=0;a<t-e.length;a++)e="0"+e;return e}return t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=t.replace("%D","%m/%d/%y")).replace("%r","%I:%M:%S %p")).replace("%Y",""+e.getFullYear())).replace("%y",""+e.getYear())).replace("%m",a(e.getMonth()+1,2))).replace("%d",a(e.getDate(),2))).replace("%H",""+a(e.getHours(),2))).replace("%M",""+a(e.getMinutes(),2))).replace("%S",""+a(e.getSeconds(),2))).replace("%I",""+((e.getHours()+11)%12+1))).replace("%p",e.getHours()<12?"AM":"PM")).replace("%B",""+this.editor.getLang("template_months_long").split(",")[e.getMonth()])).replace("%b",""+this.editor.getLang("template_months_short").split(",")[e.getMonth()])).replace("%A",""+this.editor.getLang("template_day_long").split(",")[e.getDay()])).replace("%a",""+this.editor.getLang("template_day_short").split(",")[e.getDay()])).replace("%%","%")}}),tinymce.PluginManager.add("template",tinymce.plugins.TemplatePlugin)}();
