//>>built
define("dijit/selection","dojo/_base/array dojo/dom dojo/_base/lang dojo/sniff dojo/_base/window dijit/focus".split(" "),function(p,h,q,k,l,r){var m=function(f){var e=f.document;this.getType=function(){if(e.getSelection){var a="text";try{var b=f.getSelection()}catch(c){}b&&1==b.rangeCount&&(b=b.getRangeAt(0),b.startContainer==b.endContainer&&1==b.endOffset-b.startOffset&&3!=b.startContainer.nodeType&&(a="control"));return a}return e.selection.type.toLowerCase()};this.getSelectedText=function(){if(e.getSelection){var a=
f.getSelection();return a?a.toString():""}return"control"==this.getType()?null:e.selection.createRange().text};this.getSelectedHtml=function(){if(e.getSelection){var a=f.getSelection();if(a&&a.rangeCount){var b,c="";for(b=0;b<a.rangeCount;b++){var d=a.getRangeAt(b).cloneContents(),g=e.createElement("div");g.appendChild(d);c+=g.innerHTML}return c}return null}return"control"==this.getType()?null:e.selection.createRange().htmlText};this.getSelectedElement=function(){if("control"==this.getType()){if(e.getSelection){var a=
f.getSelection();return a.anchorNode.childNodes[a.anchorOffset]}if((a=e.selection.createRange())&&a.item)return e.selection.createRange().item(0)}return null};this.getParentElement=function(){if("control"==this.getType()){var a=this.getSelectedElement();if(a)return a.parentNode}else if(e.getSelection){if(a=e.getSelection()){for(a=a.anchorNode;a&&1!=a.nodeType;)a=a.parentNode;return a}}else return a=e.selection.createRange(),a.collapse(!0),a.parentElement();return null};this.hasAncestorElement=function(a){return null!=
this.getAncestorElement.apply(this,arguments)};this.getAncestorElement=function(a){var b=this.getSelectedElement()||this.getParentElement();return this.getParentOfType(b,arguments)};this.isTag=function(a,b){if(a&&a.tagName)for(var c=a.tagName.toLowerCase(),d=0;d<b.length;d++){var g=String(b[d]).toLowerCase();if(c==g)return g}return""};this.getParentOfType=function(a,b){for(;a;){if(this.isTag(a,b).length)return a;a=a.parentNode}return null};this.collapse=function(a){if(e.getSelection){var b=f.getSelection();
b.removeAllRanges?a?b.collapseToStart():b.collapseToEnd():b.collapse(a)}else b=e.selection.createRange(),b.collapse(a),b.select()};this.remove=function(){var a=e.selection;e.getSelection?(a=f.getSelection(),a.deleteFromDocument()):"none"!=a.type.toLowerCase()&&a.clear();return a};this.selectElementChildren=function(a,b){a=h.byId(a);if(e.getSelection){var c=f.getSelection();if(k("opera")){var d=c.rangeCount?c.getRangeAt(0):e.createRange();d.setStart(a,0);d.setEnd(a,3==a.nodeType?a.length:a.childNodes.length);
c.addRange(d)}else c.selectAllChildren(a)}else if(d=a.ownerDocument.body.createTextRange(),d.moveToElementText(a),!b)try{d.select()}catch(g){}};this.selectElement=function(a,b){a=h.byId(a);if(e.getSelection){var c=e.getSelection();var d=e.createRange();c.removeAllRanges&&(k("opera")&&c.getRangeAt(0)&&(d=c.getRangeAt(0)),d.selectNode(a),c.removeAllRanges(),c.addRange(d))}else try{c=a.tagName?a.tagName.toLowerCase():"",d="img"===c||"table"===c?l.body(e).createControlRange():l.body(e).createRange(),
d.addElement(a),b||d.select()}catch(g){this.selectElementChildren(a,b)}};this.inSelection=function(a){if(a){var b;if(e.getSelection){var c=f.getSelection();c&&0<c.rangeCount&&(b=c.getRangeAt(0));if(b&&b.compareBoundaryPoints&&e.createRange)try{var d=e.createRange();d.setStart(a,0);if(1===b.compareBoundaryPoints(b.START_TO_END,d))return!0}catch(g){}}else{b=e.selection.createRange();try{d=a.ownerDocument.body.createTextRange(),d.moveToElementText(a)}catch(g){}if(b&&d&&1===b.compareEndPoints("EndToStart",
d))return!0}}return!1};this.getBookmark=function(){var a,b=e.selection,c=r.curNode;if(e.getSelection){if(b=f.getSelection())if(b.isCollapsed){if(a=c?c.tagName:"")if(a=a.toLowerCase(),"textarea"==a||"input"==a&&(!c.type||"text"==c.type.toLowerCase()))return b={start:c.selectionStart,end:c.selectionEnd,node:c,pRange:!0},{isCollapsed:b.end<=b.start,mark:b};a={isCollapsed:!0};b.rangeCount&&(a.mark=b.getRangeAt(0).cloneRange())}else{var d=b.getRangeAt(0);a={isCollapsed:!1,mark:d.cloneRange()}}}else if(b){a=
c?c.tagName:"";a=a.toLowerCase();if(c&&a&&("button"==a||"textarea"==a||"input"==a)){if(b.type&&"none"==b.type.toLowerCase())return{isCollapsed:!0,mark:null};d=b.createRange();return{isCollapsed:d.text&&d.text.length?!1:!0,mark:{range:d,pRange:!0}}}a={};try{d=b.createRange(),a.isCollapsed=!("Text"==b.type?d.htmlText.length:d.length)}catch(g){return a.isCollapsed=!0,a}if("CONTROL"==b.type.toUpperCase())if(d.length)for(a.mark=[],b=0,c=d.length;b<c;)a.mark.push(d.item(b++));else a.isCollapsed=!0,a.mark=
null;else a.mark=d.getBookmark()}return a};this.moveToBookmark=function(a){if(a=a.mark)if(e.getSelection){var b=f.getSelection();b&&b.removeAllRanges&&(a.pRange?(b=a.node,b.selectionStart=a.start,b.selectionEnd=a.end):(b.removeAllRanges(),b.addRange(a)))}else if(e.selection&&a){if(a.pRange)var c=a.range;else q.isArray(a)?(c=e.body.createControlRange(),p.forEach(a,function(d){c.addElement(d)})):(c=e.body.createTextRange(),c.moveToBookmark(a));c.select()}};this.isCollapsed=function(){return this.getBookmark().isCollapsed}},
n=new m(window);n.SelectionManager=m;return n});