var internetExplorer=document.selection&&window.ActiveXObject&&/MSIE/.test(navigator.userAgent),webkit=/AppleWebKit/.test(navigator.userAgent),safari=/Apple Computer, Inc/.test(navigator.vendor),gecko=navigator.userAgent.match(/gecko\/(\d{8})/i);gecko&&(gecko=Number(gecko[1]));var mac=/Mac/.test(navigator.platform),brokenOpera=window.opera&&/Version\/10.[56]/.test(navigator.userAgent),slowWebkit=/AppleWebKit\/533/.test(navigator.userAgent);
function makeWhiteSpace(l){for(var k=[],m=!0;0<l;l--)k.push(m||1==l?nbsp:" "),m^=1;return k.join("")}function fixSpaces(l){" "==l.charAt(0)&&(l=nbsp+l.slice(1));return l.replace(/\t/g,function(){return makeWhiteSpace(indentUnit)}).replace(/[ \u00a0]{2,}/g,function(l){return makeWhiteSpace(l.length)})}function cleanText(l){return l.replace(/\u00a0/g," ").replace(/\u200b/g,"")}
function makePartSpan(l){var k=l;3==l.nodeType?k=l.nodeValue:l=document.createTextNode(k);var m=document.createElement("span");m.isPart=!0;m.appendChild(l);m.currentText=k;return m}function alwaysZero(){return 0}var webkitLastLineHack=webkit?function(l){var k=l.lastChild;k&&k.hackBR||(k=document.createElement("br"),k.hackBR=!0,l.appendChild(k))}:function(){};
function asEditorLines(l){var k=makeWhiteSpace(indentUnit);return map(l.replace(/\t/g,k).replace(/\u00a0/g," ").replace(/\r\n?/g,"\n").split("\n"),fixSpaces)}
var Editor=function(){function l(a,b){function c(a,g){if(3==a.nodeType)(a.nodeValue=fixSpaces(a.nodeValue.replace(/[\r\u200b]/g,"").replace(/\n/g," "))).length&&(e=!1),d.push(a);else if(isBR(a)&&0==a.childNodes.length)e=!0,d.push(a);else{for(var h=a.firstChild;h;h=h.nextSibling)c(h);!e&&x.hasOwnProperty(a.nodeName.toUpperCase())&&(e=!0,b&&g||d.push(document.createElement("br")))}}var d=[],e=!0;c(a,!0);return d}function k(a){function b(a){var b=a.parentNode,c=a.nextSibling;return function(a){b.insertBefore(a,
c)}}var c=[],d=null,e=!0;return{next:function(){if(!a)throw StopIteration;var f=a;a=f.nextSibling;var g;f.isPart&&1==f.childNodes.length&&3==f.firstChild.nodeType?(g=f.firstChild.nodeValue,f.dirty=f.dirty||g!=f.currentText,f.currentText=g,g=!/[\n\t\r]/.test(f.currentText)):g=!1;if(g)return c.push(f),e=!1,f.currentText;if(isBR(f))return e&&window.opera&&f.parentNode.insertBefore(makePartSpan(""),f),c.push(f),e=!0,"\n";g=!f.nextSibling;d=b(f);removeElement(f);f=l(f,g);for(g=0;g<f.length;g++){var h=
g,r=f[g],w="\n";3==r.nodeType?(select.snapshotChanged(),r=makePartSpan(r),w=r.currentText,e=!1):(e&&window.opera&&d(makePartSpan("")),e=!0);r.dirty=!0;c.push(r);d(r);f[h]=w}return f.join("")},nodes:c}}function m(a){for(;a&&!isBR(a);)a=a.previousSibling;return a}function q(a,b){a?isBR(a)&&(a=a.nextSibling):a=b.firstChild;for(;a&&!isBR(a);)a=a.nextSibling;return a}function t(a,b,c,d){function e(b){b=cleanText(a.history.textAfter(b));return d?b.toLowerCase():b}this.editor=a;this.history=a.history;this.history.commit();
this.valid=!!b;this.atOccurrence=!1;void 0==d&&(d="string"==typeof b&&b==b.toLowerCase());var f={node:null,offset:0},g=this;c&&"object"==typeof c&&"number"==typeof c.character?(a.checkLine(c.line),c={node:c.line,offset:c.character},this.pos={from:c,to:c}):this.pos=c?{from:select.cursorPos(a.container,!0)||f,to:select.cursorPos(a.container,!1)||f}:{from:f,to:f};if("string"!=typeof b)this.matches=function(a,c,d){if(a){a=e(c).slice(0,d);var f=a.match(b);for(d=0;f;){var h=a.indexOf(f[0]);d+=h;a=a.slice(h+
1);if(h=a.match(b))f=h;else break}}else a=e(c).slice(d),d=(f=a.match(b))&&d+a.indexOf(f[0]);if(f)return g.currentMatch=f,{from:{node:c,offset:d},to:{node:c,offset:d+f[0].length}}};else{d&&(b=b.toLowerCase());var h=b.split("\n");this.matches=1==h.length?function(a,c,d){var f=e(c),g=b.length,h;if(a?d>=g&&-1!=(h=f.lastIndexOf(b,d-g)):-1!=(h=f.indexOf(b,d)))return{from:{node:c,offset:h},to:{node:c,offset:h+g}}}:function(a,b,c){var d=a?h.length-1:0,f=h[d],g=e(b),l=a?g.indexOf(f)+f.length:g.lastIndexOf(f);
if(!(a?l>=c||l!=f.length:l<=c||l!=g.length-f.length))for(c=b;!a||c;){c=a?this.history.nodeBefore(c):this.history.nodeAfter(c);if(!a&&!c)break;g=e(c);f=h[a?--d:++d];if(0<d&&d<h.length-1)if(g!=f)break;else continue;d=a?g.lastIndexOf(f):g.indexOf(f)+f.length;if(a?d!=g.length-f.length:d!=f.length)break;return{from:{node:a?c:b,offset:a?d:l},to:{node:a?b:c,offset:a?l:d}}}}}}function p(a){this.options=a;window.indentUnit=a.indentUnit;var b=this.container=document.body;this.history=new UndoHistory(b,a.undoDepth,
a.undoDelay,this);var c=this;if(!p.Parser)throw"No parser loaded.";a.parserConfig&&p.Parser.configure&&p.Parser.configure(a.parserConfig);a.readOnly||internetExplorer||select.setCursorPos(b,{node:null,offset:0});this.dirty=[];this.importCode(a.content||"");this.history.onChange=a.onChange;if(a.readOnly)a.textWrapping||(b.style.whiteSpace="nowrap");else{var d=function(){c.cursorActivity(!1)},e=function(){void 0!=document.body.contentEditable&&internetExplorer?document.body.contentEditable="true":document.designMode=
"on";internetExplorer&&"dynamic"!=a.height&&(document.body.style.minHeight=window.frameElement.clientHeight-2*document.body.offsetTop-5+"px");document.documentElement.style.borderWidth="0";a.textWrapping||(b.style.whiteSpace="nowrap")};!1!==a.continuousScanning&&(this.scanner=this.documentScanner(a.passTime),this.delayScanning());try{e()}catch(f){var g=addEventHandler(document,"focus",function(){g();e()},!0)}addEventHandler(document,"keydown",method(this,"keyDown"));addEventHandler(document,"keypress",
method(this,"keyPress"));addEventHandler(document,"keyup",method(this,"keyUp"));addEventHandler(internetExplorer?document.body:window,"mouseup",d);addEventHandler(document.body,"cut",d);gecko&&addEventHandler(window,"pagehide",function(){c.unloaded=!0});addEventHandler(document.body,"paste",function(a){d();var b=null;try{var e=a.clipboardData||window.clipboardData;e&&(b=e.getData("Text"))}catch(f){}null!==b&&(a.stop(),c.replaceSelection(b),select.scrollToCursor(c.container))});this.options.autoMatchParens&&
addEventHandler(document.body,"click",method(this,"scheduleParenHighlight"))}}function y(a){return 16<=a&&18>=a||33<=a&&40>=a}var x={P:!0,DIV:!0,LI:!0};t.prototype={findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(a){function b(){var a={node:e,offset:f};c.pos={from:a,to:a};return c.atOccurrence=!1}if(!this.valid)return!1;var c=this,d=a?this.pos.from:this.pos.to,e=d.node,f=d.offset;e&&!e.parentNode&&(e=null,f=0);for(;;){if(this.pos=this.matches(a,
e,f))return this.atOccurrence=!0;if(a){if(!e)return b();e=this.history.nodeBefore(e);f=this.history.textAfter(e).length}else{d=this.history.nodeAfter(e);if(!d)return f=this.history.textAfter(e).length,b();e=d;f=0}}},select:function(){this.atOccurrence&&(select.setCursorPos(this.editor.container,this.pos.from,this.pos.to),select.scrollToCursor(this.editor.container))},replace:function(a){if(this.atOccurrence){var b=this.currentMatch;b&&(a=a.replace(/\\(\d)/,function(a,d){return b[d]}));a=this.editor.replaceRange(this.pos.from,
this.pos.to,a);this.pos.to=a;this.atOccurrence=!1}},position:function(){if(this.atOccurrence)return{line:this.pos.from.node,character:this.pos.from.offset}}};p.prototype={importCode:function(a){var b=asEditorLines(a);if(!this.options.incrementalLoading||1E3>b.length)this.history.push(null,null,b),this.history.reset();else{var c=function(){var a=b.slice(d,d+1E3);a.push("");e.history.push(e.history.nodeBefore(null),null,a);e.history.reset();d+=1E3;d<b.length&&parent.setTimeout(c,1E3)},d=0,e=this;c()}},
getCode:function(){if(!this.container.firstChild)return"";var a=[];select.markSelection();forEach(k(this.container.firstChild),method(a,"push"));select.selectMarked();webkit&&this.container.lastChild.hackBR&&a.pop();webkitLastLineHack(this.container);return cleanText(a.join(""))},checkLine:function(a){if(!1===a||null!=a&&a.parentNode!=this.container&&!a.hackBR)throw parent.CodeMirror.InvalidLineHandle;},cursorPosition:function(a){null==a&&(a=!0);return(a=select.cursorPos(this.container,a))?{line:a.node,
character:a.offset}:{line:null,character:0}},firstLine:function(){return null},lastLine:function(){var a=this.container.lastChild;a&&(a=m(a));a&&a.hackBR&&(a=m(a.previousSibling));return a},nextLine:function(a){this.checkLine(a);a=q(a,this.container);return!a||a.hackBR?!1:a},prevLine:function(a){this.checkLine(a);return null==a?!1:m(a.previousSibling)},visibleLineCount:function(){for(var a=this.container.firstChild;a&&isBR(a);)a=a.nextSibling;return a?Math.floor((window.innerHeight||document.documentElement.clientHeight||
document.body.clientHeight)/a.offsetHeight):!1},selectLines:function(a,b,c,d){this.checkLine(a);a={node:a,offset:b};b=null;void 0!==d&&(this.checkLine(c),b={node:c,offset:d});select.setCursorPos(this.container,a,b);select.scrollToCursor(this.container)},lineContent:function(a){var b=[];for(a=a?a.nextSibling:this.container.firstChild;a&&!isBR(a);a=a.nextSibling)b.push(nodeText(a));return cleanText(b.join(""))},setLineContent:function(a,b){this.history.commit();this.replaceRange({node:a,offset:0},{node:a,
offset:this.history.textAfter(a).length},b);this.addDirtyNode(a);this.scheduleHighlight()},removeLine:function(a){for(var b=a?a.nextSibling:this.container.firstChild;b;){var c=b.nextSibling;removeElement(b);if(isBR(b))break;b=c}this.addDirtyNode(a);this.scheduleHighlight()},insertIntoLine:function(a,b,c){var d=null;if("end"==b)d=q(a,this.container);else for(var e=a?a.nextSibling:this.container.firstChild;e;e=e.nextSibling){if(0==b){d=e;break}var f=nodeText(e);if(f.length>b){d=e.nextSibling;c=f.slice(0,
b)+c+f.slice(b);removeElement(e);break}b-=f.length}b=asEditorLines(c);for(c=0;c<b.length;c++)0<c&&this.container.insertBefore(document.createElement("BR"),d),this.container.insertBefore(makePartSpan(b[c]),d);this.addDirtyNode(a);this.scheduleHighlight()},selectedText:function(){var a=this.history;a.commit();var b=select.cursorPos(this.container,!0),c=select.cursorPos(this.container,!1);if(!b||!c)return"";if(b.node==c.node)return a.textAfter(b.node).slice(b.offset,c.offset);for(var d=[a.textAfter(b.node).slice(b.offset)],
b=a.nodeAfter(b.node);b!=c.node;b=a.nodeAfter(b))d.push(a.textAfter(b));d.push(a.textAfter(c.node).slice(0,c.offset));return cleanText(d.join("\n"))},replaceSelection:function(a){this.history.commit();var b=select.cursorPos(this.container,!0),c=select.cursorPos(this.container,!1);b&&c&&(c=this.replaceRange(b,c,a),select.setCursorPos(this.container,c),webkitLastLineHack(this.container))},cursorCoords:function(a,b){function c(a,c){var d=-(document.body.scrollTop||document.documentElement.scrollTop||
0),e=-(document.body.scrollLeft||document.documentElement.scrollLeft||0)+c;forEach([a,b?null:window.frameElement],function(a){for(;a;)e+=a.offsetLeft,d+=a.offsetTop,a=a.offsetParent});return{x:e,y:d,yBot:d+a.offsetHeight}}function d(a,b){var c=document.createElement("SPAN");c.appendChild(document.createTextNode(a));try{return b(c)}finally{c.parentNode&&c.parentNode.removeChild(c)}}var e=select.cursorPos(this.container,a);if(!e)return null;for(var f=e.offset,g=e.node,h=this;f;){g=g?g.nextSibling:this.container.firstChild;
e=nodeText(g);if(f<e.length)return d(e.substr(0,f),function(a){a.style.position="absolute";a.style.visibility="hidden";a.className=g.className;h.container.appendChild(a);return c(g,a.offsetWidth)});f-=e.length}return g&&isSpan(g)?c(g,g.offsetWidth):g&&g.nextSibling&&isSpan(g.nextSibling)?c(g.nextSibling,0):d("\u200b",function(a){g?g.parentNode.insertBefore(a,g.nextSibling):h.container.insertBefore(a,h.container.firstChild);return c(a,0)})},reroutePasteEvent:function(){if(!(this.capturingPaste||window.opera||
gecko&&20101026<=gecko)){this.capturingPaste=!0;var a=window.frameElement.CodeMirror.textareaHack,b=this.cursorCoords(!0,!0);a.style.top=b.y+"px";internetExplorer&&(b=select.getBookmark(this.container))&&(this.selectionSnapshot=b);parent.focus();a.value="";a.focus();var c=this;parent.setTimeout(function(){c.capturingPaste=!1;window.focus();c.selectionSnapshot&&window.select.setBookmark(c.container,c.selectionSnapshot);var b=a.value;b&&(c.replaceSelection(b),select.scrollToCursor(c.container))},10)}},
replaceRange:function(a,b,c){c=asEditorLines(c);c[0]=this.history.textAfter(a.node).slice(0,a.offset)+c[0];var d=c[c.length-1];c[c.length-1]=d+this.history.textAfter(b.node).slice(b.offset);b=this.history.nodeAfter(b.node);this.history.push(a.node,b,c);return{node:this.history.nodeBefore(b),offset:d.length}},getSearchCursor:function(a,b,c){return new t(this,a,b,c)},reindent:function(){this.container.firstChild&&this.indentRegion(null,this.container.lastChild)},reindentSelection:function(a){if(select.somethingSelected()){var b=
select.selectionTopNode(this.container,!0),c=select.selectionTopNode(this.container,!1);!1!==b&&!1!==c&&this.indentRegion(b,c,a,!0)}else this.indentAtCursor(a)},grabKeys:function(a,b){this.frozen=a;this.keyFilter=b},ungrabKeys:function(){this.frozen="leave"},setParser:function(a,b){p.Parser=window[a];(b=b||this.options.parserConfig)&&p.Parser.configure&&p.Parser.configure(b);this.container.firstChild&&(forEach(this.container.childNodes,function(a){3!=a.nodeType&&(a.dirty=!0)}),this.addDirtyNode(this.firstChild),
this.scheduleHighlight())},keyDown:function(a){"leave"==this.frozen&&(this.keyFilter=this.frozen=null);if(!this.frozen||this.keyFilter&&!this.keyFilter(a.keyCode,a)){var b=a.keyCode;this.delayScanning();this.options.autoMatchParens&&this.scheduleParenHighlight();if(13==b)a.ctrlKey&&!a.altKey?this.reparseBuffer():(select.insertNewlineAtCursor(),b=this.options.enterMode,"flat"!=b&&this.indentAtCursor("keep"==b?"keep":void 0),select.scrollToCursor(this.container)),a.stop();else if(9!=b||"default"==this.options.tabMode||
a.ctrlKey)if(36!=b||a.shiftKey||a.ctrlKey)if(35!=b||a.shiftKey||a.ctrlKey)if(33!=b||a.shiftKey||a.ctrlKey||gecko)if(34!=b||a.shiftKey||a.ctrlKey||gecko)if(219!=b&&221!=b||!a.ctrlKey||a.altKey)if(!a.metaKey||a.shiftKey||37!=b&&39!=b)!a.ctrlKey&&!a.metaKey||a.altKey||(a.shiftKey&&90==b||89==b?(select.scrollToNode(this.history.redo()),a.stop()):90==b||safari&&8==b?(select.scrollToNode(this.history.undo()),a.stop()):83==b&&this.options.saveFunction?(this.options.saveFunction(),a.stop()):86!=b||mac||this.reroutePasteEvent());
else{var c=select.selectionTopNode(this.container);!1!==c&&this.container.firstChild&&(37==b?select.focusAfterNode(m(c),this.container):(b=q(c,this.container),select.focusAfterNode(b?b.previousSibling:this.container.lastChild,this.container)),a.stop())}else this.highlightParens(a.shiftKey,!0),a.stop();else this.pageDown()&&a.stop();else this.pageUp()&&a.stop();else this.end()&&a.stop();else this.home()&&a.stop();else this.handleTab(!a.shiftKey),a.stop()}else a.stop(),this.frozen(a)},keyPress:function(a){var b=
this.options.electricChars&&p.Parser.electricChars,c=this;if(this.frozen&&(!this.keyFilter||this.keyFilter(a.keyCode||a.code,a))||13==a.code||9==a.code&&"default"!=this.options.tabMode)a.stop();else if(mac&&(a.ctrlKey||a.metaKey)&&"v"==a.character)this.reroutePasteEvent();else if(b&&-1!=b.indexOf(a.character))parent.setTimeout(function(){c.indentAtCursor(null)},0);else if(brokenOpera)if(8==a.code){var d=select.selectionTopNode(this.container),c=this,e=d?d.nextSibling:this.container.firstChild;!1!==
d&&e&&isBR(e)&&parent.setTimeout(function(){select.selectionTopNode(c.container)==e&&select.focusAfterNode(e.previousSibling,c.container)},20)}else 46==a.code&&(d=select.selectionTopNode(this.container),c=this,d&&isBR(d)&&parent.setTimeout(function(){select.selectionTopNode(c.container)!=d&&select.focusAfterNode(d,c.container)},20));else if(slowWebkit&&(e=(d=select.selectionTopNode(this.container))?d.nextSibling:this.container.firstChild,d&&e&&isBR(e)&&!isBR(d))){var f=document.createTextNode("\u200b");
this.container.insertBefore(f,e);parent.setTimeout(function(){"\u200b"==f.nodeValue?removeElement(f):f.nodeValue=f.nodeValue.replace("\u200b","")},20)}webkit&&!this.options.textWrapping&&setTimeout(function(){var a=select.selectionTopNode(c.container,!0);a&&3==a.nodeType&&a.previousSibling&&isBR(a.previousSibling)&&a.nextSibling&&isBR(a.nextSibling)&&a.parentNode.replaceChild(document.createElement("BR"),a.previousSibling)},50)},keyUp:function(a){this.cursorActivity(y(a.keyCode))},indentLineAfter:function(a,
b){function c(a){return(a=a?a.nextSibling:d.container.firstChild)&&hasClass(a,"whitespace")?a:null}var d=this,e=c(a),f=0,g=e?e.currentText.length:0,h=e?e.nextSibling:a?a.nextSibling:this.container.firstChild;if("keep"==b){if(a){var l=c(m(a.previousSibling));l&&(f=l.currentText.length)}}else l=a&&h&&h.currentText?h.currentText:"",null!=b&&"indent"!=this.options.tabMode?f=b?g+indentUnit:Math.max(0,g-indentUnit):a?f=a.indentation(l,g,b,h):p.Parser.firstIndentation&&(f=p.Parser.firstIndentation(l,g,b,
h));g=f-g;0>g?0==f?(h&&select.snapshotMove(e.firstChild,h.firstChild||h,0),removeElement(e),e=null):(select.snapshotMove(e.firstChild,e.firstChild,g,!0),e.currentText=makeWhiteSpace(f),e.firstChild.nodeValue=e.currentText):0<g?e?(e.currentText=makeWhiteSpace(f),e.firstChild.nodeValue=e.currentText,select.snapshotMove(e.firstChild,e.firstChild,g,!0)):(e=makePartSpan(makeWhiteSpace(f)),e.className="whitespace",a?insertAfter(e,a):this.container.insertBefore(e,this.container.firstChild),select.snapshotMove(h&&
(h.firstChild||h),e.firstChild,f,!1,!0)):e&&select.snapshotMove(e.firstChild,e.firstChild,f,!1);0!=g&&this.addDirtyNode(a)},highlightAtCursor:function(){var a=select.selectionTopNode(this.container,!0),b=select.selectionTopNode(this.container,!1);if(!1===a||!1===b)return!1;select.markSelection();if(!1===this.highlight(a,q(b,this.container),!0,20))return!1;select.selectMarked();return!0},handleTab:function(a){"spaces"!=this.options.tabMode||select.somethingSelected()?this.reindentSelection(a):select.insertTabAtCursor()},
home:function(){var a=select.selectionTopNode(this.container,!0),b=a;if(!1===a||a&&!a.isPart&&!isBR(a)||!this.container.firstChild)return!1;for(;a&&!isBR(a);)a=a.previousSibling;var c=a?a.nextSibling:this.container.firstChild;c&&c!=b&&c.isPart&&hasClass(c,"whitespace")?select.focusAfterNode(c,this.container):select.focusAfterNode(a,this.container);select.scrollToCursor(this.container);return!0},end:function(){var a=select.selectionTopNode(this.container,!0);if(!1===a)return!1;a=q(a,this.container);
if(!a)return!1;select.focusAfterNode(a.previousSibling,this.container);select.scrollToCursor(this.container);return!0},pageUp:function(){var a=this.cursorPosition().line,b=this.visibleLineCount();if(!1===a||!1===b)return!1;for(var b=b-2,c=0;c<b&&(a=this.prevLine(a),!1!==a);c++);if(0==c)return!1;select.setCursorPos(this.container,{node:a,offset:0});select.scrollToCursor(this.container);return!0},pageDown:function(){var a=this.cursorPosition().line,b=this.visibleLineCount();if(!1===a||!1===b)return!1;
for(var b=b-2,c=0;c<b;c++){var d=this.nextLine(a);if(!1===d)break;a=d}if(0==c)return!1;select.setCursorPos(this.container,{node:a,offset:0});select.scrollToCursor(this.container);return!0},scheduleParenHighlight:function(){this.parenEvent&&parent.clearTimeout(this.parenEvent);var a=this;this.parenEvent=parent.setTimeout(function(){a.highlightParens()},300)},highlightParens:function(a,b){function c(a,b){a&&(h?h.call?h(a,b):a.className+=" "+h[b?0:1]:(a.style.fontWeight="bold",a.style.color=b?"#8F8":
"#F88"))}function d(a){a&&(h&&!h.call?removeClass(removeClass(a,h[0]),h[1]):g.options.unmarkParen?g.options.unmarkParen(a):(a.style.fontWeight="",a.style.color=""))}function e(a){if(a.currentText)return(a=a.currentText.match(/^[\s\u00a0]*([\(\)\[\]{}])[\s\u00a0]*$/))&&a[1]}function f(){for(var a=[],b,c=!0,d=k;d;d=p?d.nextSibling:d.previousSibling)if(d.className==m&&isSpan(d)&&(b=e(d))){if(/[\(\[\{]/.test(b)==p?a.push(b):a.length?a.pop()!=matching[b]&&(c=!1):c=!1,!a.length)break}else if(d.dirty||!isSpan(d)&&
!isBR(d))return{node:d,status:"dirty"};return{node:d,status:d&&c}}var g=this,h=this.options.markParen;"string"==typeof h&&(h=[h,h]);!b&&g.highlighted&&(d(g.highlighted[0]),d(g.highlighted[1]));if(window&&window.parent&&window.select){this.parenEvent&&parent.clearTimeout(this.parenEvent);this.parenEvent=null;var l,k=select.selectionTopNode(this.container,!0);if(k&&this.highlightAtCursor()&&(k=select.selectionTopNode(this.container,!0))&&((l=e(k))||(k=k.nextSibling)&&(l=e(k))))for(var m=k.className,
p=/[\(\[\{]/.test(l);;){var n=f();if("dirty"==n.status)this.highlight(n.node,q(n.node)),n.node.dirty=!1;else{c(k,n.status);c(n.node,n.status);b?parent.setTimeout(function(){d(k);d(n.node)},500):g.highlighted=[k,n.node];a&&n.node&&select.focusAfterNode(n.node.previousSibling,this.container);break}}}},indentAtCursor:function(a){if(this.container.firstChild&&this.highlightAtCursor()){var b=select.selectionTopNode(this.container,!1);!1!==b&&(select.markSelection(),this.indentLineAfter(m(b),a),select.selectMarked())}},
indentRegion:function(a,b,c,d){var e=a=m(a),f=a&&m(a.previousSibling);isBR(b)||(b=q(b,this.container));this.addDirtyNode(a);do{var g=q(e,this.container);e&&this.highlight(f,g,!0);this.indentLineAfter(e,c);f=e;e=g}while(e!=b);d&&select.setCursorPos(this.container,{node:a,offset:0},{node:b,offset:0})},cursorActivity:function(a){this.unloaded&&(window.document.designMode="off",window.document.designMode="on",this.unloaded=!1);if(internetExplorer){this.container.createTextRange().execCommand("unlink");
clearTimeout(this.saveSelectionSnapshot);var b=this;this.saveSelectionSnapshot=setTimeout(function(){var a=select.getBookmark(b.container);a&&(b.selectionSnapshot=a)},200)}var c=this.options.onCursorActivity;if(!a||c){var d=select.selectionTopNode(this.container,!1);!1!==d&&this.container.firstChild&&(d=d||this.container.firstChild,c&&c(d),a||(this.scheduleHighlight(),this.addDirtyNode(d)))}},reparseBuffer:function(){forEach(this.container.childNodes,function(a){a.dirty=!0});this.container.firstChild&&
this.addDirtyNode(this.container.firstChild)},addDirtyNode:function(a){if(a=a||this.container.firstChild){for(var b=0;b<this.dirty.length;b++)if(this.dirty[b]==a)return;3!=a.nodeType&&(a.dirty=!0);this.dirty.push(a)}},allClean:function(){return!this.dirty.length},scheduleHighlight:function(){var a=this;parent.clearTimeout(this.highlightTimeout);this.highlightTimeout=parent.setTimeout(function(){a.highlightDirty()},this.options.passDelay)},getDirtyNode:function(){for(;0<this.dirty.length;){var a=this.dirty.pop();
try{for(;a&&a.parentNode!=this.container;)a=a.parentNode;if(a&&(a.dirty||3==a.nodeType))return a}catch(b){}}return null},highlightDirty:function(a){if(!window||!window.parent||!window.select)return!1;this.options.readOnly||select.markSelection();for(var b,c=a?null:(new Date).getTime()+this.options.passTime;((new Date).getTime()<c||a)&&(b=this.getDirtyNode());){var d=this.highlight(b,c);d&&d.node&&d.dirty&&this.addDirtyNode(d.node.nextSibling)}this.options.readOnly||select.selectMarked();b&&this.scheduleHighlight();
return 0==this.dirty.length},documentScanner:function(a){var b=this,c=null;return function(){if(window&&window.parent&&window.select){c&&c.parentNode!=b.container&&(c=null);select.markSelection();var d=b.highlight(c,(new Date).getTime()+a,!0);select.selectMarked();d=d?d.node&&d.node.nextSibling:null;c=c==d?null:d;b.delayScanning()}}},delayScanning:function(){this.scanner&&(parent.clearTimeout(this.documentScan),this.documentScan=parent.setTimeout(this.scanner,this.options.continuousScanning))},highlight:function(a,
b,c,d){function e(a){if(a){var b=a.oldNextSibling;(n||void 0===b||a.nextSibling!=b)&&g.history.touch(a);a.oldNextSibling=a.nextSibling}else b=g.container.oldFirstChild,(n||void 0===b||g.container.firstChild!=b)&&g.history.touch(null),g.container.oldFirstChild=g.container.firstChild}var f=this.container,g=this,h=this.options.activeTokens,l="number"==typeof b?b:null;if(!f.firstChild)return!1;for(;a&&(!a.parserFromHere||a.dirty);){if(null!=d&&isBR(a)&&0>--d)return!1;a=a.previousSibling}if(a&&!a.nextSibling)return!1;
var m=k(a?a.nextSibling:f.firstChild);d=stringStream(m);var q=a?a.parserFromHere(d):p.Parser.make(d),s={current:null,get:function(){this.current||(this.current=m.nodes.shift());return this.current},next:function(){this.current=null},remove:function(){f.removeChild(this.get());this.current=null},getNonEmpty:function(){for(var a=this.get();a&&isSpan(a)&&""==a.currentText;){var b;if(b=window.opera)b=a,b=(null==b.previousSibling||isBR(b.previousSibling))&&(null==b.nextSibling||isBR(b.nextSibling));b?
(this.next(),a=this.get()):(b=a,this.remove(),a=this.get(),select.snapshotMove(b.firstChild,a&&(a.firstChild||a),0))}return a}},n=!1,t=!0,u=0;forEach(q,function(d){var k=s.getNonEmpty();if("\n"==d.value){if(!isBR(k))throw"Parser out of sync. Expected BR.";if(k.dirty||!k.indentation)n=!0;e(a);a=k;k.parserFromHere=q.copy();k.indentation=d.indentation||alwaysZero;k.dirty=!1;if(null==l&&k==b)throw StopIteration;if(null!=l&&(new Date).getTime()>=l||!n&&!t&&1<u&&!c)throw StopIteration;t=n;n=!1;u=0;s.next()}else{if(!isSpan(k))throw"Parser out of sync. Expected SPAN.";
k.dirty&&(n=!0);u++;if(k.reduced||k.currentText!=d.value||k.className!=d.style){n=!0;var m=makePartSpan(d.value);m.className=d.style;f.insertBefore(m,k);h&&h(m,d,g);d=d.value.length;for(var p=0;0<d;){var k=s.get(),v=k.currentText.length;select.snapshotReplaceNode(k.firstChild,m.firstChild,d,p);v>d?(k.currentText=k.currentText.substring(d),k.reduced=!0,d=0):(d-=v,p+=v,s.remove())}}else h&&k.dirty&&h(k,d,g),k.dirty=!1,s.next()}});e(a);webkitLastLineHack(this.container);return{node:s.getNonEmpty(),dirty:n}}};
return p}();addEventHandler(window,"load",function(){var l=window.frameElement.CodeMirror;l.editor=new Editor(l.options);parent.setTimeout(method(l,"init"),0)});

var select={};
(function(){function n(a,b){for(;a&&a.parentNode!=b;)a=a.parentNode;return a}function v(a,b){for(;!a.previousSibling&&a.parentNode!=b;)a=a.parentNode;return n(a.previousSibling,b)}function s(a){var b=a.nextSibling;if(b){for(;b.firstChild;)b=b.firstChild;return 3==b.nodeType||isBR(b)?b:s(b)}for(a=a.parentNode;a&&!a.nextSibling;)a=a.parentNode;return a&&s(a)}select.ie_selection=document.selection&&document.selection.createRangeCollection;select.scrollToNode=function(a,b){if(a){for(var c=a,d=document.body,
e=document.documentElement,g=!c.nextSibling||!c.nextSibling.nextSibling||!c.nextSibling.nextSibling.nextSibling,k=0;c&&!c.offsetTop;)k++,c=c.previousSibling;0==k&&(g=!1);if(!webkit||!c||5!=c.offsetTop||5!=c.offsetLeft){for(var k=k*(c?c.offsetHeight:0),h=0,q=a?a.offsetWidth:0;c&&c.offsetParent;)k+=c.offsetTop,isBR(c)||(h+=c.offsetLeft),c=c.offsetParent;var c=d.scrollLeft||e.scrollLeft||0,d=d.scrollTop||e.scrollTop||0,f=!1,l=window.innerWidth||e.clientWidth||0;if(b||q<l){if(b){var n=select.offsetInNode(a),
t=nodeText(a).length;t&&(h+=n/t*q)}q=h-c;if(0>q||q>l)c=h,f=!0}h=k-d;if(0>h||g||h>(window.innerHeight||e.clientHeight||0)-50)d=g?1E6:k,f=!0;f&&window.scrollTo(c,d)}}};select.scrollToCursor=function(a){select.scrollToNode(select.selectionTopNode(a,!0)||a.firstChild,!0)};var f=null;select.snapshotChanged=function(){f&&(f.changed=!0)};select.snapshotReplaceNode=function(a,b,c,d){function e(e){a==e.node?(f.changed=!0,c&&e.offset>c?e.offset-=c:(e.node=b,e.offset+=d||0)):select.ie_selection&&0==e.offset&&
e.node==s(a)&&(f.changed=!0)}f&&(e(f.start),e(f.end))};select.snapshotMove=function(a,b,c,d,e){function g(g){a!=g.node||e&&0!=g.offset||(f.changed=!0,g.node=b,g.offset=d?Math.max(0,g.offset+c):c)}f&&(g(f.start),g(f.end))};if(select.ie_selection){var w=function(a){var b=l();b&&(b.pasteHTML(a),b.collapse(!1),b.select())},x=function(a){function b(a){for(var b=null;!b&&a;)b=a.nextSibling,a=a.parentNode;return c(b)}function c(a){for(;a&&a.firstChild;)a=a.firstChild;return{node:a,offset:0}}var d=l();d.collapse(a);
a=d.parentElement();if(!isAncestor(document.body,a))return null;if(!a.firstChild)return c(a);var e=d.duplicate();e.moveToElementText(a);e.collapse(!0);for(var g=a.firstChild;g;g=g.nextSibling){if(3==g.nodeType){var k=g.nodeValue.length;e.move("character",k)}else e.moveToElementText(g),e.collapse(!1);var h=d.compareEndPoints("StartToStart",e);if(0==h)return b(g);if(1!=h){if(3!=g.nodeType)return c(g);e.setEndPoint("StartToEnd",d);return{node:g,offset:k-e.text.length}}}return b(a)},l=function(){var a=
document.selection;return a?a.createRange?a.createRange():a.createTextRange():null};select.markSelection=function(){f=null;if(document.selection){var a=x(!0),b=x(!1);a&&b&&(f={start:a,end:b,changed:!1})}};select.selectMarked=function(){function a(a){var c=document.body.createTextRange(),b=a.node;if(b)if(3==b.nodeType){c.moveToElementText(b.parentNode);for(a=a.offset;b.previousSibling;)b=b.previousSibling,a+=(b.innerText||"").length;c.move("character",a)}else c.moveToElementText(b),c.collapse(!0);
else c.moveToElementText(document.body),c.collapse(!1);return c}if(f&&f.changed){var b=a(f.start),c=a(f.end);b.setEndPoint("StartToEnd",c);b.select()}};select.offsetInNode=function(a){var b=l();if(!b)return 0;var c=b.duplicate();try{c.moveToElementText(a)}catch(d){return 0}b.setEndPoint("StartToStart",c);return b.text.length};select.selectionTopNode=function(a,b){var c=l();if(!c)return!1;var d=c.duplicate();c.collapse(b);var e=c.parentElement();if(e&&isAncestor(a,e)&&(d.moveToElementText(e),1==c.compareEndPoints("StartToStart",
d)))return n(e,a);b=0;for(e=a.childNodes.length-1;b<e;){var g=Math.ceil((e+b)/2),k=a.childNodes[g];if(!k)return!1;var h;a:{h=d;if(3==k.nodeType){for(var f=0,m=k.previousSibling;m&&3==m.nodeType;)f+=m.nodeValue.length,m=m.previousSibling;if(m){try{h.moveToElementText(m)}catch(p){h=!1;break a}h.collapse(!1)}else h.moveToElementText(k.parentNode);f&&h.move("character",f)}else try{h.moveToElementText(k)}catch(r){h=!1;break a}h=!0}if(!h)return!1;1==c.compareEndPoints("StartToStart",d)?b=g:e=g-1}if(0==
b){c=l();d=c.duplicate();try{d.moveToElementText(a)}catch(t){return null}if(0==c.compareEndPoints("StartToStart",d))return null}return a.childNodes[b]||null};select.focusAfterNode=function(a,b){var c=document.body.createTextRange();c.moveToElementText(a||b);c.collapse(!a);c.select()};select.somethingSelected=function(){var a=l();return a&&""!=a.text};select.insertNewlineAtCursor=function(){w("<br>")};select.insertTabAtCursor=function(){w("\u00a0\u00a0\u00a0\u00a0")};select.cursorPos=function(a,b){var c=
l();if(!c)return null;for(var d=select.selectionTopNode(a,b);d&&!isBR(d);)d=d.previousSibling;var e=c.duplicate();c.collapse(b);if(d)e.moveToElementText(d),e.collapse(!1);else{try{e.moveToElementText(a)}catch(g){return null}e.collapse(!0)}c.setEndPoint("StartToStart",e);return{node:d,offset:c.text.length}};select.setCursorPos=function(a,b,c){function d(c){var b=document.body.createTextRange();c.node?(b.moveToElementText(c.node),b.collapse(!1)):(b.moveToElementText(a),b.collapse(!0));b.move("character",
c.offset);return b}var e=d(b);c&&c!=b&&e.setEndPoint("EndToEnd",d(c));e.select()};select.getBookmark=function(a){var b=select.cursorPos(a,!0);a=select.cursorPos(a,!1);if(b&&a)return{from:b,to:a}};select.setBookmark=function(a,b){b&&select.setCursorPos(a,b.from,b.to)}}else{var p=function(){var a=window.getSelection();return a&&0!=a.rangeCount?a.getRangeAt(0):!1},r=function(a){var b=window.getSelection();b&&(b.removeAllRanges(),b.addRange(a))},u=function(a,b){for(;3!=a.nodeType&&!isBR(a);){var c=a.childNodes[b]||
a.nextSibling;for(b=0;!c&&a.parentNode;)a=a.parentNode,c=a.nextSibling;a=c;if(!c)break}return{node:a,offset:b}};select.markSelection=function(){var a=window.getSelection();if(!a||0==a.rangeCount)return f=null;a=a.getRangeAt(0);f={start:u(a.startContainer,a.startOffset),end:u(a.endContainer,a.endOffset),changed:!1}};select.selectMarked=function(){function a(){if(c.start.node==c.end.node&&c.start.offset==c.end.offset){var a=window.getSelection();if(!a||0==a.rangeCount)return!0;a=a.getRangeAt(0);a=u(a.startContainer,
a.startOffset);return c.start.node!=a.node||c.start.offset!=a.offset}}function b(a,b){if(a.node)if(0==a.offset)d["set"+b+"Before"](a.node);else d["set"+b](a.node,a.offset);else d.setStartAfter(document.body.lastChild||document.body)}var c=f;if(c&&(c.changed||webkit&&a())){var d=document.createRange();b(c.end,"End");b(c.start,"Start");r(d)}};select.selectionTopNode=function(a,b){var c=p();if(!c)return!1;var d=b?c.startContainer:c.endContainer,e=b?c.startOffset:c.endOffset;window.opera&&!b&&c.endContainer==
a&&c.endOffset==c.startOffset+1&&a.childNodes[c.startOffset]&&isBR(a.childNodes[c.startOffset])&&e--;return 3==d.nodeType?0<e?n(d,a):v(d,a):"HTML"==d.nodeName.toUpperCase()?1==e?null:a.lastChild:d==a?0==e?null:d.childNodes[e-1]:e==d.childNodes.length?n(d,a):0==e?v(d,a):n(d.childNodes[e-1],a)};select.focusAfterNode=function(a,b){var c=document.createRange();c.setStartBefore(b.firstChild||b);a&&!a.firstChild?c.setEndAfter(a):a?c.setEnd(a,a.childNodes.length):c.setEndBefore(b.firstChild||b);c.collapse(!1);
r(c)};select.somethingSelected=function(){var a=p();return a&&!a.collapsed};select.offsetInNode=function(a){var b=p();if(!b)return 0;b=b.cloneRange();b.setStartBefore(a);return b.toString().length};select.insertNodeAtCursor=function(a){var b=p();if(b){b.deleteContents();b.insertNode(a);webkitLastLineHack(document.body);if(window.opera&&isBR(a)&&isSpan(a.parentNode)){var b=a.nextSibling,c=a.parentNode,d=c.parentNode;d.insertBefore(a,c.nextSibling);for(c="";b&&3==b.nodeType;b=b.nextSibling)c+=b.nodeValue,
removeElement(b);d.insertBefore(makePartSpan(c,document),a.nextSibling)}b=document.createRange();b.selectNode(a);b.collapse(!1);r(b)}};select.insertNewlineAtCursor=function(){select.insertNodeAtCursor(document.createElement("BR"))};select.insertTabAtCursor=function(){select.insertNodeAtCursor(document.createTextNode("\u00a0\u00a0\u00a0\u00a0"))};select.cursorPos=function(a,b){var c=p();if(c){for(var d=select.selectionTopNode(a,b);d&&!isBR(d);)d=d.previousSibling;c=c.cloneRange();c.collapse(b);d?c.setStartAfter(d):
c.setStartBefore(a);return{node:d,offset:c.toString().length}}};select.setCursorPos=function(a,b,c){function d(b,c,d){function f(a){3==a.nodeType?m.push(a):forEach(a.childNodes,f)}if(0==c&&b&&!b.nextSibling)return e["set"+d+"After"](b),!0;if(b=b?b.nextSibling:a.firstChild){if(0==c)return e["set"+d+"Before"](b),!0;for(var m=[];;){for(;b&&!m.length;)f(b),b=b.nextSibling;var l=m.shift();if(!l)return!1;var n=l.nodeValue.length;if(n>=c)return e["set"+d](l,c),!0;c-=n}}}var e=document.createRange();c=c||
b;d(c.node,c.offset,"End")&&d(b.node,b.offset,"Start")&&r(e)}}})();

var stringStream=function(g){function e(){for(;c==a.length;){d+=a;a="";c=0;try{a=g.next()}catch(b){if(b!=StopIteration)throw b;return!1}}return!0}var a="",c=0,d="";return{peek:function(){return e()?a.charAt(c):null},next:function(){if(!e()){if(0<d.length)throw"End of stringstream reached without emptying buffer ('"+d+"').";throw StopIteration;}return a.charAt(c++)},get:function(){var b=d;d="";0<c&&(b+=a.slice(0,c),a=a.slice(c),c=0);return b},push:function(b){a=a.slice(0,c)+b+a.slice(c)},lookAhead:function(b,
h,f,p){function k(b){return p?b.toLowerCase():b}b=k(b);var l=!1,e=d,q=c;for(f&&this.nextWhileMatches(/[\s\u00a0]/);;){f=c+b.length;var m=a.length-c;if(f<=a.length){l=b==k(a.slice(c,f));c=f;break}else if(b.slice(0,m)==k(a.slice(c))){d+=a;a="";try{a=g.next()}catch(n){if(n!=StopIteration)throw n;break}c=0;b=b.slice(m)}else break}l&&h||(a=d.slice(e.length)+a,c=q,d=e);return l},lookAheadRegex:function(b,h){if("^"!=b.source.charAt(0))throw Error("Regexps passed to lookAheadRegex must start with ^");for(;-1==
a.indexOf("\n",c);)try{a+=g.next()}catch(d){if(d!=StopIteration)throw d;break}var e=a.slice(c).match(b);e&&h&&(c+=e[0].length);return e},more:function(){return null!==this.peek()},applies:function(b){var a=this.peek();return null!==a&&b(a)},nextWhile:function(b){for(var a;null!==(a=this.peek())&&b(a);)this.next()},matches:function(b){var a=this.peek();return null!==a&&b.test(a)},nextWhileMatches:function(b){for(var a;null!==(a=this.peek())&&b.test(a);)this.next()},equals:function(a){return a===this.peek()},
endOfLine:function(){var a=this.peek();return null==a||"\n"==a}}};

function tokenizer(b,e){function c(a){return"\n"!=a&&/^[\s\u00a0]*$/.test(a)}var d={state:e,take:function(a){"string"==typeof a&&(a={style:a,type:a});a.content=(a.content||"")+b.get();/\n$/.test(a.content)||b.nextWhile(c);a.value=a.content+b.get();return a},next:function(){if(!b.more())throw StopIteration;var a;if(b.equals("\n"))return b.next(),this.take("whitespace");if(b.applies(c))a="whitespace";else for(;!a;)a=this.state(b,function(a){d.state=a});return this.take(a)}};return d};

function UndoHistory(a,b,c,g){this.container=a;this.maxDepth=b;this.commitDelay=c;this.editor=g;this.last=this.first=a={text:"",from:null,to:null};this.firstTouched=!1;this.history=[];this.redoHistory=[];this.touched=[];this.lostundo=0}
UndoHistory.prototype={scheduleCommit:function(){var a=this;parent.clearTimeout(this.commitTimeout);this.commitTimeout=parent.setTimeout(function(){a.tryCommit()},this.commitDelay)},touch:function(a){this.setTouched(a);this.scheduleCommit()},undo:function(){this.commit();if(this.history.length){var a=this.history.pop();this.redoHistory.push(this.updateTo(a,"applyChain"));this.notifyEnvironment();return this.chainNode(a)}},redo:function(){this.commit();if(this.redoHistory.length){var a=this.redoHistory.pop();
this.addUndoLevel(this.updateTo(a,"applyChain"));this.notifyEnvironment();return this.chainNode(a)}},clear:function(){this.history=[];this.redoHistory=[];this.lostundo=0},historySize:function(){return{undo:this.history.length,redo:this.redoHistory.length,lostundo:this.lostundo}},push:function(a,b,c){for(var g=[],e=0;e<c.length;e++){var f=e==c.length-1?b:document.createElement("br");g.push({from:a,to:f,text:cleanText(c[e])});a=f}this.pushChains([g],null==a&&null==b);this.notifyEnvironment()},pushChains:function(a,
b){this.commit(b);this.addUndoLevel(this.updateTo(a,"applyChain"));this.redoHistory=[]},chainNode:function(a){for(var b=0;b<a.length;b++){var c=a[b][0];if(c=c&&(c.from||c.to))return c}},reset:function(){this.history=[];this.redoHistory=[];this.lostundo=0},textAfter:function(a){return this.after(a).text},nodeAfter:function(a){return this.after(a).to},nodeBefore:function(a){return this.before(a).from},tryCommit:function(){window&&window.parent&&window.UndoHistory&&(this.editor.highlightDirty()?this.commit(!0):
this.scheduleCommit())},commit:function(a){parent.clearTimeout(this.commitTimeout);a||this.editor.highlightDirty(!0);a=this.touchedChains();a.length&&(this.addUndoLevel(this.updateTo(a,"linkChain")),this.redoHistory=[],this.notifyEnvironment())},updateTo:function(a,b){for(var c=[],g=[],e=0;e<a.length;e++)c.push(this.shadowChain(a[e])),g.push(this[b](a[e]));"applyChain"==b&&this.notifyDirty(g);return c},notifyDirty:function(a){forEach(a,method(this.editor,"addDirtyNode"));this.editor.scheduleHighlight()},
notifyEnvironment:function(){if(this.onChange)this.onChange(this.editor);window.frameElement&&window.frameElement.CodeMirror.updateNumbers&&window.frameElement.CodeMirror.updateNumbers()},linkChain:function(a){for(var b=0;b<a.length;b++){var c=a[b];c.from?c.from.historyAfter=c:this.first=c;c.to?c.to.historyBefore=c:this.last=c}},after:function(a){return a?a.historyAfter:this.first},before:function(a){return a?a.historyBefore:this.last},setTouched:function(a){a?a.historyTouched||(this.touched.push(a),
a.historyTouched=!0):this.firstTouched=!0},addUndoLevel:function(a){this.history.push(a);this.history.length>this.maxDepth&&(this.history.shift(),lostundo+=1)},touchedChains:function(){function a(a){for(var b=[],d=a?a.nextSibling:c.container.firstChild;d&&(!isBR(d)||d.hackBR);d=d.nextSibling)!d.hackBR&&d.currentText&&b.push(d.currentText);return{from:a,to:d,text:cleanText(b.join(""))}}function b(a,c){for(var d=c+"Sibling",b=a[d];b&&!isBR(b);)b=b[d];return b}var c=this,g=null,e=[];c.firstTouched&&
c.touched.push(null);forEach(c.touched,function(b){if(!b||b.parentNode==c.container&&!b.hackBR){b?b.historyTouched=!1:c.firstTouched=!1;var f=a(b),d=c.after(b);d&&d.text==f.text&&d.to==f.to||(e.push(f),b?b.historyTemp=f:g=f)}});var f=[];c.touched=[];forEach(e,function(e){var h=e.from;if(h?h.historyTemp:g){for(var h=[],d=e.from,l=!0;;){var k=d?d.historyTemp:g;if(!k)if(l)break;else k=a(d);h.unshift(k);d?d.historyTemp=null:g=null;if(!d)break;l=c.after(d);d=b(d,"previous")}d=e.to;for(l=c.before(e.from);d;){k=
d?d.historyTemp:g;if(!k)if(l)break;else k=a(d);h.push(k);d?d.historyTemp=null:g=null;l=c.before(d);d=b(d,"next")}f.push(h)}});return f},shadowChain:function(a){var b=[],c=this.after(a[0].from);for(a=a[a.length-1].to;;)if(b.push(c),(c=c.to)&&c!=a)c=c.historyAfter||this.before(a);else break;return b},applyChain:function(a){for(var b=select.cursorPos(this.container,!1),c=a[0].from,g=a[a.length-1].to,e=c?c.nextSibling:this.container.firstChild;e!=g;){var f=e.nextSibling;removeElement(e);e=f}for(e=0;e<
a.length;e++){f=a[e];0<e&&this.container.insertBefore(f.from,g);var m=makePartSpan(fixSpaces(f.text));this.container.insertBefore(m,g);if(b&&b.node==f.from){var m=0,h=this.after(f.from);if(h&&e==a.length-1){for(var d=0;d<b.offset&&f.text.charAt(d)==h.text.charAt(d);d++);b.offset>d&&(m=f.text.length-h.text.length)}select.setCursorPos(this.container,{node:f.from,offset:Math.max(0,b.offset+m)})}else b&&e==a.length-1&&b.node&&b.node.parentNode!=this.container&&select.setCursorPos(this.container,{node:f.from,
offset:f.text.length})}this.linkChain(a);return c}};

function method(a,b){return function(){a[b].apply(a,arguments)}}var StopIteration={toString:function(){return"StopIteration"}};function forEach(a,b){if(a.next)try{for(;;)b(a.next())}catch(c){if(c!=StopIteration)throw c;}else for(var d=0;d<a.length;d++)b(a[d])}function map(a,b){var c=[];forEach(a,function(a){c.push(b(a))});return c}function matcher(a){return function(b){return a.test(b)}}function hasClass(a,b){var c=a.className;return c&&(new RegExp("(^| )"+b+"($| )")).test(c)}
function removeClass(a,b){a.className=a.className.replace(new RegExp(" "+b+"\\b","g"),"");return a}function insertAfter(a,b){b.parentNode.insertBefore(a,b.nextSibling);return a}function removeElement(a){a.parentNode&&a.parentNode.removeChild(a)}function clearElement(a){for(;a.firstChild;)a.removeChild(a.firstChild)}function isAncestor(a,b){for(;b=b.parentNode;)if(a==b)return!0;return!1}var nbsp="\u00a0",matching={"{":"}","[":"]","(":")","}":"{","]":"[",")":"("};
function normalizeEvent(a){a.stopPropagation||(a.stopPropagation=function(){this.cancelBubble=!0},a.preventDefault=function(){this.returnValue=!1});a.stop||(a.stop=function(){this.stopPropagation();this.preventDefault()});"keypress"==a.type&&(a.code=null==a.charCode?a.keyCode:a.charCode,a.character=String.fromCharCode(a.code));return a}
function addEventHandler(a,b,c,d){function e(a){c(normalizeEvent(a||window.event))}if("function"==typeof a.addEventListener){if(a.addEventListener(b,e,!1),d)return function(){a.removeEventListener(b,e,!1)}}else if(a.attachEvent("on"+b,e),d)return function(){a.detachEvent("on"+b,e)}}function nodeText(a){return a.textContent||a.innerText||a.nodeValue||""}function nodeTop(a){for(var b=0;a.offsetParent;)b+=a.offsetTop,a=a.offsetParent;return b}function isBR(a){a=a.nodeName;return"BR"==a||"br"==a}
function isSpan(a){a=a.nodeName;return"SPAN"==a||"span"==a};

var SqlParser=Editor.Parser=function(){function l(b){return new RegExp("^(?:"+b.join("|")+")$","i")}function g(b){return function(d){d=d&&d.charAt(0);d=b&&d==b.type;return b?b.align?b.col-(d?b.width:0):b.indent+(d?0:indentUnit):0}}var h=l("abs acos adddate aes_encrypt aes_decrypt ascii asin atan atan2 avg benchmark bin bit_and bit_count bit_length bit_or cast ceil ceiling char_length character_length coalesce concat concat_ws connection_id conv convert cos cot count curdate current_date current_time current_timestamp current_user curtime database date_add date_format date_sub dayname dayofmonth dayofweek dayofyear decode degrees des_encrypt des_decrypt elt encode encrypt exp export_set extract field find_in_set floor format found_rows from_days from_unixtime get_lock greatest group_unique_users hex ifnull inet_aton inet_ntoa instr interval is_free_lock isnull last_insert_id lcase least left length ln load_file locate log log2 log10 lower lpad ltrim make_set master_pos_wait max md5 mid min mod monthname now nullif oct octet_length ord password period_add period_diff pi position pow power quarter quote radians rand release_lock repeat reverse right round rpad rtrim sec_to_time session_user sha sha1 sign sin soundex space sqrt std stddev strcmp subdate substring substring_index sum sysdate system_user tan time_format time_to_sec to_days trim ucase unique_users unix_timestamp upper user version week weekday yearweek".split(" ")),
f=l("alter grant revoke primary key table start top transaction select update insert delete create describe from into values where join inner left natural and or in not xor like using on order group by asc desc limit offset union all as distinct set commit rollback replace view database separator if exists null truncate status show lock unique having drop procedure begin end delimiter call else leave declare temporary then definer event schedule comment enable disable slave".split(" ")),q=l("bigint binary bit blob bool char character date datetime dec decimal double enum float float4 float8 int int1 int2 int3 int4 int8 integer long longblob longtext mediumblob mediumint mediumtext middleint nchar numeric real set smallint text time timestamp tinyblob tinyint tinytext varbinary varchar year".split(" ")),
k=l(":= < <= == <> > >= like rlike in xor between".split(" ")),m=/[*+\-<>=&|:\/]/,n={},p=function(){function b(c,b){var a=c.next();if("@"==a||"$"==a)return c.nextWhileMatches(/[\w\d]/),"sql-var";if("["==a)return b(d(a)),null;if('"'==a||"'"==a||"`"==a)return b(g(a)),null;if(","==a||";"==a)return"sql-separator";if("#"==a){for(;!c.endOfLine();)c.next();return"sql-comment"}if("-"==a){if("-"==c.peek()){for(;!c.endOfLine();)c.next();return"sql-comment"}return/\d/.test(c.peek())?(c.nextWhileMatches(/\d/),
"."==c.peek()&&(c.next(),c.nextWhileMatches(/\d/)),"sql-number"):"sql-operator"}if(m.test(a)){if("/"==a&&"*"==c.peek())return b(e("sql-comment","*/")),null;c.nextWhileMatches(m);return"sql-operator"}if(/\d/.test(a))return c.nextWhileMatches(/\d/),"."==c.peek()&&(c.next(),c.nextWhileMatches(/\d/)),"sql-number";if(/[()]/.test(a))return"sql-punctuation";c.nextWhileMatches(/[_\w\d]/);a=c.get();return{style:k.test(a)?"sql-operator":f.test(a)?"sql-keyword":h.test(a)?"sql-function":q.test(a)?"sql-type":
"sql-word",content:a}}function d(c){return function(c,a){for(;!c.endOfLine();)if("]"==c.next()){a(b);break}return"sql-word"}}function g(c){return function(d,a){for(var e=!1;!d.endOfLine();){var g=d.next();if(g==c&&!e){a(b);break}e="T-SQL"==n.extension?!e&&c==g&&d.equals(c):!e&&"\\"==g}return"`"==c?"sql-quoted-word":"sql-literal"}}function e(c,d){return function(a,e){for(;!a.endOfLine();){if(a.lookAhead(d,!0)){e(b);break}a.next()}return c}}return function(c,d){return tokenizer(c,d||b)}}();return{make:function(b){function d(a,
d,b){e={prev:e,indent:c,col:f,type:a,width:d,align:b}}var h=p(b),e=null,c=0,f=0,a={next:function(){var a=h.next(),b=a.style,k=a.content,l=a.value.length;"\n"==k?(a.indentation=g(e),c=f=0,e&&null==e.align&&(e.align=!1)):"whitespace"==b&&0==f?c=l:e||"sql-comment"==b||d(";",0,!1);"\n"!=k&&(f+=l);"sql-punctuation"==b?"("==k?d(")",l):")"==k&&(e=e.prev):"sql-separator"==b&&";"==k&&e&&!e.prev&&(e=e.prev);return a},copy:function(){var b=e,d=c,g=f,k=h.state;return function(l){h=p(l,k);e=b;c=d;f=g;return a}}};
return a},electricChars:")",configure:function(b){for(var d in b)b.hasOwnProperty(d)&&(n[d]=b[d])}}}(),StopIteration={toString:function(){return"StopIteration"}},indentUnit=2;
(function(){function l(g){for(var h="",f=0;f<indentUnit;f++)h+=" ";g=g.replace(/\t/g,h).replace(/\u00a0/g," ").replace(/\r\n?/g,"\n");var l=0,k=[];g=g.split("\n");for(h=0;h<g.length;h++)0!=h&&k.push("\n"),k.push(g[h]);return{next:function(){if(l<k.length)return k[l++];throw StopIteration;}}}window.highlightSql=function(g,h,f){parser=(SqlParser||Editor.Parser).make(stringStream(l(f)));var q=1;callback=function(b){h.append(document.createTextNode(String(q++)));h.append(document.createElement("BR"));
for(var d=0;d<b.length;d++)g.append(b[d]);g.append(document.createElement("BR"))};f=[];if(1==callback.nodeType){var k=callback;callback=function(b){for(var d=0;d<b.length;d++)k.appendChild(b[d]);k.appendChild(document.createElement("br"))}}try{for(;;){var m=parser.next();if("\n"==m.value)callback(f),f=[];else{var n=document.createElement("span");n.className=m.style;n.appendChild(document.createTextNode(m.value));f.push(n)}}}catch(p){if(p!=StopIteration)throw p;}f.length&&callback(f)}})();

