CKEDITOR.dom.range.prototype.wrapSelectionWith=function(E,B){var C,A;var D;this.enlarge(CKEDITOR.ENLARGE_ELEMENT);C=CKEDITOR.dom.element.createFromHtml(E,this.document);A=CKEDITOR.dom.element.createFromHtml(B,this.document);D=this.clone();D.collapse();D.insertNode(A);if(this.collapsed){this.moveToPosition(A,CKEDITOR.POSITION_BEFORE_START)}D=this.clone();D.collapse(true);D.insertNode(C);if(this.collapsed){this.moveToPosition(C,CKEDITOR.POSITION_AFTER_END)}if(!this.collapsed){this.setEndBefore(A);this.setStartAfter(C)}};CKEDITOR.editor.prototype.getSelectedText=function(){if(CKEDITOR.env.ie){return this.getSelection().document.$.selection.createRange().text}else{return this.getSelection().getNative()}};CKEDITOR.editor.prototype.wrapSelectionWith=function(D,B){if(this.mode=="wysiwyg"){if(CKEDITOR.env.ie){this.focus()}var A=this.getSelection().getRanges();for(var C=0;C<A.length;C++){A[C].wrapSelectionWith(D,B)}this.getSelection().selectRanges(A)}else{if(this.mode=="enhancedsource"){this.esWrapAroundSelection(D,B)}}};CKEDITOR.plugins.add("codetags",{requires:["button"],init:function(editor){var phrase=editor.config.vbulletin.phrase;var addButtonCommand=function(buttonName,buttonLabel,tagName,option,image){editor.addCommand(buttonName,{exec:function(editor){if(option=="1"){var optionString=prompt(editor.lang.vbulletin.enter_tag_option.replace(/\%1\$s/,"["+tagName+"]"));if(typeof optionString=="string"&&optionString.length>0){editor.wrapSelectionWith("["+tagName+"="+optionString+"]","[/"+tagName+"]")}else{editor.wrapSelectionWith("["+tagName+"]","[/"+tagName+"]")}}else{editor.wrapSelectionWith("["+tagName+"]","[/"+tagName+"]")}}});var buttonDefinition={label:buttonLabel,command:buttonName};if(image){buttonDefinition.icon=image}editor.ui.addButton(buttonName,buttonDefinition)};var previewBreakCommand=function(buttonName,buttonLabel,tagName){editor.addCommand(buttonName,{exec:function(editor){if(editor.mode=="wysiwyg"){var hr_tags=editor.document.getElementsByTag("hr");for(var i=0;i<hr_tags.count();i++){var tag=hr_tags.getItem(i);if(tag.hasClass("previewbreak")){alert(phrase.this_message_already_contains_a_preview_break);return }}}editor.insertHtml("["+tagName+"][/"+tagName+"]")}});editor.ui.addButton(buttonName,{label:buttonLabel,command:buttonName})};var pageBreakCommand=function(buttonName,buttonLabel,tagName){editor.addCommand(buttonName,{exec:function(editor){editor.insertHtml("["+tagName+"]"+editor.getSelectedText()+"[/"+tagName+"]")}});editor.ui.addButton(buttonName,{label:buttonLabel,command:buttonName})};var iespellCommand=function(buttonName,buttonLabel){editor.addCommand(buttonName,{exec:function(editor){try{eval("new ActiveXObject('ieSpell.ieSpellExtension').CheckDocumentNode(editor.document.$.body);")}catch(e){if(e.number==-2146827859&&confirm(editor.lang.vbulletin.iespell_not_installed)){window.open("http://www.iespell.com/download.php")}}}});editor.ui.addButton(buttonName,{label:buttonLabel,command:buttonName})};var emailCommand=function(buttonName,buttonLabel){editor.addCommand(buttonName,{exec:function(editor){}});editor.ui.addButton(buttonName,{label:buttonLabel,command:buttonName})};var phrase=editor.config.vbulletin.phrase;addButtonCommand("Quote",phrase.wrap_quote_tags,"QUOTE");addButtonCommand("Code",phrase.wrap_code_tags,"CODE");addButtonCommand("Html",phrase.wrap_html_tags,"HTML");addButtonCommand("Php",phrase.wrap_php_tags,"PHP");previewBreakCommand("PreviewBreak",phrase.insert_preview_break,"PRBREAK");pageBreakCommand("PageBreak",phrase.insert_page_break,"PAGE");iespellCommand("iespell",editor.lang.vbulletin.spell_check);emailCommand("Email",editor.lang.vbulletin.email);for(var i in editor.config.vbulletin.bbcodecache){var bbcode=editor.config.vbulletin.bbcodecache[i];var resource=bbcode.buttonimage;if(resource.indexOf(":/")==-1&&resource.indexOf("/")!==0){resource=editor.config.baseHref+resource}addButtonCommand(bbcode.title,phrase.wrap_x_tags.replace(/\%1\$s/,bbcode.bbcodetag),bbcode.bbcodetag.toUpperCase(),bbcode.twoparams,resource)}}});