var jQuery,$,$dlg,AttachDlg={preInit:function(){tinyMCEPopup.requireLangPack()},init:function(t){if(void 0===jQuery){var e=document.getElementsByTagName("body")[0];jQuery=parent.window.jQuery,$=jQuery,$dlg=function(t){return parent.jQuery(t,e)}}$dlg("#insert").click((function(){AttachDlg.insert($dlg("#attachments_select").val())})),FoswikiTiny.getListOfAttachments((function(t){var e=$dlg("#attachments_select");if(t.length>0)for(var n=0;n<t.length;n++)e.append('<option value="'+t[n].name+'">'+t[n].name+"</option>");else $dlg("#general_tab").removeClass("current"),$dlg("#general_panel").removeClass("current"),$dlg("#upload_tab").addClass("current"),$dlg("#upload_panel").addClass("current")}));var n=$dlg("#upload_form"),a=FoswikiTiny.getScriptURL("upload");$dlg("#upload_form_topic").val(FoswikiTiny.getTopicPath()),n.submit((function(){return AttachDlg.submit(a,n)})),tinyMCEPopup.resizeToInnerSize()},insert:function(t){var e,n=tinyMCE.activeEditor,a=FoswikiTiny.getFoswikiVar("ATTACHURL")+"/"+t,i=t.lastIndexOf(".");i>=0&&(i=t.substring(i+1,t.length).toLowerCase()),e="jpg"==i||"gif"==i||"jpeg"==i||"png"==i||"bmp"==i?"<img src='"+a+"' alt='"+t+"'>":"<a href='"+a+"'>"+t+"</a>",n.execCommand("mceInsertContent",!1,e),n.nodeChanged(),tinyMCEPopup.close()},submit:function(t,e){var n=parent.document.EditForm.validation_key;if("undefined"!=typeof StrikeOne&&n){var a=n.value;a&&$dlg("#validation_key").val(StrikeOne.calculateNewKey(a))}return $dlg("#status_frame").text("Uploading..."),e.attr("action",t),e[0].preserve_vk||e.append('<input type="hidden" name="preserve_vk" value="1" />'),$dlg('iframe[name="upload_iframe"]').load((function(t){var e=$(t.target.contentDocument);AttachDlg.handle_message($("body",e).html())})),!0},handle_message:function(t){var e=/OopsException\(attention\/(\w+)/.exec(t);if(e){var n=$dlg("#"+e[1]);if(n.length)return void $dlg("#status_frame").html(n.html())}$dlg("#status_frame").text(t)}};AttachDlg.preInit(),tinyMCEPopup.onInit.add(AttachDlg.init,AttachDlg);
