/* Copyright (c) 2006-2007, Apple Inc. All rights reserved. */
/* Compressed JavaScript. Do not modify. */


/* editor.js */

var JSEditor=Class.create();JSEditor.prototype={mUseDesignMode:MozillaFixes.isGecko,mCleanupTimeout:10,mEditMode:false,mService:'wiki',mDefaultImageURL:'',mDefaultLinkURL:'',mButtons:[['header_button','lists_button','forecolor_button','createlink_button'],['image_button','attach_button','table_button','html_button']],mHeaderPopupOptions:['p','blockquote','pre','h1','h2','h3'],mListsPopupOptions:['insertunorderedlist','insertorderedlist','-','outdent','indent'],mInlineStyles:['color_none','bold','italic','underline','forecolor_important','forecolor_emphasis','backcolor_highlight'],initialize:function(inElement){bindEventListeners(this,['handleToolbarMouseDown','handleEditButtonClick','handleHeaderStyleClick','handleInlineStyleClick','handleListsMenuItemClick','handleEditorFocus','handleEditorBlur','handleEditorKeypress','handleEditorMouseUp','handleEditorClick','handleFileDragOver','handleFileDrop','handlePaste','handleCancelClick','handleDocumentKeypress']);this.mStylesheets=new Array();this.mElement=$(inElement);this.mButtonFuncs=this.mButtons.inject([],function(arr,subarr){subarr.each(function(item){arr.push(item.replace(/_button/,''))});return arr;});Element.cleanWhitespace(this.mElement);var aStyleElms=document.getElementsByTagName('link');for(var i=0,c=aStyleElms.length;i<c;i++){var elm=aStyleElms[i];if(elm.getAttribute('rel')=='stylesheet'&&elm.getAttribute('media')&&elm.getAttribute('media').indexOf('screen')!=-1){this.mStylesheets.push(elm.getAttribute('href'));}}
if(arguments.length>1)Object.extend(this,arguments[1]);this.addHeaderAndStylePopups();this.addToolbarItems();observeEvents(this,d,{keypress:'handleDocumentKeypress'});},addHeaderAndStylePopups:function(){this.mHeaderPopup=gPopupManager.createPopupElement('toolbarpopup');this.mHeaderPopupOptions.each(function(blockType){var contents=Builder.node('span',{className:blockType},[Loc.wysiwyg_header_popup[blockType]||blockType]);var item=gPopupManager.itemWithTitle(this.mHeaderPopup,"\u00A0",null,this.handleHeaderStyleClick);replaceElementContents(item,contents);}.bind(this));this.mListsPopup=gPopupManager.createPopupElement('toolbarpopup');this.mListsPopupOptions.each(function(listPopupItem){if(listPopupItem=='-'){gPopupManager.divider(this.mListsPopup);return true;}
var sText='';switch(listPopupItem){case'indent':sText+='>';break;case'insertorderedlist':sText+='1.';break;case'insertunorderedlist':sText+='•';break;case'outdent':sText+='<';break;}
var oTitle=Builder.node('span',{className:'titleWithPrefix'},[Builder.node('span',{className:'prefix'},[sText]),Builder.node('span',{className:'title'},Loc.wysiwyg_lists_popup[listPopupItem])]);var item=gPopupManager.itemWithTitle(this.mListsPopup,oTitle,null,this.handleListsMenuItemClick);item.id='lists_popup_'+listPopupItem;}.bind(this));this.mStylePopup=gPopupManager.createPopupElement('toolbarpopup');this.mColorKey={};this.mStylePopup.style.visibility='hidden';Element.show(this.mStylePopup);var hasDrawnSeparator=false;this.mInlineStyles.each(function(s,i){if((!hasDrawnSeparator)&&s.match(/.+color_/)){hasDrawnSeparator=true;gPopupManager.divider(this.mStylePopup);}
var item=gPopupManager.itemWithTitle(this.mStylePopup,(Loc.wysiwyg_forecolor_popup[s]||s),null,this.handleInlineStyleClick);var exampleElm=Builder.node('span',{className:'forecolor_example custom_'+s},["T"]);insertAtBeginning(Builder.node('span',{className:'forecolor_example_container'},[exampleElm," "]),item);var styleKey=s.indexOf('backcolor')>=0?'background-color':'color';this.mColorKey['custom_'+s]=[styleKey,Element.getStyle(exampleElm,styleKey)];}.bind(this));this.mStylePopup.style.visibility='';Element.hide(this.mStylePopup);},addToolbarItems:function(){var tb=gToolbar.mEditToolbar;this.mButtons.each(function(set){gToolbar.addButtonsToToolbar(tb,set,this.handleToolbarMouseDown);}.bind(this));var ul=gToolbar.addButtonsToToolbar(tb,['done_button','cancel_button']);ul.className='tbactions';this.mDoneButton=$('done_button');this.mStyleButton=$('forecolor_button');if(this.mStyleButton){a=this.mStyleButton.getElementsByTagName('a').item(0);replaceElementContents(a,'S'),a.id='forecolor_link';}
gToolbar.setToolbarButtonCallback(this.mDoneButton,this.handleEditButtonClick);gToolbar.setToolbarButtonCallback('cancel_button',this.handleCancelClick);return true;},resetToolbarState:function(){$A(this.mToolbarRow.childNodes).each(function(cell){delete cell.down('a').style.opacity;if(IEFixes.isIE)delete cell.down('a').style.filter;});},updateToolbarState:function(){if(this.mEditMode){this.mButtonFuncs.each(function(jsfunction){var cell=$(jsfunction+'_button');if(!cell)alert('cell not found');var enabled=false;switch(jsfunction){case'header':try{enabled=this.d.queryCommandEnabled('formatblock')&&this.mHasFocus;}
catch(e){enabled=false;}
break;case'image':case'table':case'attach':enabled=(!this.mHTMLEditField);break;case'html':enabled=true;break;case'createlink':enabled=true;break;case'lists':try{enabled=this.d.queryCommandEnabled('insertorderedlist')&&this.mHasFocus&&(!this.isFormattedBlockSelected());}
catch(e){enabled=false;}
break;default:try{enabled=this.d.queryCommandEnabled(jsfunction)&&this.mHasFocus&&(!this.isFormattedBlockSelected());}
catch(e){enabled=false;}}
var wasEnabled=(cell.className.match(/enabled/)!=null);if(enabled==wasEnabled)return true;var opacity=0.99999;if(enabled){Element.removeClassName(cell,'disabled');Element.addClassName(cell,'enabled');}else{Element.removeClassName(cell,'enabled');Element.addClassName(cell,'disabled');opacity=0.3;}
cell.down('a').style.opacity=opacity;if(IEFixes.isIE)cell.down('a').style.filter='alpha(opacity:'+(opacity*100)+')';}.bind(this));}},showImageDialog:function(){var url=prompt('Image URL:',this.mDefaultImageURL);if(url)this.insertImage(url);},insertImage:function(inImageURL,inOptWidth,inOptHeight,inOptID){var str='<img src="'+inImageURL+'"';if(inOptWidth)str+=' width="'+inOptWidth+'"';if(inOptHeight)str+=' height="'+inOptHeight+'"';if(inOptID)str+=' id="'+inOptID+'"';str+=' alt="" />';this.insertHTML(str);},showTableDialog:function(){if(!this.mTableDialog)this.mTableDialog=new ModalTableDialogManager({mDocument:this.d});this.mTableDialog.drawDialog('tableDialog',null);},insertTable:function(inHTMLString,inEditedTable){if(inEditedTable){Element.addClassName(inEditedTable,'data');if(IEFixes.isIE){var sID=inEditedTable.id;var sClass=inEditedTable.className;var div=d.createElement('div');inEditedTable.parentNode.insertBefore(div,inEditedTable);Element.remove(inEditedTable);div.innerHTML='<table>'+inHTMLString+'</table>';inEditedTable=div.childNodes.item(0);inEditedTable.className=sClass;if(sID)inEditedTable.id=sID;promoteElementChildren(div);}else{inEditedTable.innerHTML=inHTMLString;}}else{this.insertHTML('<table class="data __useTableEditor">'+inHTMLString+'</table>');}
movableTable().collapseTablesAfterEditing();movableTable().expandTablesForEditing();},insertHTML:function(inHTML){if(IEFixes.isIE){if(this.d.selection.type=='None'){this.mEditorBody.innerHTML=this.mEditorBody.innerHTML+inHTML;}
else{var rng=this.d.selection.createRange();rng.pasteHTML(inHTML);}}
else{if(this.d.queryCommandEnabled('inserthtml')&&this.mSelectionManager.mSelection){this.d.execCommand('inserthtml',false,inHTML);}
else{if(this.mUseDesignMode)this.d.designMode='off';this.mEditorBody.firstChild.innerHTML+=inHTML;if(this.mUseDesignMode)this.d.designMode='on';movableTable().collapseTablesAfterEditing();movableTable().expandTablesForEditing();}}},fixInlineStyles:function(){$A(this.mEditorBody.getElementsByTagName("*")).each(function(elm){if(elm.style&&elm.nodeName.toLowerCase()!='a'){if(elm.style.fontWeight=='bold')changeNodeName(elm,'b');else if(elm.style.fontStyle=='italic')changeNodeName(elm,'i');else if(elm.style.textDecoration=='underline')changeNodeName(elm,'u');else if(elm.style.fontWeight=='normal')Element.addClassName(elm,'wiki_unbold');else if(elm.style.fontStyle=='normal')Element.addClassName(elm,'wiki_unitalic');else if(elm.style.textDecoration=='none')Element.addClassName(elm,'wiki_ununderline');}});$$('.wiki_unbold').each(function(elm){Element.unwrap(elm,'b',function(){return Builder.node('b')});});$$('.wiki_unitalic').each(function(elm){Element.unwrap(elm,'i',function(){return Builder.node('i')});});$$('.wiki_ununderline').each(function(elm){Element.unwrap(elm,'u',function(){return Builder.node('u')});});$A(this.mEditorBody.getElementsByTagName('span')).each(function(elm){if(Element.hasClassName(elm,'Apple-style-span')){Element.removeClassName('Apple-style-span');if(!elm.className.match(/\S/))promoteElementChildren(elm);}});$A(this.mEditorBody.getElementsByTagName('br')).each(function(elm){Element.removeClassName(elm,'webkit-block-placeholder');});},exchangeStylesForClasses:function(){$H(this.mColorKey).each(function(c){$A(this.mEditorBody.getElementsByTagName("*")).each(function(elm){if(elm.style&&(elm.style[c.value[0]]==c.value[1])){elm.style[c.value[0]]='';if(c.key!='custom_color_none')Element.addClassName(elm,c.key);}});}.bind(this));this.fixInlineStyles();},exchangeClassesForStyles:function(){$H(this.mColorKey).each(function(c){$A(this.mEditorBody.getElementsByTagName("*")).each(function(elm){if(Element.hasClassName(elm,c.key)){elm.style[c.value[0]]=c.value[1];Element.removeClassName(elm,c.key);}});}.bind(this));},addLinkTargets:function(inOptElement){var bodyElm=(inOptElement?$(inOptElement):this.mEditorBody);$A(bodyElm.getElementsByTagName('a')).each(function(elm){if(!elm.getAttribute('target'))elm.setAttribute('target','wiki_link_preview');});},removeLinkTargets:function(inOptElement){var bodyElm=(inOptElement?$(inOptElement):this.mEditorBody);$A(bodyElm.getElementsByTagName('a')).each(function(elm){if(elm.getAttribute('target')=='wiki_link_preview')elm.removeAttribute('target');});},getHTML:function(){if(this.mHTMLEditField)this.mEditorBody.innerHTML=$F(this.mHTMLEditField);this.exchangeStylesForClasses();this.removeLinkTargets(this.mEditorDiv);movableTable().collapseTablesAfterEditing(this.mEditorBody);return this.mEditorBody.innerHTML;},setHTML:function(inHTML){if(this.mHTMLEditField){this.mHTMLEditField.value=inHTML;}
else{this.mEditorBody.innerHTML=inHTML;this.exchangeClassesForStyles();this.addLinkTargets();}},showLinkDialog:function(){var url=prompt('URL:',this.mDefaultLinkURL);if(url)this.createLink(url);},createLink:function(inLinkURL,inOptTitle){try{this.mSelectionManager.retrieve()}catch(e){};var command=((inLinkURL&&(inLinkURL!=''))?'createlink':'unlink');if(this.mSelectionManager.isEmptySelection()){var linkUrlMatch=inLinkURL.match(/\/([^\/])$/);var linkTitle=inOptTitle||(linkUrlMatch?linkUrlMatch[1]:inLinkURL);this.insertHTML('<a href="'+inLinkURL+'">'+linkTitle.escapeHTML()+'</a>');}
else{this.d.execCommand(command,false,inLinkURL);}
this.addLinkTargets();},showAttachDialog:function(){},getUpdateDictionary:function(){return{content:this.cleanForSaving(this.getHTML())};},saveDocument:function(){dialogManager().showProgressMessage('save_page_dialog_progress');var updateDictionary=this.getUpdateDictionary();this.mSaveRequest=server()[this.mService].updateEntry(this.gotSaveDocumentResponse.bind(this),this.mPageUID,updateDictionary).makeRequired();},gotSaveDocumentResponse:function(inRequestObj,inResponseObj){dialogManager().hide();gNotifier.print(Loc.document_saved);if(this.mEditorDiv.nodeName.toLowerCase()=='div'){replaceElementContents(this.mEditorDiv,inResponseObj.content,true);}
this.cleanElementAfterEditing(this.mEditorDiv,inResponseObj);},cleanElementForEditing:function(inElement){},cleanElementAfterEditing:function(inElement,inResponseDict){},getSelection:function(){return(this.mEditorWindow.getSelection?this.mEditorWindow.getSelection():document.selection);},isFormattedBlockSelected:function(){var sel=this.getSelection();for(var i=0;i<sel.rangeCount;i++){var rng=sel.getRangeAt(i);var found=this.mHeaderPopupOptions.detect(function(h){var elm=rng.commonAncestorContainer;if(h!='p'){if(elm.getElementsByTagName&&elm.getElementsByTagName(h).length>0)return true;while(elm.parentNode){if(elm.nodeName.toLowerCase()==h.toLowerCase())return true;elm=elm.parentNode;}}
return false;});if(found)return true;}
return false;},switchToEditor:function(){if(SafariFixes.isTigerSafari)alert(Loc.edit_unsupported_error);gToolbar.expandToolbar();var afterFinish=function(){this.updateToolbarState();}.bind(this);var oldDiv=$('editable_content');this.addLinkTargets(oldDiv);this.cleanElementForEditing(oldDiv);if(oldDiv.childNodes.length==0)replaceElementContents(oldDiv,'<br>',true);if(this.mUseDesignMode){var loc=(d.getElementsByTagName('base').length>0)?d.getElementsByTagName('base').item(0).href:location.href;var ssLinks=this.mStylesheets.inject('',function(str,ss){return str+'<link media="screen,projection" rel="stylesheet" href="'+ss+'">'});var contents=oldDiv.innerHTML;this.mEditorFrame=Builder.node('iframe',{id:'editable_content',name:'editable_content',title:Loc.editorFrameTitle,style:'visibility:hidden;height:200px;width:99%'});insertAfter(this.mEditorFrame,oldDiv);this.mEditorWindow=this.mEditorFrame.contentWindow;this.d=this.mEditorWindow.document;this.d.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html class="editorIframe" lang="'+Loc.bodyLangAttribute+'"><head><base href="'+loc+'" /><meta http-equiv="Content-Type" content="text/html;charset="utf-8" />'+ssLinks+'</head><body>'+contents+'</body></html>');var setupEditorBody=function(){if(this.d&&this.d.body){this.mEditorBody=this.d.body;this.mOriginalText=this.mEditorBody.innerHTML;movableTable().expandTablesForEditing(this.mEditorBody);this.exchangeClassesForStyles();if(this.setupEditor)this.setupEditor(this.mEditorBody);this.mEditorWindow.focus();var clickCallback=function(){return true;}
this.d.onmousedown=clickCallback;this.mEditorBody.onmousedown=clickCallback;this.mEditorFrame.onmousedown=clickCallback;}
else{setTimeout(setupEditorBody.bind(this),100);}}
afterFinish=function(){this.updateToolbarState();this.mEditorFrame.style.visibility='visible';Element.remove(oldDiv);this.mViewSprings=new ViewSprings(this.mEditorFrame,null,this.mSidebarElement);this.mViewSprings.boing();setTimeout(setupEditorBody.bind(this),100);}.bind(this);this.d.close();this.d.designMode='on';}
else{Object.extend(oldDiv,{ondragover:this.handleFileDragOver,ondrop:this.handleFileDrop,onpaste:this.handlePaste});this.mEditorWindow=window;this.d=d;this.mEditorFrame=oldDiv;this.mEditorBody=oldDiv;afterFinish=function(){this.updateToolbarState();Element.addClassName(oldDiv,'contenteditable');this.exchangeClassesForStyles();oldDiv.contentEditable=true;this.mOriginalText=this.mEditorBody.innerHTML;movableTable().expandTablesForEditing(this.mEditorBody);this.mViewSprings=new ViewSprings(this.mEditorFrame,null,this.mSidebarElement);this.mViewSprings.boing();if(this.setupEditor)this.setupEditor(this.mEditorBody);}.bind(this);}
this.mSelectionManager=new JSSelectionManager({mDocument:this.d,mWindow:this.mEditorWindow,mRetrieveCallback:this.updateToolbarState.bind(this)});observeEvents(this,this.d,{focus:'handleEditorFocus',blur:'handleEditorBlur',mousedown:'handleEditorClick',mouseup:'handleEditorMouseUp',keypress:'handleEditorKeypress'});if(this.mUseDesignMode)observeEvents(this,this.d,{keypress:'handleEditorKeypress'});else observeEvents(this,this.d.getElementById('editable_content'),{keypress:'handleEditorKeypress'});this.mPageUID=CollabUID.sharedInstance().mValue;this.mHasFocus=false;afterFinish();},switchToDisplay:function(inOptRevert){if(this.mHTMLEditField)this.toggleHTMLMode();gToolbar.collapseToolbar();stopObservingEvents(this,this.d,{focus:'handleEditorFocus',blur:'handleEditorBlur',mousedown:'handleEditorClick',mouseup:'handleEditorMouseUp'});if(this.mViewSprings){this.mViewSprings.destroy();delete this.mViewSprings;}
if(this.mUseDesignMode)stopObservingEvents(this,this.d,{keypress:'handleEditorKeypress'});else stopObservingEvents(this,this.d.getElementById('editable_content'),{keypress:'handleEditorKeypress'});var afterFinish=function(){};if(this.mUseDesignMode){var content=this.getHTML();this.d.designMode='off';delete this.mSelectionManager;delete this.mTableDialog;if($('tableDialog'))Element.remove($('tableDialog'));var div=d.createElement('div');div.id='editable_content';replaceElementContents(div,(inOptRevert?this.mOriginalText:content),true);var iframe=this.mEditorFrame;insertAfter(div,iframe);Element.remove(iframe);delete this.mEditorFrame;delete this.d;this.mEditorDiv=div;}
else{if(inOptRevert)this.setHTML(this.mOriginalText);this.mEditorFrame.style.height='';Element.removeClassName(this.mEditorFrame,'contenteditable');blur();this.mEditorFrame.contentEditable=false;var div=d.createElement('div');this.mEditorFrame.parentNode.insertBefore(div,this.mEditorFrame);Element.remove(this.mEditorFrame);div.parentNode.insertBefore(this.mEditorFrame,div);Element.remove(div);this.mEditorDiv=this.mEditorFrame;delete this.mEditorFrame;delete this.d;}},hideComments:function(){if($('comments'))Element.hide($('comments'));},showComments:function(){if($('comments'))Element.show($('comments'));},cleanForSaving:function(inString){inString=inString.replace(/&nbsp;/gi,' ').replace(/ /g,' ');inString=inString.replace(/<([^<>]+)href="wiki\//g,'<$1href=\"/'+uid().mBasePath+'/wiki/');inString=inString.replace(/<pre>[\s\t\n\r]*<\/pre>/gi,'');inString=inString.replace(/<([\/]*)li([^<>]*)>[\s\t\n\r]*<br[^<>]*>/gi,'<$1li$2>').replace(/<br[^<>]*>[\s\t\n\r]*<([\/]*)li([^<>]*)>/gi,'<$1li$2>');return inString;},toggleEditMode:function(inOptBypassSave){if(this.mHTMLEditField){var content=$F(this.mHTMLEditField);Element.remove(this.mHTMLEditField);this.mHTMLEditField=null;this.setHTML(content);Element.show(this.mEditorFrame);}
this.mEditMode=!this.mEditMode;if(this.mEffect)this.mEffect.cancel();if(this.mEditMode){this.hideComments();this.switchToEditor();}else{this.showComments();if(!inOptBypassSave){try{this.saveDocument()}catch(e){}}
this.switchToDisplay(inOptBypassSave);if(inOptBypassSave){this.cleanElementAfterEditing(this.mElement.lastChild);this.removeLinkTargets(this.mElement.lastChild);}}},toggleHTMLMode:function(inOptRequestObj,inOptResponseObj){if(inOptRequestObj&&inOptResponseObj&&(inOptRequestObj==this.mFilterRequest)){delete this.mFilterRequest;var content=inOptResponseObj.filteredText;if(this.mHTMLEditField){Element.remove(this.mHTMLEditField);this.mHTMLEditField=null;this.setHTML(content);Element.show(this.mEditorFrame);movableTable().expandTablesForEditing();}
else{this.mHTMLEditField=Builder.node('textarea',{id:'editable_raw_html'},[content]);this.mEditorFrame.parentNode.insertBefore(this.mHTMLEditField,this.mEditorFrame);Position.clone(this.mEditorFrame,this.mHTMLEditField,{setLeft:false,setTop:false,setWidth:false});Element.hide(this.mEditorFrame);this.mHasFocus=false;}
this.updateToolbarState();}
else{this.mFilterRequest=server().wiki.filterText(this.toggleHTMLMode.bind(this),this.getHTML());}},handleToolbarMouseDown:function(inEvent){var elm=Event.findElement(inEvent,'li')
Event.stop(inEvent);this.mSelectionManager.store();var jsfunction=elm.id.replace(/_button/,'');switch(jsfunction){case'header':if(this.mHasFocus){gPopupManager.show(elm,this.mHeaderPopup,[IEFixes.isIE7?-767:0,0]);}
break;case'forecolor':if(this.mHasFocus){gPopupManager.show(elm,this.mStylePopup,[IEFixes.isIE7?-767:0,0]);}
break;case'image':this.showImageDialog();break;case'table':this.showTableDialog();break;case'createlink':this.showLinkDialog();break;case'attach':this.showAttachDialog();break;case'html':this.toggleHTMLMode();break;case'lists':if(this.mHasFocus){gPopupManager.show(elm,this.mListsPopup,[IEFixes.isIE7?-767:0,0]);}
break;default:if(this.mHasFocus&&(!this.isFormattedBlockSelected()))this.d.execCommand(jsfunction,false,null);}
return false;},handleEditButtonClick:function(inEvent){this.toggleEditMode();},handleHeaderStyleClick:function(inEvent){gPopupManager.hide();var elm=Event.findElement(inEvent,'a');try{gEditor.mSelectionManager.retrieve()}catch(e){};var blockType=elm.firstChild.className;if(IEFixes.isIE)blockType='<'+blockType+'>';if(elm&&elm.firstChild){this.d.execCommand('formatblock',false,(IEFixes.isIE?'<p>':'p'));this.d.execCommand('outdent',false,null);this.d.execCommand('formatblock',false,blockType);}
this.mSelectionManager.removeAppleStyleSpan();return false;},handleInlineStyleClick:function(inEvent){var elm=Event.findElement(inEvent,'a').down().down();gPopupManager.hide();try{gEditor.mSelectionManager.retrieve()}catch(e){};if(elm.hasClassName('custom_color_none')){if(this.mSelectionManager.isEmptySelection){if(this.d.queryCommandState('bold'))this.d.execCommand('bold',false,null);if(this.d.queryCommandState('italic'))this.d.execCommand('italic',false,null);if(this.d.queryCommandState('underline'))this.d.execCommand('underline',false,null);this.d.execCommand('foreColor',false,'inherit');this.d.execCommand('backColor',false,'inherit');}
this.d.execCommand('removeformat',false,null);return false;}
var match=elm.className.match(/custom_(\S*)color_\S+/);if((!match)||(!this.mColorKey[match[0]])){match=elm.className.match(/custom_(\S*)/);if(match)this.d.execCommand(match[1],false,null);this.fixInlineStyles();return false;}
if(!IEFixes.isIE)this.d.execCommand('styleWithCSS',false,true);var command=(match[1]=='back')?'BackColor':'ForeColor';var color=this.mColorKey[match[0]][1];if(IEFixes.isIE)color=color.replace(/^#/,'');this.d.execCommand(command,false,color);if(!IEFixes.isIE)this.d.execCommand('styleWithCSS',false,false);return false;},handleListsMenuItemClick:function(inEvent){gPopupManager.hide();var jsfunction=Event.findElement(inEvent,'a').id.match(/lists_popup_(.+)$/)[1];try{this.mSelectionManager.retrieve()}catch(e){};this.d.execCommand(jsfunction,false,null);return false;},handleEditorFocus:function(inEvent){this.mHasFocus=true;this.updateToolbarState();},handleEditorMouseUp:function(inEvent){this.handleEditorFocus();if(!MozillaFixes.isGecko)movableTable().checkEditor(this.d);this.checkEventForTable(inEvent);},handleEditorBlur:function(inEvent){this.mHasFocus=false;this.updateToolbarState();},handleEditorKeypress:function(inEvent){if((inEvent.keyCode==Event.KEY_RETURN)){var callback=function(){var selection=this.getSelection();var currentNode=null;if(selection&&selection.rangeCount>0){currentNode=selection.getRangeAt(0).startContainer;}
else if(selection&&selection.anchorNode){currentNode=selection.anchorNode;}
while(currentNode){if(currentNode.nodeName&&currentNode.nodeName.match(/[Hh]\d/)){if(currentNode.innerText&&(!currentNode.innerText.match(/\S/)))this.d.execCommand('formatblock',false,'p');break;}
currentNode=currentNode.parentNode;}};setTimeout(callback.bind(this),this.mCleanupTimeout);}
else if(SafariFixes.isWebKit&&(inEvent.keyCode==32)){var sel=window.getSelection();var pnode=sel.anchorNode.parentNode;if(pnode.nodeName.toLowerCase()=='a'&&sel.anchorNode.nodeValue&&sel.anchorOffset==sel.anchorNode.nodeValue.length){Event.stop(inEvent);var textNode=this.d.createTextNode("\u00A0");insertAfter(textNode,pnode);var styleSpan=pnode.up('span.Apple-style-span');if(styleSpan&&styleSpan.style.textDecoration=='underline')promoteElementChildren(styleSpan);sel.setBaseAndExtent(textNode,1,textNode,1);}}
this.updateToolbarState();if(this.mUseDesignMode)this.handleDocumentKeypress(inEvent);},handleEditorClick:function(inEvent){this.handleEditorFocus(inEvent);},handleFileDragOver:function(inEvent){if(inEvent&&inEvent.dataTransfer&&inEvent.dataTransfer.types&&$A(inEvent.dataTransfer.types).indexOf('text/uri-list')>0&&inEvent.srcElement&&inEvent.srcElement.src&&(inEvent.srcElement.src.match(/^file:/i)||inEvent.srcElement.src.match(/^webkit-fake-url:/i)))return false;return true;},handleFileDrop:function(inEvent){alert(Loc.image_dragdrop_error)
return true;},handlePaste:function(inEvent){var lookForLocalImages=function(){var foundLocalImage=false;$A(this.mEditorBody.getElementsByTagName('img')).each(function(img){if(!img.src)return true;if(img.src.match(/^file:/i)||img.src.match(/^webkit-fake-url:/i)){foundLocalImage=true;$(img).remove();}});if(foundLocalImage)alert(Loc.image_dragdrop_error);}
setTimeout(lookForLocalImages.bind(this),100);},handleCancelClick:function(inEvent){this.toggleEditMode(true);return false;},handleDocumentKeypress:function(inEvent){},checkEventForTable:function(inEvent,inOptTable){var table='';if(inOptTable){table=inOptTable;}else{var elm=Event.element(inEvent);var tagName='table';table=Event.findElement(inEvent,tagName);if(inEvent.type.indexOf('key')==0){if(this.getSelection().focusNode&&this.getSelection().focusNode.parentNode){elm=this.getSelection().focusNode.parentNode;var parent=elm;while(parent.parentNode&&(!parent.tagName||(parent.tagName.toLowerCase()!=tagName.toLowerCase()))){parent=parent.parentNode;}
table=parent;}}}
if(!table||((!this.mUseDesignMode)&&!Element.childOf(table,$('editable_content'))))return;if($('tableDialog'))Element.remove('tableDialog');if(typeof table.tagName!='undefined'&&table.tagName.toLowerCase()=='table'){if(table){if(Element.hasClassName(table,'__doNotUseTableEditor')){return;}else if(!Element.hasClassName(table,'__useTableEditor')){if(!window.confirm(Loc.table_dialog_use_editor)){Element.addClassName(table,'__doNotUseTableEditor');return;}else{Element.addClassName(table,'__useTableEditor');}}}
if(!this.mTableDialog)this.mTableDialog=new ModalTableDialogManager({mDocument:this.d});this.mTableDialog.mCurrentTable=table||null;this.mTableDialog.drawDialog('tableDialog',table);Event.stop(inEvent);}else{if(typeof this.mTableDialog!='undefined')delete this.mTableDialog;if($('tableDialog'))Element.remove($('tableDialog'));}}}
var JSSelectionManager=Class.create();JSSelectionManager.prototype={initialize:function(){this.mDocument=document;this.mWindow=window;if(arguments.length>0)Object.extend(this,arguments[0]);},store:function(){if(this.mWindow.getSelection){var sel=this.mWindow.getSelection();if(sel)this.mSelection={anchorNode:sel.anchorNode,anchorOffset:sel.anchorOffset,focusNode:sel.focusNode,focusOffset:sel.focusOffset};if(!sel||!this.mSelection.anchorNode)this.mSelection=null;}
else if(this.mDocument.selection&&this.mDocument.selection.createRange){this.mSelection=this.mDocument.selection.createRange();}
else{this.mSelection=null;}},getSelectedString:function(){var str='';if(this.mWindow.getSelection&&this.mWindow.getSelection.toString){str=this.mWindow.getSelection().toString()||'';}
else if(this.mDocument.selection&&this.mDocument.selection.createRange){str=this.mDocument.selection.createRange().text.replace(/^\s+/,'').replace(/\s+$/,'');}
return str;},retrieve:function(){if(this.mSelection){if(this.mWindow.getSelection){var sel=this.mWindow.getSelection();if(sel.setBaseAndExtent){sel.setBaseAndExtent(this.mSelection.anchorNode,this.mSelection.anchorOffset,this.mSelection.focusNode,this.mSelection.focusOffset);}
else if(this.mDocument.createRange){var rng=this.mDocument.createRange();rng.setStart(this.mSelection.anchorNode,this.mSelection.anchorOffset);rng.setEnd(this.mSelection.focusNode,this.mSelection.focusOffset);sel.removeAllRanges();sel.addRange(rng);this.mWindow.focus();}}
else if(this.mDocument.selection&&this.mDocument.selection.createRange){this.mSelection.select();}
if(this.mRetrieveCallback)this.mRetrieveCallback();}},moveCursorToBeginning:function(){var elm=this.mDocument;var wikiEntryDivs=document.getElementsByClassName('wiki_entry',this.mDocument);if(wikiEntryDivs.length>0)elm=wikiEntryDivs[0];var sel=null;if(this.mWindow.getSelection)sel=this.mWindow.getSelection();if(sel){if(sel.setBaseAndExtent){sel.setBaseAndExtent(elm,0,elm,0);}
else if(sel.selectAllChildren){sel.selectAllChildren(elm);sel.collapseToStart();}}
else if(this.mDocument.selection&&this.mDocument.selection.createRange){var rng=this.mDocument.body.createTextRange();rng.moveToElementText(elm);rng.select();rng.moveEnd('character',rng.text.length*(-1));rng.select();}},isEmptySelection:function(){var sel=null;if(this.mWindow.getSelection)sel=this.mWindow.getSelection();if(sel){return(sel.anchorNode==sel.focusNode&&sel.anchorOffset==sel.focusOffset);}
else if(this.mDocument.selection&&this.mDocument.selection.type){return this.mDocument.selection.type=='None';}
return true;},selectElementChildren:function(inElement){var elm=$(inElement);if(!elm)return false;var sel=null;if(this.mWindow.getSelection)sel=this.mWindow.getSelection();if(sel){if(sel.setBaseAndExtent){sel.setBaseAndExtent(elm,0,elm,Math.max(elm.innerText.length-1,0));}
else if(sel.selectAllChildren){sel.selectAllChildren(elm);}}
else if(this.mDocument.selection&&this.mDocument.body.createTextRange){var rng=this.mDocument.body.createTextRange();rng.moveToElementText(elm);rng.select();}},removeAppleStyleSpan:function(){if(!SafariFixes.isWebKit)return true;var sel=this.mWindow.getSelection();if(sel&&sel.anchorNode&&sel.anchorNode.parentNode){var span=$(sel.anchorNode.parentNode).down('span.Apple-style-span');if(span){promoteElementChildren(span);this.selectElementChildren(sel.anchorNode.parentNode);}}}}
if(window.loaded)loaded('editor.js');

/* wiki.js */

gTooltipManager=new TooltipManager();gTagger=null;gPrepareIteration=0;function prepare(inAlwaysRun){if(OperaFixes.isOpera&&gPrepareIteration++>0)return true;if(window.unitTestHandler&&(!inAlwaysRun))return true;drawTooltips();localizeDocument('comments');var isNewPage=/notify=new_page_confirm/.test(d.cookie);server();serverui();gPoofManager=new PoofManager();gNotifier=new Notifier();gToolbar=new Toolbar();gPopupManager=new PopupManager();gNewPageDialogManager=new NewPageDialogManager();gImageThumbnailManager=new ImageThumbnailManager();if(!Element.hasClassName($('wikid'),'grouphome'))gCommentManager=new CommentManager('comments');if($('wysiwyg_container')){gLinkSearchDialogManager=new LinkSearchDialogManager();gLinkPopupManager=new LinkPopupManager();gEditor=new WLTEditor('wysiwyg_container',{mSelectOnEdit:isNewPage});}
if(/\/_/.test(uid().mValue)){gToolbar.mChildren.edit.setEnabled(false);gToolbar.mChildren.add.setCallback(gNewPageDialogManager.handleAddButtonClick.bind(gNewPageDialogManager));}
else if(uid().mValue!='none/none'){gToolbar.mChildren.edit.setCallback(gEditor.handleEditButtonClick);gToolbar.mChildren.add.setCallback(gNewPageDialogManager.handleAddButtonClick.bind(gNewPageDialogManager));gToolbar.mChildren.remove.setCallback(gToolbar.mChildren.remove.clickedButtonCallback.bind(gToolbar.mChildren.remove));gToolbar.mChildren.remove.setEnabled(!(/\/welcome$/.test(uid().mValue)));}
else{gToolbar.mChildren.edit.setEnabled(false);gToolbar.mChildren.add.setEnabled(false);gToolbar.mChildren.remove.setEnabled(false);}
if($('history_link'))gHistoryModeManager=new HistoryModeManager();gModeManager=new ModeManager();gAttachmentExpander=new AttachmentExpander();gQTMediaExpander=new QTMediaExpander();gLinkPreviewGenerator=new LinkPreviewGenerator();if((!$('directory_listing'))&&(!$('login_link'))&&uid().mItemName!='_recentEntries'&&uid().mItemName!='_weblogEntries'){gTagger=new Tagger('apple_collab_tags');}
if(isNewPage)gEditor.handleEditButtonClick();if($('page_listing'))gSidebarUpdater=new SidebarUpdater();gSearchPopup=new SearchPopup();gTombstoneResurrector=new TombstoneResurrector();window.onbeforeunload=function(){return eval("documentShouldUnload()")};}
function drawTooltips(){d.body.appendChild(Builder.node('div',{id:'appointment_tooltip',className:'tooltip',style:'display:none'},[Builder.node('h2',{id:'appointment_tooltip_summary'}),Builder.node('h4',{id:'appointment_tooltip_time_string'}),Builder.node('dl',[Builder.node('dt',Loc.tt_location),Builder.node('dd',{id:'appointment_tooltip_location'}),Builder.node('dt',Loc.tt_description),Builder.node('dd',{id:'appointment_tooltip_description'})])]));}
function documentShouldUnload(){if(($('wysiwyg_container')&&window.gEditor&&window.gEditor.mEditMode)||server().isSavingSomething()){return Loc.unloadConfirm;}}
function reportFrameError(){if(UploadProgressPlaceholder.allPlaceholders)$H(UploadProgressPlaceholder.allPlaceholders).each(function(ph){ph.value.cancel();});dialogManager().hide();alert(Loc.attach_upload_error);}
var Toolbar=Class.create();Toolbar.prototype={initialize:function(){this.mFinalWidth=Toolbar.finalWidth||824;this.draw();this.mChildren={edit:new EditToolbarButton(),add:new AddToolbarButton(),remove:new RemoveToolbarButton()};},draw:function(){this.mMainToolbar=this.buildToolbar('main_toolbar');this.addButtonsToToolbar(this.mMainToolbar,['edit_button','add_button','remove_button']);this.mEditToolbar=this.buildToolbar('edit_toolbar');var form=Builder.node('form',[Builder.node('div',{className:'form'},[Builder.node('input',{type:'text',id:'editing_document_title',title:Loc.editing_document_title,value:'',maxLength:'255'})])]);form.onsubmit=invalidate;this.addElementToToolbar(this.mEditToolbar,form);Element.hide(this.mEditToolbar);insertAtBeginning(Builder.node('div',{id:'toolbars',className:'toolbars'},[this.mMainToolbar,this.mEditToolbar]),'page_toolbar');},buildToolbar:function(inClassName){return Builder.node('div',{className:inClassName},[Builder.node('div',{className:'tbtoolbar'},[Builder.node('div',{className:'start starttoolbar'},[Builder.node('span')]),Builder.node('div',{className:'contents contentstoolbar'}),Builder.node('div',{className:'end endtoolbar'},[Builder.node('span')])])]);},setToolbarButtonCallback:function(inButton,inCallback){if(IEFixes.isIE)$(inButton).unselectable='On';Object.extend($(inButton),{onmousedown:invalidate,onmouseup:invalidate,onclick:inCallback});},addElementToToolbar:function(inToolbar,inElement){inToolbar.firstChild.childNodes.item(1).appendChild(inElement);},addButtonsToToolbar:function(inToolbar,inButtonIDs,inOptCallback){var ul=Builder.node('ul',{className:'tbbuttons'});inButtonIDs.each(function(id){ul.appendChild(Builder.node('li',{id:id,className:'enabled'},[Builder.node('a',{href:'#',title:Loc.tooltips[id]||Loc.toolbar_buttons[id]},[Loc.toolbar_buttons[id]||Loc.tooltips[id]])]));this.setToolbarButtonCallback(ul.lastChild,inOptCallback||invalidate);}.bind(this));this.addElementToToolbar(inToolbar,ul);return ul;},expandToolbar:function(){if(this.mEffect){this.mEffect.cancel();delete this.mEffect;}
this.mOrigWidth=this.mMainToolbar.offsetWidth;this.mEditToolbar.style.width=this.mOrigWidth+'px';this.mEditToolbar.style.opacity=0.01;Element.show(this.mEditToolbar);this.mEffect=new Effect.Parallel([new Effect.ResizeBy(this.mEditToolbar,this.mFinalWidth-this.mOrigWidth,null,{duration:0.4}),new Effect.Opacity('document_title',{from:1.0,to:0.01,duration:0.5}),new Effect.Opacity(this.mMainToolbar,{from:1.0,to:0.01,duration:0.5}),new Effect.Appear(this.mEditToolbar,{duration:0.55})],{});},collapseToolbar:function(){if(this.mEffect){this.mEffect.cancel();delete this.mEffect;}
this.mEffect=new Effect.Parallel([new Effect.ResizeBy(this.mEditToolbar,this.mOrigWidth-this.mFinalWidth,null,{duration:0.4}),new Effect.Appear('document_title',{duration:0.4}),new Effect.Fade(this.mEditToolbar,{duration:0.4}),new Effect.Appear(this.mMainToolbar,{duration:0.55})],{});}}
var ToolbarButton=Class.create();ToolbarButton.prototype={finishInitialize:function(){bindEventListeners(this,['clickedButton']);},enabled:function(){var a=$(this.mElement).down('a');if(!a)return true;return(a.style.cursor!='default');},setEnabled:function(inEnable){var opacity=0.99999;if(inEnable){Element.removeClassName(this.mElement,'disabled');Element.addClassName(this.mElement,'enabled');}else{Element.removeClassName(this.mElement,'enabled');Element.addClassName(this.mElement,'disabled');opacity=0.3;}
this.mElement.down('a').style.opacity=opacity;if(IEFixes.isIE)this.mElement.down('a').style.filter='alpha(opacity:'+(opacity*100)+')';var a=$(this.mElement).down('a');if(a)a.style.cursor=inEnable?'':'default';},setCallback:function(inCallback){this.clickedButtonCallback=inCallback;gToolbar.setToolbarButtonCallback(this.mElement,this.clickedButton);this.setEnabled(this.clickedButton);},clickedButton:function(e){if(this.clickedButtonCallback&&this.enabled())this.clickedButtonCallback(e);return false;}}
var EditToolbarButton=Class.create();Object.extend(Object.extend(EditToolbarButton.prototype,ToolbarButton.prototype),{initialize:function(){this.mElement=$('edit_button');this.finishInitialize();}});var AddToolbarButton=Class.create();Object.extend(Object.extend(AddToolbarButton.prototype,ToolbarButton.prototype),{initialize:function(){this.mElement=$('add_button');this.finishInitialize();}});var RemoveToolbarButton=Class.create();Object.extend(Object.extend(RemoveToolbarButton.prototype,ToolbarButton.prototype),{mIsVersioned:true,initialize:function(){this.mElement=$('remove_button');this.finishInitialize();},drawDialog:function(){if(!this.mDeleteConfirmDialog){var fields=[];if(this.mIsVersioned&&this.mIsAdmin){fields.push({label:'',contents:'<label for="delete_page_confirm_permanent_delete"><input id="delete_page_confirm_permanent_delete" type="checkbox" />'+Loc.delete_page_confirm_permanent_delete+'</label>'});}
this.mDeleteConfirmDialog=dialogManager().drawDialog('delete_page_confirm',fields,'delete_page_confirm_ok');}
var delCheckbox=$('delete_page_confirm_permanent_delete');var callback=function(){var command=((!this.mIsVersioned)||(delCheckbox&&delCheckbox.checked))?'permanentlyDeleteEntry':'deleteEntry';dialogManager().showProgressMessage('delete_page_progress');server()[uid().mService][command](this.gotDeleteEntryResponse.bind(this),uid().mValue);}
targetedDialogManager().show(this.mDeleteConfirmDialog,null,callback.bind(this),'remove_button');},clickedButtonCallback:function(e){if(this.enabled())serverui().ensureLogin(this.deletePage.bind(this));},deletePage:function(){if(this.mIsVersioned&&(!this.mIsAdmin)){var adminAccessCallback=function(){this.mIsAdmin=true;this.drawDialog();}
var noAdminAccessCallback=function(){this.mIsAdmin=false;var writeAccessCallback=function(){serverui().ensureLogin([adminAccessCallback.bind(this),this.drawDialog.bind(this)],'admin',true);}
serverui().ensureLogin(writeAccessCallback.bind(this));}
serverui().ensureLogin([adminAccessCallback.bind(this),noAdminAccessCallback.bind(this)],'admin',true);}
else{this.drawDialog();}},gotDeleteEntryResponse:function(inRequestObj,inResponseObj){dialogManager().hide();if(gAnimate)gPoofManager.showOverElement('document_title');gNotifier.printAtPage('page_deleted_message',(uid().mService=='wiki'?uid().mBaseLocation:uid().mParentLocation));}});var UploadProgressPlaceholder=Class.create();UploadProgressPlaceholder.prototype={mCheckInterval:1000,initialize:function(inElement,inUpdateID,inCallback){if(!UploadProgressPlaceholder.allPlaceholders)UploadProgressPlaceholder.allPlaceholders={};UploadProgressPlaceholder.allPlaceholders[inUpdateID]=this;this.mElement=$(inElement);this.mCallback=inCallback;this.mUpdateID=inUpdateID;if(arguments.length>1)Object.extend(this,arguments[1]);this.mTimer=setTimeout(this.sendUpdateRequest.bind(this),500);},sendUpdateRequest:function(){server().getUploadProgress(this.gotUpdateResponse.bind(this),this.mUpdateID);},gotUpdateResponse:function(q,r){if(!this.mTimer)return false;if(r.done){if(this.mCallback)this.mCallback(this,r);this.destroy();}
else if(SafariFixes.isWebKit&&this.mFrameFinishedLoading){if(this.mCallback)this.mCallback(this,{retry:true});}
else if(this.mFileSizeError||(r.error=='2')){if(this.mCallback)this.mCallback(this,{fileSizeError:true,maxFileSize:r.maxFileSizeInBytes||this.mMaxFileSize});}
else{if(this.mElement&&r['size']&&r.uploaded){if(Element.hasClassName(this.mElement,'progress_bar')){if(gDebug)gNotifier.print('File upload: '+Math.floor((r.uploaded/r['size'])*100)+'%');this.mElement.firstChild.style.width=((r.uploaded/r['size'])*this.mElement.offsetWidth)+'px';}
else{if(gDebug)gNotifier.print('File upload: '+Math.floor((r.uploaded/r.size)*100)+'%');var offset=Math.min(Math.floor((r.uploaded/r.size)*10),8)*this.mElement.offsetWidth;this.mElement.style.backgroundPosition=(offset*(-1))+'px 0';}}
else if(this.mElement){if(Element.hasClassName(this.mElement,'progress_bar'))this.mElement.firstChild.style.width='0';else this.mElement.style.backgroundPosition='0 0';}
this.mTimer=setTimeout(this.sendUpdateRequest.bind(this),this.mCheckInterval);}},cancel:function(){if(this.mTimer){clearTimeout(this.mTimer);this.mTimer=null;}},destroy:function(){this.cancel();delete UploadProgressPlaceholder.allPlaceholders[this.mUpdateID];}}
UploadProgressPlaceholder.handleUploadFrameLoad=function(){if(!UploadProgressPlaceholder.allPlaceholders)return true;$H(UploadProgressPlaceholder.allPlaceholders).each(function(ph){ph.value.mFrameFinishedLoading=true;});}
UploadProgressPlaceholder.handleFileSizeError=function(inMaxFileSizeString){if(!UploadProgressPlaceholder.allPlaceholders)return true;$H(UploadProgressPlaceholder.allPlaceholders).each(function(ph){ph.value.mFileSizeError=true;ph.value.mMaxFileSize=inMaxFileSizeString;});}
var WLTEditor=Class.create();Object.extend(Object.extend(WLTEditor.prototype,JSEditor.prototype),{mMaxImageWidth:300,mSidebarElement:$('content_extras_column'),mHasSaveComment:true,super_initialize:JSEditor.prototype.initialize,initialize:function(inElement,options){bindEventListeners(this,['handleHotButtonChange','handleSaveButtonHover']);this.super_initialize(inElement,options);Event.observe(this.mDoneButton,'mouseover',this.handleSaveButtonHover);},checkServerForEdits:function(inOptEditedCallback,inOptUneditedCallback,inShowProgress){if(!this.mModifiedDate){this.mModifiedDate=new Date();var dateStr=getMetaTagValue('apple_collab_modified_date');if(dateStr)this.mModifiedDate=createDateObjFromISO8601(dateStr);}
var gotEntryCallback=function(q,r){dialogManager().hideProgressMessage();var latestModifiedDate=createDateObjFromISO8601(r.modifiedDate);if(latestModifiedDate>this.mModifiedDate){this.mModifiedDate=latestModifiedDate;replaceElementContents($('history_time_author'),String.format(Loc.link_tooltip_lastmod_format,{date:latestModifiedDate.formatDate(Loc.dateFormats.mediumDateAndShortTime),author:r.lastModifiedAuthorLongName}));if(inOptEditedCallback)inOptEditedCallback(r);}
else if(inOptUneditedCallback){inOptUneditedCallback(r);}}
if(inShowProgress)dialogManager().showProgressMessage('save_overwrite_check_progress',true,invalidate);server().wiki.getEntryWithUID(gotEntryCallback.bind(this),uid().mValue);},cleanElementForEditing:function(inElement){$('editing_document_title').value=Element.firstNodeValue('document_title');this.mOriginalTitle=$F('editing_document_title');if($('entry_date')){$('entry_date').hide();var saveExtras='<div id="save_page_comment_container"><label for="save_page_comment">'
+Loc.save_page_dialog_comment
+'<input name="title" id="save_page_comment" class="text" type="text" size="30"></label></div>'
+'<div id="save_page_hot_container"><label for="save_page_hot"><input id="save_page_hot" type="checkbox" class="checkbox">'
+Loc.save_page_dialog_hot
+'</label></div>';new Insertion.Before('entry_date',saveExtras);$('save_page_hot').checked=gTagger.hasTag('hot');if(this.mHasSaveComment)this.mSaveCommentHinter=new HintedTextField('save_page_comment','save_comment_hint');Event.observe('save_page_hot','change',this.handleHotButtonChange);}
if(window.gSidebarUpdater){gSidebarUpdater.startEdit();}
gAttachmentExpander.collapseAttachments();gQTMediaExpander.collapseAllMedia();gImageThumbnailManager.prepareForEditing();gTagger.switchToEditor();Element.cleanWhitespace(inElement);if(inElement.lastChild&&(inElement.lastChild.nodeName.toLowerCase()=='pre')){inElement.appendChild(d.createElement('p'));}
if($('tombstoned'))$('tombstoned').remove();gToolbar.mChildren.edit.setEnabled(false);if($('paginator'))Element.hide('paginator');},setupEditor:function(inElement,inSkipUpdateCheck){if(this.mUseDesignMode){callback=function(inEvent){var elm=Event.element(inEvent);if(elm.tagName.match(/html/i)){var sel=this.mEditorWindow.getSelection();sel.selectAllChildren(this.mEditorBody.firstChild);sel.collapseToEnd();}
if(elm&&elm.nodeName&&elm.nodeName.toLowerCase()=='img'){this.handleImageClick(inEvent);}}
if(this.d)Event.observe(this.d,'click',callback.bindAsEventListener(this));if(this.d)Event.observe(this.d,'dragdrop',this.checkEditorForMovedTable.bindAsEventListener(this));}
else{$A(inElement.getElementsByTagName('img')).each(function(img){img.onclick=this.handleImageClick.bindAsEventListener(this);}.bind(this));}
if(this.d&&!IEFixes.isIE&&!OperaFixes.isOpera)this.d.execCommand('styleWithCSS',false,false);if(this.mSelectionManager){if(this.mSelectOnEdit||MozillaFixes.isGecko){this.mSelectOnEdit=false;this.mSelectionManager.selectElementChildren($(inElement).down?($(inElement).down('p')||inElement):inElement);if(MozillaFixes.isGecko)this.mEditorWindow.getSelection().collapseToStart();}
else{this.mSelectionManager.moveCursorToBeginning();}}
var pageIsUpdatedCallback=function(r){$('editing_document_title').value=r.title;this.mOriginalTitle=r.title;inElement.innerHTML=r.content;gAttachmentExpander.collapseAttachments();Element.cleanWhitespace(inElement);if(inElement.lastChild&&(inElement.lastChild.nodeName.toLowerCase()=='pre')){inElement.appendChild(d.createElement('p'));}
this.setupEditor(inElement,true);movableTable().expandTablesForEditing(inElement);}
if(!inSkipUpdateCheck)setTimeout(function(){this.checkServerForEdits(pageIsUpdatedCallback.bind(this))}.bind(this),900);},getUpdateDictionary:function(){var content=this.cleanForSaving(this.getHTML());var updateDictionary={content:content};if($('editing_document_title')&&$F('editing_document_title').match(/\S/))updateDictionary.title=$F('editing_document_title');if(this.mSaveCommentHinter)updateDictionary['commit-comment']=this.mSaveCommentHinter.getValue();return updateDictionary;},cleanElementAfterEditing:function(inElement,inResponseDict){if(inResponseDict){if($F('editing_document_title').match(/\S/))replaceElementContents('document_title',$F('editing_document_title'));if(inResponseDict.modifiedDate)this.mModifiedDate=createDateObjFromISO8601(inResponseDict.modifiedDate);}
if(window.gSidebarUpdater){gSidebarUpdater.endEdit();}
if($('save_page_hot')){if($('save_page_hot').checked){gTagger.addTag('hot',true);}
else{gTagger.removeTag('hot');}}
if($('entry_date')){if(inResponseDict)replaceElementContents($('history_time_author'),Loc['history_updated']+String.format(Loc.link_tooltip_lastmod_format,{date:createDateObjFromISO8601(inResponseDict.modifiedDate).formatDate(Loc.dateFormats.mediumDate),author:inResponseDict.lastModifiedAuthorLongName}));$('entry_date').show();Event.stopObserving('save_page_hot','change',this.handleHotButtonChange);$('save_page_comment_container').remove();$('save_page_hot_container').remove();}
gAttachmentExpander.expandAttachments();gQTMediaExpander.findMedia();gImageThumbnailManager.findThumbnails();gTagger.switchToDisplay();gLinkPreviewGenerator.scan();gToolbar.mChildren.edit.setEnabled(true);if($('paginator'))Element.show('paginator');},showLinkDialog:function(){this.mSelectionManager.store();gLinkPopupManager.show();},showImageDialog:function(inAuthorized){if(!inAuthorized){serverui().ensureLogin(function(){this.showImageDialog(true)}.bind(this));return false;}
if(!this.mImageDialog){this.mImageDialog=dialogManager().drawDialog('image_dialog',[{label:'image_dialog_file',contents:'<input id="image_dialog_upload_id" name="upload_id" type="hidden"><input id="image_dialog_file" name="Image" type="file">'},{label:'image_dialog_alt',contents:'<input id="image_dialog_alt" name="image_dialog_alt" type="text">'},{label:'image_dialog_align',contents:'<div id="image_dialog_align_widget"></div>'},{label:'',contents:'<br />'+Loc.image_dialog_explanation1+'<br />'+Loc.image_dialog_explanation2+'<br />'+Loc.image_dialog_explanation3}],'image_dialog_ok','images');this.mImageDialogAlignWidget=new ButtonBarWidget('image_dialog_align_widget','img_align_widget',['image_dialog_align_left','image_dialog_align_center','image_dialog_align_right','image_dialog_align_none'],{mOffsetWidth:32,mSelectedIndex:1});}
this.mSelectionManager.store();$('image_dialog_upload_id').value=''+server().getNextUploadID();$('image_dialog_alt').value='';addUploadFrame();targetedDialogManager().show(this.mImageDialog,this.handleImageUploadCancel.bind(this),this.handleImageDialogOK.bind(this),'image_button',true,null,true);},insertActiveUpload:function(){try{this.mSelectionManager.retrieve()}catch(e){};this.insertHTML('<br style="clear:both" />');this.insertImage('/collaboration/images/blank.gif',null,null,'apple_active_upload');var elm=this.d.getElementById('apple_active_upload');elm.id='';elm.className='upload_progress';return elm;},documentHasChanged:function(){return((this.getHTML()!=this.mOriginalText)||($('editing_document_title')&&($F('editing_document_title')!=this.mOriginalTitle)));},handleHotButtonChange:function(inEvent){if($F('save_page_hot')){gTagger.addTag('hot',true);}
else{gTagger.removeTag('hot');}},handleSaveButtonHover:function(inEvent){if(this.mSaveCommentHinter&&(this.mSaveCommentHinter.getValue()=='')){if(this.mSaveCommentEffect){this.mSaveCommentEffect.cancel();if($('save_page_comment'))$('save_page_comment').setStyle({backgroundColor:''});delete this.mSaveCommentEffect;}
this.mSaveCommentEffect=new Effect.Highlight('save_page_comment');}},handleDocumentKeypress:function(inEvent){if(inEvent.ctrlKey&&(inEvent.keyCode==76||inEvent.charCode==108)){Event.stop(inEvent);if(this.mEditMode&&this.documentHasChanged()&&this.mSaveCommentHinter&&(this.mSaveCommentHinter.getValue()=='')){this.handleSaveButtonHover();$('save_page_comment').focus();}
else{this.toggleEditMode();}}},handleEditButtonClick:function(inEvent){if(inEvent)Event.stop(inEvent);if((!this.mEditMode)&&(gToolbar.mChildren.edit.enabled())){var toggleCallback=function(r){if((!this.mEditMode)&&(gToolbar.mChildren.edit.enabled()))this.toggleEditMode();};serverui().ensureLogin(toggleCallback.bind(this));}
else{if(!this.documentHasChanged()){if($('save_page_hot'))$('save_page_hot').checked=gTagger.hasTag('hot');this.toggleEditMode(true);return true;}
var changesCallback=function(r){if(confirm(String.format(Loc.save_overwrite_confirm,{lastModifiedAuthorLongName:r.lastModifiedAuthorLongName}))){this.toggleEditMode();}}
var noChangesCallback=function(r){this.toggleEditMode();}
gPopupManager.hide();this.checkServerForEdits(changesCallback.bind(this),noChangesCallback.bind(this),true);}
return false;},checkEditorForMovedTable:function(inEvent){movableTable().checkEditor(this.d);},handleImageClick:function(inEvent){this.img=Event.element(inEvent);if(Element.hasClassName(this.img,'__tableEditorDragHandle')){movableTable().handleClick(inEvent);return;}
if(Element.hasClassName(this.img,'attachment_handle_img'))return true;if(!this.mImageSettingsDialog){this.mImageSettingsDialog=dialogManager().drawDialog('image_settings_dialog',[{label:'image_dialog_alt',contents:'<input id="image_settings_alt" name="image_settings_alt" type="text">'},{label:'image_dialog_align',contents:'<div id="image_settings_align_widget"></div>'},{label:'',contents:'<div id="image_settings_delete_div"></div>'}],'image_settings_dialog_ok');this.mImageSettingsAlignWidget=new ButtonBarWidget('image_settings_align_widget','img_align_widget',['image_dialog_align_left','image_dialog_align_center','image_dialog_align_right','image_dialog_align_none'],{mOffsetWidth:32,mSelectedIndex:1});}
if(!this.oDeleteImageLink){this.oDeleteImageLink=Builder.node('a',{href:'#',id:'image_dialog_delete',title:Loc.tooltips.image_dialog_delete||''},[Loc.image_dialog_delete]);Event.observe(this.oDeleteImageLink,'click',function(inEvent){Event.stop(inEvent);Element.remove(this.img);if(MozillaFixes.isGecko){this.d.designMode='off';this.d.designMode='on';}
movableTable().collapseTablesAfterEditing();movableTable().expandTablesForEditing();dialogManager().hide();}.bindAsEventListener(this));$('image_settings_delete_div').appendChild(this.oDeleteImageLink);}
['alignleft','aligncenter','alignright','donotalign'].each(function(key,i){if(Element.hasClassName(this.img,key))this.mImageSettingsAlignWidget.setSelectedIndex(i);}.bind(this));$('image_settings_alt').value=this.img.getAttribute('alt')||'';var callback=function(){var aClasses=['alignleft','aligncenter','alignright','donotalign'];aClasses.each(function(sClass){Element.removeClassName(this.img,sClass);}.bind(this));Element.addClassName(this.img,aClasses[this.mImageSettingsAlignWidget.getSelectedIndex()]);this.img.setAttribute('alt',$F('image_settings_alt'));if(this.mUseDesignMode){this.d.designMode='off';this.d.designMode='on';movableTable().collapseTablesAfterEditing();movableTable().expandTablesForEditing();}}
targetedDialogManager().show(this.mImageSettingsDialog,null,callback.bind(this),this.img);},handleImageUploadCancel:function(){removeUploadFrame();},handleImageDialogOK:function(){this.mRetryCount=0;var elm=this.insertActiveUpload();var className=['alignleft','aligncenter','alignright','donotalign'][this.mImageDialogAlignWidget.getSelectedIndex()];Element.addClassName(elm,className);var uploadCompleteCallback=function(inProgressObj,inUploadInfo){removeUploadFrame();dialogManager().hide();if(inUploadInfo.retry){if(this.mRetryCount++>=3){Element.remove(inProgressObj.mElement);alert(Loc.attach_upload_error);}
else{debug_message('Upload failed. Retrying...');addUploadFrame();$('image_dialog_upload_id').value=''+server().getNextUploadID();$('image_dialog_form').submit();this.mUploadProgress=new UploadProgressPlaceholder(dialogManager().mProgressBar,$F('image_dialog_upload_id'),uploadCompleteCallback.bind(this));}}
else if(inUploadInfo.uploaded<=0){Element.remove(elm);alert(Loc.attach_upload_nofile_error);}
else if(inUploadInfo.isImage){var filename=inUploadInfo.filename||'';gNotifier.print(String.format(Loc.attach_confirm,{filename:filename}));inUploadInfo.sources.each(function(sourceDict){var img=Builder.node('img',{className:className,src:sourceDict.source,alt:$F('image_dialog_alt')});if(!this.mUseDesignMode)img.onclick=this.handleImageClick.bindAsEventListener(this);if(sourceDict.fullSizeSource){Element.addClassName(img,'thumbnail');img.setAttribute('longdesc',sourceDict.fullSizeSource+'#'+sourceDict.fullSizeWidth+'x'+sourceDict.fullSizeHeight);}
else if(sourceDict.qtSource&&sourceDict.width&&sourceDict.height){Element.addClassName(img,'posterimg');img.setAttribute('longdesc',sourceDict.qtSource);img.width=sourceDict.width;img.height=sourceDict.height;}
img.title=sourceDict.originalFilename||'';if(window.unitTestHandler)img.onload=function(){unitTestHandler.messageFromJS_('inserted image finished loading');img.onload='';}
elm.parentNode.insertBefore(img,elm);}.bind(this));Element.remove(elm);}
else if(inUploadInfo.fileSizeError){Element.remove(elm);alert(String.format(Loc.attach_upload_toobig_error,{maxFileSize:inUploadInfo.maxFileSize}));}
else{Element.remove(inProgressObj.mElement);alert(Loc.image_invalid_error);}}
var uploadCancelledCallback=function(){if(elm)Element.remove(elm);this.handleUploadCancelled();}
dialogManager().showProgressMessage(Loc.image_upload_progress,true,uploadCancelledCallback.bind(this));this.mUploadProgress=new UploadProgressPlaceholder(dialogManager().mProgressBar,$F('image_dialog_upload_id'),uploadCompleteCallback.bind(this));},showAttachDialog:function(inAuthorized){if(!inAuthorized){serverui().ensureLogin(function(){this.showAttachDialog(true)}.bind(this));return false;}
if(!this.mAttachDialog){this.mAttachDialog=dialogManager().drawDialog('attach_dialog',[{label:'attach_dialog_file',contents:'<input id="attach_dialog_file" name="Attachment" type="file" />'}],'attach_dialog_ok','attachments');this.mAttachDialog.firstChild.appendChild(Builder.node('input',{type:'hidden',id:'attach_dialog_upload_id',name:'upload_id'}));}
this.mSelectionManager.store();$('attach_dialog_upload_id').value=''+server().getNextUploadID();targetedDialogManager().show('attach_dialog',this.handleAttachDialogCancel.bind(this),this.handleAttachDialogOK.bind(this),'attach_button',true,null,true);addUploadFrame();},handleAttachDialogCancel:function(){removeUploadFrame();},handleAttachDialogOK:function(){this.mRetryCount=0;var elm=this.insertActiveUpload();var uploadCompleteCallback=function(inProgressObj,inUploadInfo){var filename=inUploadInfo.filename||'';var originalFilename=inUploadInfo.originalFilename||filename;gNotifier.print(String.format(Loc.attach_confirm,{filename:filename.split('/').pop()}));removeUploadFrame();dialogManager().hide();if(inUploadInfo.retry){if(this.mRetryCount++>=3){Element.remove(inProgressObj.mElement);alert(Loc.attach_upload_error);}
else{debug_message('Upload failed. Retrying...');addUploadFrame();$('attach_dialog_upload_id').value=''+server().getNextUploadID();$('attach_dialog_form').submit();this.mUploadProgress=new UploadProgressPlaceholder(dialogManager().mProgressBar,$F('attach_dialog_upload_id'),uploadCompleteCallback.bind(this));}}
else if(inUploadInfo.uploaded&&inUploadInfo.uploaded>0){var altAndTitle=String.format(Loc.attach_alt.replace(':',''),{filename:'"'+originalFilename+'"'});Element.addClassName(elm,'attachment_handle_img');elm.setAttribute('src','/collaboration/images/generic_document.png');elm.setAttribute('title',altAndTitle);elm.setAttribute('alt',altAndTitle);elm.setAttribute('longdesc',filename);if(inUploadInfo.sources&&inUploadInfo.sources.length>0){elm.setAttribute('src',filename+'.png');}}
else if(inUploadInfo.fileSizeError){$(elm).remove();alert(String.format(Loc.attach_upload_toobig_error,{maxFileSize:inUploadInfo.maxFileSize}));}
else{$(elm).remove();alert(Loc.attach_upload_nofile_error);}}
var uploadCancelledCallback=function(){if(elm)Element.remove(elm);this.handleUploadCancelled();}
dialogManager().showProgressMessage(Loc.attach_upload_progress,true,uploadCancelledCallback.bind(this));this.mUploadProgress=new UploadProgressPlaceholder(dialogManager().mProgressBar,$F('attach_dialog_upload_id'),uploadCompleteCallback.bind(this));},handleUploadCancelled:function(){removeUploadFrame();dialogManager().hide();if(this.mUploadProgress){this.mUploadProgress.destroy();delete this.mUploadProgress;}}});var ModeManager=Class.create();ModeManager.prototype={initialize:function(){bindEventListeners(this,['handleKeyPress']);this.mModes=new Array(($('wysiwyg_container')||$('entries_list')));},toggleMode:function(inMode,inOptAfterFinish){var afterFinishHide=function(effect){Element.hide(effect.element);effect.element.style.height='';if(inOptAfterFinish)inOptAfterFinish(effect);};var status=!Element.visible(inMode);var activeMode=status?$(inMode):this.mModes[0];this.mModes.each(function(mode){if(mode!=activeMode&&Element.visible(mode))Effect.BlindUp(mode,{duration:0.5,afterFinish:afterFinishHide});});Effect.BlindDown(activeMode,{duration:0.2,afterFinish:afterFinishShow});gToolbar.mChildren.edit.setEnabled(activeMode==this.mModes[0]);if(activeMode==this.mModes[0]){gToolbar.mChildren.edit.setEnabled(true);Event.stopObserving(d,'keypress',this.handleKeyPress);}
else{gToolbar.mChildren.edit.setEnabled(false);Event.observe(d,'keypress',this.handleKeyPress);}
return status;},handleKeyPress:function(inEvent){if(inEvent.keyCode==Event.KEY_ESC){this.toggleMode(this.mModes[0]);}}}
var HistoryModeManager=Class.create();HistoryModeManager.prototype={mKeys:['lastModifiedBy','comment','time'],mHistoryListHeight:75,initialize:function(){bindEventListeners(this,['handleHistoryButtonClick','handleRevisionClick','handleCompareButtonClick','handleDeleteButtonClick','handleRevertButtonClick','handleKeyPress']);this.mContainer=Builder.node('div',{id:'history_view',className:'contents contentshistory'});this.mOriginalTitle=$('document_title').innerHTML;this.mOriginalContent=$('editable_content').innerHTML;this.mElement=Builder.node('div',{id:'history_mode',className:'history',style:'display:none'},[Builder.node('div',{className:'start starthistory'},[Builder.node('span')]),this.mContainer,Builder.node('div',{className:'end endhistory'},[Builder.node('span')])]);insertAfter(this.mElement,'entry_date');this.mButton=$('history_link');this.createHistoryList();this.mSplitView=new SplitView(this.mContainer);Event.observe(this.mButton,'click',this.handleHistoryButtonClick);this.bShowDiffs=false;this.showing=false;},createHistoryList:function(){this.mList=Builder.node('ul',{id:'history_list'});this.mHistoryRevert=Builder.node('a',{id:'history_revert',title:Loc.history_revert_tooltip},[Loc.history_revert]);Event.observe(this.mHistoryRevert,'click',this.handleRevertButtonClick);this.mHistoryCompare=Builder.node('a',{href:'#compare',id:'history_compare',title:Loc.history_compare_tooltip},[Loc.history_compare]);Event.observe(this.mHistoryCompare,'click',this.handleCompareButtonClick);this.mHistoryControls=Builder.node('div',{className:'historycontrols'},[Builder.node('ul',{id:'historycontrolslist'},[Builder.node('li',{},[this.mHistoryRevert]),Builder.node('li',{},[this.mHistoryCompare])])]);this.mHistoryContainer=Builder.node('div',{id:'historycontainer',className:'historycontainer',style:'height:'+this.mHistoryListHeight+'px;'},[this.mList]);this.mContainer.appendChild(this.mHistoryContainer);this.mContainer.appendChild(Builder.node('div',{className:'splitter'},[Builder.node('div',{className:'splitter_handle'})]));this.mContainer.appendChild(this.mHistoryControls);if(d.cookie.match(/sessionID/)&&!d.cookie.match(/sessionID=unauthenticated/)){serverui().ensureLogin(this.drawDeleteButton.bind(this),'admin',true);}},drawDeleteButton:function(){this.mHistoryDelete=Builder.node('a',{id:'history_delete',title:Loc.history_delete_tooltip},[Loc.history_delete]);Event.observe(this.mHistoryDelete,'click',this.handleDeleteButtonClick);$('historycontrolslist').appendChild(Builder.node('li',{},[this.mHistoryDelete]));},handleHistoryButtonClick:function(inEvent){Event.stop(inEvent);serverui().ensureLogin(this.toggle.bind(this),'read');},handleRevisionClick:function(inOptEvent){if(this.mCurrentRow)Element.removeClassName(this.mCurrentRow,'current_row');this.mCurrentRow=Event.findElement(inOptEvent,'li');if(this.mCurrentRow==this.mList.getElementsByTagName('li')[0]){this.mHistoryRevert.removeAttribute('href');if(this.mHistoryDelete)this.mHistoryDelete.removeAttribute('href');}else{this.mHistoryRevert.setAttribute('href','#revert');if(this.mHistoryDelete)this.mHistoryDelete.setAttribute('href','#delete');}
if(this.mList.getElementsByTagName('li').length==1)this.disableCompareAndDelete();this.updateRevision();},updateRevision:function(){Element.addClassName(this.mCurrentRow,'current_row');if(this.mComparedRow){Element.removeClassName(this.mComparedRow,'compared_row');this.mComparedRow=null;}
if(this.mList.getElementsByTagName('li').length==1)return;var uid=this.mCurrentRow.dataSource.uid;if(this.bShowDiffs&&this.mCurrentRow.nextSibling){this.mComparedRow=this.mCurrentRow.nextSibling;Element.addClassName(this.mComparedRow,'compared_row');uid2=uid;uid=this.mComparedRow.dataSource.uid;uid+='-'+uid2.substring(uid2.lastIndexOf('/')+1,uid2.length);}
this.mRevisionRequest=server().versions.getEntryWithUID(this.gotRevisionResponse.bind(this),uid);},toggle:function(inOptDoNotReset){this.mHistoryContainer.style.overflow='hidden';if(!this.showing){this.mOriginalTitle=$('document_title').innerHTML;this.mOriginalContent=$('editable_content').innerHTML;this.mHistoryContainer.style.overflow='auto';this.mHistoryContainer.style.overflowX='hidden';this.mHistoryContainer.style.overflowY='scroll';dialogManager().showProgressMessage('history_popup_progress');this.sendHistoryRequest();this.showing=true;Event.observe(d,'keypress',this.handleKeyPress);this.mHistoryCompare.setAttribute('href','#compare');}else{this.showing=false;Event.stopObserving(d,'keypress',this.handleKeyPress);this.disableCompareAndDelete();replaceElementContents(this.mButton,Loc.last_edited);this.mButton.setAttribute('title',Loc.tooltips.history_link);this.mHistoryCompare.setAttribute('title',Loc.history_compare_tooltip);replaceElementContents(this.mHistoryCompare,Loc.history_compare);this.bShowDiffs=false;if(!inOptDoNotReset){replaceElementContents('document_title',this.mOriginalTitle);replaceElementContents('editable_content',this.mOriginalContent,true);}
Element.removeClassName(this.mButton,'historyopen');this.mEffect=Effect.BlindUp(this.mHistoryContainer,{duration:0.25,afterFinish:function(){Element.show($('history_time_author'));Element.show($('toolbars'));}.bind(this)});setTimeout("Effect.Fade($('history_mode'),{duration:0.1})",150);}},disableCompareAndDelete:function(){this.mHistoryCompare.removeAttribute('href');if(this.mHistoryDelete)this.mHistoryDelete.removeAttribute('href');},handleKeyPress:function(inEvent){if(inEvent.keyCode==Event.KEY_ESC)this.toggle();},sendHistoryRequest:function(){removeAllChildNodes(this.mList);server().versions.getEntries(this.gotHistoryResponse.bind(this),uid().mBasePath,{page:uid().mValue});},gotHistoryResponse:function(inRequestObj,inResponseObj){var rows=inResponseObj;dialogManager().hide();Element.hide($('toolbars'));Element.hide($('history_time_author'));replaceElementContents(this.mButton,Loc.history_cancel);this.mButton.setAttribute('title',Loc.tooltips.history_cancel);Element.addClassName(this.mButton,'historyopen');Element.hide(this.mHistoryContainer);rows.inject(rows.length,function(i,row){var sEditType=Loc.history_updated;switch(row['editType']){case'updated':break;case'created':sEditType=Loc.history_created;break;default:return i;}
var date=createDateObjFromISO8601(row['time'],true);var sDate=Loc.getDateString(date);var dtint=parseInt(dateObjToISO8601(date));var today=new Date();var yesterday=new Date();yesterday.setTime(today.valueOf()-86400000);if(dtint==parseInt(dateObjToISO8601(today)))sDate=Loc['today'];else if(dtint==parseInt(dateObjToISO8601(yesterday)))sDate=Loc['yesterday'];var commitcomment=row['comment'];var commitdatematch=commitcomment.match(/##(\d{8}T\d{6}Z)$/);if(commitdatematch){var localdatestr=Loc.getLongDateString(createDateObjFromISO8601(commitdatematch[1],true));commitcomment=commitcomment.replace(/##(\d{8}T\d{6}Z)$/,localdatestr);}
var commitcommentescaped=commitcomment.replace(/\"/g,'&quot;').replace(/\'/g,'&apos;');if(commitcomment=='')commitcomment=Builder.node('em',{},[String.format(Loc.history_no_comment,{author:row['lastModifiedBy']})]);var elItem=Builder.node('li',{},[Builder.node('span',{className:'lastModifiedBy'},[sEditType,sDate,Loc.history_by,row['lastModifiedBy']]),' ',Builder.node('span',{className:'commitcomment',title:commitcommentescaped},[commitcomment]),' ',Builder.node('span',{className:'committime'},[Loc.getTimeString(date)])]);elItem.dataSource=row;this.mList.appendChild(elItem);Event.observe(elItem,'mousedown',this.handleRevisionClick);return i;}.bind(this));if(!this.mList.getElementsByTagName('li').length){this.toggle();return;}else if(this.mList.getElementsByTagName('li').length==1){this.disableCompareAndDelete();}
this.mCurrentRow=this.mList.getElementsByTagName('li')[0];Element.addClassName(this.mCurrentRow,'current_row');this.mComparedRow=null;this.mLatestRevision=this.mCurrentRow.dataSource.uid;Element.show(this.mElement);if(SafariFixes.isWebKit)Element.getInvisibleSize(this.mHistoryContainer);this.mHistoryContainer.style.height=this.mHistoryListHeight+'px';this.mEffect=Effect.BlindDown(this.mHistoryContainer,{duration:0.25,afterFinish:function(){this.mHistoryContainer.style.overflow='auto';}.bind(this)});},gotRevisionResponse:function(inRequestObj,inResponseObj){dialogManager().hide();this.mCurrentTitle=inResponseObj.title;this.mCurrentContent=inResponseObj.content;Element.hide($('editable_content'));replaceElementContents($('editable_content'),this.mCurrentContent,true);replaceElementContents($('document_title'),this.mCurrentTitle,true);this.mEffect=Effect.BlindDown($('editable_content'),{duration:0.2,afterFinish:afterFinishShow});},handleCompareButtonClick:function(inEvent){Event.stop(inEvent);if(!Event.element(inEvent).getAttribute('href'))return;this.bShowDiffs=!this.bShowDiffs;if(this.bShowDiffs){this.mHistoryCompare.setAttribute('title',Loc.history_view_alone_tooltip);replaceElementContents(this.mHistoryCompare,Loc.history_view_alone);}else{this.mHistoryCompare.setAttribute('title',Loc.history_compare_tooltip);replaceElementContents(this.mHistoryCompare,Loc.history_compare);}
this.updateRevision();},handleDeleteButtonClick:function(inEvent){Event.stop(inEvent);if(!Event.element(inEvent).getAttribute('href')||this.mList.getElementsByTagName('li').length==1)return;if(confirm(Loc.history_delete_confirm))serverui().ensureLogin(this.deleteRevision.bind(this),'admin');},deleteRevision:function(){dialogManager().showProgressMessage('history_deleted');this.mRevisionRequest=server().wiki.removeVersionFromEntry(this.gotDeleteConfirmation.bind(this),uid().mValue,this.mCurrentRow.dataSource.uid);},gotDeleteConfirmation:function(inRequestObj,inResponseObj){dialogManager().hide();this.mEffect=Effect.BlindUp(this.mCurrentRow,{duration:0.2,afterFinish:this.showLatestRevision.bind(this)});},showLatestRevision:function(){if(this.mCurrentRow)Element.remove(this.mCurrentRow);this.mCurrentRow=this.mList.getElementsByTagName('li')[0];this.mHistoryRevert.removeAttribute('href');if(this.mHistoryDelete)this.mHistoryDelete.removeAttribute('href');this.updateRevision();if(this.mList.getElementsByTagName('li').length==1)this.disableCompareAndDelete();this.mButton.focus();},handleRevertButtonClick:function(inEvent){Event.stop(inEvent);if(Event.element(inEvent).getAttribute('href'))this.revert();},revert:function(){if(confirm(Loc.history_revert_confirm)){dialogManager().showProgressMessage('history_reverted');this.mRevisionRequest=server().versions.getEntryWithUID(this.getRevertConfirmation.bind(this),this.mCurrentRow.dataSource.uid);}},getRevertConfirmation:function(inRequestObj,inResponseObj){this.mCurrentContent=inResponseObj.content;replaceElementContents('document_title',this.mCurrentTitle);replaceElementContents('editable_content',this.mCurrentContent,true);var comment=Loc.history_reverted_comment+'##'+dateObjToISO8601(createDateObjFromISO8601(this.mCurrentRow.dataSource.time));server().wiki.updateEntry(this.gotRevertConfirmation.bind(this),uid().mValue,{'title':this.mCurrentTitle,'content':this.mCurrentContent,'commit-comment':comment}).makeRequired();},gotRevertConfirmation:function(inRequestObj,inResponseObj){dialogManager().hide();gNotifier.print('history_reverted_notify');this.toggle(true);}}
var LinkPopupManager=Class.create();LinkPopupManager.prototype={initialize:function(){bindEventListeners(this,['handleUnlinkItemClick','handleSubmenuItemClick','handleNewPageItemClick','handleSearchItemClick','handleOtherURLItemClick']);this.mLinkPopup=gPopupManager.createPopupElement('toolbarpopup','link_popup');gPopupManager.itemWithTitle(this.mLinkPopup,Loc.link_manager_popup.newpage,null,this.handleNewPageItemClick);gPopupManager.itemWithTitle(this.mLinkPopup,Loc.link_manager_popup.search,null,this.handleSearchItemClick);gPopupManager.itemWithTitle(this.mLinkPopup,Loc.link_manager_popup.other,null,this.handleOtherURLItemClick);gPopupManager.itemWithTitle(this.mLinkPopup,Loc.link_manager_popup.unlink,null,this.handleUnlinkItemClick);},show:function(){this.mSelectedString=gEditor.mSelectionManager.getSelectedString();gPopupManager.show('createlink_button',this.mLinkPopup,[IEFixes.isIE7?-767:0,0]);var filterList=[{name:'SettingsFilter',parameters:{settingsKeys:['recentPages']}}];this.mRecentsRequest=server().preferences.getUsersRecentPages([this.gotRecentEntries.bind(this),invalidate],uid().mBasePath);},gotRecentEntries:function(inRequestObj,inResponseObj){if(!this.mHasDrawnDivider){this.mHasDrawnDivider=true;gPopupManager.divider(this.mLinkPopup);}
$$('#link_popup .link_popup_recent_item').invoke('remove');$H(inResponseObj).each(function(row){var item=gPopupManager.itemWithTitle(this.mLinkPopup,row.value.title,row.value.url||gBasePath+row.key+'/',this.handleSubmenuItemClick);Element.addClassName(item.parentNode,'link_popup_recent_item');}.bind(this));gLinkPreviewGenerator.scan(this.mLinkPopup);},handleSubmenuItemClick:function(inEvent){gPopupManager.hide();var elm=Event.element(inEvent);try{gEditor.mSelectionManager.retrieve()}catch(e){};gEditor.createLink(elm.getAttribute('href')||'',Element.firstNodeValue(elm)||null);return false;},handleUnlinkItemClick:function(inEvent){try{gEditor.mSelectionManager.retrieve()}catch(e){};gEditor.createLink('');return false;},handleNewPageItemClick:function(inEvent){gPopupManager.hide();gNewPageDialogManager.showNewPageDialog(this.handleNewPageCreated.bind(this));$('new_page_title').value=this.mSelectedString;return false;},handleNewPageCreated:function(inUID,inURL){try{gEditor.mSelectionManager.retrieve()}catch(e){};var linkTitle=$F('new_page_title');gEditor.createLink(inURL||gBasePath+inUID+'/',linkTitle||null);return false;},handleSearchItemClick:function(inEvent){gPopupManager.hide();var callback=function(){try{gEditor.mSelectionManager.retrieve()}catch(e){};gEditor.createLink(gLinkSearchDialogManager.mChosenUID,gLinkSearchDialogManager.mChosenTitle||null);}
gLinkSearchDialogManager.show(null,callback,this.mSelectedString);return false;},handleOtherURLItemClick:function(inEvent){try{gEditor.mSelectionManager.retrieve()}catch(e){};var selectedString=gEditor.mSelectionManager.getSelectedString();gPopupManager.hide();if(this.mLinkOtherDialog){Element.remove(this.mLinkOtherDialog);delete this.mLinkOtherDialog;}
var aInputs=[{label:'link_other_dialog_title',contents:'<input name="title" id="link_other_title" type="text" size="48">'}];if(!selectedString)aInputs.push({label:'link_other_dialog_text',contents:'<input name="title" id="link_other_text" type="text" size="48">'});this.mLinkOtherDialog=dialogManager().drawDialog('link_other_dialog',aInputs,'link_other_dialog_ok');$('link_other_title').value='';callback=function(){try{gEditor.mSelectionManager.retrieve()}catch(e){};var linkText=$('link_other_text')?$F('link_other_text').trim():'';var url=$F('link_other_title').trim();if(!url.match(/^mailto\:/)&&!url.match(/\//)&&url.match(/^[^@\/]+@[^@\/\.]+\.[^@\/]+$/)){url='mailto:'+url;}
else if(!url.match(/[a-z]:/i)&&url.split('/')[0].match(/^[^.]+\./)){url='http://'+url;}
gEditor.createLink(url,linkText||null);}
dialogManager().show(this.mLinkOtherDialog,null,callback);return false;}}
var LinkSearchDialogManager=Class.create();LinkSearchDialogManager.prototype={initialize:function(){},show:function(inCancelCallback,inOKCallback,inOptSearchString){if(!this.mSearchField){this.mLinkSearchField=Builder.node('input',{type:(SafariFixes.isWebKit?'search':'text'),id:'link_dialog_q',placeholder:Loc.search_hint,className:'search_field'});if(SafariFixes.isWebKit){Object.extend(this.mLinkSearchField,{placeholder:Loc.search_hint,incremental:'incremental',results:'10'});}
var form=Builder.node('form',{action:'#',method:'get',id:'link_dialog_form'},[this.mLinkSearchField,Builder.node('div',{id:'link_dialog_results'},[Builder.node('table',{id:'link_dialog_top_matches'},[Builder.node('tbody')])]),Builder.node('p',{id:'link_dialog_footer'},[Builder.node('input',{name:'cancel_button',id:'link_dialog_cancel',type:'button',value:Loc.cancel}),Builder.node('input',{name:'login_button',id:'link_dialog_ok',type:'submit',value:Loc.link_other_dialog_ok})])]);form.onsubmit=invalidate;this.mElement=Builder.node('div',{id:'link_dialog',className:'dialog',style:'display:none'},[form]);d.body.appendChild(this.mElement);this.mSearchField=new LinkSearchField(this.mLinkSearchField,{mResultTable:$('link_dialog_top_matches'),mClickedItemCallback:this.handleItemClick.bind(this)});}
this.mCancelCallback=inCancelCallback;this.mOKCallback=inOKCallback;targetedDialogManager().show('link_dialog',this.handleCancel.bind(this),this.handleOK.bind(this),'createlink_button');if(inOptSearchString){this.mLinkSearchField.value=inOptSearchString;this.mSearchField.runQuery();}},handleCancel:function(){if(this.mCancelCallback)this.mCancelCallback();},handleOK:function(){if(this.mOKCallback)this.mOKCallback();},handleItemClick:function(inDisplayString,inOptURL){this.mChosenUID=inOptURL||(gBasePath+(this.mSearchField.mChosenUID||'')+'/');this.mChosenTitle=this.mSearchField.mChosenDataSource.title;dialogManager().hide();this.handleOK();delete this.mChosenUID;delete this.mChosenTitle;}}
var LinkSearchField=Class.create();Object.extend(Object.extend(LinkSearchField.prototype,SearchFieldBase.prototype),{mPositionResults:false,gotSearchResult:function(inRequestObj,inResponseObj){this.mRows=inResponseObj;var q=inRequestObj.requestMessageObj.params[2].q[0].toLowerCase();this.mRows=inResponseObj.partition(function(row){return(row.title.toLowerCase().indexOf(q)>=0);}).flatten();this.draw();this.mTimer=null;},drawCell:function(inCell){var div=d.createElement('div');div.appendChild(d.createTextNode(inCell.dataSource.title));inCell.appendChild(div);div=Object.extend(d.createElement('div'),{className:'snippet'});var content=inCell.dataSource.contentSnippet||'';div.appendChild(d.createTextNode(content.substring(0,100)));inCell.appendChild(div);},constructQuery:function(inSearchString){return server().search.getEntries([this.gotSearchResult.bind(this),this.handleError.bind(this)],uid().mBasePath,{q:[inSearchString],sortDirection:'forward',sort:'title',howMany:50},['title','uid','contentSnippet','url']);},fieldChanged:function(e){if(!this.mTimer)this.mTimer=setTimeout(this.runQuery.bind(this),this.mInterval);},mousedOutUser:function(e){this.suggestUID(null);},handleChanged:function(e){}});var NewPageDialogManager=Class.create();NewPageDialogManager.prototype={initialize:function(){},showNewPageDialog:function(inOptCallback){if(!this.mElement){this.mElement=dialogManager().drawDialog('new_page_dialog',[{label:'new_page_dialog_title',contents:'<input name="title" id="new_page_title" type="text" size="30" />'}],'new_page_dialog_ok');}
this.mCallback=inOptCallback;targetedDialogManager().show(this.mElement,null,this.handleNewPageDialogOK.bind(this),'add_button',true);},handleAddButtonClick:function(inEvent){serverui().ensureLogin(this.showNewPageDialog.bind(this));},handleNewPageDialogOK:function(){var pageDict={title:$F('new_page_title')};server()[uid().mService].addEntry(this.gotNewPageResponse.bind(this),uid().mBasePath,pageDict);},gotNewPageResponse:function(inRequestObj,inResponseObj){var r=inResponseObj;dialogManager().hide();if(r&&r.uid){if(this.mCallback){gNotifier.print('new_page_confirm');this.mCallback(r.uid,r.url);}
else{gNotifier.printAtPage('new_page_confirm',r.url||gBasePath+r.uid+'/');}}}}
var MovableTableManager=Class.createWithSharedInstance('movableTable');MovableTableManager.prototype={initialize:function(inElement){if(IEFixes.isIE)return;if(!inElement)inElement='editable_content';this.elm=$(inElement);this.elmId=this.elm.id;bindEventListeners(this,['handleClick']);},checkEditor:function(inOptElement){if(IEFixes.isIE)return;this.elm=inOptElement||this.elm;var aImgs=this.elm.getElementsByTagName('img');for(var i=0,c=aImgs.length;i<c;i++){if(Element.hasClassName(aImgs[i],'__tableEditorDragHandle')){var index=aImgs[i].id.replace('draghandle_','');if(aImgs[i].parentNode.getAttribute('id')!='tablecontainer_'+index){this.handleMove(aImgs[i],index);}}}},collapseTablesAfterEditing:function(inOptElement){if(IEFixes.isIE)return;this.elm=inOptElement||this.elm;var aImgs=this.elm.getElementsByTagName('img');for(var i=0,c=aImgs.length;i<c;i++)if(Element.hasClassName(aImgs[i],'__tableEditorDragHandle'))aImgs[i].parentNode.removeChild(aImgs[i]);var aDivs=this.elm.getElementsByTagName('div');for(var i=0,c=aDivs.length;i<c;i++)if(Element.hasClassName(aDivs[i],'__tableContainer'))this.unwrapTableDragContainer(aDivs[i]);},expandTablesForEditing:function(inOptElement){if(IEFixes.isIE)return;this.elm=inOptElement||this.elm;var aTables=this.elm.getElementsByTagName('table');for(var i=0,c=aTables.length;i<c;i++){if(Element.hasClassName(aTables[i],'__useTableEditor'))this.wrapTableDragContainer(aTables[i]);}},handleClick:function(inEvent){var oImg=Event.element(inEvent);if(oImg.tagName.toLowerCase()!='img'&&!Element.hasClassName(oImg,'__tableEditorDragHandle'))return;var oTable=oImg.parentNode.getElementsByTagName('table').item(0);if(!Element.hasClassName(oTable,'__useTableEditor'))return;gEditor.checkEventForTable(inEvent,oTable);},handleMove:function(inImage,inIndex){if(IEFixes.isIE)return;var oDiv=this.elm.getElementById('tablecontainer_'+inIndex);if(!oDiv)return inImage.parentNode.removeChild(inImage);var oTable=oDiv.getElementsByTagName('table').item(0);if(!oTable)return;var extra=oDiv.nextSibling;if(extra&&extra.tagName&&extra.tagName.match(/br/i))extra.parentNode.removeChild(extra);if(inImage.parentNode.tagName.match(/table|caption|thead|tbody|tfoot|tr|th|td/i)){var oParent=inImage.parentNode;oParent.removeChild(inImage);while(oParent.parentNode&&!oParent.tagName.match(/table/i))oParent=oParent.parentNode;if(Element.hasClassName(oParent.parentNode,'__tableContainer'))oParent=oParent.parentNode;inImage=Builder.node('img',{id:'draghandle_'+inIndex,className:'__tableEditorDragHandle',src:'/collaboration/images/blank.gif',width:1,height:1});oParent.parentNode.insertBefore(inImage,oParent);}
inImage.parentNode.insertBefore(oTable,inImage);inImage.parentNode.insertBefore(Builder.node('br'),inImage);oDiv.parentNode.removeChild(oDiv);inImage.parentNode.removeChild(inImage);this.wrapTableDragContainer(oTable,inIndex);},unwrapTableDragContainer:function(elm){if(IEFixes.isIE)return;promoteElementChildren(elm);},wrapTableDragContainer:function(elm,index){if(IEFixes.isIE)return;if(!index&&!(index===0))index=Math.floor(Math.random()*999999);var oImg=Builder.node('img',{id:'draghandle_'+index,className:'__tableEditorDragHandle',src:'/collaboration/images/blank.gif',width:1,height:1});var oDiv=Builder.node('div',{id:'tablecontainer_'+index,className:'__tableContainer'},[oImg]);elm.parentNode.insertBefore(oDiv,elm);elm.parentNode.removeChild(elm);oDiv.appendChild(elm);if(!this.mUseDesignMode)oImg.onclick=gEditor.handleImageClick.bindAsEventListener(gEditor);}}
var AttachmentExpander=Class.create();AttachmentExpander.prototype={initialize:function(){this.expandAttachments();},collapseAttachments:function(){$A(d.getElementsByClassName('attachment')).each(function(a){Element.cleanWhitespace(a);var img=a.firstChild;if((a.nodeName.toLowerCase()=='a')&&img&&(img.nodeName.toLowerCase()=='img')){img.parentNode.removeChild(img);a.parentNode.insertBefore(img,a);a.parentNode.removeChild(a);}});},expandAttachments:function(){$A(d.getElementsByClassName('attachment_handle_img')).each(function(img){Element.cleanWhitespace(img);if(img.nodeName.toLowerCase()=='img'&&img.parentNode.className!='attachment'){var sFullSrc=img.getAttribute('longdesc')||img.getAttribute('name')||img.getAttribute('alt')||img.getAttribute('src');if(!sFullSrc.match(/^\//))sFullSrc='attachments/'+sFullSrc;var a=Builder.node('a',{className:'attachment',href:sFullSrc});img.parentNode.insertBefore(a,img);Element.remove(img);a.appendChild(img);if(img.getAttribute('src').match(/generic_document\.png$/))a.appendChild(d.createTextNode(img.getAttribute('title')));}});}}
var QTMediaExpander=Class.create();QTMediaExpander.prototype={initialize:function(){bindEventListeners(this,['handleClick']);this.mEmbedFrameID=0;this.findMedia();},findMedia:function(){if(!$('page_body'))return false;if(SafariFixes.isMobileSafari){$$('#page_body img.posterimg').each(function(img){var alignMatch=img.className.match(/align\S+/);var fullSrc=img.getAttribute('longdesc')||img.getAttribute('name')||img.getAttribute('alt');var embed='<div id="qtmovie'
+server().getNextUploadID()
+'" class="qtmedia'
+(alignMatch?' '+alignMatch[0]:'')
+'" style="width:'
+img.width
+'px;height:'
+img.height
+'px;"><embed width="'
+img.width
+'" height="'
+img.height
+'" src="'
+img.src
+'" type="video/quicktime" scale="aspect" autoplay="true" controller="false" href="'
+fullSrc
+'?sessionID='
+server().sessionID
+'" target="myself"></div>'
new Insertion.Before(img,embed);Element.remove(img);});return true;}
$A($('page_body').getElementsByTagName('img')).each(function(img){if(Element.hasClassName(img,'posterimg')&&img.onclick!=this.handleClick){img.onclick=this.handleClick;}}.bind(this));},collapseAllMedia:function(){if(!$('page_body'))return false;$A($('page_body').getElementsByTagName('div')).each(function(div){if(!Element.hasClassName(div,'qtmedia'))return false;var img=div.next('img');if(!img||!img.hasClassName('posterimg'))return false;div.remove();img.show();});$A($('page_body').getElementsByTagName('img')).each(function(img){if(Element.hasClassName(img,'posterimg'))img.onclick=invalidate;});},expandMedia:function(inImg){var img=$(inImg);var fullSrc=img.getAttribute('longdesc')||img.getAttribute('name')||img.getAttribute('alt');if(img.width&&img.height&&fullSrc&&fullSrc!=''){var extendHeight=(img.height>=20);var embed=Builder.node('div',{id:'qtmovie1',className:'qtmedia',style:'width:'+img.width+'px;height:'+(img.height+(extendHeight?12:0))+'px'});var alignMatch=img.className.match(/align\S+/);if(alignMatch)Element.addClassName(embed,alignMatch[0]);img.parentNode.insertBefore(embed,img);var objectHTML='<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'+img.width+'" height="'+(img.height+(extendHeight?16:0))+'" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="SRC" value="/collaboration/fake.qti"><param name="QTSRC" value="'+fullSrc+'?sessionID='+server().sessionID+'"><param name="TYPE" value="video/quicktime"><param name="SCALE" value="aspect"><param name="AUTOPLAY" value="true"><param name="CONTROLLER" value="true"><param name="TARGET" value="myself"><param name="BGCOLOR" value="#000000"></object>';if(MozillaFixes.isGecko){Element.hide(img);embed.innerHTML='<embed src="/collaboration/fake.qti" qtsrc="'+fullSrc+'?sessionID='+encodeURIComponent(server().sessionID)+'" type="video/quicktime" autoplay="true", controller="true" target="myself" bgcolor="#ffffff" width="'+img.width+'" height="'+(img.height+(extendHeight?16:0))+'" pluginspage="http://www.apple.com/quicktime/download/" scale="aspect" />';}
else if(IEFixes.isIE){var frmID='qFrame'+(this.mEmbedFrameID++);var qFrame=Builder.node('iframe',{border:'0',frameborder:'0',id:frmID,name:frmID,style:'width:'+img.width+'px;height:'+(img.height+(extendHeight?16:0))+'px;border:0;overflow:hidden'});embed.appendChild(qFrame);$(frmID).contentWindow.document.write('<html><body style="padding:0;margin:0;overflow:hidden">'+objectHTML.replace(/<object/,'<object id="qtmovie1"')+'</body></html>');Element.hide(img);var attempts=0;var checkForPlayer=function(){try{$(frmID).contentWindow.document.qtmovie1.Play();}
catch(e){if(++attempts>10)return false;setTimeout(checkForPlayer,1000);}}
setTimeout(checkForPlayer,1000);}
else{embed.innerHTML=objectHTML;Element.hide(img);}}},handleClick:function(inEvent){var img=Event.element(inEvent);this.expandMedia(img);}}
var TOCGenerator=Class.create();TOCGenerator.prototype={initialize:function(){bindEventListeners(this,['handleShowPopup','handleHidePopup']);$A(d.getElementsByClassName('toc_anchor')).each(function(elm){promoteElementChildren(elm);});this.draw();},draw:function(){var docTitle=$('document_title');if(docTitle&&(!$('directory_listing'))&&(!$('entries_list'))){this.mLinkPopup=gPopupManager.createPopupElement('toolbarpopup','toc_popup');this.mParentElement=$('editable_content');$A(this.mParentElement.getElementsByTagName('*')).each(function(currentNode){var headerMatch=currentNode.nodeName.match(/^h(\d)/i);if(currentNode.firstChild&&headerMatch){var innerText=currentNode.innerText||currentNode.textContent;if(innerText&&innerText.length>0){var callback=function(){Element.scrollTo(currentNode);gPopupManager.hide();if(currentNode.focus)currentNode.focus();return false;}
var item=gPopupManager.itemWithTitle(this.mLinkPopup,innerText,null,callback);item.style.paddingLeft=(parseInt(headerMatch[1])-1)+'em';item.style.paddingRight='1em';}}}.bind(this));docTitle.style.cursor='pointer';Event.observe(docTitle,'mousedown',this.handleShowPopup);}},remove:function(){var docTitle=$('document_title');if(this.mElement){Element.remove(this.mElement);docTitle.setAttribute(title,'');Event.stopObserving(docTitle,'mousedown',this.handleShowPopup);Element.removeClassName(docTitle,'document_toc_link');delete this.mElement;delete this.mParentElement;}},handleShowPopup:function(inEvent){Event.stop(inEvent);gPopupManager.show('document_title',this.mLinkPopup);},handleHidePopup:function(inEvent){Event.stop(inEvent);gPopupManager.hide();}}
TombstoneResurrector=Class.create();TombstoneResurrector.prototype={initialize:function(){if($('tombstoned')&&$('editable_content'))$('tombstoned').onclick=this.handleResurrectLinkClick.bindAsEventListener(this);},handleResurrectLinkClick:function(inEvent){var callback=function(inRequestObj,inResponseObj){dialogManager().hide();replaceElementContents('editable_content',inResponseObj.content,true);gNotifier.print('undelete_page_message');}
dialogManager().showProgressMessage('undelete_page_progress');server()[uid().mService].undeleteEntry(callback.bind(this),uid().mValue);return false;}}
var LinkPreviewGenerator=Class.create();LinkPreviewGenerator.prototype={initialize:function(){this.mApptElement=$('appointment_tooltip');this.mBaseURLRegex=new RegExp(".+"+uid().mBaseLocation);if(this.mApptElement)this.scan();},scan:function(inOptElement){var scanElement=$(inOptElement||d.body);$A(scanElement.getElementsByTagName('a')).each(function(a){if(a.href&&/\/calendar\/[^\/]+\/?$/.test(a.href)){var appointmentUIDMatch=a.href.match(/\/groups\/([^\/]+)\/calendar\/([^\/]+)$/);if(appointmentUIDMatch){a.tooltipUID='groups/'+appointmentUIDMatch[1]+'/calendar/'+appointmentUIDMatch[2];a.tooltipElement=this.mApptElement;a.tooltipCallback=this.getAppointment.bind(this);gTooltipManager.observe(a);}}}.bind(this));},getAppointment:function(inElement){this.mCurrentElement=inElement;serverui().ensureLogin(this.sendAppointmentRequest.bind(this),'read',true);},sendAppointmentRequest:function(){if(this.mCurrentElement.tooltipUID){this.mRequest=server().calendar.getEntryWithUID([this.gotAppointment.bind(this),invalidate],decodeURI(decodeURI(this.mCurrentElement.tooltipUID)));}},gotAppointment:function(inRequestObj,inResponseObj){if(inRequestObj==this.mRequest){var values=inResponseObj;var startDate=createDateObjFromISO8601(values.dtstart);var duration=durationFromISO8601(values.duration);values.time_string=Loc.getTimeRangeDisplayString(startDate,duration);this.mCurrentElement.tooltipValues=values;gTooltipManager.show(this.mApptElement,values);}}}
function addUploadFrame(){if(!$('image_upload_iframe')){d.body.appendChild(Builder.node('iframe',{name:'image_upload_iframe',id:'image_upload_iframe',src:'about:blank',style:'position:absolute;top:0;left:0;width:1px;height:1px;visibility:hidden'}));}
$('image_upload_iframe').show();}
function removeUploadFrame(){if($('image_upload_iframe'))Element.remove('image_upload_iframe');}
if(window.loaded)loaded('wiki.js');

/* ModalTableDialogManager.js */

var ModalTableDialogManager=Class.create();Object.extend(Object.extend(ModalTableDialogManager.prototype,ModalDialogManager.prototype),{showDialog:function(){if(typeof this.mCurrentTable=='undefined'||this.mCurrentTable==this.d)this.mCurrentTable=null;this.drawDialog('',this.mCurrentTable);this.currents=new Object();},getTableInfo:function(inTable){var bEdit=true;if(!inTable){inTable=Builder.node('table',{className:'data'},[Builder.node('tr',{},[Builder.node('th'),Builder.node('th'),Builder.node('th')]),Builder.node('tr',{},[Builder.node('td'),Builder.node('td'),Builder.node('td')]),Builder.node('tr',{},[Builder.node('td'),Builder.node('td'),Builder.node('td')])]);bEdit=false;}else{}
var mTable=new Object();mTable.caption='';mTable.rows=inTable.getElementsByTagName('tr');for(var iRow=0,c=mTable.rows.length;iRow<c;iRow++){Element.cleanWhitespace(mTable.rows[iRow]);}
mTable.headerRow=(mTable.rows[0].lastChild.nodeName.toLowerCase()=='th');mTable.headerCol=(mTable.rows[mTable.rows.length-1].firstChild.nodeName.toLowerCase()=='th');mTable.matrix=new Array();for(var iRow=0,c=mTable.rows.length;iRow<c;iRow++){var elRow=mTable.rows[iRow];mTable.matrix[iRow]=new Object();mTable.matrix[iRow].cells=new Array();for(var iCol=0,c2=elRow.childNodes.length;iCol<c2;iCol++){var elCell=elRow.childNodes[iCol];mTable.matrix[iRow].cells[iCol]=new Object();mTable.matrix[iRow].cells[iCol].href='';mTable.matrix[iRow].cells[iCol].text=elCell.innerHTML.replace(/<br[\s\t\r\n]*\/?>/gi,'\n').replace(/\n$/gi,'');}}
delete mTable.rows;var response=new Object();response.data=mTable;if(bEdit)response.node=inTable;return response;},insertTable:function(inTable){this.syncMatrix();var str='';for(var iRow=0,c=this.mTable.data.matrix.length;iRow<c;iRow++){var bHeaderRow=(this.mTable.data.headerRow&&iRow==0);if(bHeaderRow)str+='<thead>';str+='<tr>';for(var iCol=0,c2=this.mTable.data.matrix[iRow].cells.length;iCol<c2;iCol++){var oCell=this.mTable.data.matrix[iRow].cells[iCol];var bHeaderCol=(this.mTable.data.headerCol&&iCol==0);var sTagName='td';if(bHeaderRow||bHeaderCol)sTagName='th';str+='<'+sTagName+'>'+oCell.text.replace(/[\n]$/gi,'').replace(/[\n]/gi,'<br>')+'</'+sTagName+'>'}
str+='</tr>';if(bHeaderRow)str+='</thead>';}
try{gEditor.mSelectionManager.retrieve()}catch(e){};gEditor.insertTable(str,(inTable&&inTable.node?inTable.node:null));},drawDialog:function(inID,inTable){gEditor.mSelectionManager.store();if(gEditor.mUseDesignMode){gEditor.d.designMode='off';gEditor.d.designMode='on';Event.observe(gEditor.d,'dragdrop',gEditor.checkEditorForMovedTable.bindAsEventListener(gEditor));}
bindEventListeners(this,['handleInputFocus','handleInputBlur','handleOKClick','handleCancelClick','handleDeleteClick','handleKeyPress','handleHeaderRow','handleHeaderCol','handleAddCol','handleDelCol','handleAddRow','handleDelRow']);if(!inID)var inID='tableDialog';this.mTable=this.getTableInfo(inTable);var sHeaderRowButton=(this.mTable.data.headerRow?Loc.table_dialog_row_header_del:Loc.table_dialog_row_header_add);var sHeaderColButton=(this.mTable.data.headerCol?Loc.table_dialog_col_header_del:Loc.table_dialog_col_header_add);var oTableDialogToolbar=Builder.node('div',{className:'tbtoolbar'},[Builder.node('div',{className:'start starttoolbar'},[Builder.node('span')]),Builder.node('div',{className:'contents contentstoolbar'},[Builder.node('ul',{className:'tbbuttons'},[Builder.node('li',{id:'addrow_button',className:'enabled'},[Builder.node('a',{href:'#',id:inID+'AddRow',title:(Loc.table_dialog_addrow)},[Loc.table_dialog_addrow])]),Builder.node('li',{id:'addcol_button',className:'enabled'},[Builder.node('a',{href:'#',id:inID+'AddCol',title:(Loc.table_dialog_addcol)},[Loc.table_dialog_addcol])]),Builder.node('li',{id:'delrow_button',className:'enabled'},[Builder.node('a',{href:'#',id:inID+'DelRow',title:(Loc.table_dialog_delrow)},[Loc.table_dialog_delrow])]),Builder.node('li',{id:'delcol_button',className:'enabled'},[Builder.node('a',{href:'#',id:inID+'DelCol',title:(Loc.table_dialog_delcol)},[Loc.table_dialog_delcol])]),Builder.node('li',{id:'headrow_button',className:'enabled'},[Builder.node('a',{href:'#',id:inID+'HeaderRow',title:sHeaderRowButton},[sHeaderRowButton])]),Builder.node('li',{id:'headcol_button',className:'enabled'},[Builder.node('a',{href:'#',id:inID+'HeaderCol',title:sHeaderColButton},[sHeaderColButton])])]),Builder.node('ul',{className:'tbactions'},[Builder.node('li',{},[Builder.node('a',{href:'#',id:(inID+'Delete'),title:(Loc.table_dialog_delete)},[Loc.table_dialog_delete])])])]),Builder.node('div',{className:'end endtoolbar'},[Builder.node('span')])]);this.oContents=Builder.node('div',{id:(inID+'Contents')});var oForm=Builder.node('form',{id:inID+'Form',method:'get',action:'#',onsubmit:'return false;'},[oTableDialogToolbar,this.oContents]);var oDialog=Builder.node('div',{id:inID,className:'dialog'},[oForm]);this.drawDialogTable();oForm.appendChild(Builder.node('div',{id:inID+'Submit',className:'submit'},[Builder.node('input',{type:'submit',className:'primaryaction',id:inID+'_ok',value:(Loc.table_dialog_ok),name:'ok_button'}),Builder.node('input',{type:'button',className:'secondaryaction',id:inID+'_cancel',value:Loc.cancel,name:'cancel_button'})]));d.body.appendChild(oDialog);this.mActiveElement=oDialog;Event.observe($(inID+'_ok'),'click',this.handleOKClick);Event.observe($(inID+'_cancel'),'click',this.handleCancelClick);Event.observe($(inID+'Delete'),'click',this.handleDeleteClick);Event.observe(d,'keypress',this.handleKeyPress);this.headerRowButton=$(inID+'HeaderRow');this.headerColButton=$(inID+'HeaderCol');Event.observe(this.headerRowButton,'click',this.handleHeaderRow);Event.observe(this.headerColButton,'click',this.handleHeaderCol);Event.observe($(inID+'AddCol'),'click',this.handleAddCol);Event.observe($(inID+'DelCol'),'click',this.handleDelCol);Event.observe($(inID+'AddRow'),'click',this.handleAddRow);Event.observe($(inID+'DelRow'),'click',this.handleDelRow);$(inID+'Form').onsubmit=invalidate;dialogManager().show(this.mActiveElement,null,null,null,null,document.getElementsByName('cell_0_0').item(0));return this.mActiveElement;},drawDialogTable:function(){this.currents=new Object();if(this.oEditTable)Element.remove(this.oEditTable);this.oEditTable=Builder.node('table',{className:'tableEditor'});var oThead=Builder.node('thead');var oTbody=Builder.node('tbody');this.oEditTable.appendChild(oThead);this.oEditTable.appendChild(oTbody);for(var iRow=0,c=this.mTable.data.matrix.length;iRow<c;iRow++){var row=this.mTable.data.matrix[iRow];var oRow=Builder.node('tr');var bHeaderRow=(this.mTable.data.headerRow&&iRow==0);for(var iCol=0,c2=row.cells.length;iCol<c2;iCol++){var cell=row.cells[iCol];var inputName='cell_'+(iRow)+'_'+(iCol);var oInput=Builder.node('textarea',{type:'text',name:inputName,rows:'1'},[cell.text]);var bHeaderCol=(this.mTable.data.headerCol&&iCol==0);var sTagName='td';if(bHeaderRow||bHeaderCol)sTagName='th';var oCell=Builder.node(sTagName,{},[oInput]);oRow.appendChild(oCell);Event.observe(oInput,'focus',this.handleInputFocus);Event.observe(oInput,'blur',this.handleInputBlur);}
if(bHeaderRow)oThead.appendChild(oRow);else oTbody.appendChild(oRow);}
this.oContents.appendChild(this.oEditTable);},syncMatrix:function(){var elements=this.oContents.getElementsByTagName('textarea');for(var i=0,c=elements.length;i<c;i++){var input=elements[i];var coords=input.name.replace('cell_','').split('_');this.mTable.data.matrix[coords[0]].cells[coords[1]].text=$F(input);}},handleInputFocus:function(inEvent){var elm=Event.element(inEvent);if(!elm.tagName||elm.tagName.toLowerCase()!='textarea')return;if(this.mTimer)clearTimeout(this.mTimer);this.currents=new Object();this.currents.input=elm;this.currents.coords=null;if(this.currents.input)this.currents.coords=this.currents.input.getAttribute('name').replace('cell_','').split('_');},handleInputBlur:function(inEvent){this.mTimer=setTimeout(this.clearCurrents.bind(this),200);},clearCurrents:function(){this.currents=new Object();},handleAddCol:function(inEvent){Event.stop(inEvent);this.syncMatrix();var iColIndex=this.mTable.data.matrix[0].cells.length;for(var i=0,c=this.mTable.data.matrix.length;i<c;i++){if(this.currents.coords){iColIndex=parseInt(this.currents.coords[1])+1;this.mTable.data.matrix[i].cells.splice(iColIndex,0,{tagName:'td',href:'',text:''});}else{this.mTable.data.matrix[i].cells.push({tagName:'td',href:'',text:''});}}
this.drawDialogTable();document.getElementsByName('cell_0_'+iColIndex).item(0).focus();},handleDelCol:function(inEvent){Event.stop(inEvent);if(this.mTable.data.matrix[0].cells.length>1){this.syncMatrix();for(var i=0,c=this.mTable.data.matrix.length;i<c;i++){if(this.currents.coords)this.mTable.data.matrix[i].cells.splice(this.currents.coords[1],1);else this.mTable.data.matrix[i].cells.pop();}
this.drawDialogTable();this.clearCurrents();}},handleHeaderCol:function(inEvent){Event.stop(inEvent);this.mTable.data.headerCol=!this.mTable.data.headerCol;this.syncMatrix();this.drawDialogTable();},handleAddRow:function(inEvent){Event.stop(inEvent);this.syncMatrix();var oRow=new Object();oRow.cells=new Array();for(var i=0,c=this.mTable.data.matrix[0].cells.length;i<c;i++){oRow.cells[i]={href:'',text:''}}
if(this.currents.coords){var iRowIndex=parseInt(this.currents.coords[0])+1;this.mTable.data.matrix.splice(iRowIndex,0,oRow);}
else this.mTable.data.matrix.push(oRow);this.drawDialogTable();if(!iRowIndex)iRowIndex=this.mTable.data.matrix.length-1;document.getElementsByName('cell_'+iRowIndex+'_0').item(0).focus();},handleDelRow:function(inEvent){Event.stop(inEvent);if(this.mTable.data.matrix.length>1){this.syncMatrix();if(this.currents.coords)this.mTable.data.matrix.splice(this.currents.coords[0],1);else this.mTable.data.matrix.pop();this.drawDialogTable();this.clearCurrents();}},handleHeaderRow:function(inEvent){Event.stop(inEvent);this.mTable.data.headerRow=!this.mTable.data.headerRow;this.syncMatrix();this.drawDialogTable();},handleKeyPress:function(inEvent){if(inEvent.keyCode==Event.KEY_ESC){this.handleCancelClick(inEvent);}},handleDeleteClick:function(inEvent){if(this.mTable.node)Element.remove(this.mTable.node);this.handleCancelClick(inEvent);},handleCancelClick:function(inEvent){dialogManager().hide();Event.stop(inEvent);Event.stopObserving(d,'keypress',this.handleKeyPress,false);delete gEditor.mTableDialog;if($('tableDialog'))Element.remove($('tableDialog'));},handleOKClick:function(inEvent){this.insertTable(this.mTable);this.handleCancelClick(inEvent);}});if(window.loaded)loaded('ModalTableDialogManager.js');