/*
Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

(function(){(function(){function a(j,k){var l=[];if(!k)return j;else for(var m in k)l.push(m+'='+encodeURIComponent(k[m]));return j+(j.indexOf('?')!=-1?'&':'?')+l.join('&');};function b(j){j+='';var k=j.charAt(0).toUpperCase();return k+j.substr(1);};function c(j){var k=this,l=k.getDialog(),m=l.getParentEditor();m._.filebrowserSe=k;var n=m.config['filebrowser'+b(l.getName())+'WindowWidth']||m.config.filebrowserWindowWidth||'80%',o=m.config['filebrowser'+b(l.getName())+'WindowHeight']||m.config.filebrowserWindowHeight||'70%',p=k.filebrowser.params||{};p.CKEditor=m.name;p.CKEditorFuncNum=m._.filebrowserFn;if(!p.langCode)p.langCode=m.langCode;if(typeof k.filebrowser.url=='function')k.filebrowser.url(p);else{var q=a(k.filebrowser.url,p);m.popup(q,n,o,m.config.fileBrowserWindowFeatures);}};function d(j){var k=this,l=k.getDialog(),m=l.getParentEditor();m._.filebrowserSe=k;if(!l.getContentElement(k['for'][0],k['for'][1]).getInputElement().$.value)return false;if(!l.getContentElement(k['for'][0],k['for'][1]).getAction())return false;return true;};function e(j,k,l){var m=l.params||{};m.CKEditor=j.name;m.CKEditorFuncNum=j._.filebrowserFn;if(!m.langCode)m.langCode=j.langCode;k.action=a(l.url,m);k.filebrowser=l;};function f(j,k,l,m){var n,o;for(var p in m){n=m[p];if(n.type=='hbox'||n.type=='vbox')f(j,k,l,n.children);if(!n.filebrowser)continue;if(typeof n.filebrowser=='string'){var q={action:n.type=='fileButton'?'QuickUpload':'Browse',target:n.filebrowser};n.filebrowser=q;}if(n.filebrowser.action=='Browse'){var r=n.filebrowser.url;if(r===undefined){r=j.config['filebrowser'+b(k)+'BrowseUrl'];if(r===undefined){r=j.config['filebrowser'+b(k)+'BrowseFunc'];if(r===undefined){r=j.config.filebrowserBrowseFunc;if(r===undefined)r=j.config.filebrowserBrowseUrl;}}}if(r){n.onClick=c;if(r){n.filebrowser.url=r;n.hidden=false;}}}else if(n.filebrowser.action=='QuickUpload'&&n['for']){r=n.filebrowser.url;if(r===undefined){r=j.config['filebrowser'+b(k)+'UploadUrl'];if(r===undefined)r=j.config.filebrowserUploadUrl;}if(r){var s=n.onClick;n.onClick=function(t){var u=t.sender;if(s&&s.call(u,t)===false)return false;return d.call(u,t);};n.filebrowser.url=r;n.hidden=false;e(j,l.getContents(n['for'][0]).get(n['for'][1]),n.filebrowser);}}}};function g(j,k){var l=k.getDialog(),m=k.filebrowser.target||null;j=j.replace(/#/g,'%23');if(m){var n=m.split(':'),o=l.getContentElement(n[0],n[1]);if(o){o.setValue(j);l.selectPage(n[0]);}}};function h(j,k,l){if(l.indexOf(';')!==-1){var m=l.split(';');for(var n=0;
n<m.length;n++){if(h(j,k,m[n]))return true;}return false;}var o=j.getContents(k).get(l).filebrowser;return o&&o.url;};function i(j,k){var l=this,m=l._.filebrowserSe.getDialog(),n=l._.filebrowserSe['for'],o=l._.filebrowserSe.filebrowser.onSelect;if(n)m.getContentElement(n[0],n[1]).reset();if(typeof k=='function'&&k.call(l._.filebrowserSe)===false)return;if(o&&o.call(l._.filebrowserSe,j,k)===false)return;if(typeof k=='string'&&k)alert(k);if(j)g(j,l._.filebrowserSe);};CKEDITOR.plugins.add('filebrowser',{init:function(j,k){j._.filebrowserFn=CKEDITOR.tools.addFunction(i,j);j.on('destroy',function(){CKEDITOR.tools.removeFunction(this._.filebrowserFn);});}});CKEDITOR.on('dialogDefinition',function(j){var k=j.data.definition,l;for(var m in k.contents){if(l=k.contents[m]){f(j.editor,j.data.name,k,l.elements);if(l.hidden&&l.filebrowser)l.hidden=!h(k,l.id,l.filebrowser);}}});})();})();
