//crunchinatorvariable_compressed
function fCurrentRowIndex(){fDebugPoint('fCurrentRowIndex','finding row index of caret position');if(document.selection.type=='Control')return-1;var rPos=document.selection.createRange();var oRow=fParentElement(rPos.parentElement(),'TR');if(oRow==null)return-1;return oRow.rowIndex;}function fCurrentCellIndex(){fDebugPoint('fCurrentCellIndex','finding cell index of caret position');if(document.selection.type=='Control')return-1;var rPos=document.selection.createRange();var oCell=fParentElement(rPos.parentElement(),'TD');var oRow=fParentElement(rPos.parentElement(),'TR');if((oRow==null)||(oCell==null))return-1;if(!oRow.contains(oCell))return-1;return(oCell.cellIndex);}function fCurrentTableElement(sElementName,oDoc){fDebugPoint('fCurrentTableElement','finding current '+sElementName);if(oDoc==null)oDoc=document;if(document.selection.type=='Control')return null;var rPos=document.selection.createRange();var oElement=fParentElement(rPos.parentElement(),sElementName);if(!oDoc.all.oEditor.contains(oElement))return null;return oElement;}function fActualRowLength(oRow){fDebugPoint('fActualRowLength','finding actual length of row '+oRow.rowIndex);var nRowWidth=0;for(var i=0;i<oRow.cells.length;i++)nRowWidth+=oRow.cells[i].colSpan;return nRowWidth;}function fMaxTableWidth(oTable){fDebugPoint('fMaxTableWidth','finding max width');if(oTable==null)return 0;var nMaxWidth=0;for(var i=0;i<oTable.rows.length;i++){nRowWidth=fActualRowLength(oTable.rows[i]);if(nRowWidth>nMaxWidth)nMaxWidth=nRowWidth;}return nMaxWidth;}function fFixTable(oTable){fDebugPoint('fFixTable','fixing table');var nMaxTableWidth=fMaxTableWidth(oTable);var aRowSpanEffects=new Array();for(var i=0;i<oTable.rows.length;i++)aRowSpanEffects[i]=0;for(var i=0;i<oTable.rows.length;i++){for(var j=0;j<oTable.rows[i].cells.length;j++){var nSpanFX=oTable.rows[i].cells[j].rowSpan-1;for(var n=1;n<=nSpanFX;n++){aRowSpanEffects[i+n]+=1;}}if((fActualRowLength(oTable.rows[i])+aRowSpanEffects[i])<nMaxTableWidth){oNewCell=oTable.rows[i].insertCell(fCurrentCellIndex);oNewCell.innerHTML='&nbsp;';}}}function fDeleteRow(){fDebugPoint('fDeleteRow','deleting current row');var nCurrentRow=fCurrentRowIndex();var oTable=fCurrentTableElement('TABLE');if(oTable==null)return;oTable.deleteRow(nCurrentRow);fFixTable(oTable);}function fAddColumn(nRowIndex){fDebugPoint('fAddColumn','adding column at '+nRowIndex);if(document.selection.type=='Control')return;var oTable=fCurrentTableElement('TABLE');if(oTable==null)return;for(var i=0;i<oTable.rows.length;i++){oNewCell=oTable.rows[i].insertCell(nRowIndex);oNewCell.innerHTML='&nbsp;';}}function fDeleteColumn(){fDebugPoint('fDeleteColumn','deleting current column');var nCurrentCell=fCurrentCellIndex();var oTable=fCurrentTableElement('TABLE');if(oTable==null)return;for(var i=0;i<oTable.rows.length;i++){oTable.rows[i].deleteCell(nCurrentCell);}}function fAddRow(nRowIndex){fDebugPoint('fAddRow','adding row at '+nRowIndex);var oTable=fCurrentTableElement('TABLE');if(oTable==null)return;var iCellCount=oTable.rows[0].cells.length;oNewRow=oTable.insertRow(nRowIndex);for(var i=0;i<iCellCount;i++){oNewRow.insertCell(-1);oNewRow.cells[i].innerHTML='&nbsp;';}}function fDeleteTable(){fDebugPoint('fDeleteTable','deleting current table');var oTable=fCurrentTableElement('TABLE');if(oTable==null)return;oTable.removeNode(true);}function fMoveColumn(nDirection){fDebugPoint('fMoveColumn','moving column in direction '+nDirection);var oCell=fCurrentTableElement('TD');if(oCell==null)return;var oRow=fParentElement(oCell,'TR');var nCell=oCell.cellIndex;var nRow=oRow.rowIndex;var nDestination=nCell+nDirection;var oTable=fParentElement(oRow,'TABLE');if(nDestination<0)return;for(var i=0;i<oTable.rows.length;i++){if(nCell>oTable.rows[i].cells.length-1)continue;if(nDestination>oTable.rows[i].cells.length-1)continue;if(i==nRow){var nColSpanCache=oTable.rows[i].cells[nCell].colSpan;oTable.rows[i].cells[nCell].colSpan=oTable.rows[i].cells[nDestination].colSpan;oTable.rows[i].cells[nDestination].colSpan=nColSpanCache;}if((oTable.rows[i].cells[nCell].colSpan<=1)){var sHTMLCache=oTable.rows[i].cells[nCell].innerHTML;oTable.rows[i].cells[nCell].innerHTML=oTable.rows[i].cells[nDestination].innerHTML;oTable.rows[i].cells[nDestination].innerHTML=sHTMLCache;}}}function fMoveRow(nDirection){fDebugPoint('fMoveRow','moving row in direction '+nDirection);var nRow=fCurrentRowIndex();var nDestination=nRow+nDirection;oTable=fCurrentTableElement('TABLE');if(oTable==null)return;if((nDestination<0)||(nDestination>oTable.rows.length-1))return;oTable.moveRow(nRow,nDestination);}function fSplitHor(){fDebugPoint('fSplitHor','splitting cell');var oCell=fCurrentTableElement('TD');if(oCell==null)return;if(oCell.rowSpan>1)return;if(oCell.colSpan<=1){var oTable=fParentElement(oCell,'TABLE');for(var i=0;i<oTable.rows.length;i++){var nInsertHere=oCell.cellIndex;if(nInsertHere>=oTable.rows[i].cells.length)nInsertHere=oTable.rows[i].cells.length-1;oTable.rows[i].cells[nInsertHere].colSpan+=1;}}oCell.colSpan-=1;var oRow=fParentElement(oCell,'TR');var oNewCell=oRow.insertCell(oCell.cellIndex+1);oNewCell.innerHTML='&nbsp';}function fSplitVert(){fDebugPoint('fSplitVert','splitting cell');var oCell=fCurrentTableElement('TD');if(oCell==null)return;var oRow=fParentElement(oCell,'TR');var oTable=fParentElement(oRow,'TABLE');if(oCell.rowSpan<=1){oTable.insertRow(oRow.rowIndex+1);var nCurrentRow=oRow.rowIndex;for(var i=0;i<oRow.cells.length;i++)oTable.rows[nCurrentRow].cells[i].rowSpan+=1;}oCell.rowSpan-=1;var oNewCell=oTable.rows[oRow.rowIndex+1].insertCell(oCell.cellIndex);oNewCell.innerHTML='&nbsp';fFixTable(oTable);}function fMergeCellsHor(){fDebugPoint('fMergeCellsHor','merging cells horizontally');var oCell=fCurrentTableElement('TD');if(oCell==null)return;if(oCell.rowSpan>1)return;var oRow=fParentElement(oCell,'TR');var nCell=oCell.cellIndex;if(nCell+1>=oRow.cells.length)return;if(oRow.cells[nCell+1].rowSpan>1)return;oCell.innerHTML+=oRow.cells[nCell+1].innerHTML;oRow.deleteCell(nCell+1);oCell.colSpan+=1;}function fMergeCellsVert(){fDebugPoint('fMergeCellsVert','merging cells vertically');var oCell=fCurrentTableElement('TD');if(oCell==null)return;if(oCell.colSpan>1)return;var oRow=fParentElement(oCell,'TR');var oTable=fParentElement(oRow,'TABLE');var nCell=oCell.cellIndex;var nRow=oRow.rowIndex;if(nRow+oCell.rowSpan>=oTable.rows.length)return;if(oTable.rows[nRow+1].cells[nCell].colSpan>1)return;oCell.innerHTML+=oTable.rows[nRow+1].cells[nCell].innerHTML;oTable.rows[nRow+oCell.rowSpan].deleteCell(nCell);oCell.rowSpan+=1;}fRegister('table.js v.1411022053');
