/**
* @version		$Id: fckeditor.php 1154 18-1-2008 AW
* @package		JoomlaFCK
* @copyright	Copyright (C) 2006 - 2008 WebXSolution Ltd. All rights reserved.
* @license		Creative Commons Licence
* The code for this additional work for the FCKeditor has been  been written/modified by WebxSolution Ltd.
* You may not copy or distribute the work without written consent
* from WebxSolution Ltd.
*/
var _node=null;var _type=null;var IStylesSelection=function(){};var IStylesSelection=FCKSelection;var ExcludeNodes=['A','SPAN','LI','OL','UL'];IStylesSelection.GetSelectedNode=function(){var node;if(FCKBrowserInfo.IsIE){node=this.GetSelectedElement_IE()}else node=this.GetSelectedElement_Gecko();return node};IStylesSelection.GetSelectedElement_Gecko=function(){var node;node=this.GetSelectedElement();if(node)return node;var ancestorNodes=['TABLE'];var sel=this.GetSelection().toString();if(FCKBrowserInfo.IsGecko&&this.HasAncestorNode('LI')){node=this.GetParentElement();this.SelectNode(node);return node};if(!FCKBrowserInfo.IsGecko&&this.HasAncestorNode('TD')){node=this.MoveToAncestorNode('TD');if(!(IStylesSelection.IsBlock(node))){if(sel.length==0){node=this.MoveToAncestorNode('TABLE');this.SelectNode(node)}};return node};for(var i=0;i<ancestorNodes.length;i++){var isAncestor=this.HasAncestorNode(ancestorNodes[i]);if(isAncestor){if(FCKBrowserInfo.IsGecko&&ancestorNodes[i]=='TABLE'&&sel.length==0){node=this.MoveToAncestorNode(ancestorNodes[i]);this.SelectNode(node);return node}else if(FCKBrowserInfo.IsGecko&&ancestorNodes[i]=='TABLE'&&sel.length>0){break}else{node=this.MoveToAncestorNode(ancestorNodes[i]);this.SelectNode(node);return node}}};return this.GetParentElement()};IStylesSelection.GetSelectedElement_IE=function(){var node;node=this.GetSelectedElement();if(node)return node;return this.GetParentElement()};IStylesSelection.IsBlock=function(node){if(FCKBrowserInfo.IsIE){return(this.SelectionData.text.replace(/\s/g,'').length==node.innerText.replace(/\s/g,'').length)}else{var sel=this.GetSelection().toString();return(sel.replace(/\s/g,'').length==node.textContent.replace(/\s/g,'').length)};return false};IStylesSelection.IsCollaspe=function(){var oSel=this.GetSelection();var empty=false;if(!oSel||oSel==""){empty=true}else if(FCKBrowserInfo.IsIE){var range=oSel.createRange();if(this.GetType()=='Control'){empty=false}else if(!range.text){empty=true}}else{var range=oSel.getRangeAt(0);if(this.GetType()!='Control'&&range.collapsed){if((range.startContainer&&range.startContainer.nodeType==1)||(FCKBrowserInfo.IsGecko&&range.startContainer.parentNode.tagName=='TD'))return false;empty=true}};return empty};var IStylesEditor=function(){};IStylesEditor.prototype.GetState=function(){if(!!FCK.EditorWindow&&IStylesSelection.IsCollaspe()){return FCK_TRISTATE_DISABLED};return FCK_TRISTATE_OFF};function isExcludeNode(node){for(var i=0;i<ExcludeNodes.length;i++){if(node.tagName==ExcludeNodes[i]){return true}};return false};function applyCSS(css){if(FCKBrowserInfo.IsIE){if(_type=='Text'&&!IStylesSelection.IsBlock(_node)){_range.pasteHTML('<span style="'+css+'">'+_range.htmlText+'</span>')}else{if(_node.tagName=='SPAN'){if(!_node.className&&!_node.id&&!css){FCKDomTools.RemoveNode(_node,true)}else{_node.style.cssText=css}}else{_node.style.cssText=css}}}else{if(_node&&IStylesSelection.GetType()=='Text'&&!IStylesSelection.IsBlock(_node)){var oSelection=FCK.ToolbarSet.CurrentInstance.EditorWindow.getSelection();var html=_node.parentNode.innerHTML;var mod;var selectText=oSelection.toString();var regExp=new RegExp('\\S[^\\S\\d&#160;]'+oSelection+'[^\\S\\d&#160;]\\S');if(FCKBrowserInfo.IsOpera&&html.match(regExp)){FCK.InsertHtml('<span id="tmp_span">XYZtemp</span>');_node=FCK.ToolbarSet.CurrentInstance.EditorDocument.getElementById("tmp_span");html=_node.parentNode.innerHTML;_node.parentNode.innerHTML=html.replace(/\s\s\<?SPAN.*id="tmp_span"*.\>?XYZtemp\<?\/?SPAN\>?/,' <span style="'+css.replace(/"/g,"'")+'">'+selectText+'</span> ')}else if(FCKBrowserInfo.IsSafari){FCK.InsertHtml('__FCK_XYZtemp');var body=FCK.ToolbarSet.CurrentInstance.EditorDocument.body;var html=body.innerHTML;body.innerHTML=html.replace(/__FCK_XYZtemp/,'<span style="'+css.replace(/"/g,"'")+'">'+selectText+'</span>');body=null}else{FCK.InsertHtml('<span style="'+css.replace(/"/g,"'")+'">'+oSelection+'</span>')}}else{if(_node.tagName=='SPAN'){if(!_node.className&&!_node.id&&!css){FCKDomTools.RemoveNode(_node,true);if(FCKBrowserInfo.IsOpera)FCK.SetData(FCK.GetData(FCKConfig.FormatSource))}else{_node.style.cssText=css.replace(/"/g,"'")}}else _node.style.cssText=css}}};IStylesEditor.prototype.Execute=function(key){FCKUndo.SaveUndoStep();var s='';var node=IStylesSelection.GetSelectedNode();_node=node;if(FCK.ToolbarSet.CurrentInstance.EditorDocument.selection)_type=IStylesSelection.GetType();if(_node&&_type=='Text'){_range=FCK.ToolbarSet.CurrentInstance.EditorDocument.selection.createRange()};if(node){s=node.style.cssText;FCKDialog.OpenDialog(FCKLang.AAStyleTitle,FCKLang.AAStyleTitle,FCKConfig.BasePath+'/istyles/istyles.html#'+s,780,490,applyCSS,window)};FCK.Focus();FCK.Events.FireEvent('OnSelectionChange')};FCKCommands.RegisterCommand('istyles',new IStylesEditor());var item=new FCKToolbarButton('istyles',"IStylesEditor","IStylesEditor",null,false,true);item.IconPath=FCKConfig.BasePath+'/istyles/aa.gif';FCKToolbarItems.RegisterItem('istyles',item);