CKEDITOR.dialog.add('link',function(a){var b={},c={image:['jpg','jpeg','gif','png','bmp'],video:['avi','rm','rmvb','mpg','mpeg','3gp','mp4','wmv','ra'],flash:['swf','flv','fla'],zip:['zip','rar','gz','tgz','7z','bz2'],word:['doc'],excel:['xls']};for(var d in c)for(var e in c[d])b[c[d][e]]=d;delete c._map;function f(L){var M=L.lastIndexOf('.'),N=L.substr(M!=-1?M+1:0).toLowerCase().replace(/(?:\?|#).*/g,'');return '<img src="'+CKEDITOR.basePath+'images/icons/'+(b[N]?b[N]:'default')+'.gif" />';};var g=false,h=CKEDITOR.plugins.link,i=function(){var L=this.getDialog(),M=L.getContentElement('target','popupFeatures'),N=L.getContentElement('target','linkTargetName'),O=this.getValue();if(!M||!N)return;M=M.getElement();M.hide();N.setValue('');switch(O){case 'frame':N.setLabel(a.lang.link.targetFrameName);N.getElement().show();break;case 'popup':M.show();N.setLabel(a.lang.link.targetPopupName);N.getElement().show();break;default:N.setValue(O);N.getElement().hide();break;}},j=function(){var L=this.getDialog(),M=['urlOptions','anchorOptions','emailOptions'],N=this.getValue(),O=L.definition.getContents('upload'),P=O&&O.hidden;if(N=='url'){if(a.config.linkShowTargetTab)L.showPage('target');if(!P)L.showPage('upload');}else{L.hidePage('target');if(!P)L.hidePage('upload');}for(var Q=0;Q<M.length;Q++){var R=L.getContentElement('info',M[Q]);if(!R)continue;R=R.getElement().getParent().getParent();if(M[Q]==N+'Options')R.show();else R.hide();}L.layout();},k=/^javascript:/,l=/^mailto:([^?]+)(?:\?(.+))?$/,m=/subject=([^;?:@&=$,\/]*)/,n=/body=([^;?:@&=$,\/]*)/,o=/^#(.*)$/,p=/^((?:http|https|ftp|news):\/\/)?(.*)$/,q=/^(_(?:self|top|parent|blank))$/,r=/^javascript:void\(location\.href='mailto:'\+String\.fromCharCode\(([^)]+)\)(?:\+'(.*)')?\)$/,s=/^javascript:([^(]+)\(([^)]+)\)$/,t=/\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/,u=/(?:^|,)([^=]+)=(\d+|yes|no)/gi,v=function(L,M){var N=M&&(M.data('cke-saved-href')||M.getAttribute('href'))||'',O,P,Q,R,S={};if(O=N.match(k))if(E=='encode')N=N.replace(r,function(ai,aj,ak){return 'mailto:'+String.fromCharCode.apply(String,aj.split(','))+(ak&&C(ak));});else if(E)N.replace(s,function(ai,aj,ak){if(aj==F.name){S.type='email';var al=S.email={},am=/[^,\s]+/g,an=/(^')|('$)/g,ao=ak.match(am),ap=ao.length,aq,ar;for(var as=0;as<ap;as++){ar=decodeURIComponent(C(ao[as].replace(an,'')));aq=F.params[as].toLowerCase();al[aq]=ar;}al.address=[al.name,al.domain].join('@');}});if(!S.type)if(Q=N.match(o)){S.type='anchor';
S.anchor={};S.anchor.name=S.anchor.id=Q[1];}else if(P=N.match(l)){var T=N.match(m),U=N.match(n);S.type='email';var V=S.email={};V.address=P[1];T&&(V.subject=decodeURIComponent(T[1]));U&&(V.body=decodeURIComponent(U[1]));}else if(N&&(R=N.match(p))){S.type='url';S.url={};S.url.protocol=R[1];S.url.url=R[2];}else S.type='url';if(M){var W=M.getAttribute('target');S.target={};S.adv={};if(!W){var X=M.data('cke-pa-onclick')||M.getAttribute('onclick'),Y=X&&X.match(t);if(Y){S.target.type='popup';S.target.name=Y[1];var Z;while(Z=u.exec(Y[2])){if((Z[2]=='yes'||Z[2]=='1')&&!(Z[1] in {height:1,width:1,top:1,left:1}))S.target[Z[1]]=true;else if(isFinite(Z[2]))S.target[Z[1]]=Z[2];}}}else{var aa=W.match(q);if(aa)S.target.type=S.target.name=W;else{S.target.type='frame';S.target.name=W;}}var ab=this,ac=function(ai,aj){var ak=M.getAttribute(aj);if(ak!==null)S.adv[ai]=ak||'';};ac('advId','id');ac('advLangDir','dir');ac('advAccessKey','accessKey');S.adv.advName=M.data('cke-saved-name')||M.getAttribute('name')||'';ac('advLangCode','lang');ac('advTabIndex','tabindex');ac('advTitle','title');ac('advContentType','type');CKEDITOR.plugins.link.synAnchorSelector?S.adv.advCSSClasses=I(M):ac('advCSSClasses','class');ac('advCharset','charset');ac('advStyles','style');ac('advRel','rel');}var ad=new CKEDITOR.dom.nodeList(L.document.$.anchors),ae=S.anchors=[],af;for(var ag=0,ah=ad.count();ag<ah;ag++){af=ad.getItem(ag);ae[ag]={name:af.getAttribute('name'),id:af.getAttribute('id')};}this._.selectedElement=M;return S;},w=function(L,M){if(M[L])this.setValue(M[L][this.id]||'');},x=function(L){return w.call(this,'target',L);},y=function(L){return w.call(this,'adv',L);},z=function(L,M){if(!M[L])M[L]={};M[L][this.id]=this.getValue()||'';},A=function(L){return z.call(this,'target',L);},B=function(L){return z.call(this,'adv',L);};function C(L){return L.replace(/\\'/g,"'");};function D(L){return L.replace(/'/g,'\\$&');};var E=a.config.emailProtection||'';if(E&&E!='encode'){var F={};E.replace(/^([^(]+)\(([^)]+)\)$/,function(L,M,N){F.name=M;F.params=[];N.replace(/[^,\s]+/g,function(O){F.params.push(O);});});}function G(L){var M,N=F.name,O=F.params,P,Q;M=[N,'('];for(var R=0;R<O.length;R++){P=O[R].toLowerCase();Q=L[P];R>0&&M.push(',');M.push("'",Q?D(encodeURIComponent(L[P])):'',"'");}M.push(')');return M.join('');};function H(L){var M,N=L.length,O=[];for(var P=0;P<N;P++){M=L.charCodeAt(P);O.push(M);}return 'String.fromCharCode('+O.join(',')+')';};function I(L){var M=L.getAttribute('class');return M?M.replace(/\s*(?:cke_anchor_empty|cke_anchor)(?:\s*$)?/g,''):'';
};var J=a.lang.common,K=a.lang.link;return{title:K.title,minWidth:350,minHeight:230,contents:[{id:'info',label:K.info,title:K.info,elements:[{type:'vbox',children:[{type:'hbox',padding:0,children:[{type:'button',label:a.lang.common.browseServer,onClick:function(){var L=this.getDialog();L.P8_CKEDITOR_uploader.browser();L.from_upload=false;}},{type:'button',label:a.lang.common.upload,onClick:function(){var L=this.getDialog();L.P8_CKEDITOR_uploader.uploader();L.from_upload=false;}}]},{type:'html',html:'<div id="P8_CKEDITOR_multi_links" style="display: none;"></div>'}]},{id:'linkType',type:'select',label:K.type,'default':'url',items:[[K.toUrl,'url'],[K.toAnchor,'anchor'],[K.toEmail,'email']],onChange:j,setup:function(L){if(L.type)this.setValue(L.type);},commit:function(L){L.type=this.getValue();}},{type:'vbox',id:'urlOptions',children:[{type:'hbox',widths:['25%','75%'],children:[{id:'protocol',type:'select',label:J.protocol,'default':'http://',items:[['http://‎','http://'],['https://‎','https://'],['ftp://‎','ftp://'],['news://‎','news://'],[K.other,'']],setup:function(L){if(L.url)this.setValue(L.url.protocol||'');},commit:function(L){if(!L.url)L.url={};L.url.protocol=this.getValue();}},{type:'text',id:'url',label:J.url,required:true,onLoad:function(){this.allowOnChange=true;},onKeyUp:function(){var Q=this;Q.allowOnChange=false;var L=Q.getDialog().getContentElement('info','protocol'),M=Q.getValue(),N=/^(http|https|ftp|news):\/\/(?=.)/i,O=/^((javascript:)|[#\/\.\?])/i,P=N.exec(M);if(P){Q.setValue(M.substr(P[0].length));L.setValue(P[0].toLowerCase());}else if(O.test(M))L.setValue('');Q.allowOnChange=true;},onChange:function(){if(this.allowOnChange)this.onKeyUp();},validate:function(){var L=this.getDialog();if(L.getContentElement('info','linkType')&&L.getValueOf('info','linkType')!='url')return true;if(this.getDialog().fakeObj)return true;var M=CKEDITOR.dialog.validate.notEmpty(K.noUrl);return M.apply(this);},setup:function(L){this.allowOnChange=false;if(L.url)this.setValue(L.url.url);this.allowOnChange=true;},commit:function(L){this.onChange();if(!L.url)L.url={};L.url.url=this.getValue();this.allowOnChange=false;}}],setup:function(L){if(!this.getDialog().getContentElement('info','linkType'))this.getElement().show();}},{type:'button',id:'browse',hidden:'true',filebrowser:'info:url',label:J.browseServer}]},{type:'vbox',id:'anchorOptions',width:260,align:'center',padding:0,children:[{type:'fieldset',id:'selectAnchorText',label:K.selectAnchor,setup:function(L){if(L.anchors.length>0)this.getElement().show();
else this.getElement().hide();},children:[{type:'hbox',id:'selectAnchor',children:[{type:'select',id:'anchorName','default':'',label:K.anchorName,style:'width: 100%;',items:[['']],setup:function(L){var O=this;O.clear();O.add('');for(var M=0;M<L.anchors.length;M++){if(L.anchors[M].name)O.add(L.anchors[M].name);}if(L.anchor)O.setValue(L.anchor.name);var N=O.getDialog().getContentElement('info','linkType');if(N&&N.getValue()=='email')O.focus();},commit:function(L){if(!L.anchor)L.anchor={};L.anchor.name=this.getValue();}},{type:'select',id:'anchorId','default':'',label:K.anchorId,style:'width: 100%;',items:[['']],setup:function(L){var N=this;N.clear();N.add('');for(var M=0;M<L.anchors.length;M++){if(L.anchors[M].id)N.add(L.anchors[M].id);}if(L.anchor)N.setValue(L.anchor.id);},commit:function(L){if(!L.anchor)L.anchor={};L.anchor.id=this.getValue();}}],setup:function(L){if(L.anchors.length>0)this.getElement().show();else this.getElement().hide();}}]},{type:'html',id:'noAnchors',style:'text-align: center;',html:'<div role="label" tabIndex="-1">'+CKEDITOR.tools.htmlEncode(K.noAnchors)+'</div>',focus:true,setup:function(L){if(L.anchors.length<1)this.getElement().show();else this.getElement().hide();}}],setup:function(L){if(!this.getDialog().getContentElement('info','linkType'))this.getElement().hide();}},{type:'vbox',id:'emailOptions',padding:1,children:[{type:'text',id:'emailAddress',label:K.emailAddress,required:true,validate:function(){var L=this.getDialog();if(!L.getContentElement('info','linkType')||L.getValueOf('info','linkType')!='email')return true;var M=CKEDITOR.dialog.validate.notEmpty(K.noEmail);return M.apply(this);},setup:function(L){if(L.email)this.setValue(L.email.address);var M=this.getDialog().getContentElement('info','linkType');if(M&&M.getValue()=='email')this.select();},commit:function(L){if(!L.email)L.email={};L.email.address=this.getValue();}},{type:'text',id:'emailSubject',label:K.emailSubject,setup:function(L){if(L.email)this.setValue(L.email.subject);},commit:function(L){if(!L.email)L.email={};L.email.subject=this.getValue();}},{type:'textarea',id:'emailBody',label:K.emailBody,rows:3,'default':'',setup:function(L){if(L.email)this.setValue(L.email.body);},commit:function(L){if(!L.email)L.email={};L.email.body=this.getValue();}}],setup:function(L){if(!this.getDialog().getContentElement('info','linkType'))this.getElement().hide();}}]},{id:'target',label:K.target,title:K.target,elements:[{type:'hbox',widths:['50%','50%'],children:[{type:'select',id:'linkTargetType',label:J.target,'default':'_blank',style:'width : 100%;',items:[[J.notSet,'notSet'],[K.targetFrame,'frame'],[K.targetPopup,'popup'],[J.targetNew,'_blank'],[J.targetTop,'_top'],[J.targetSelf,'_self'],[J.targetParent,'_parent']],onChange:i,setup:function(L){if(L.target)this.setValue(L.target.type||'notSet');
i.call(this);},commit:function(L){if(!L.target)L.target={};L.target.type=this.getValue();}},{type:'text',id:'linkTargetName',label:K.targetFrameName,'default':'',setup:function(L){if(L.target)this.setValue(L.target.name);},commit:function(L){if(!L.target)L.target={};L.target.name=this.getValue().replace(/\W/gi,'');}}]},{type:'vbox',width:'100%',align:'center',padding:2,id:'popupFeatures',children:[{type:'fieldset',label:K.popupFeatures,children:[{type:'hbox',children:[{type:'checkbox',id:'resizable',label:K.popupResizable,setup:x,commit:A},{type:'checkbox',id:'status',label:K.popupStatusBar,setup:x,commit:A}]},{type:'hbox',children:[{type:'checkbox',id:'location',label:K.popupLocationBar,setup:x,commit:A},{type:'checkbox',id:'toolbar',label:K.popupToolbar,setup:x,commit:A}]},{type:'hbox',children:[{type:'checkbox',id:'menubar',label:K.popupMenuBar,setup:x,commit:A},{type:'checkbox',id:'fullscreen',label:K.popupFullScreen,setup:x,commit:A}]},{type:'hbox',children:[{type:'checkbox',id:'scrollbars',label:K.popupScrollBars,setup:x,commit:A},{type:'checkbox',id:'dependent',label:K.popupDependent,setup:x,commit:A}]},{type:'hbox',children:[{type:'text',widths:['50%','50%'],labelLayout:'horizontal',label:J.width,id:'width',setup:x,commit:A},{type:'text',labelLayout:'horizontal',widths:['50%','50%'],label:K.popupLeft,id:'left',setup:x,commit:A}]},{type:'hbox',children:[{type:'text',labelLayout:'horizontal',widths:['50%','50%'],label:J.height,id:'height',setup:x,commit:A},{type:'text',labelLayout:'horizontal',label:K.popupTop,widths:['50%','50%'],id:'top',setup:x,commit:A}]}]}]}]},{id:'upload',label:K.upload,title:K.upload,hidden:true,filebrowser:'uploadButton',elements:[{type:'file',id:'upload',label:J.upload,style:'height:40px',size:29},{type:'fileButton',id:'uploadButton',label:J.uploadSubmit,filebrowser:'info:url','for':['upload','upload']}]},{id:'advanced',label:K.advanced,title:K.advanced,elements:[{type:'vbox',padding:1,children:[{type:'hbox',widths:['45%','35%','20%'],children:[{type:'text',id:'advId',label:K.id,setup:y,commit:B},{type:'select',id:'advLangDir',label:K.langDir,'default':'',style:'width:110px',items:[[J.notSet,''],[K.langDirLTR,'ltr'],[K.langDirRTL,'rtl']],setup:y,commit:B},{type:'text',id:'advAccessKey',width:'80px',label:K.acccessKey,maxLength:1,setup:y,commit:B}]},{type:'hbox',widths:['45%','35%','20%'],children:[{type:'text',label:K.name,id:'advName',setup:y,commit:B},{type:'text',label:K.langCode,id:'advLangCode',width:'110px','default':'',setup:y,commit:B},{type:'text',label:K.tabIndex,id:'advTabIndex',width:'80px',maxLength:5,setup:y,commit:B}]}]},{type:'vbox',padding:1,children:[{type:'hbox',widths:['45%','55%'],children:[{type:'text',label:K.advisoryTitle,'default':'',id:'advTitle',setup:y,commit:B},{type:'text',label:K.advisoryContentType,'default':'',id:'advContentType',setup:y,commit:B}]},{type:'hbox',widths:['45%','55%'],children:[{type:'text',label:K.cssClasses,'default':'',id:'advCSSClasses',setup:y,commit:B},{type:'text',label:K.charset,'default':'',id:'advCharset',setup:y,commit:B}]},{type:'hbox',widths:['45%','55%'],children:[{type:'text',label:K.rel,'default':'',id:'advRel',setup:y,commit:B},{type:'text',label:K.styles,'default':'',id:'advStyles',setup:y,commit:B}]}]}]}],onShow:function(){var L=this.getParentEditor(),M=L.getSelection(),N=null;
if((N=h.getSelectedLink(L))&&N.hasAttribute('href'))M.selectElement(N);else N=null;this.setupContent(v.apply(this,[L,N]));},onOk:function(){var L={},M=[],N={},O=this,P=this.getParentEditor();this.commitContent(N);switch(N.type||'url'){case 'url':var Q=N.url&&N.url.protocol!=undefined?N.url.protocol:'http://',R=N.url&&N.url.url||'';L['data-cke-saved-href']=R.indexOf('/')===0?R:Q+R;break;case 'anchor':var S=N.anchor&&N.anchor.name,T=N.anchor&&N.anchor.id;L['data-cke-saved-href']='#'+(S||T||'');break;case 'email':var U,V=N.email,W=V.address;switch(E){case '':case 'encode':var X=encodeURIComponent(V.subject||''),Y=encodeURIComponent(V.body||''),Z=[];X&&Z.push('subject='+X);Y&&Z.push('body='+Y);Z=Z.length?'?'+Z.join('&'):'';if(E=='encode'){U=["javascript:void(location.href='mailto:'+",H(W)];Z&&U.push("+'",D(Z),"'");U.push(')');}else U=['mailto:',W,Z];break;default:var aa=W.split('@',2);V.name=aa[0];V.domain=aa[1];U=['javascript:',G(V)];}L['data-cke-saved-href']=U.join('');break;}if(N.target)if(N.target.type=='popup'){var ab=["window.open(this.href, '",N.target.name||'',"', '"],ac=['resizable','status','location','toolbar','menubar','fullscreen','scrollbars','dependent'],ad=ac.length,ae=function(ar){if(N.target[ar])ac.push(ar+'='+N.target[ar]);};for(var af=0;af<ad;af++)ac[af]=ac[af]+(N.target[ac[af]]?'=yes':'=no');ae('width');ae('left');ae('height');ae('top');ab.push(ac.join(','),"'); return false;");L['data-cke-pa-onclick']=ab.join('');M.push('target');}else{if(N.target.type!='notSet'&&N.target.name)L.target=N.target.name;else M.push('target');M.push('data-cke-pa-onclick','onclick');}if(N.adv){var ag=function(ar,as){var at=N.adv[ar];if(at)L[as]=at;else M.push(as);};ag('advId','id');ag('advLangDir','dir');ag('advAccessKey','accessKey');if(N.adv.advName)L.name=L['data-cke-saved-name']=N.adv.advName;else M=M.concat(['data-cke-saved-name','name']);ag('advLangCode','lang');ag('advTabIndex','tabindex');ag('advTitle','title');ag('advContentType','type');ag('advCSSClasses','class');ag('advCharset','charset');ag('advStyles','style');ag('advRel','rel');}L.href=L['data-cke-saved-href'];if(!this._.selectedElement){var ah=P.getSelection(),ai=ah.getRanges(true);if(ai.length==1&&ai[0].collapsed){var aj=new CKEDITOR.dom.text(L.title?L.title:N.type=='email'?N.email.address:L['data-cke-saved-href'],P.document);ai[0].insertNode(aj);if(this.from_upload&&!(CKEDITOR.env.ie&&CKEDITOR.env.version==6)){var ak=new CKEDITOR.dom.element.createFromHtml(f(L.title));ai[0].insertNode(ak,true);
ai[0].setStartBefore(ak);ai[0].setEndAfter(aj);}else ai[0].selectNodeContents(aj);ah.selectRanges(ai);}var al=new CKEDITOR.style({element:'a',attributes:L});al.type=CKEDITOR.STYLE_INLINE;al.apply(P.document);var am=$('#P8_CKEDITOR_multi_links input[type=text]');if(am.length)if(CKEDITOR.env.ie)P.document.$.selection.empty();else ah.getNative().collapseToEnd();am.each(function(){var at=this;var ar=P.document.createElement('p'),as=P.document.createElement('a');as.appendTo(ar);as.setAttribute('href',at.value);as.setAttribute('title',at.name);as.setAttribute('target','_blank');as.setHtml(f(at.value)+at.name);P.insertElement(ar);});$('#P8_CKEDITOR_multi_links').empty();if(N.adv&&N.adv.advId){var an=this.getParentEditor().document.$.getElementsByTagName('a');for(af=0;af<an.length;af++){if(an[af].href==L.href){an[af].id=N.adv.advId;break;}}}}else{var ao=this._.selectedElement,ap=ao.data('cke-saved-href'),aq=ao.getHtml();ao.setAttributes(L);ao.removeAttributes(M);if(N.adv&&N.adv.advName&&CKEDITOR.plugins.link.synAnchorSelector)ao.addClass(ao.getChildCount()?'cke_anchor':'cke_anchor_empty');if(ap==aq||N.type=='email'&&aq.indexOf('@')!=-1)ao.setHtml(N.type=='email'?N.email.address:L['data-cke-saved-href']);delete this._.selectedElement;}},onLoad:function(){if(!a.config.linkShowAdvancedTab)this.hidePage('advanced');if(!a.config.linkShowTargetTab)this.hidePage('target');var L=this;this.P8_CKEDITOR_uploader=new P8_Upload({element:{src:$(this.getContentElement('info','url').getInputElement().$),attribute:'value'},param:{count:-2},callback:function(M){if(!M.attachments.length)return;L.setValueOf('info','url',M.attachments[0].file);L.setValueOf('advanced','advTitle',M.attachments[0].name);M=M.attachments.slice(1);var N=$('<input type="text" value="" />');$('#P8_CKEDITOR_multi_links').empty();for(var O=0;O<M.length;O++)$('#P8_CKEDITOR_multi_links').append(N.clone(true).val(M[O].file).attr('name',M[O].name));L.from_upload=true;}});},onFocus:function(){var L=this.getContentElement('info','linkType'),M;if(L&&L.getValue()=='url'){M=this.getContentElement('info','url');M.select();}}};});
