var AttachDlg={preInit:function(){tinyMCEPopup.requireLangPack();},init:function(ed){FoswikiTiny.getListOfAttachments(function(atts){var select=document.getElementById("attachments_select");for(var i=0;i<atts.length;i++){select.options[i]=new Option(atts[i].name,atts[i].name);}});var el=document.getElementById('upload_form');el.action=FoswikiTiny.getRESTURL('upload');el=document.getElementById('upload_form_topic');el.value=FoswikiTiny.getTopicPath();tinyMCEPopup.resizeToInnerSize();},insertLink:function(){var inst=tinyMCE.activeEditor;var select=document.getElementById("attachments_select");var filename=select.value;var url=FoswikiTiny.getFoswikiVar("ATTACHURL")+'/'+filename;var tmp=filename.lastIndexOf(".");if(tmp>=0)
tmp=filename.substring(tmp+1,filename.length).toLowerCase();var html;if(tmp=="jpg"||tmp=="gif"||tmp=="jpeg"||tmp=="png"||tmp=="bmp"){html="<img src='"+url+"' alt='"+filename+"'>";}else{html="<a href='"+url+"'>"+filename+"</a>";}
inst.execCommand('mceInsertContent',false,html);inst.nodeChanged();tinyMCEPopup.close();}};AttachDlg.preInit();tinyMCEPopup.onInit.add(AttachDlg.init,AttachDlg);