/*!
*   This file is part of Aloha Editor
*   Author & Copyright (c) 2010 Gentics Software GmbH, aloha@gentics.com
*   Licensed unter the terms of http://www.aloha-editor.com/license.html
*//*
*   Aloha Editor is free software: you can redistribute it and/or modify
*   it under the terms of the GNU Affero General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.*
*
*   Aloha Editor is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU Affero General Public License for more details.
*
*   You should have received a copy of the GNU Affero General Public License
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*//**
 * jQuery between Extension
 * 
 * insert either html code, a dom object OR a jQuery object inside of an existing text node.
 * if the chained jQuery object is not a text node, nothing will happen.
 * 
 * @param content HTML Code, DOM object or jQuery object to be inserted
 * @param offset character offset from the start where the content should be inserted
 */jQuery.fn.between=function(a,b){if(this[0].nodeType!==3)b>this.children().size()&&(b=this.children().size()),b<=0?this.prepend(a):this.children().eq(b-1).after(a);else if(b<=0)this.before(a);else if(b>=this[0].length)this.after(a);else{var c=this[0].data;this[0].data=c.substring(0,b),this.after(c.substring(b,c.length)),this.after(a)}},jQuery.fn.contentEditable=function(a){var b="contenteditable";jQuery.browser.msie&&parseInt(jQuery.browser.version)==7&&(b="contentEditable");if(a==undefined)return jQuery(this).attr(b);a===""?jQuery(this).removeAttr(b):(a&&a!=="false"?a="true":a="false",jQuery(this).attr(b,a))};if(typeof GENTICS=="undefined"||!GENTICS)var GENTICS={};if(typeof GENTICS.Utils=="undefined"||!GENTICS)GENTICS.Utils={};GENTICS.Utils.applyProperties=function(a,b){var c;for(c in b)b.hasOwnProperty(c)&&(a[c]=b[c])},GENTICS.Utils.uniqeString4=function(){return((1+Math.random())*65536|0).toString(16).substring(1)},GENTICS.Utils.guid=function(){var a=GENTICS.Utils.uniqeString4;return a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()};if(typeof GENTICS=="undefined"||!GENTICS)var GENTICS={};if(typeof GENTICS.Utils=="undefined"||!GENTICS)GENTICS.Utils={};GENTICS.Utils.RangeObject=function(a){this.startContainer,this.startOffset,this.endContainer,this.endOffset,this.startParents=[],this.endParents=[],this.rangeTree=[],typeof a=="object"?(a.startContainer!==undefined&&(this.startContainer=a.startContainer),a.startOffset!==undefined&&(this.startOffset=a.startOffset),a.endContainer!==undefined&&(this.endContainer=a.endContainer),a.endOffset!==undefined&&(this.endOffset=a.endOffset)):a===!0&&this.initializeFromUserSelection()},GENTICS.Utils.RangeObject.prototype.log=function(a,b){if(GENTICS&&GENTICS.Aloha&&GENTICS.Aloha.Log)return GENTICS.Aloha.Log.debug(this,a),!1;console&&(console.log(a),b&&console.log(b))},GENTICS.Utils.RangeObject.prototype.isCollapsed=function(){return!this.endContainer||this.startContainer===this.endContainer&&this.startOffset===this.endOffset},GENTICS.Utils.RangeObject.prototype.getCommonAncestorContainer=function(){return this.commonAncestorContainer?this.commonAncestorContainer:(this.updateCommonAncestorContainer(),this.commonAncestorContainer)},GENTICS.Utils.RangeObject.prototype.getContainerParents=function(a,b){var c=b?this.endContainer:this.startContainer,d=b?this.endParents:this.startParents;if(!c)return!1;typeof a=="undefined"&&(a=jQuery("body"));if(!d[a.get(0)]){var e;if(c.nodeType==3)e=jQuery(c).parents();else{e=jQuery(c).parents();for(var f=e.length;f>0;--f)e[f]=e[f-1];e[0]=c}var g=e.index(a);g>=0&&(e=e.slice(0,g)),d[a.get(0)]=e}return d[a.get(0)]},GENTICS.Utils.RangeObject.prototype.getStartContainerParents=function(a){return this.getContainerParents(a,!1)},GENTICS.Utils.RangeObject.prototype.getEndContainerParents=function(a){return this.getContainerParents(a,!0)},GENTICS.Utils.RangeObject.prototype.updateCommonAncestorContainer=function(a){var b=this.getStartContainerParents(),c=this.getEndContainerParents();if(!a){if(!(b.length>0&&c.length>0))return GENTICS.Utils.RangeObject.prototype.log("could not find commonAncestorContainer"),!1;for(var d=0;d<b.length;d++)if(c.index(b[d])!=-1){this.commonAncestorContainer=b[d];break}}else this.commonAncestorContainer=a;return GENTICS.Utils.RangeObject.prototype.log(a?"commonAncestorContainer was set successfully":"commonAncestorContainer was calculated successfully"),!0},GENTICS.Utils.RangeObject.prototype.getCollapsedIERange=function(a,b){var c=document.body.createTextRange(),d=this.searchElementToLeft(a,b);if(d.element){var e=document.body.createTextRange();e.moveToElementText(d.element),c.setEndPoint("StartToEnd",e),d.characters!=0?c.moveStart("character",d.characters):(c.moveStart("character",1),c.moveStart("character",-1))}else{var f=this.searchElementToRight(a,b),g=a.nodeType==3?a.parentNode:a,e=document.body.createTextRange();e.moveToElementText(g),c.setEndPoint("StartToStart",e),d.characters!=0&&c.moveStart("character",d.characters)}return c.collapse(),c},GENTICS.Utils.RangeObject.prototype.select=document.createRange===undefined?function(){GENTICS.Aloha.Log.isDebugEnabled()&&GENTICS.Aloha.Log.debug(this,"Set selection to current range (IE version)"),this.startContainer.nodeType==3&&GENTICS.Utils.Dom.isBlockLevelElement(this.startContainer.nextSibling)&&(jQuery(this.startContainer).after("<br/>"),this.endContainer===this.startContainer.parentNode&&GENTICS.Utils.Dom.getIndexInParent(this.startContainer)<this.endOffset&&this.endOffset++);var a=document.body.createTextRange(),b=this.getCollapsedIERange(this.startContainer,this.startOffset);a.setEndPoint("StartToStart",b);if(this.isCollapsed())a.collapse();else{var c=this.getCollapsedIERange(this.endContainer,this.endOffset);a.setEndPoint("EndToStart",c)}a.select()}:function(){GENTICS.Aloha.Log.isDebugEnabled()&&GENTICS.Aloha.Log.debug(this,"Set selection to current range (non IE version)");var a=document.createRange();try{a.setStart(this.startContainer,this.startOffset),a.setEnd(this.endContainer,this.endOffset)}catch(b){}window.getSelection().removeAllRanges(),window.getSelection().addRange(a)},GENTICS.Utils.RangeObject.prototype.searchElementToLeft=function(a,b){var c=undefined,d=0;a.nodeType==3?(d=b,c=a.previousSibling):b>0&&(c=a.childNodes[b-1]);while(c&&c.nodeType==3)d+=c.data.length,c=c.previousSibling;return{element:c,characters:d}},GENTICS.Utils.RangeObject.prototype.searchElementToRight=function(a,b){var c=undefined,d=0;a.nodeType==3?(d=a.data.length-b,c=a.nextSibling):b<a.childNodes.length&&(c=a.childNodes[b]);while(c&&c.nodeType==3)d+=c.data.length,c=c.nextSibling;return{element:c,characters:d}},GENTICS.Utils.RangeObject.prototype.update=function(a){GENTICS.Utils.RangeObject.prototype.log("=========="),GENTICS.Utils.RangeObject.prototype.log("now updating rangeObject"),this.initializeFromUserSelection(a),this.updateCommonAncestorContainer()},GENTICS.Utils.RangeObject.prototype.initializeFromUserSelection=function(a){var b=window.getSelection();if(!b)return!1;try{var c=b.getRangeAt(0)}catch(d){return!0}if(!c)return!1;this.startContainer=c.startContainer,this.endContainer=c.endContainer,this.startOffset=c.startOffset,this.endOffset=c.endOffset,this.correctRange();return},GENTICS.Utils.RangeObject.prototype.correctRange=function(){this.clearCaches();if(this.isCollapsed()){if(this.startContainer.nodeType==1){if(this.startOffset>0&&this.startContainer.childNodes[this.startOffset-1].nodeType==3){this.startContainer=this.startContainer.childNodes[this.startOffset-1],this.startOffset=this.startContainer.data.length,this.endContainer=this.startContainer,this.endOffset=this.startOffset;return}if(this.startOffset>0&&this.startContainer.childNodes[this.startOffset-1].nodeType==1){var a=GENTICS.Utils.Dom.searchAdjacentTextNode(this.startContainer,this.startOffset,!0);if(a){this.startContainer=this.endContainer=a,this.startOffset=this.endOffset=a.data.length;return}a=GENTICS.Utils.Dom.searchAdjacentTextNode(this.startContainer,this.startOffset,!1);if(a){this.startContainer=this.endContainer=a,this.startOffset=this.endOffset=0;return}}if(this.startOffset<this.startContainer.childNodes.length&&this.startContainer.childNodes[this.startOffset].nodeType==3){this.startContainer=this.startContainer.childNodes[this.startOffset],this.startOffset=0,this.endContainer=this.startContainer,this.endOffset=0;return}}if(this.startContainer.nodeType==3&&this.startOffset==0){var a=GENTICS.Utils.Dom.searchAdjacentTextNode(this.startContainer.parentNode,GENTICS.Utils.Dom.getIndexInParent(this.startContainer),!0);a&&(this.startContainer=this.endContainer=a,this.startOffset=this.endOffset=a.data.length)}}else{if(this.startContainer.nodeType==1)if(this.startOffset<this.startContainer.childNodes.length&&this.startContainer.childNodes[this.startOffset].nodeType==3)this.startContainer=this.startContainer.childNodes[this.startOffset],this.startOffset=0;else if(this.startOffset<this.startContainer.childNodes.length&&this.startContainer.childNodes[this.startOffset].nodeType==1){var b=!1,c=this.startContainer.childNodes[this.startOffset];while(b===!1&&c.childNodes&&c.childNodes.length>0)c=c.childNodes[0],c.nodeType==3&&(b=c);b!==!1&&(this.startContainer=b,this.startOffset=0)}if(this.startContainer.nodeType==3&&this.startOffset==this.startContainer.data.length){var a=GENTICS.Utils.Dom.searchAdjacentTextNode(this.startContainer.parentNode,GENTICS.Utils.Dom.getIndexInParent(this.startContainer)+1,!1);a&&(this.startContainer=a,this.startOffset=0)}if(this.endContainer.nodeType==3&&this.endOffset==0)if(this.endContainer.previousSibling&&this.endContainer.previousSibling.nodeType==3)this.endContainer=this.endContainer.previousSibling,this.endOffset=this.endContainer.data.length;else if(this.endContainer.previousSibling&&this.endContainer.previousSibling.nodeType==1&&this.endContainer.parentNode){var d=this.endContainer.parentNode;for(var e=0;e<d.childNodes.length;++e)if(d.childNodes[e]==this.endContainer){this.endOffset=e;break}this.endContainer=d}this.endContainer.nodeType==1&&this.endOffset==0&&this.endContainer.previousSibling&&(this.endContainer.previousSibling.nodeType==3?(this.endContainer=this.endContainer.previousSibling,this.endOffset=this.endContainer.data.length):this.endContainer.previousSibling.nodeType==1&&this.endContainer.previousSibling.childNodes&&this.endContainer.previousSibling.childNodes.length>0&&(this.endContainer=this.endContainer.previousSibling,this.endOffset=this.endContainer.childNodes.length));if(this.endContainer.nodeType==1)if(this.endOffset>0&&this.endContainer.childNodes[this.endOffset-1].nodeType==3)this.endContainer=this.endContainer.childNodes[this.endOffset-1],this.endOffset=this.endContainer.data.length;else if(this.endOffset>0&&this.endContainer.childNodes[this.endOffset-1].nodeType==1){var b=!1,c=this.endContainer.childNodes[this.endOffset-1];while(b===!1&&c.childNodes&&c.childNodes.length>0)c=c.childNodes[c.childNodes.length-1],c.nodeType==3&&(b=c);b!==!1&&(this.endContainer=b,this.endOffset=this.endContainer.data.length)}}},GENTICS.Utils.RangeObject.prototype.clearCaches=function(){this.rangeTree=[],this.startParents=[],this.endParents=[],this.commonAncestorContainer=undefined},GENTICS.Utils.RangeObject.prototype.getRangeTree=function(a){return typeof a=="undefined"&&(a=this.getCommonAncestorContainer()),this.rangeTree[a]?this.rangeTree[a]:(this.inselection=!1,this.rangeTree[a]=this.recursiveGetRangeTree(a),this.rangeTree[a])},GENTICS.Utils.RangeObject.prototype.recursiveGetRangeTree=function(a){var b=jQuery(a),c=0,d=this,e=new Array;return b.contents().each(function(b){var f="none",g=!1,h=!1,i=!1;d.isCollapsed()&&a===d.startContainer&&d.startOffset==b&&(e[c]=new GENTICS.Utils.RangeTree,e[c].type="collapsed",e[c].domobj=undefined,d.inselection=!1,i=!0,c++);if(!d.inselection&&!i)switch(this.nodeType){case 3:this===d.startContainer&&(d.inselection=!0,f=d.startOffset>0?"partial":"full",g=d.startOffset,h=this.length);break;case 1:this===d.startContainer&&d.startOffset==0&&(d.inselection=!0,f="full"),a===d.startContainer&&d.startOffset==b&&(d.inselection=!0,f="full")}if(d.inselection&&!i){f=="none"&&(f="full");switch(this.nodeType){case 3:this===d.endContainer&&(d.inselection=!1,d.endOffset<this.length&&(f="partial"),g===!1&&(g=0),h=d.endOffset);break;case 1:this===d.endContainer&&d.endOffset==0&&(d.inselection=!1)}a===d.endContainer&&d.endOffset<=b&&(d.inselection=!1,f="none")}e[c]=new GENTICS.Utils.RangeTree,e[c].domobj=this,e[c].type=f,f=="partial"&&(e[c].startOffset=g,e[c].endOffset=h),e[c].children=d.recursiveGetRangeTree(this);if(e[c].children.length>0){var j=!1,k=!1,l=!1;for(var m=0;m<e[c].children.length;++m)switch(e[c].children[m].type){case"none":j=!0;break;case"full":l=!0;break;case"partial":k=!0}k||l&&j?e[c].type="partial":l&&!k&&!j&&(e[c].type="full")}c++}),this.isCollapsed()&&a===this.startContainer&&this.startOffset==a.childNodes.length&&(e[c]=new GENTICS.Utils.RangeTree,e[c].type="collapsed",e[c].domobj=undefined),e},GENTICS.Utils.RangeObject.prototype.findMarkup=function(a,b,c){var d=this.getContainerParents(b,c),e=!1;return jQuery.each(d,function(b,c){if(a.apply(c))return e=c,!1}),e},GENTICS.Utils.RangeTree=function(){this.domobj=new Object,this.type,this.children=new Array};if(typeof GENTICS=="undefined"||!GENTICS)var GENTICS={};if(typeof GENTICS.Utils=="undefined"||!GENTICS)GENTICS.Utils={};GENTICS.Utils.Position={},GENTICS.Utils.Position.w=jQuery(window),GENTICS.Utils.Position.Scroll={top:0,left:0,isScrolling:!1},GENTICS.Utils.Position.Mouse={x:0,y:0,oldX:0,oldY:0,isMoving:!1,triggeredMouseStop:!0},GENTICS.Utils.Position.mouseStopCallbacks=new Array,GENTICS.Utils.Position.mouseMoveCallbacks=new Array,GENTICS.Utils.Position.update=function(){var a=this.w.scrollTop(),b=this.w.scrollLeft();if(this.Scroll.isScrolling)this.Scroll.top==a&&this.Scroll.left==b&&(this.Scroll.isScrolling=!1);else if(this.Scroll.top!=a||this.Scroll.left!=b)this.Scroll.isScrolling=!0;this.Scroll.top=a,this.Scroll.left=b;if(this.Mouse.x==this.Mouse.oldX&&this.Mouse.y==this.Mouse.oldY){this.Mouse.isMoving=!1;if(!this.Mouse.triggeredMouseStop){this.Mouse.triggeredMouseStop=!0;for(var c=0;c<this.mouseStopCallbacks.length;c++)this.mouseStopCallbacks[c].call()}}else{this.Mouse.isMoving=!0,this.Mouse.triggeredMouseStop=!1;for(var c=0;c<this.mouseMoveCallbacks.length;c++)this.mouseMoveCallbacks[c].call()}this.Mouse.oldX=this.Mouse.x,this.Mouse.oldY=this.Mouse.y},GENTICS.Utils.Position.addMouseStopCallback=function(a){return this.mouseStopCallbacks.push(a),this.mouseStopCallbacks.length-1},GENTICS.Utils.Position.addMouseMoveCallback=function(a){return this.mouseMoveCallbacks.push(a),this.mouseMoveCallbacks.length-1},setInterval("GENTICS.Utils.Position.update()",500),jQuery("html").mousemove(function(a){GENTICS.Utils.Position.Mouse.x=a.pageX,GENTICS.Utils.Position.Mouse.y=a.pageY});if(typeof GENTICS=="undefined"||!GENTICS)var GENTICS={};if(typeof GENTICS.Utils=="undefined"||!GENTICS.Utils)GENTICS.Utils={};if(typeof GENTICS.Utils.Dom=="undefined"||!GENTICS.Utils.Dom)GENTICS.Utils.Dom=function(){};GENTICS.Utils.Dom.prototype.mergeableTags=["a","b","code","del","em","i","ins","strong","sub","sup","#text"],GENTICS.Utils.Dom.prototype.nonWordBoundaryTags=["a","b","code","del","em","i","ins","span","strong","sub","sup","#text"],GENTICS.Utils.Dom.prototype.nonEmptyTags=["br"],GENTICS.Utils.Dom.prototype.tags={flow:["a","abbr","address","area","article","aside","audio","b","bdo","blockquote","br","button","canvas","cite","code","command","datalist","del","details","dfn","div","dl","em","embed","fieldset","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","i","iframe","img","input","ins","kbd","keygen","label","map","mark","math","menu","meter","nav","noscript","object","ol","output","p","pre","progress","q","ruby","samp","script","section","select","small","span","strong","style","sub","sup","svg","table","textarea","time","ul","var","video","wbr","#text"],phrasing:["a","abbr","area","audio","b","bdo","br","button","canvas","cite","code","command","datalist","del","dfn","em","embed","i","iframe","img","input","ins","kbd","keygen","label","map","mark","math","meter","noscript","object","output","progress","q","ruby","samp","script","select","small","span","strong","sub","sup","svg","textarea","time","var","video","wbr","#text"]},GENTICS.Utils.Dom.prototype.children={a:"phrasing",abbr:"phrasing",address:"flow",area:"empty",article:"flow",aside:"flow",audio:"source",b:"phrasing",base:"empty",bdo:"phrasing",blockquote:"flow",body:"flow",br:"empty",button:"phrasing",canvas:"phrasing",caption:"flow",cite:"phrasing",code:"phrasing",col:"empty",colgroup:"col",command:"empty",datalist:["phrasing","option"],dd:"flow",del:"phrasing",div:"flow",details:["summary","flow"],dfn:"flow",div:"flow",dl:["dt","dd"],dt:"phrasing",em:"phrasing",embed:"empty",fieldset:["legend","flow"],figcaption:"flow",figure:["figcaption","flow"],footer:"flow",form:"flow",h1:"phrasing",h2:"phrasing",h3:"phrasing",h4:"phrasing",h5:"phrasing",h6:"phrasing",header:"flow",hgroup:["h1","h2","h3","h4","h5","h6"],hr:"empty",i:"phrasing",iframe:"#text",img:"empty",input:"empty",ins:"phrasing",kbd:"phrasing",keygen:"empty",label:"phrasing",legend:"phrasing",li:"flow",link:"empty",map:"area",mark:"phrasing",menu:["li","flow"],meta:"empty",meter:"phrasing",nav:"flow",noscript:"phrasing",object:"param",ol:"li",optgroup:"option",option:"#text",output:"phrasing",p:"phrasing",param:"empty",pre:"phrasing",progress:"phrasing",q:"phrasing",rp:"phrasing",rt:"phrasing",ruby:["phrasing","rt","rp"],s:"phrasing",samp:"pharsing",script:"#script",section:"flow",select:["option","optgroup"],small:"phrasing",source:"empty",span:"phrasing",strong:"phrasing",style:"phrasing",sub:"phrasing",summary:"phrasing",sup:"phrasing",table:["caption","colgroup","thead","tbody","tfoot","tr"],tbody:"tr",td:"flow",textarea:"#text",tfoot:"tr",th:"phrasing",thead:"tr",time:"phrasing",title:"#text",tr:["th","td"],track:"empty",ul:"li","var":"phrasing",video:"source",wbr:"empty"},GENTICS.Utils.Dom.prototype.blockLevelElements=["p","h1","h2","h3","h4","h5","h6","blockquote","div","pre"],GENTICS.Utils.Dom.prototype.listElements=["li","ol","ul"],GENTICS.Utils.Dom.prototype.split=function(a,b,c){var d=jQuery(a.startContainer),e=a.startOffset;c&&(d=jQuery(a.endContainer),e=a.endOffset),b.length<1&&(b=jQuery(document.body));var f=!a.isCollapsed()&&!c,g,h=d.parents().get();h.unshift(d.get(0)),jQuery.each(h,function(a,c){var d=b.filter(function(){return this==c}).length;if(d)return a>0&&(g=h.slice(0,a)),!1});if(!g)return!0;g=g.reverse();var i,j;for(var k=0;k<g.length;k++){var l=g[k];if(k===g.length-1){var m;if(l.nodeType===3)m=document.createTextNode(l.data.substring(e,l.data.length)),l.data=l.data.substring(0,e);else{var n=jQuery(l).clone(!1).empty(),o=jQuery(l).contents();m=n.append(o.slice(e,o.length)).get(0)}f&&a.endContainer===l&&(a.endContainer=m,a.endOffset-=e,a.clearCaches()),j?j.prepend(m):jQuery(l).after(m)}else{var n=jQuery(l).clone(!1).empty();i?(j.prepend(n),j=n):(i=n,j=n);var p;while(p=g[k+1].nextSibling)j.append(p);if(f&&a.endContainer===l){a.endContainer=n.get(0);var q=g[k+1],r=0;while(q=q.previousSibling)r++;a.endOffset-=r,a.clearCaches()}}}return jQuery(g[0]).after(i),jQuery([g[0],i?i.get(0):m])},GENTICS.Utils.Dom.prototype.allowsNesting=function(a,b){if(!a||!a.nodeName||!b||!b.nodeName)return!1;var c=a.nodeName.toLowerCase(),d=b.nodeName.toLowerCase();return this.children[c]?this.children[c]==d?!0:jQuery.isArray(this.children[c])&&jQuery.inArray(d,this.children[c])>=0?!0:jQuery.isArray(this.tags[this.children[c]])&&jQuery.inArray(d,this.tags[this.children[c]])>=0?!0:!1:!1},GENTICS.Utils.Dom.prototype.addMarkup=function(a,b,c){a.startContainer.nodeType==3&&a.startOffset>0&&a.startOffset<a.startContainer.data.length&&this.split(a,jQuery(a.startContainer).parent(),!1),a.endContainer.nodeType==3&&a.endOffset>0&&a.endOffset<a.endContainer.data.length&&this.split(a,jQuery(a.endContainer).parent(),!0);var d=a.getRangeTree();this.recursiveAddMarkup(d,b,a,c),this.doCleanup({merge:!0,removeempty:!0},a)},GENTICS.Utils.Dom.prototype.recursiveAddMarkup=function(a,b,c,d){for(var e=0;e<a.length;++e)if(a[e].type=="full"&&this.allowsNesting(b.get(0),a[e].domobj)){if((d||a[e].domobj.nodeName!=b.get(0).nodeName)&&(a[e].domobj.nodeType!=3||jQuery.trim(a[e].domobj.data).length!=0)){jQuery(a[e].domobj).wrap(b);if(!d&&a[e].domobj.nodeType!=3){var f=new GENTICS.Utils.RangeObject;f.startContainer=f.endContainer=a[e].domobj.parentNode,f.startOffset=0,f.endOffset=f.endContainer.childNodes.length,this.removeMarkup(f,b,jQuery(a[e].domobj.parentNode))}}}else(d||a[e].domobj.nodeName!=b.get(0).nodeName)&&a[e].children&&a[e].children.length>0&&this.recursiveAddMarkup(a[e].children,b)},GENTICS.Utils.Dom.prototype.findHighestElement=function(a,b,c){var d=a;b=b.toLowerCase();var e=c?function(){return c.filter(function(){return d==this}).length}:function(){return!1},f=undefined;while(!e()&&d)d.nodeName.toLowerCase()==b&&(f=d),d=d.parentNode;return f},GENTICS.Utils.Dom.prototype.removeMarkup=function(a,b,c){var d=b.get(0).nodeName,e=this.findHighestElement(a.startContainer,d,c),f=this.findHighestElement(a.endContainer,d,c),g=!1;e&&(this.split(a,jQuery(e).parent(),!1),g=!0),f&&(this.split(a,jQuery(f).parent(),!0),g=!0),g&&a.correctRange();var h=this.findHighestElement(a.getCommonAncestorContainer(),d,c),i=h?h.parentNode:undefined,j=a.getRangeTree(i);this.recursiveRemoveMarkup(j,b),this.doCleanup({merge:!0,removeempty:!0},a,i)},GENTICS.Utils.Dom.prototype.recursiveRemoveMarkup=function(a,b){for(var c=0;c<a.length;++c){if(a[c].type=="full"&&a[c].domobj.nodeName==b.get(0).nodeName){var d=jQuery(a[c].domobj).contents();d.length>0?d.first().unwrap():jQuery(a[c].domobj).remove()}a[c].children&&this.recursiveRemoveMarkup(a[c].children,b)}},GENTICS.Utils.Dom.prototype.doCleanup=function(a,b,c){var d=this;typeof a=="undefined"&&(a={merge:!0,removeempty:!0}),typeof c=="undefined"&&b&&(c=b.getCommonAncestorContainer());var e=!1,f=!1,g=jQuery(c);return g.contents().each(function(c){switch(this.nodeType){case 1:if(e&&e.nodeName==this.nodeName)b.startContainer===g&&b.startOffset>c&&(b.startOffset-=1,f=!0),b.endContainer===g&&b.endOffset>c&&(b.endOffset-=1,f=!0),jQuery(e).append(jQuery(this).contents()),f|=d.doCleanup(a,b,e),jQuery(this).remove();else{f|=d.doCleanup(a,b,this);var h=!1;a.removeempty&&(GENTICS.Utils.Dom.isBlockLevelElement(this)&&this.childNodes.length==0&&(jQuery(this).remove(),h=!0),jQuery.inArray(this.nodeName.toLowerCase(),d.mergeableTags)>=0&&jQuery(this).text().length==0&&this.childNodes.length==0&&(jQuery(this).remove(),h=!0)),h||(jQuery.inArray(this.nodeName.toLowerCase(),d.mergeableTags)>=0?e=this:e=!1)}break;case 3:e&&e.nodeType==3&&a.merge?(b.startContainer===this&&(b.startContainer=e,b.startOffset+=e.length,f=!0),b.endContainer===this&&(b.endContainer=e,b.endOffset+=e.length,f=!0),b.startContainer===g&&b.startOffset>c&&(b.startOffset-=1,f=!0),b.endContainer===g&&b.endOffset>c&&(b.endOffset-=1,f=!0),e.data+=this.data,jQuery(this).remove()):e=this}}),a.removeempty&&GENTICS.Utils.Dom.isBlockLevelElement(c)&&(!c.childNodes||c.childNodes.length==0)&&(b.startContainer==c&&(b.startContainer=c.parentNode,b.startOffset=GENTICS.Utils.Dom.getIndexInParent(c)),b.endContainer==c&&(b.endContainer=c.parentNode,b.endOffset=GENTICS.Utils.Dom.getIndexInParent(c)),g.remove(),f=!0),f&&b.clearCaches(),f},GENTICS.Utils.Dom.prototype.getIndexInParent=function(a){if(!a)return!1;var b=0,c=a.previousSibling;while(c)b++,c=c.previousSibling;return b},GENTICS.Utils.Dom.prototype.isBlockLevelElement=function(a){return a?a.nodeType==1&&jQuery.inArray(a.nodeName.toLowerCase(),this.blockLevelElements)>=0?!0:!1:!1},GENTICS.Utils.Dom.prototype.isLineBreakElement=function(a){return a?a.nodeType==1&&a.nodeName.toLowerCase()=="br":!1},GENTICS.Utils.Dom.prototype.isListElement=function(a){return a?a.nodeType==1&&jQuery.inArray(a.nodeName.toLowerCase(),this.listElements)>=0:!1},GENTICS.Utils.Dom.prototype.isSplitObject=function(a){if(a.nodeType===1)switch(a.nodeName.toLowerCase()){case"p":case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":case"li":return!0}return!1},GENTICS.Utils.Dom.prototype.searchAdjacentTextNode=function(a,b,c,d){if(!a||a.nodeType!=1||b<0||b>a.childNodes.length)return!1;typeof d=="undefined"&&(d={blocklevel:!0,list:!0,linebreak:!0}),d.blocklevel=="undefined"&&(stopal.blocklevel=!0),d.list=="undefined"&&(stopal.list=!0),d.linebreak=="undefined"&&(stopal.linebreak=!0),typeof c=="undefined"&&(c=!0);var e=undefined,f=a;c&&b>0&&(e=a.childNodes[b-1]),!c&&b<a.childNodes.length&&(e=a.childNodes[b]);while(typeof f!="undefined")if(!e){if(d.blocklevel&&this.isBlockLevelElement(f))return!1;if(d.list&&this.isListElement(f))return!1;e=c?f.previousSibling:f.nextSibling,f=f.parentNode}else{if(e.nodeType==3&&jQuery.trim(e.data).length>0)return e;if(d.blocklevel&&this.isBlockLevelElement(e))return!1;if(d.linebreak&&this.isLineBreakElement(e))return!1;if(d.list&&this.isListElement(e))return!1;e.nodeType==3?e=c?e.previousSibling:e.nextSibling:(f=e,e=c?e.lastChild:e.firstChild)}},GENTICS.Utils.Dom.prototype.insertIntoDOM=function(a,b,c,d){var e=b.getContainerParents(c,d),f=this,g;c||(c=jQuery(document.body)),e.length==0?g=c.get(0):jQuery.each(e,function(b,c){if(f.allowsNesting(c,a.get(0)))return g=c,!1}),typeof g=="undefined"&&c.length>0&&(g=c.get(0));if(typeof g!="undefined"){var h=this.split(b,jQuery(g),d);if(h===!0){var i=b.startContainer,j=b.startOffset;d&&(i=b.endContainer,j=b.endOffset);if(j==0){var k=jQuery(i).contents();return k.length>0?k.eq(0).before(a):jQuery(i).append(a),!0}return jQuery(i).contents().eq(j-1).after(a),!0}return h?(h.eq(0).after(a),!0):!1}return!1},GENTICS.Utils.Dom.prototype.removeFromDOM=function(a,b,c){if(c){var d=this.getIndexInParent(a),e=jQuery(a).contents().length,f=a.parentNode;b.startContainer==f&&b.startOffset>d?b.startOffset+=e-1:b.startContainer==a&&(b.startContainer=f,b.startOffset=d+b.startOffset),b.endContainer==f&&b.endOffset>d?b.endOffset+=e-1:b.endContainer==a&&(b.endContainer=f,b.endOffset=d+b.endOffset),jQuery(a).contents().unwrap(),this.doCleanup({merge:!0},b,f)}},GENTICS.Utils.Dom.prototype.extendToWord=function(a,b){var c=this.searchWordBoundary(a.startContainer,a.startOffset,!0),d=this.searchWordBoundary(a.endContainer,a.endOffset,!1);if(!b){if(a.startContainer==c.container&&a.startOffset==c.offset)return;if(a.endContainer==d.container&&a.endOffset==d.offset)return}a.startContainer=c.container,a.startOffset=c.offset,a.endContainer=d.container,a.endOffset=d.offset,a.correctRange(),a.clearCaches()},GENTICS.Utils.Dom.prototype.isWordBoundaryElement=function(a){return!a||!a.nodeName?!1:jQuery.inArray(a.nodeName.toLowerCase(),this.nonWordBoundaryTags)==-1},GENTICS.Utils.Dom.prototype.searchWordBoundary=function(a,b,c){typeof c=="undefined"&&(c=!0);var d=!1;while(!d)if(a.nodeType==3)if(!c){var e=a.data.substring(b).search(/\W/);e!=-1?(b+=e,d=!0):(b=this.getIndexInParent(a)+1,a=a.parentNode)}else{var e=a.data.substring(0,b).search(/\W/),f=e;while(f!=-1)e=f,f=a.data.substring(e+1,b).search(/\W/),f!=-1&&(f=f+e+1);e!=-1?(b=e+1,d=!0):(b=this.getIndexInParent(a),a=a.parentNode)}else a.nodeType==1&&(c?b>0?this.isWordBoundaryElement(a.childNodes[b-1])?d=!0:(a=a.childNodes[b-1],b=a.nodeType==3?a.data.length:a.childNodes.length):this.isWordBoundaryElement(a)?d=!0:(b=this.getIndexInParent(a),a=a.parentNode):b<a.childNodes.length?this.isWordBoundaryElement(a.childNodes[b])?d=!0:(a=a.childNodes[b],b=0):this.isWordBoundaryElement(a)?d=!0:(b=this.getIndexInParent(a)+1,a=a.parentNode));if(a.nodeType!=3){var g=this.searchAdjacentTextNode(a,b,!c);g&&(a=g,b=c?0:a.data.length)}return{container:a,offset:b}},GENTICS.Utils.Dom.prototype.isEmpty=function(a){if(!a)return!0;if(jQuery.inArray(a.nodeName.toLowerCase(),this.nonEmptyTags)!=-1)return!1;if(a.nodeType==3)return a.data.search(/\S/)==-1;for(var b=0;b<a.childNodes.length;++b)if(!this.isEmpty(a.childNodes[b]))return!1;return!0},GENTICS.Utils.Dom.prototype.setCursorAfter=function(a){var b=new GENTICS.Utils.RangeObject;b.startContainer=b.endContainer=a.parentNode,b.startOffset=b.endOffset=this.getIndexInParent(a),b.select()},GENTICS.Utils.Dom.prototype.setCursorInto=function(a){var b=new GENTICS.Utils.RangeObject;b.startContainer=b.endContainer=a,b.startOffset=b.endOffset=0,b.select()},GENTICS.Utils.Dom=new GENTICS.Utils.Dom;if(typeof GENTICS=="undefined"||!GENTICS)var GENTICS={};GENTICS.Aloha=function(){},GENTICS.Aloha.setAutobase=function(){var a=jQuery("script"),b=a[a.length-1].src.split("?")[0];b=b.split("/");var c=1;"core"===b[b.length-2]&&(c=2),GENTICS.Aloha.prototype.autobase=b.slice(0,c*-1).join("/")+"/"},GENTICS.Aloha.setAutobase(),GENTICS.Aloha.prototype.version="##ALOHAVERSION##",GENTICS.Aloha.prototype.editables=[],GENTICS.Aloha.prototype.activeEditable=null,GENTICS.Aloha.prototype.ready=!1,GENTICS.Aloha.prototype.settings={},GENTICS.Aloha.prototype.OSName="Unknown",GENTICS.Aloha.prototype.readyCallbacks=[],GENTICS.Aloha.prototype.init=function(){if(jQuery.browser.webkit&&parseFloat(jQuery.browser.version)<532.5||jQuery.browser.mozilla&&parseFloat(jQuery.browser.version)<1.9||jQuery.browser.msie&&jQuery.browser.version<7||jQuery.browser.opera&&parseFloat(jQuery.browser.version)<11){alert("Sorry, your browser is not supported at the moment.");return}var a=this;jQuery("html").mousedown(function(b){if(b.target.tagName.toLowerCase()=="img")return;$(b.target).parents(".wig-dialog, .wig-widget").length==0&&a.activeEditable&&(a.activeEditable.blur(),a.activeEditable=null)});if(typeof this.settings.base=="undefined"||!this.settings.base)this.settings.base=GENTICS.Aloha.autobase,typeof GENTICS_Aloha_base!="undefined"&&(this.settings.base=GENTICS_Aloha_base);this.Log.init(),this.settings.errorhandling!=0&&(window.onerror=function(a,b,c){return GENTICS.Aloha.Log.error(GENTICS.Aloha,"Error message: "+a+"\nURL: "+b+"\nLine Number: "+c),!0}),navigator.appVersion.indexOf("Win")!=-1&&(this.OSName="Win"),navigator.appVersion.indexOf("Mac")!=-1&&(this.OSName="Mac"),navigator.appVersion.indexOf("X11")!=-1&&(this.OSName="Unix"),navigator.appVersion.indexOf("Linux")!=-1&&(this.OSName="Linux"),this.ready=!0;for(var b=0;b<this.editables.length;b++)this.editables[b].ready||this.editables[b].init();GENTICS.Aloha.EventRegistry.trigger(new GENTICS.Aloha.Event("alohaready",GENTICS.Aloha,null))},GENTICS.Aloha.prototype.activateEditable=function(a){for(var b=0;b<this.editables.length;b++)if(this.editables[b]!=a&&this.editables[b].isActive){var c=this.editables[b];this.editables[b].blur()}this.activeEditable=a},GENTICS.Aloha.prototype.getActiveEditable=function(){return this.activeEditable},GENTICS.Aloha.prototype.deactivateEditable=function(){if(typeof this.activeEditable=="undefined"||this.activeEditable==null)return;this.activeEditable.blur(),this.activeEditable=null},GENTICS.Aloha.prototype.getEditableById=function(a){for(var b=0;b<GENTICS.Aloha.editables.length;b++)if(GENTICS.Aloha.editables[b].getId()==a)return GENTICS.Aloha.editables[b];return null},GENTICS.Aloha.prototype.log=function(a,b,c){GENTICS.Aloha.Log.log(a,b,c)},GENTICS.Aloha.prototype.identStr=function(a){a instanceof jQuery&&(a=a[0]);if(a instanceof HTMLElement){var b=a.tagName.toLowerCase();return a.id?b+"#"+a.id:a.className?b+"."+a.className:b}return GENTICS.Aloha.Log.warn(this,"{"+a.toString()+"} provided is not an HTML element"),a.toString()},GENTICS.Aloha.prototype.registerEditable=function(a){this.editables.push(a)},GENTICS.Aloha.prototype.unregisterEditable=function(a){var b=jQuery.inArray(a,this.editables);b!=-1&&this.editables.splice(b,1)},GENTICS.Aloha.prototype.toString=function(){return"GENTICS.Aloha"},GENTICS.Aloha.prototype.isModified=function(){for(var a in this.editables)if(this.editables[a].isModified&&this.editables[a].isModified())return!0;return!1},GENTICS.Aloha=new GENTICS.Aloha,jQuery.isAloha=!0,jQuery(document).ready(function(){!jQuery.isAloha&&window.console&&console.error&&console.error("Aloha ERROR: jQuery was included at least a second time after loading Aloha. This will cause serious problems. You must not load other versions of jQuery with Aloha."),GENTICS.Aloha.init()}),GENTICS.Aloha.Editable=function(a){a.attr("id")||a.attr("id",GENTICS.Utils.guid()),this.obj=a,this.ready=!1,GENTICS.Aloha.registerEditable(this),this.init()},GENTICS.Aloha.Editable.prototype.isActive=!1,GENTICS.Aloha.Editable.prototype.originalContent=null,GENTICS.Aloha.Editable.prototype.range=undefined,GENTICS.Aloha
.Editable.prototype.check=function(){var a=this.obj,b=a.get(0),c=b.nodeName.toLowerCase(),d=["a","abbr","address","article","aside","b","bdo","blockquote","cite","code","command","del","details","dfn","div","dl","em","footer","h1","h2","h3","h4","h5","h6","header","i","ins","menu","nav","p","pre","q","ruby","section","small","span","strong","sub","sup","var"];for(var e=0;e<d.length;e++)if(c==d[e])return!0;switch(c){case"label":case"button":break;case"textarea":var f=jQuery("<div/>").insertAfter(a);f.html(a.val()),a.hide();var g=function(){var b=f.html();a.val(b)};return a.parents("form:first").submit(g),this.obj=f,!0;default:}return!1},GENTICS.Aloha.Editable.prototype.init=function(){var a=this;if(!this.check(this.obj)){this.destroy();return}GENTICS.Aloha.ready&&(this.obj.addClass("GENTICS_editable"),this.obj.attr("contentEditable",!0),this.obj.mousedown(function(b){a.activate(b),b.stopPropagation()}),this.obj.focus(function(b){a.activate(b)}),this.obj.keydown(function(a){return GENTICS.Aloha.Markup.preProcessKeyStrokes(a)}),this.obj.keyup(function(a){if(a["keyCode"]==27)return GENTICS.Aloha.deactivateEditable(),!1}),this.obj.keypress(function(a){if(GENTICS.Aloha.activeEditable.eventHandled)return a.preventDefault(),a.stopPropagation(),!1}),this.obj.GENTICS_contentEditableSelectionChange(function(b){return GENTICS.Aloha.Selection.onChange(a.obj,b),a.obj}),GENTICS.Aloha.EventRegistry.trigger(new GENTICS.Aloha.Event("editableCreated",GENTICS.Aloha,[this])),this.setUnmodified(),this.ready=!0)},GENTICS.Aloha.Editable.prototype.destroy=function(){var a=this;this.blur(),this.ready=!1,this.obj.removeClass("GENTICS_editable"),this.obj.removeAttr("contentEditable"),this.obj.unbind("mousedown"),this.obj.unbind("focus"),this.obj.unbind("keydown"),this.obj.unbind("keyup"),GENTICS.Aloha.EventRegistry.trigger(new GENTICS.Aloha.Event("editableDestroyed",GENTICS.Aloha,[this])),GENTICS.Aloha.unregisterEditable(this)},GENTICS.Aloha.Editable.prototype.setUnmodified=function(){this.originalContent=this.getContents()},GENTICS.Aloha.Editable.prototype.isModified=function(){return this.originalContent!=this.getContents()},GENTICS.Aloha.Editable.prototype.toString=function(){return"GENTICS.Aloha.Editable"},GENTICS.Aloha.Editable.prototype.isDisabled=function(){return this.obj.attr("contentEditable")=="false"||!this.obj.attr("contentEditable")},GENTICS.Aloha.Editable.prototype.disable=function(){this.isDisabled()||this.obj.attr("contentEditable","false")},GENTICS.Aloha.Editable.prototype.enable=function(){this.isDisabled()&&this.obj.attr("contentEditable","true")},GENTICS.Aloha.Editable.prototype.activate=function(a){if(this.isActive||this.isDisabled())return;var b=GENTICS.Aloha.getActiveEditable();GENTICS.Aloha.activateEditable(this),document.selection&&document.selection.createRange&&this.obj.mouseup(),this.isActive=!0,GENTICS.Aloha.EventRegistry.trigger(new GENTICS.Aloha.Event("editableActivated",GENTICS.Aloha,{oldActive:b,editable:this})),GENTICS.Aloha.EventRegistry.trigger(new GENTICS.Aloha.Event("editableActivated",this,{oldActive:GENTICS.Aloha.getActiveEditable()}))},GENTICS.Aloha.Editable.prototype.blur=function(){this.obj.blur(),this.isActive=!1,GENTICS.Aloha.EventRegistry.trigger(new GENTICS.Aloha.Event("editableDeactivated",GENTICS.Aloha,{editable:this})),GENTICS.Aloha.EventRegistry.trigger(new GENTICS.Aloha.Event("editableDeactivated",this))},GENTICS.Aloha.Editable.prototype.empty=function(a){return null===a||jQuery.trim(a)==""||a=="<br>"},GENTICS.Aloha.Editable.prototype.getContents=function(){var a=this.obj.clone(!0);return a.html()},GENTICS.Aloha.Editable.prototype.getId=function(){return this.obj.attr("id")},GENTICS.Aloha.Event=function(a,b,c){this.name=a,b?this.source=b:this.source=GENTICS.Aloha,this.properties=c},GENTICS.Aloha.EventRegistry=function(){},GENTICS.Aloha.EventRegistry.prototype.subscribe=function(a,b,c){jQuery(a).bind(b,c)},GENTICS.Aloha.EventRegistry.prototype.trigger=function(a){jQuery(a.source).trigger(a.name,a.properties)},GENTICS.Aloha.EventRegistry=new GENTICS.Aloha.EventRegistry,document.attachEvent&&document.selection&&function(){function c(b){this._document=b,this.startContainer=this.endContainer=b.body,this.endOffset=a.getNodeLength(b.body)}function d(b){this.range=b;if(b.collapsed)return;var c=b.commonAncestorContainer;this._next=b.startContainer==c&&!a.isDataNode(b.startContainer)?b.startContainer.childNodes[b.startOffset]:a.findClosestAncestor(c,b.startContainer),this._end=b.endContainer==c&&!a.isDataNode(b.endContainer)?b.endContainer.childNodes[b.endOffset]:a.findClosestAncestor(c,b.endContainer).nextSibling}function e(a){this._document=a;var b=this;a.attachEvent("onselectionchange",function(){b._selectionChangeHandler()})}var a={findChildPosition:function(a){for(var b=0;a=a.previousSibling;b++)continue;return b},isDataNode:function(a){return a&&a.nodeValue!==null&&a.data!==null},isAncestorOf:function(b,c){return!a.isDataNode(b)&&(b.contains(a.isDataNode(c)?c.parentNode:c)||c.parentNode==b)},isAncestorOrSelf:function(b,c){return a.isAncestorOf(b,c)||b==c},findClosestAncestor:function(b,c){if(a.isAncestorOf(b,c))while(c&&c.parentNode!=b)c=c.parentNode;return c},getNodeLength:function(b){return a.isDataNode(b)?b.length:b.childNodes.length},splitDataNode:function(b,c){if(!a.isDataNode(b))return!1;var d=b.cloneNode(!1);b.deleteData(c,b.length),d.deleteData(0,c),b.parentNode.insertBefore(d,b.nextSibling)}},b={convertToDOMRange:function(a,b){function d(a,c,d){var e=b.createElement("a"),f=c.duplicate();f.collapse(d);var g=f.parentElement();do g.insertBefore(e,e.previousSibling),f.moveToElementText(e);while(f.compareEndPoints(d?"StartToStart":"StartToEnd",c)>0&&e.previousSibling);f.compareEndPoints(d?"StartToStart":"StartToEnd",c)==-1&&e.nextSibling?(f.setEndPoint(d?"EndToStart":"EndToEnd",c),a[d?"setStart":"setEnd"](e.nextSibling,f.text.length)):a[d?"setStartBefore":"setEndBefore"](e),e.parentNode.removeChild(e)}var e=new c(b);return d(e,a,!0),d(e,a,!1),e},convertFromDOMRange:function(b){function c(b,c,d){var e=c[d?"startContainer":"endContainer"],f=c[d?"startOffset":"endOffset"],g=0,h=a.isDataNode(e)?e:e.childNodes[f],i=a.isDataNode(e)?e.parentNode:e;if(e.nodeType==3||e.nodeType==4)g=f;var j=c._document.createElement("a");i.insertBefore(j,h);var k=c._document.body.createTextRange();k.moveToElementText(j),j.parentNode.removeChild(j),b.setEndPoint(d?"StartToStart":"EndToStart",k),b[d?"moveStart":"moveEnd"]("character",g)}var d=b._document.body.createTextRange();return c(d,b,!0),c(d,b,!1),d}};c.START_TO_START=0,c.START_TO_END=1,c.END_TO_END=2,c.END_TO_START=3,c.prototype={startContainer:null,startOffset:0,endContainer:null,endOffset:0,commonAncestorContainer:null,collapsed:!1,_document:null,_refreshProperties:function(){this.collapsed=this.startContainer==this.endContainer&&this.startOffset==this.endOffset;var b=this.startContainer;while(b&&b!=this.endContainer&&!a.isAncestorOf(b,this.endContainer))b=b.parentNode;this.commonAncestorContainer=b},setStart:function(a,b){this.startContainer=a,this.startOffset=b,this._refreshProperties()},setEnd:function(a,b){this.endContainer=a,this.endOffset=b,this._refreshProperties()},setStartBefore:function(b){this.setStart(b.parentNode,a.findChildPosition(b))},setStartAfter:function(b){this.setStart(b.parentNode,a.findChildPosition(b)+1)},setEndBefore:function(b){this.setEnd(b.parentNode,a.findChildPosition(b))},setEndAfter:function(b){this.setEnd(b.parentNode,a.findChildPosition(b)+1)},selectNode:function(a){this.setStartBefore(a),this.setEndAfter(a)},selectNodeContents:function(b){this.setStart(b,0),this.setEnd(b,a.getNodeLength(b))},collapse:function(a){a?this.setEnd(this.startContainer,this.startOffset):this.setStart(this.endContainer,this.endOffset)},cloneContents:function(){return function a(b){for(var c,d=document.createDocumentFragment();c=b.next();)c=c.cloneNode(!b.hasPartialSubtree()),b.hasPartialSubtree()&&c.appendChild(a(b.getSubtreeIterator())),d.appendChild(c);return d}(new d(this))},extractContents:function(){var b=this.cloneRange();return this.startContainer!=this.commonAncestorContainer&&this.setStartAfter(a.findClosestAncestor(this.commonAncestorContainer,this.startContainer)),this.collapse(!0),function c(a){for(var b,d=document.createDocumentFragment();b=a.next();)a.hasPartialSubtree()?b=b.cloneNode(!1):a.remove(),a.hasPartialSubtree()&&b.appendChild(c(a.getSubtreeIterator())),d.appendChild(b);return d}(new d(b))},deleteContents:function(){var b=this.cloneRange();this.startContainer!=this.commonAncestorContainer&&this.setStartAfter(a.findClosestAncestor(this.commonAncestorContainer,this.startContainer)),this.collapse(!0),function c(a){while(a.next())a.hasPartialSubtree()?c(a.getSubtreeIterator()):a.remove()}(new d(b))},insertNode:function(b){a.isDataNode(this.startContainer)?(a.splitDataNode(this.startContainer,this.startOffset),this.startContainer.parentNode.insertBefore(b,this.startContainer.nextSibling)):this.startContainer.insertBefore(b,this.startContainer.childNodes[this.startOffset]),this.setStart(this.startContainer,this.startOffset)},surroundContents:function(a){var b=this.extractContents();this.insertNode(a),a.appendChild(b),this.selectNode(a)},compareBoundaryPoints:function(a,b){var d,e,f,g;switch(a){case c.START_TO_START:case c.START_TO_END:d=this.startContainer,e=this.startOffset;break;case c.END_TO_END:case c.END_TO_START:d=this.endContainer,e=this.endOffset}switch(a){case c.START_TO_START:case c.END_TO_START:f=b.startContainer,g=b.startOffset;break;case c.START_TO_END:case c.END_TO_END:f=b.endContainer,g=b.endOffset}return d.sourceIndex<f.sourceIndex?-1:d.sourceIndex==f.sourceIndex?e<g?-1:e==g?0:1:1},cloneRange:function(){var a=new c(this._document);return a.setStart(this.startContainer,this.startOffset),a.setEnd(this.endContainer,this.endOffset),a},detach:function(){},toString:function(){return b.convertFromDOMRange(this).text},createContextualFragment:function(b){var c=(a.isDataNode(this.startContainer)?this.startContainer.parentNode:this.startContainer).cloneNode(!1);c.innerHTML=b;for(var d=this._document.createDocumentFragment();c.firstChild;)d.appendChild(c.firstChild);return d}},d.prototype={range:null,_current:null,_next:null,_end:null,hasNext:function(){return!!this._next},next:function(){var b=this._current=this._next;return this._next=this._current&&this._current.nextSibling!=this._end?this._current.nextSibling:null,a.isDataNode(this._current)&&(this.range.endContainer==this._current&&(b=b.cloneNode(!0)).deleteData(this.range.endOffset,b.length-this.range.endOffset),this.range.startContainer==this._current&&(b=b.cloneNode(!0)).deleteData(0,this.range.startOffset)),b},remove:function(){if(!a.isDataNode(this._current)||this.range.startContainer!=this._current&&this.range.endContainer!=this._current)this._current.parentNode.removeChild(this._current);else{var b=this.range.startContainer==this._current?this.range.startOffset:0,c=this.range.endContainer==this._current?this.range.endOffset:this._current.length;this._current.deleteData(b,c-b)}},hasPartialSubtree:function(){return!a.isDataNode(this._current)&&(a.isAncestorOrSelf(this._current,this.range.startContainer)||a.isAncestorOrSelf(this._current,this.range.endContainer))},getSubtreeIterator:function(){var b=new c(this.range._document);return b.selectNodeContents(this._current),a.isAncestorOrSelf(this._current,this.range.startContainer)&&b.setStart(this.range.startContainer,this.range.startOffset),a.isAncestorOrSelf(this._current,this.range.endContainer)&&b.setEnd(this.range.endContainer,this.range.endOffset),new d(b)}},e.prototype={rangeCount:0,_document:null,_selectionChangeHandler:function(){this.rangeCount=this._selectionExists(this._document.selection.createRange())?1:0},_selectionExists:function(a){return a.compareEndPoints("StartToEnd",a)!=0||a.parentElement().isContentEditable},addRange:function(a){var c=this._document.selection.createRange(),d=b.convertFromDOMRange(a);this._selectionExists(c)?(d.compareEndPoints("StartToStart",c)==-1&&(d.compareEndPoints("StartToEnd",c)>-1&&d.compareEndPoints("EndToEnd",c)==-1?c.setEndPoint("StartToStart",d):d.compareEndPoints("EndToStart",c)<1&&d.compareEndPoints("EndToEnd",c)>-1&&c.setEndPoint("EndToEnd",d)),c.select()):d.select()},removeAllRanges:function(){this._document.selection.empty()},getRangeAt:function(a){var c=this._document.selection.createRange();return this._selectionExists(c)?b.convertToDOMRange(c,this._document):null},toString:function(){return this._document.selection.createRange().text}},document.createRange=function(){return new c(document)};var f=new e(document);window.getSelection=function(){return f}}(),jQuery.fn.GENTICS_contentEditableSelectionChange=function(a){var b=this;return this.keyup(function(b){var c=GENTICS.Aloha.Selection.getRangeObject();a(b)}),this.dblclick(function(b){a(b)}),this.mousedown(function(a){b.selectionStarted=!0}),jQuery(document).mouseup(function(c){GENTICS.Aloha.Selection.eventOriginalTarget=b,b.selectionStarted&&a(c),GENTICS.Aloha.Selection.eventOriginalTarget=!1,b.selectionStarted=!1}),this},jQuery.fn.outerHTML=function(a){return a?this.before(a).remove():jQuery("<p>").append(this.eq(0).clone()).html()},GENTICS.Aloha.Log=function(){},GENTICS.Aloha.Log.prototype.logHistory=null,GENTICS.Aloha.Log.prototype.highWaterMarkReached=!1,GENTICS.Aloha.Log.prototype.init=function(){if(typeof GENTICS.Aloha.settings.logLevels=="undefined"||!GENTICS.Aloha.settings.logLevels)GENTICS.Aloha.settings.logLevels={error:!0,warn:!0};if(typeof GENTICS.Aloha.settings.logHistory=="undefined"||!GENTICS.Aloha.settings.logHistory)GENTICS.Aloha.settings.logHistory={};GENTICS.Aloha.settings.logHistory.maxEntries||(GENTICS.Aloha.settings.logHistory.maxEntries=100),GENTICS.Aloha.settings.logHistory.highWaterMark||(GENTICS.Aloha.settings.logHistory.highWaterMark=90),GENTICS.Aloha.settings.logHistory.levels||(GENTICS.Aloha.settings.logHistory.levels={error:!0,warn:!0}),this.flushLogHistory()},GENTICS.Aloha.Log.prototype.log=function(a,b,c){if(typeof a=="undefined"||!a)a="error";a=a.toLowerCase();if(!GENTICS.Aloha.settings.logLevels[a])return;this.addToLogHistory({level:a,component:b.toString(),message:c,date:new Date});switch(a){case"error":window.console&&console.error&&console.error(b.toString()+": "+c);break;case"warn":window.console&&console.warn&&console.warn(b.toString()+": "+c);break;case"info":window.console&&console.info&&console.info(b.toString()+": "+c);break;case"debug":window.console&&console.log&&console.log(b.toString()+" ["+a+"]: "+c);break;default:window.console&&console.log&&console.log(b.toString()+" ["+a+"]: "+c)}},GENTICS.Aloha.Log.prototype.error=function(a,b){this.log("error",a,b)},GENTICS.Aloha.Log.prototype.warn=function(a,b){this.log("warn",a,b)},GENTICS.Aloha.Log.prototype.info=function(a,b){this.log("info",a,b)},GENTICS.Aloha.Log.prototype.debug=function(a,b){this.log("debug",a,b)},GENTICS.Aloha.Log.prototype.isLogLevelEnabled=function(a){return GENTICS.Aloha.settings&&GENTICS.Aloha.settings.logLevels&&GENTICS.Aloha.settings.logLevels[a]==1},GENTICS.Aloha.Log.prototype.isErrorEnabled=function(){return this.isLogLevelEnabled("error")},GENTICS.Aloha.Log.prototype.isWarnEnabled=function(){return this.isLogLevelEnabled("warn")},GENTICS.Aloha.Log.prototype.isInfoEnabled=function(){return this.isLogLevelEnabled("info")},GENTICS.Aloha.Log.prototype.isDebugEnabled=function(){return this.isLogLevelEnabled("debug")},GENTICS.Aloha.Log.prototype.addToLogHistory=function(a){if(GENTICS.Aloha.settings.logHistory.maxEntries<=0||!GENTICS.Aloha.settings.logHistory.levels[a.level])return;this.logHistory.push(a),this.highWaterMarkReached==0&&this.logHistory.length>=GENTICS.Aloha.settings.logHistory.maxEntries*GENTICS.Aloha.settings.logHistory.highWaterMark/100&&(GENTICS.Aloha.EventRegistry.trigger(new GENTICS.Aloha.Event("logFull",GENTICS.Aloha.Log)),this.highWaterMarkReached=!0);while(this.logHistory.length>GENTICS.Aloha.settings.logHistory.maxEntries)this.logHistory.shift()},GENTICS.Aloha.Log.prototype.getLogHistory=function(){return this.logHistory},GENTICS.Aloha.Log.prototype.flushLogHistory=function(){this.logHistory=[],this.highWaterMarkReached=!1},GENTICS.Aloha.Log=new GENTICS.Aloha.Log,GENTICS.Aloha.Markup=function(){},GENTICS.Aloha.Markup.prototype.keyHandlers={},GENTICS.Aloha.Markup.prototype.addKeyHandler=function(a,b){this.keyHandlers[a]||(this.keyHandlers[a]=[]),this.keyHandlers[a].push(b)},GENTICS.Aloha.Markup.prototype.insertBreak=function(){var a=GENTICS.Aloha.Selection.rangeObject;a.isCollapsed()||this.removeSelectedMarkup();var b=jQuery("<br/>");GENTICS.Utils.Dom.insertIntoDOM(b,a,GENTICS.Aloha.activeEditable.obj);var c=GENTICS.Utils.Dom.searchAdjacentTextNode(b.parent().get(0),GENTICS.Utils.Dom.getIndexInParent(b.get(0))+1,!1);if(c){var d=c.data.search(/\S/);d>0&&(c.data=c.data.substring(d))}a.startContainer=a.endContainer=b.get(0).parentNode,a.startOffset=a.endOffset=GENTICS.Utils.Dom.getIndexInParent(b.get(0))+1,a.correctRange(),a.clearCaches(),a.select()},GENTICS.Aloha.Markup.prototype.preProcessKeyStrokes=function(a){function g(a,b,c){return GENTICS.Aloha.activeEditable?a.findMarkup(function(){return $.inArray(this.nodeName.toLowerCase(),b)!=-1},GENTICS.Aloha.activeEditable.obj,c):null}function h(a,b){var c=!1,d=$(b).looksEmpty();if(d)c=!0;else if(a.startContainer==b.childNodes[0]&&a.startOffset==0)c=!0;else{var e=g(a,f);e&&!e.previousSibling&&a.startOffset==0&&(c=!0)}return c}function i(a){if(a.nodeType==1){var b=a.nodeName.toLowerCase();return $.inArray(b,f)!=-1?a.nextSibling?!1:i(a.parentNode):!0}return i(a.parentNode)}function j(a,b){var c=!1,d=$(b).looksEmpty();return d?c=!0:a.startOffset==a.startContainer.length&&i(a.startContainer)&&(c=!0),c}function k(a){if(a.nodeName.toLowerCase()=="a"&&a.childNodes.length==1){var b=a.childNodes[0];if(b.nodeType==1&&b.nodeName.toLowerCase()=="img")return!0}return!1}function l(a){if(a.nodeType==1&&a.nodeName.toLowerCase()=="p"&&$(a).find("img").length){for(var b=0;b<a.childNodes.length;b++){var c=a.childNodes[b];if(c.nodeType!=1)return!1;var d=c.nodeName.toLowerCase();if(!k(c)&&d!="img"&&d!="br")return!1}return!0}return!1}function m(){GENTICS.Aloha.activeEditable.eventHandled=!0}function n(){if(p.looksEmpty()){var a=p.parents(".GENTICS_editable");p.remove();var b=a.find("textarea, p");if(b.length){var c=b[0];c.tagName.toLowerCase()=="textarea"?c.focus():GENTICS.Utils.Dom.setCursorInto(c)}}}GENTICS.Aloha.activeEditable.eventHandled=!1;if(a.type!="keydown")return!1;var b=GENTICS.Aloha.Selection.rangeObject;if(this.keyHandlers[a.keyCode]){var c=this.keyHandlers[a.keyCode];for(var d=0;d<c.length;++d)if(!c[d](a))return!1}var e=["p","h1","h2","h3","h4","h5","h6","li"],f=["a","b","i"];switch(a.keyCode){case 8:if(!b.isCollapsed())return!0;var o=g(b,e),p=$(o);if(h(b,o)){var q=o.previousSibling;if(q&&q.nodeType==1){var r=$(q);if(r.explicitlyNotContenteditable())return n(p),m(),!1;if(l(q))return n(p),m(),!1}}break;case 46:if(!b.isCollapsed())return!0;var o=g(b,e),p=$(o);if(j(b,o)){var s=o.nextSibling;if(s&&s.nodeType==1){var t=$(s);if(t.explicitlyNotContenteditable())return n(p),m(),!1;if(l(s))return n(p),m(),!1}}break;case 13:return m(),a.shiftKey?(GENTICS.Aloha.Log.debug(this,"... got a smoking Shift+Enter, Cowboy"),b.isCollapsed()||this.removeSelectedMarkup(),GENTICS.Aloha.Selection.updateSelection(!1,!0),this.processShiftEnter(b),!1):(GENTICS.Aloha.Log.debug(this,"... got a lonely Enter, Mum"),b.isCollapsed()||this.removeSelectedMarkup(),GENTICS.Aloha.Selection.updateSelection(!1,!0),this.processEnter(b),!1)}return!0},GENTICS.Aloha.Markup.prototype.processShiftEnter=function(a){this.insertHTMLBreak(a.getSelectionTree(),a)},GENTICS.Aloha.Markup.prototype.processEnter=function(a){a.splitObject?(jQuery.browser.msie&&GENTICS.Utils.Dom.isListElement(a.splitObject)&&jQuery(a.splitObject).append(jQuery(document.createTextNode(""))),this.splitRangeObject(a)):this.insertHTMLBreak(a.getSelectionTree(),a)},GENTICS.Aloha.Markup.prototype.insertHTMLCode=function(a){var b=GENTICS.Aloha.Selection.rangeObject;this.insertHTMLBreak(b.getSelectionTree(),b,jQuery(a))},GENTICS.Aloha.Markup.prototype.insertHTMLBreak=function(a,b,c){c=c?c:jQuery("<br />");for(var d=0;d<a.length;d++){var e=a[d],f=e.domobj?jQuery(e.domobj):undefined;if(e.selection!=="none")if(e.selection=="collapsed"){if(d>0){var g=jQuery(a[d-1].domobj);g.after(c)}else{var h=jQuery(a[1].domobj);h.before(c)}b.startContainer=b.endContainer=c[0].parentNode,b.startOffset=b.endOffset=GENTICS.Utils.Dom.getIndexInParent(c[0])+1,b.correctRange()}else if(e.domobj&&e.domobj.nodeType===3){e.domobj.nextSibling&&e.domobj.nextSibling.nodeType==1&&GENTICS.Aloha.Selection.replacingElements[e.domobj.nextSibling.nodeName.toLowerCase()]&&f.after("<br/>");var i=e.domobj;while(i)if(i.nextSibling)i=!1;else{i=i.parentNode,i===b.limitObject&&(i=!1);if(GENTICS.Utils.Dom.isBlockLevelElement(i))break}i&&jQuery(i).append("<br/>"),f.between(c,e.startOffset);var j=0,k=c[0];while(k)k=k.previousSibling,j++;b.startContainer=c[0].parentNode,b.endContainer=c[0].parentNode,b.startOffset=j,b.endOffset=j,b.correctRange()}else e.domobj&&e.domobj.nodeType===1&&(f.parent().find("br.GENTICS_ephemera").length===0&&(jQuery(b.limitObject).find("br.GENTICS_ephemera").remove(),jQuery(b.commonAncestorContainer).append(this.getFillUpElement(b.splitObject))),f.after(c),b.startContainer=b.commonAncestorContainer,b.endContainer=b.startContainer,b.startOffset=d+2,b.endOffset=d+2,b.update())}b.select()},GENTICS.Aloha.Markup.prototype.getSelectedText=function(){var a=GENTICS.Aloha.Selection.rangeObject;return a.isCollapsed()?!1:this.getFromSelectionTree(a.getSelectionTree(),!0)},GENTICS.Aloha.Markup.prototype.getFromSelectionTree=function(a,b){var c="";for(var d=0;d<a.length;d++){var e=a[d];if(e.selection=="partial"){if(e.domobj.nodeType==3)c+=e.domobj.data.substring(e.startOffset,e.endOffset);else if(e.domobj.nodeType==1&&e.children)if(b)c+=this.getFromSelectionTree(e.children,b);else{var f=jQuery(e.domobj).clone(!1).empty();f.html(this.getFromSelectionTree(e.children,b)),c+=f.outerHTML()}}else e.selection=="full"&&(e.domobj.nodeType==3?c+=jQuery(e.domobj).text():e.domobj.nodeType==1&&e.children&&(c+=b?jQuery(e.domobj).text():jQuery(e.domobj).outerHTML()))}return c},GENTICS.Aloha.Markup.prototype.getSelectedMarkup=function(){var a=GENTICS.Aloha.Selection.rangeObject;return a.isCollapsed()?!1:this.getFromSelectionTree(a.getSelectionTree(),!1)},GENTICS.Aloha.Markup.prototype.removeSelectedMarkup=function(){var a=GENTICS.Aloha.Selection.rangeObject;if(a.isCollapsed())return;var b=new GENTICS.Aloha.Selection.SelectionRange;a.updateCommonAncestorContainer(),this.removeFromSelectionTree(a.getSelectionTree(),b),b.update(),GENTICS.Utils.Dom.doCleanup({merge:!0,removeempty:!0},GENTICS.Aloha.Selection.rangeObject),GENTICS.Aloha.Selection.rangeObject=b;try{b.correctRange(),b.update(),b.select()}catch(c){}GENTICS.Aloha.Selection.updateSelection()},GENTICS.Aloha.Markup.prototype.removeFromSelectionTree=function(a,b){var c=undefined;for(var d=0;d<a.length;d++){var e=a[d];if(e.selection=="partial")if(e.domobj.nodeType==3){var f="";e.startOffset>0&&(f+=e.domobj.data.substring(0,e.startOffset)),e.endOffset<e.domobj.data.length&&(f+=e.domobj.data.substring(e.endOffset,e.domobj.data.length)),e.domobj.data=f,b.startContainer||(b.startContainer=b.endContainer=e.domobj,b.startOffset=b.endOffset=e.startOffset)}else e.domobj.nodeType==1&&e.children&&(this.removeFromSelectionTree(e.children,b),c?c.nodeName==e.domobj.nodeName&&(jQuery(c).append(jQuery(e.domobj).contents()),jQuery(e.domobj).remove()):c=e.domobj);else if(e.selection=="full"){if(!b.startContainer){var g=GENTICS.Utils.Dom.searchAdjacentTextNode(e.domobj.parentNode,GENTICS.Utils.Dom.getIndexInParent(e.domobj)+1,!1,{blocklevel:!1});g?(b.startContainer=b.endContainer=g,b.startOffset=b.endOffset=0):(b.startContainer=b.endContainer=e.domobj.parentNode,b.startOffset=b.endOffset=GENTICS.Utils.Dom.getIndexInParent(e.domobj)+1)}jQuery(e.domobj).remove()}}},GENTICS.Aloha.Markup.prototype.splitRangeObject=function(a,b){var c=jQuery(a.splitObject);a.update(a.splitObject);var d=a.getSelectionTree(),e=this.getSplitFollowUpContainer(a);this.splitRangeObjectHelper(d,a,e),e.hasClass("preparedForRemoval")&&e.removeClass("preparedForRemoval");var f=this.getInsertAfterObject(a,e);jQuery(e).insertAfter(f),a.splitObject.nodeName.toLowerCase()==="li"&&!GENTICS.Aloha.Selection.standardTextLevelSemanticsComparator(a.splitObject,e)&&jQuery(a.splitObject).remove(),a.startContainer=e.textNodes(!0,!0).first().get(0),a.startContainer||(a.startContainer=e.textNodes(!1).first().parent().get(0)),a.startContainer?(a.endContainer=a.startContainer,a.startOffset=0,a.endOffset=0):(a.startContainer=a.endContainer=e.parent().get(0),a.startOffset=a.endOffset=GENTICS.Utils.Dom.getIndexInParent(e.get(0))),a.update(),a.select()},GENTICS.Aloha.Markup.prototype.getInsertAfterObject=function(a,b){for(var c=0;c<a.markupEffectiveAtStart.length;c++){el=a.markupEffectiveAtStart[c];if(el===a.splitObject)var d=!0;if(!d)continue;if(GENTICS.Aloha.Selection.canTag1WrapTag2(jQuery(el).parent()[0].nodeName,b[0].nodeName))return el}return!1},GENTICS.Aloha.Markup.prototype.getFillUpElement=function(a){return jQuery.browser.msie?!1:jQuery('<br class="GENTICS_ephemera" />')},GENTICS.Aloha.Markup.prototype.removeElementContentWhitespaceObj=function(a){var b=0,c=[];for(var d=0;d<a.length;d++){var e=a[d];e.isElementContentWhitespace&&(c[c.length]=d)}for(var d=0;d<c.length;d++){var f=c[d];a.splice(f-b,1),b++}},GENTICS.Aloha.Markup.prototype.splitRangeObjectHelper=function(a,b,c,d){c||GENTICS.Aloha.Log.warn(this,"no followUpContainer, no inBetweenMarkup, nothing to do...");var e=this.getFillUpElement(b.splitObject),f=jQuery(b.splitObject),g=!1;if(a.length>0){var h=c.contents();h.length!==a.length&&this.removeElementContentWhitespaceObj(h);for(var i=0;i<a.length;i++){var j=a[i];if(j.selection==="none"&&g===!1||j.domobj&&j.domobj.nodeType===3&&j===a[a.length-1]&&j.startOffset===j.domobj.data.length){c.textNodes().length>1?h.eq(i).remove():GENTICS.Utils.Dom.isSplitObject(c[0])?e?c.html(e):c.empty():(c.empty(),c.addClass("preparedForRemoval"));continue}if(j.selection!=="none"){if(j.domobj&&j.domobj.nodeType===3&&j.startOffset!==undefined){var k=j.domobj.data;if(j.startOffset>0)j.domobj.data=k.substr(0,j.startOffset);else if(a.length>1)jQuery(j.domobj).remove();else{var l=jQuery(j.domobj).parent();GENTICS.Utils.Dom.isSplitObject(l[0])?e?l.html(e):l.empty():l.remove()}k.length-j.startOffset>0?h[i].data=k.substr(j.startOffset,k.length):h.length>1?h.eq(i).remove():GENTICS.Utils.Dom.isBlockLevelElement(c[0])?e?c.html(e):c.empty():(c.empty(),c.addClass("preparedForRemoval"))}g=!0,j.children.length>0&&this.splitRangeObjectHelper(j.children,b,h.eq(i),d)}else j.selection==="none"&&g===!0&&(jqObj=jQuery(j.domobj).remove())}}else GENTICS.Aloha.Log.error(this,"can not split splitObject due to an empty selection tree");f.find("br.GENTICS_ephemera:gt(0)").remove(),c.find("br.GENTICS_ephemera:gt(0)").remove(),f.find(".preparedForRemoval").remove(),c.find(".preparedForRemoval").remove(),f.contents().length===0&&GENTICS.Utils.Dom.isSplitObject(f[0])&&e&&f.html(e),c.contents().length===0&&GENTICS.Utils.Dom.isSplitObject(c[0])&&e&&c.html(e)},GENTICS.Aloha.Markup.prototype.getSplitFollowUpContainer=function(a){var b=a.splitObject.nodeName.toLowerCase();switch(b){case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":var c=jQuery(a.splitObject).textNodes().last()[0];if(c&&a.startContainer===c&&a.startOffset===c.length){var d=jQuery("<p></p>"),e=jQuery(a.splitObject).clone().contents();return d.append(e),d}break;case"li":var f=a.startContainer;f.nodeType==3&&f.nextSibling&&(f=f.nextSibling),f.nodeName.toLowerCase()=="li"&&(f=f.children[0]);if(f.nodeName.toLowerCase()==="br"&&jQuery(f).hasClass("GENTICS_ephemera")){var d=jQuery("<p></p>"),e=jQuery(a.splitObject).clone().contents();return d.append(e),d}if(!a.splitObject.nextSibling&&jQuery.trim(jQuery(a.splitObject).text()).length==0){var d=jQuery("<p></p>");return d}}return jQuery(a.splitObject).clone()},GENTICS.Aloha.Markup.prototype.transformDomObject=function(a,b){var c=jQuery(a),d=jQuery("<"+b+"></"+b+">");return c.contents().appendTo(d),c.replaceWith(d),d},GENTICS.Aloha.Markup.prototype.toString=function(){return"GENTICS.Aloha.Markup"},GENTICS.Aloha.Markup=new GENTICS.Aloha.Markup,jQuery.fn.zap=function(){return this.each(function(){jQuery(this.childNodes).insertBefore(this)}).remove()},jQuery.fn.textNodes=function(a,b){var c=[];return function(d){if(d.nodeType==3&&jQuery.trim(d.data)!=""&&!b||d.nodeType==3&&b||d.nodeName=="BR"&&!a)c.push(d);else for(var e=0;e<d.childNodes.length;++e)arguments.callee(d.childNodes[e])}(this[0]),jQuery(c)},GENTICS.Aloha.Selection=function(){this.rangeObject={},this.tagHierarchy={textNode:[],abbr:["textNode"],b:["textNode","b","i","em","sup","sub","br","span","img","a","del","ins","u","cite","q","code","abbr","strong"],pre:["textNode","b","i","em","sup","sub","br","span","img","a","del","ins","u","cite","q","code","abbr","code"],blockquote:["textNode","b","i","em","sup","sub","br","span","img","a","del","ins","u","cite","q","code","abbr","p","h1","h2","h3","h4","h5","h6"],ins:["textNode","b","i","em","sup","sub","br","span","img","a","u","p","h1","h2","h3","h4","h5","h6"],ul:["li"],ol:["li"],li:["textNode","b","i","em","sup","sub","br","span","img","ul","ol","h1","h2","h3","h4","h5","h6","del","ins","u"],tr:["td","th"],table:["tr"],div:["textNode","b","i","em","sup","sub","br","span","img","ul","ol","table","h1","h2","h3","h4","h5","h6","del","ins","u","p","div","pre","blockquote"],h1:["textNode","b","i","em","sup","sub","br","span","img","a","del","ins","u"]},this.tagHierarchy={textNode:this.tagHierarchy.textNode,abbr:this.tagHierarchy.abbr,br:this.tagHierarchy.textNode,img:this.tagHierarchy.textNode,b:this.tagHierarchy.b,strong:this.tagHierarchy.b,code:this.tagHierarchy.b,q:this.tagHierarchy.b,blockquote:this.tagHierarchy.blockquote,cite:this.tagHierarchy.b,i:this.tagHierarchy.b,em:this.tagHierarchy.b,sup:this.tagHierarchy.b,sub:this.tagHierarchy.b,span:this.tagHierarchy.b,del:this.tagHierarchy.del,ins:this.tagHierarchy.ins,u:this.tagHierarchy.b,p:this.tagHierarchy.b,pre:this.tagHierarchy.pre,a:this.tagHierarchy.b,ul:this.tagHierarchy.ul,ol:this.tagHierarchy.ol,li:this.tagHierarchy.li,td:this.tagHierarchy.li,div:this.tagHierarchy.div,h1:this.tagHierarchy.h1,h2:this.tagHierarchy.h1,h3:this.tagHierarchy.h1,h4:this.tagHierarchy.h1,h5:this.tagHierarchy.h1,h6:this.tagHierarchy.h1,table:this.tagHierarchy.table},this.replacingElements={h1:["p","h1","h2","h3","h4","h5","h6","pre"],blockquote:["blockquote"]},this.replacingElements={h1:this.replacingElements.h1,h2:this.replacingElements.h1,h3:this.replacingElements.h1,h4:this.replacingElements.h1,h5:this.replacingElements.h1,h6:this.replacingElements.h1,pre:this.replacingElements.h1,p:this.replacingElements.h1,blockquote:this.replacingElements.blockquote},this.allowedToStealElements={h1:["textNode"]},this.allowedToStealElements={h1:this.allowedToStealElements.h1,h2:this.allowedToStealElements.h1,h3:this.allowedToStealElements.h1,h4:this.allowedToStealElements.h1,h5:this.allowedToStealElements.h1,h6:this.allowedToStealElements.h1,p:this.tagHierarchy.b}},GENTICS.Aloha.Selection.prototype.SelectionTree=function(){this.domobj={},this.selection,this.children=[]},GENTICS.Aloha.Selection.prototype.onChange=function(a,b){this.updateSelectionTimeout&&(window.clearTimeout(this.updateSelectionTimeout),this.updateSelectionTimeout=undefined),this.updateSelectionTimeout=window.setTimeout(function(){GENTICS.Aloha.Selection.updateSelection(b)},5)},GENTICS.Aloha.Selection.prototype.updateSelection=function(a){var b=this.rangeObject=new GENTICS.Aloha.Selection.SelectionRange(!0);return b.update(),GENTICS.Aloha.EventRegistry.trigger(new GENTICS.Aloha.Event("selectionChanged",GENTICS.Aloha,[b,a])),!0},GENTICS.Aloha.Selection.prototype.getSelectionTree=function(a){return a?a.commonAncestorContainer?(this.inselection=!1,GENTICS.Utils.Dom.doCleanup({mergetext:!0},a)&&(this.rangeObject.update(),this.rangeObject.select()),this.recursiveGetSelectionTree(a,a.commonAncestorContainer)):(GENTICS.Aloha.Log.error(this,"the rangeObject is missing the commonAncestorContainer"),!1):this.rangeObject.getSelectionTree()},GENTICS.Aloha.Selection.prototype.recursiveGetSelectionTree=function(a,b){var c=jQuery(b),d=0,e=this,f=[];return c.contents().each(function(c){var g="none",h=!1,i=!1,j=!1;a.isCollapsed()&&b===a.startContainer&&a.startOffset==c&&(f[d]=new GENTICS.Aloha.Selection.SelectionTree,f[d].selection="collapsed",f[d].domobj=undefined,e.inselection=!1,j=!0,d++);if(!e.inselection&&!j)switch(this.nodeType){case 3:this===a.startContainer&&(e.inselection=!0
,g=a.startOffset>0?"partial":"full",h=a.startOffset,i=this.length);break;case 1:this===a.startContainer&&a.startOffset==0&&(e.inselection=!0,g="full"),b===a.startContainer&&a.startOffset==c&&(e.inselection=!0,g="full")}if(e.inselection&&!j){g=="none"&&(g="full");switch(this.nodeType){case 3:this===a.endContainer&&(e.inselection=!1,a.endOffset<this.length&&(g="partial"),h===!1&&(h=0),i=a.endOffset);break;case 1:this===a.endContainer&&a.endOffset==0&&(e.inselection=!1)}b===a.endContainer&&a.endOffset<=c&&(e.inselection=!1,g="none")}f[d]=new GENTICS.Aloha.Selection.SelectionTree,f[d].domobj=this,f[d].selection=g,g=="partial"&&(f[d].startOffset=h,f[d].endOffset=i),f[d].children=e.recursiveGetSelectionTree(a,this);if(f[d].children.length>0){var k=!1,l=!1,m=!1;for(var n=0;n<f[d].children.length;++n)switch(f[d].children[n].selection){case"none":k=!0;break;case"full":m=!0;break;case"partial":l=!0}l||m&&k?f[d].selection="partial":m&&!l&&!k&&(f[d].selection="full")}d++}),a.isCollapsed()&&b===a.startContainer&&a.startOffset==b.childNodes.length&&(f[d]=new GENTICS.Aloha.Selection.SelectionTree,f[d].selection="collapsed",f[d].domobj=undefined),f},GENTICS.Aloha.Selection.prototype.getRangeObject=function(){return this.rangeObject},GENTICS.Aloha.Selection.prototype.isRangeObjectWithinMarkup=function(a,b,c,d,e){domObj=b?a.endContainer:a.startContainer,typeof d!="undefined"&&typeof d!="function"&&GENTICS.Aloha.Log.error(this,"parameter tagComparator is not a function");var f=this;typeof d=="undefined"&&(d=function(a,b){return f.standardTextLevelSemanticsComparator(a,b)});var g=jQuery(domObj).parents(),h=!1,i=-1,f=this;return g.length>0&&g.each(function(){if(this===e)return GENTICS.Aloha.Log.debug(f,"reached limit dom obj"),!1;if(d(this,c))return h===!1&&(h=[]),GENTICS.Aloha.Log.debug(f,"reached object equal to markup"),i++,h[i]=this,!0}),h},GENTICS.Aloha.Selection.prototype.standardSectionsAndGroupingContentComparator=function(a,b){if(a.nodeType===1){if(b[0].tagName&&GENTICS.Aloha.Selection.replacingElements[a.tagName.toLowerCase()]&&jQuery.inArray(b[0].tagName.toLowerCase(),GENTICS.Aloha.Selection.replacingElements[a.tagName.toLowerCase()])!=-1)return!0}else GENTICS.Aloha.Log.debug(this,"only element nodes (nodeType == 1) can be compared");return!1},GENTICS.Aloha.Selection.prototype.standardTextLevelSemanticsComparator=function(a,b){return a.nodeType===1?a.tagName.toLowerCase()!=b[0].tagName.toLowerCase()?!1:this.standardAttributesComparator(a,b)?!0:!1:(GENTICS.Aloha.Log.debug(this,"only element nodes (nodeType == 1) can be compared"),!1)},GENTICS.Aloha.Selection.prototype.standardAttributesComparator=function(a,b){if(a.attributes&&a.attributes.length&&a.attributes.length>0)for(var c=0;c<a.attributes.length;c++){var d=a.attributes[c];if(d.nodeName.toLowerCase()=="class"&&d.nodeValue.length>0)var e=d.nodeValue,f=e.split(" ")}if(b[0].attributes&&b[0].attributes.length&&b[0].attributes.length>0)for(var c=0;c<b[0].attributes.length;c++){var d=b[0].attributes[c];if(d.nodeName.toLowerCase()=="class"&&d.nodeValue.length>0)var e=d.nodeValue,g=e.split(" ")}if(f&&!g||g&&!f)return GENTICS.Aloha.Log.debug(this,"tag comparison for <"+a.tagName.toLowerCase()+"> failed because one element has classes and the other has not"),!1;if(f&&g&&f.length!=f.length)return GENTICS.Aloha.Log.debug(this,"tag comparison for <"+a.tagName.toLowerCase()+"> failed because of a different amount of classes"),!1;if(f&&g&&f.length==g.length&&f.length!=0)for(var c=0;c<f.length;c++)if(!b.hasClass(f[c]))return GENTICS.Aloha.Log.debug(this,"tag comparison for <"+a.tagName.toLowerCase()+"> failed because of different classes"),!1;return!0},GENTICS.Aloha.Selection.prototype.changeMarkup=function(a,b,c){var d=b[0].tagName.toLowerCase();if(this.replacingElements[d]){var e=a;a=new this.SelectionRange(a);if(GENTICS.Aloha.activeEditable)var f=GENTICS.Aloha.activeEditable.obj.get(0);else var f=jQuery("body");a.update(f),b.isReplacingElement=!0}else if(a.isCollapsed())return GENTICS.Aloha.Log.debug(this,"early returning from applying markup because nothing is currently selected"),!1;if(GENTICS.Aloha.activeEditable)var g=GENTICS.Aloha.activeEditable.obj[0];else var g=jQuery("body");var h=this.isRangeObjectWithinMarkup(a,!1,b,c,g),i=this.isRangeObjectWithinMarkup(a,!0,b,c,g);if(!b.isReplacingElement&&a.startOffset==0){var j;if(j=this.getTextNodeSibling(!1,a.commonAncestorContainer.parentNode,a.startContainer))var k=this.isRangeObjectWithinMarkup({startContainer:j,startOffset:0},!1,b,c,g)}if(!b.isReplacingElement&&a.endOffset==a.endContainer.length){var l;if(l=this.getTextNodeSibling(!0,a.commonAncestorContainer.parentNode,a.endContainer))var m=this.isRangeObjectWithinMarkup({startContainer:l,startOffset:0},!1,b,c,g)}if(!b.isReplacingElement&&h&&!i)GENTICS.Aloha.Log.info(this,"markup 2 non-markup"),this.prepareForRemoval(a.getSelectionTree(),b,c),jQuery(h).addClass("preparedForRemoval"),this.insertCroppedMarkups(h,a,!1,c);else if(!b.isReplacingElement&&h&&i)GENTICS.Aloha.Log.info(this,"markup 2 markup"),this.prepareForRemoval(a.getSelectionTree(),b,c),this.splitRelevantMarkupObject(h,i,a,c);else if(!b.isReplacingElement&&(!h&&i||m||k)){GENTICS.Aloha.Log.info(this,"non-markup 2 markup OR with next2markup");if(k&&m){var n=new GENTICS.Aloha.Selection.SelectionRange(a);n.startContainer=jQuery(k[k.length-1]).textNodes()[0],n.startOffset=0,n.endContainer=jQuery(m[m.length-1]).textNodes().last()[0],n.endOffset=n.endContainer.length,n.update(),this.applyMarkup(n.getSelectionTree(),a,b,c),GENTICS.Aloha.Log.info(this,"double extending previous markup(previous and after selection), actually wrapping it ...")}else if(k&&!m&&!i)this.extendExistingMarkupWithSelection(k,a,!1,c),GENTICS.Aloha.Log.info(this,"extending previous markup");else if(k&&!m&&i){var n=new GENTICS.Aloha.Selection.SelectionRange(a);n.startContainer=jQuery(k[k.length-1]).textNodes()[0],n.startOffset=0,n.endContainer=jQuery(i[i.length-1]).textNodes().last()[0],n.endOffset=n.endContainer.length,n.update(),this.applyMarkup(n.getSelectionTree(),a,b,c),GENTICS.Aloha.Log.info(this,"double extending previous markup(previous and relevant at the end), actually wrapping it ...")}else!k&&m?(this.extendExistingMarkupWithSelection(m,a,!0,c),GENTICS.Aloha.Log.info(this,"extending following markup backwards")):this.extendExistingMarkupWithSelection(i,a,!0,c)}else if(b.isReplacingElement||!h&&!i&&!k&&!m)GENTICS.Aloha.Log.info(this,"non-markup 2 non-markup"),this.applyMarkup(a.getSelectionTree(),a,b,c,{setRangeObject2NewMarkup:!0});jQuery(".preparedForRemoval").zap(),a.update(),b.isReplacingElement?e.select():a.select()},GENTICS.Aloha.Selection.prototype.areMarkupObjectsAsLongAsRangeObject=function(a,b,c){if(c.startOffset!==0)return!1;for(var d=0;d<a.length;d++){var e=jQuery(a[d]);if(e.textNodes().first()[0]!==c.startContainer)return!1}for(var d=0;d<b.length;d++){var e=jQuery(b[d]);if(e.textNodes().last()[0]!==c.endContainer||e.textNodes().last()[0].length!=c.endOffset)return!1}return!0},GENTICS.Aloha.Selection.prototype.splitRelevantMarkupObject=function(a,b,c,d){jQuery(a).addClass("preparedForRemoval"),jQuery(b).addClass("preparedForRemoval");if(this.areMarkupObjectsAsLongAsRangeObject(a,b,c))return!0;var e=this.intersectRelevantMarkupObjects(a,b);return e?(this.insertCroppedMarkups([e],c,!1,d),this.insertCroppedMarkups([e],c,!0,d)):(this.insertCroppedMarkups(a,c,!1,d),this.insertCroppedMarkups(b,c,!0,d)),!0},GENTICS.Aloha.Selection.prototype.intersectRelevantMarkupObjects=function(a,b){var c=!1;if(!a||!b)return c;for(var d=0;d<a.length;d++){var e=a[d];for(var f=0;f<b.length;f++){var g=b[f];e===g&&(c=e)}}return c},GENTICS.Aloha.Selection.prototype.extendExistingMarkupWithSelection=function(a,b,c,d){if(!c)var e=!0;if(c)var f=!0;var g=[];for(var h=0;h<a.length;h++)g[h]=new this.SelectionRange,el=a[h],f&&!e&&(g[h].startContainer=b.startContainer,g[h].startOffset=b.startOffset,textnodes=jQuery(el).textNodes(!0),g[h].endContainer=textnodes[textnodes.length-1],g[h].endOffset=textnodes[textnodes.length-1].length,g[h].update(),this.applyMarkup(g[h].getSelectionTree(),b,this.getClonedMarkup4Wrapping(el),d,{setRangeObject2NewMarkup:!0})),!f&&e&&(textnodes=jQuery(el).textNodes(!0),g[h].startContainer=textnodes[0],g[h].startOffset=0,g[h].endContainer=b.endContainer,g[h].endOffset=b.endOffset,g[h].update(),this.applyMarkup(g[h].getSelectionTree(),b,this.getClonedMarkup4Wrapping(el),d,{setRangeObject2NewMarkup:!0}));return!0},GENTICS.Aloha.Selection.prototype.getClonedMarkup4Wrapping=function(a){var b=jQuery(a).clone().removeClass("preparedForRemoval").empty();return b.attr("class").length==0&&b.removeAttr("class"),b},GENTICS.Aloha.Selection.prototype.insertCroppedMarkups=function(a,b,c,d){if(!c)var e=!0;else var f=!0;var g=[];for(var h=0;h<a.length;h++){g[h]=new this.SelectionRange;var i=a[h];if(e&&!f){var j=jQuery(i).textNodes(!0);g[h].startContainer=j[0],g[h].startOffset=0;if(g[h].startContainer===b.startContainer&&g[h].startOffset===b.startOffset)continue;b.startOffset==0?(g[h].endContainer=this.getTextNodeSibling(!1,i,b.startContainer),g[h].endOffset=g[h].endContainer.length):(g[h].endContainer=b.startContainer,g[h].endOffset=b.startOffset),g[h].update(),this.applyMarkup(g[h].getSelectionTree(),b,this.getClonedMarkup4Wrapping(i),d,{setRangeObject2NextSibling:!0})}!e&&f&&(g[h].startContainer=b.endContainer,g[h].startOffset=b.endOffset,textnodes=jQuery(i).textNodes(!0),g[h].endContainer=textnodes[textnodes.length-1],g[h].endOffset=textnodes[textnodes.length-1].length,g[h].update(),this.applyMarkup(g[h].getSelectionTree(),b,this.getClonedMarkup4Wrapping(i),d,{setRangeObject2PreviousSibling:!0}))}return!0},GENTICS.Aloha.Selection.prototype.changeMarkupOnSelection=function(a){this.changeMarkup(this.getRangeObject(),a,this.getStandardTagComparator(a)),GENTICS.Utils.Dom.doCleanup({mergetext:!0},this.rangeObject),this.rangeObject.update(),this.rangeObject.select()},GENTICS.Aloha.Selection.prototype.applyMarkup=function(a,b,c,d,e){e=e?e:{},this.prepareForRemoval(a,c,d);var f=this.optimizeSelectionTree4Markup(a,c,d);breakpoint=!0;for(var g=0;g<f.length;g++){var h=f[g];h.wrappable?this.wrapMarkupAroundSelectionTree(h.elements,b,c,d,e):(GENTICS.Aloha.Log.debug(this,"dive further into non-wrappable object"),this.applyMarkup(h.element.children,b,c,d,e))}},GENTICS.Aloha.Selection.prototype.getMarkupType=function(a){var b=jQuery(a)[0].nodeName.toLowerCase();a.outerHTML&&GENTICS.Aloha.Log.debug(this,"Node name detected: "+b+" for: "+a.outerHTML());if(b=="#text")return"textNode";if(this.replacingElements[b])return"sectionOrGroupingContent";if(this.tagHierarchy[b])return"textLevelSemantics";GENTICS.Aloha.Log.warn(this,"unknown markup passed to this.getMarkupType(...): "+a.outerHTML())},GENTICS.Aloha.Selection.prototype.getStandardTagComparator=function(a){var b=this;switch(this.getMarkupType(a)){case"textNode":return function(a,b){return!1};case"sectionOrGroupingContent":return function(a,c){return b.standardSectionsAndGroupingContentComparator(a,c)};case"textLevelSemantics":default:return function(a,c){return b.standardTextLevelSemanticsComparator(a,c)}}},GENTICS.Aloha.Selection.prototype.prepareForRemoval=function(a,b,c){var d=this;typeof c!="undefined"&&typeof c!="function"&&GENTICS.Aloha.Log.error(this,"parameter tagComparator is not a function"),typeof c=="undefined"&&(c=this.getStandardTagComparator(b));for(var e=0;e<a.length;e++){var f=a[e];f.domobj&&(f.selection=="full"||f.selection=="partial"&&b.isReplacingElement)&&f.domobj.nodeType===1&&c(f.domobj,b)&&(GENTICS.Aloha.Log.debug(this,"Marking for removal: "+f.domobj.nodeName),jQuery(f.domobj).addClass("preparedForRemoval")),f.selection!="none"&&f.children.length>0&&this.prepareForRemoval(f.children,b,c)}},GENTICS.Aloha.Selection.prototype.wrapMarkupAroundSelectionTree=function(a,b,c,d,e){var f=[],g=-1;GENTICS.Aloha.Log.debug(this,"The formatting <"+c[0].tagName+"> will be wrapped around the selection");var h="",i="";for(var j=0;j<a.length;j++){var k=a[j];if(k.domobj&&!this.canTag1WrapTag2(k.domobj.parentNode.tagName.toLowerCase(),c[0].tagName.toLowerCase())){GENTICS.Aloha.Log.info(this,"Skipping the wrapping of <"+c[0].tagName.toLowerCase()+"> because this tag is not allowed inside <"+k.domobj.parentNode.tagName.toLowerCase()+">");continue}if(k.domobj&&k.domobj.nodeType==3&&jQuery.trim(jQuery(k.domobj).outerHTML()).length==0)continue;if(k.domobj&&k.selection=="partial"&&!c.isReplacingElement)if(k.startOffset!==undefined&&k.endOffset===undefined)g++,h+=k.domobj.data.substr(0,k.startOffset),k.domobj.data=k.domobj.data.substr(k.startOffset,k.domobj.data.length-k.startOffset),f[g]=k.domobj;else if(k.endOffset!==undefined&&k.startOffset===undefined)g++,i+=k.domobj.data.substr(k.endOffset,k.domobj.data.length-k.endOffset),k.domobj.data=k.domobj.data.substr(0,k.endOffset),f[g]=k.domobj;else if(k.endOffset!==undefined&&k.startOffset!==undefined){if(k.startOffset==k.endOffset){GENTICS.Aloha.Log.debug(this,"skipping empty selection");continue}g++,h+=k.domobj.data.substr(0,k.startOffset);var l=k.domobj.data.substr(k.startOffset,k.endOffset-k.startOffset);i+=k.domobj.data.substr(k.endOffset,k.domobj.data.length-k.endOffset),k.domobj.data=l,f[g]=k.domobj}else GENTICS.Aloha.Log.debug(this,"diving into object"),this.applyMarkup(k.children,b,c,d,e);k.domobj&&(k.selection=="full"||k.selection=="partial"&&c.isReplacingElement)&&(g++,f[g]=k.domobj)}n=!0;if(f.length>0){f=jQuery(f),jQuery.each(f,function(a,b){jQuery.browser.msie&&b.nodeType==3&&!b.nextSibling&&!b.previousSibling&&b.parentNode&&b.parentNode.nodeName.toLowerCase()=="li"&&(b.data=jQuery.trim(b.data))});var m=f.wrapAll(c).parent();m.before(h).after(i);var n=!0;if(e.setRangeObject2NewMarkup){var o=f.textNodes();o.index(b.startContainer)!=-1&&(b.startOffset=0),o.index(b.endContainer)!=-1&&(b.endOffset=b.endContainer.length);var n=!0}if(e.setRangeObject2NextSibling){var p=!0,q=m.textNodes(!0).last()[0];f.index(b.startContainer)!=-1&&(b.startContainer=this.getTextNodeSibling(p,m.parent(),q),b.startOffset=0),f.index(b.endContainer)!=-1&&(b.endContainer=this.getTextNodeSibling(p,m.parent(),q),b.endOffset=b.endOffset-q.length)}if(e.setRangeObject2PreviousSibling){var p=!1,q=m.textNodes(!0).first()[0];f.index(b.startContainer)!=-1&&(b.startContainer=this.getTextNodeSibling(p,m.parent(),q),b.startOffset=0),f.index(b.endContainer)!=-1&&(b.endContainer=this.getTextNodeSibling(p,m.parent(),q),b.endOffset=b.endContainer.length)}}},GENTICS.Aloha.Selection.prototype.getTextNodeSibling=function(a,b,c){var d=jQuery(b).textNodes(!0);index=d.index(c);if(index==-1)return!1;var e=index+(a?1:-1);return d[e]?d[e]:!1},GENTICS.Aloha.Selection.prototype.optimizeSelectionTree4Markup=function(a,b,c){var d=[],e=0,f=0,g=this;typeof c=="undefined"&&(c=function(a,b){return g.standardTextLevelSemanticsComparator(b)});for(var h=0;h<a.length;h++)if(a[h].domobj&&a[h].selection!="none")if(b.isReplacingElement&&c(b[0],jQuery(a[h].domobj)))d[e]!==undefined&&e++,d[e]={},d[e].wrappable=!0,d[e].elements=[],d[e].elements[f]=a[h],e++;else if(this.canMarkupBeApplied2ElementAsWhole([a[h]],b)){d[e]===undefined&&(d[e]={},d[e].wrappable=!0,d[e].elements=[]);if(b.isReplacingElement){var i=h;for(var j=h-1;j>=0;j--)if(this.canMarkupBeApplied2ElementAsWhole([a[j]],b)&&this.isMarkupAllowedToStealSelectionTreeElement(a[j],b))i=j;else break;var k=h;for(var j=h+1;j<a.length;j++)if(this.canMarkupBeApplied2ElementAsWhole([a[j]],b)&&this.isMarkupAllowedToStealSelectionTreeElement(a[j],b))k=j;else break;f=0;for(var j=i;j<=k;j++)d[e].elements[f]=a[j],d[e].elements[f].selection="full",f++;f=0}else d[e].elements[f]=a[h],f++}else d[e]!==undefined&&e++,d[e]={},d[e].wrappable=!1,d[e].element=a[h],f=0,e++;return d},GENTICS.Aloha.Selection.prototype.isMarkupAllowedToStealSelectionTreeElement=function(a,b){if(!a.domobj)return!1;var c=a.domobj.nodeName.toLowerCase();c=c=="#text"?"textNode":c;var d=b[0].nodeName.toLowerCase();return this.allowedToStealElements[d]?jQuery.inArray(c,this.allowedToStealElements[d])==-1?!1:!0:!1},GENTICS.Aloha.Selection.prototype.canMarkupBeApplied2ElementAsWhole=function(a,b){b.jquery&&(htmlTag=b[0].tagName),b.tagName&&(htmlTag=b.tagName),returnVal=!0;for(var c=0;c<a.length;c++){var d=a[c];if(d.domobj&&(d.selection!="none"||b.isReplacingElement)){if(!this.canTag1WrapTag2(htmlTag,d.domobj.nodeName))return!1;if(d.children.length>0&&!this.canMarkupBeApplied2ElementAsWhole(d.children,b))return!1}}return returnVal},GENTICS.Aloha.Selection.prototype.canTag1WrapTag2=function(a,b){a=a=="#text"?"textNode":a.toLowerCase(),b=b=="#text"?"textNode":b.toLowerCase();if(!this.tagHierarchy[a])return!0;if(!this.tagHierarchy[b])return!0;var c=this.tagHierarchy[a],d=jQuery.inArray(b,c)!=-1?!0:!1;return d},GENTICS.Aloha.Selection.prototype.mayInsertTag=function(a){if(typeof this.rangeObject.unmodifiableMarkupAtStart=="object"){for(var b=0;b<this.rangeObject.unmodifiableMarkupAtStart.length;++b)if(!this.canTag1WrapTag2(this.rangeObject.unmodifiableMarkupAtStart[b].nodeName,a))return!1;return!0}return GENTICS.Aloha.Log.warn(this,"Unable to determine whether tag "+a+" may be inserted"),!0},GENTICS.Aloha.Selection.prototype.toString=function(){return"GENTICS.Aloha.Selection"},GENTICS.Aloha.Selection.prototype.SelectionRange=function(a){GENTICS.Utils.RangeObject.apply(this,arguments),this.commonAncestorContainer,this.selectionTree,this.markupEffectiveAtStart=[],this.unmodifiableMarkupAtStart=[],this.limitObject,this.splitObject,a&&(a.commonAncestorContainer&&(this.commonAncestorContainer=a.commonAncestorContainer),a.selectionTree&&(this.selectionTree=a.selectionTree),a.limitObject&&(this.limitObject=a.limitObject),a.markupEffectiveAtStart&&(this.markupEffectiveAtStart=a.markupEffectiveAtStart),a.unmodifiableMarkupAtStart&&(this.unmodifiableMarkupAtStart=a.unmodifiableMarkupAtStart),a.splitObject&&(this.splitObject=a.splitObject))},GENTICS.Aloha.Selection.prototype.SelectionRange.prototype=new GENTICS.Utils.RangeObject,GENTICS.Aloha.Selection.prototype.SelectionRange.prototype.select=function(){GENTICS.Utils.RangeObject.prototype.select.apply(this,arguments),GENTICS.Aloha.Selection.updateSelection()},GENTICS.Aloha.Selection.prototype.SelectionRange.prototype.update=function(a){this.updatelimitObject(),this.updateMarkupEffectiveAtStart(),this.updateCommonAncestorContainer(a),this.selectionTree=undefined},GENTICS.Aloha.Selection.prototype.SelectionRange.prototype.getSelectionTree=function(){return this.selectionTree||(this.selectionTree=GENTICS.Aloha.Selection.getSelectionTree(this)),this.selectionTree},GENTICS.Aloha.Selection.prototype.SelectionRange.prototype.getSelectedSiblings=function(a){var b=this.getSelectionTree();return this.recursionGetSelectedSiblings(a,b)},GENTICS.Aloha.Selection.prototype.SelectionRange.prototype.recursionGetSelectedSiblings=function(a,b){var c=!1,d=!1;for(var e=0;e<b.length;++e)if(b[e].domobj===a)d=!0,c=[];else if(!d&&b[e].children){c=this.recursionGetSelectedSiblings(a,b[e].children);if(c!==!1)break}else if(d&&b[e].domobj&&b[e].selection!="collapsed"&&b[e].selection!="none")c.push(b[e].domobj);else if(d&&b[e].selection=="none")break;return c},GENTICS.Aloha.Selection.prototype.SelectionRange.prototype.updateMarkupEffectiveAtStart=function(){this.markupEffectiveAtStart=[],this.unmodifiableMarkupAtStart=[];var a=this.getStartContainerParents(),b=!1;for(var c=0;c<a.length;c++){var d=a[c];if(!b&&d!==this.limitObject){this.markupEffectiveAtStart[c]=d;if(!e&&GENTICS.Utils.Dom.isSplitObject(d)){var e=!0;this.splitObject=d}}else b=!0,this.unmodifiableMarkupAtStart.push(d)}e||(this.splitObject=!1);return},GENTICS.Aloha.Selection.prototype.SelectionRange.prototype.updatelimitObject=function(){if(GENTICS.Aloha.editables&&GENTICS.Aloha.editables.length>0){var a=this.getStartContainerParents(),b=GENTICS.Aloha.editables;for(var c=0;c<a.length;c++){var d=a[c];for(var e=0;e<b.length;e++){var f=b[e].obj[0];if(d===f)return this.limitObject=d,!0}}}return this.limitObject=jQuery("body"),!0},GENTICS.Aloha.Selection.prototype.SelectionRange.prototype.toString=function(a){return a?"GENTICS.Aloha.Selection.SelectionRange {start ["+this.startContainer.nodeValue+"] offset "+this.startOffset+", end ["+this.endContainer.nodeValue+"] offset "+this.endOffset+"}":"GENTICS.Aloha.Selection.SelectionRange"},GENTICS.Aloha.Selection=new GENTICS.Aloha.Selection
