/*------------------------------------------------------------------------
# Copyright (C) 2005-2012 WebxSolution Ltd. All Rights Reserved.
# @license - GPLv2.0
# Author: WebxSolution Ltd
# Websites:  http://www.webxsolution.com
# Terms of Use: An extension that is derived from the JoomlaCK editor will only be allowed under the following conditions: http://joomlackeditor.com/terms-of-use
# ------------------------------------------------------------------------*/ 
CKEDITOR.plugins.add("ie9selectionoverride",{init:function(a){},afterInit:function(a){CKEDITOR.dom.selection.prototype.getRanges=function(){var a=CKEDITOR.env.ie?function(){function a(a){return(new CKEDITOR.dom.node(a)).getIndex()}var b=function(b,c){b=b.duplicate();b.collapse(c);var d=b.parentElement(),e=d.ownerDocument;if(!d.hasChildNodes())return{container:d,offset:0};var f=d.children,g,h,i=b.duplicate(),j=0,k=f.length-1,l=-1,m,n;while(j<=k){l=Math.floor((j+k)/2);g=f[l];i.moveToElementText(g);m=i.compareEndPoints("StartToStart",b);if(m>0)k=l-1;else if(m<0)j=l+1;else{if(CKEDITOR.env.ie9Compat&&g.tagName=="BR"){var o="cke_range_marker";b.execCommand("CreateBookmark",false,o);g=e.getElementsByName(o)[0];var p=a(g);d.removeChild(g);return{container:d,offset:p}}else return{container:d,offset:a(g)}}}if(l==-1||l==f.length-1&&m<0){i.moveToElementText(d);i.setEndPoint("StartToStart",b);n=i.text.replace(/(\r\n|\r)/g,"\n").length;f=d.childNodes;if(!n){g=f[f.length-1];if(g.nodeType==CKEDITOR.NODE_ELEMENT)return{container:d,offset:f.length};else return{container:g,offset:g.nodeValue.length}}var q=f.length;while(n>0)n-=f[--q].nodeValue.length;return{container:f[q],offset:-n}}else{i.collapse(m>0?true:false);i.setEndPoint(m>0?"StartToStart":"EndToStart",b);n=i.text.replace(/(\r\n|\r)/g,"\n").length;if(!n)return{container:d,offset:a(g)+(m>0?0:1)};while(n>0){try{h=g[m>0?"previousSibling":"nextSibling"];n-=h.nodeValue.length;g=h}catch(r){return{container:d,offset:a(g)}}}return{container:g,offset:m>0?-n:g.nodeValue.length+n}}};return function(){var a=this.getNative(),c=a&&a.createRange(),d=this.getType(),e;if(!a)return[];if(d==CKEDITOR.SELECTION_TEXT){e=new CKEDITOR.dom.range(this.document);var f=b(c,true);e.setStart(new CKEDITOR.dom.node(f.container),f.offset);f=b(c);e.setEnd(new CKEDITOR.dom.node(f.container),f.offset);if(e.endContainer.getPosition(e.startContainer)&CKEDITOR.POSITION_PRECEDING&&e.endOffset<=e.startContainer.getIndex()){e.collapse()}return[e]}else if(d==CKEDITOR.SELECTION_ELEMENT){var g=[];for(var h=0;h<c.length;h++){var i=c.item(h),j=i.parentNode,k=0;e=new CKEDITOR.dom.range(this.document);for(;k<j.childNodes.length&&j.childNodes[k]!=i;k++){}e.setStart(new CKEDITOR.dom.node(j),k);e.setEnd(new CKEDITOR.dom.node(j),k+1);g.push(e)}return g}return[]}}():function(){var a=[],b,c=this.document,d=this.getNative();if(!d)return a;if(!d.rangeCount){b=new CKEDITOR.dom.range(c);b.moveToElementEditStart(c.getBody());a.push(b)}for(var e=0;e<d.rangeCount;e++){var f=d.getRangeAt(e);b=new CKEDITOR.dom.range(c);b.setStart(new CKEDITOR.dom.node(f.startContainer),f.startOffset);b.setEnd(new CKEDITOR.dom.node(f.endContainer),f.endOffset);a.push(b)}return a};return function(b){var c=this._.cache;if(c.ranges&&!b)return c.ranges;else if(!c.ranges)c.ranges=new CKEDITOR.dom.rangeList(a.call(this));if(b){var d=c.ranges;for(var e=0;e<d.length;e++){var f=d[e];var g=f.getCommonAncestor();if(g.isReadOnly())d.splice(e,1);if(f.collapsed)continue;var h=f.startContainer,i=f.endContainer,j=f.startOffset,k=f.endOffset,l=f.clone();var m;if(m=h.isReadOnly())f.setStartAfter(m);if(h&&h.type==CKEDITOR.NODE_TEXT){if(j>=h.getLength())l.setStartAfter(h);else l.setStartBefore(h)}if(i&&i.type==CKEDITOR.NODE_TEXT){if(!k)l.setEndBefore(i);else l.setEndAfter(i)}var n=new CKEDITOR.dom.walker(l);n.evaluator=function(a){if(a.type==CKEDITOR.NODE_ELEMENT&&a.isReadOnly()){var b=f.clone();f.setEndBefore(a);if(f.collapsed)d.splice(e--,1);if(!(a.getPosition(l.endContainer)&CKEDITOR.POSITION_CONTAINS)){b.setStartAfter(a);if(!b.collapsed)d.splice(e+1,0,b)}return true}return false};n.next()}}return c.ranges}}()}})