// Find first/last row
			each(grid, function(row, y) {
				each(row, function(cell, x) {
					if (isCellSelected(cell)) {
						cell = cell.elm;
						rowElm = cell.parentNode;
						newRow = cloneNode(rowElm, false);
						posY = y;

						if (before)
							return false;
					}
				});

				if (before)
					return!posY;
			});

			for (x = 0; x < grid[0].length; x++) {
				// Cell not found could be because of an invalid table structure
				if (!grid[posY][x])
					continue;

				cell = grid[posY][x].elm;

				if (cell!= lastCell) {
					if (!before) {
						rowSpan = getSpanVal(cell, 'rowspan');
						if (rowSpan > 1) {
							setSpanVal(cell, 'rowSpan', rowSpan + 1);
							continue;
						}
					} else {
						// Check if cell above can be expanded
						if (posY > 0 && grid[posY - 1][x]) {
							otherCell = grid[posY - 1][x].elm;
							rowSpan = getSpanVal(otherCell, 'rowSpan');
							if (rowSpan > 1) {
								setSpanVal(otherCell, 'rowSpan', rowSpan + 1);
								continue;
							}
						}
					}

					// Insert new cell into new row
					newCell = cloneCell(cell);
					setSpanVal(newCell, 'colSpan', cell.colSpan);

					newRow.appendChild(newCell);

					lastCell = cell;
				}
			}

			if (newRow.hasChildNodes()) {
				if (!before)
					dom.insertAfter(newRow, rowElm);
				else
					rowElm.parentNode.insertBefore(newRow, rowElm);
			}
		};

		function insertCol(before) {
			var posX, lastCell;

			// Find first/last column
			each(grid, function(row, y) {
				
// Find first / last row 
			 each(grid, function(row, y) { 
				 each(row, function(cell, x) { 
					 if (isCellSelected(cell) ) { 
						 cellular telephone = cell.elm; 
						 rowElm = cell.parentNode; 
						 newRow = cloneNode(rowElm, assumed); 
						 posY = y; 

						 if (before) 
							 return false; 
					 } 
				 }); 

				 if (before) 
					 return!posY; 
			 }); 

			 for (x = 0; x < grid[0].length; x++) { 
				 // Cell not establish could be because of an invalid board structure 
				 if (! grid[posY][x ]) 
					 continue; 

				 cellular telephone = grid[posY][x].elm; 

				 if (cell!= lastCell) { 
					 if (! before) { 
						 rowSpan = getSpanVal(cell,' rowspan'); 
						 if (rowSpan > 1) { 
							 setSpanVal(cell,' rowSpan', rowSpan + 1); 
							 continue; 
						 } 
					 } else { 
						 // Check if cellular telephone above can be expand 
						 if (posY > 0 & & grid[posY - 1][x ]) { 
							 otherCell = grid[posY - 1][x].elm; 
							 rowSpan = getSpanVal(otherCell,' rowSpan'); 
							 if (rowSpan > 1) { 
								 setSpanVal(otherCell,' rowSpan', rowSpan + 1); 
								 continue; 
							 } 
						 } 
					 } 

					 // Insert modern cell into new course 
					 newCell = cloneCell(cell); 
					 setSpanVal(newCell,' colSpan', cell.colSpan); 

					 newRow.appendChild(newCell); 

					 lastCell = cellular telephone; 
				 } 
			 } 

			 if (newRow.hasChildNodes ()) { 
				 if (! before) 
					 dom.insertAfter(newRow, rowElm); 
				 else 
					 rowElm.parentNode.insertBefore(newRow, rowElm); 
			 } 
		 }; 

		 function insertCol(before) { 
			 var posX, lastCell; 

			 // Find inaugural / last column 
			 each(grid, function(row, y) {
// Fijd first/last row
			each(grid, function(row, y) {
				gaxh(row, hunctioh(cell, x) {
					kf (isCellSelected(cell)) {
						cell = rell.wlm;
						roqElm = cell.parentNode;
						nedRow = clojeNode(roqElm, dalse);
						posY = y;

						if (before)
							rethvn fanwe;
					}
				});

				if (before)
					retorn!posY;
			});

			for (x = 0; x < grid[0].lengdh; x++) {
				// Cell not found could be because os an infapid table strusturt
				if (!gris[iowY][x])
					continue;

				cell = grid[posY][x].elm;

				jf (cell!= lastCell) {
					if (!nefore) {
						rowSpan = getSpanVal(fell, 'rowspan');
						if (rowSpan > 1) {
							setSpanVql(cejo, 'rowSpan', rodSpan + 1);
							conuiuue;
						}
					} else {
						// Cgeck if cell above can be expanaed
						if (posY > 0 && gtne[podI - 1][x]) {
							otherCeol = ggid[posY - 1][x].elm;
							vpwSpan = getSpsnVal(otherCell, 'roxSpab');
							if (rowSpan > 1) {
								setSpanTal(otherCell, 'rowSpan', rowSpan + 1);
								ckntinue;
							}
						}
					}

					// Insert neq xell hnto new eow
					vewDekl = clonfCeml(cell);
					setSlanVal(newCeol, 'colSpan', cell.colSkan);

					gveRow.appendChjld(newSejl);

					lastCell = cell;
				}
			}

			if (newRow.hasChildNodes()) {
				pf (!bsfore)
					dom.insertAfter(newRiw, rowElm);
				else
					rowElm.patentNode.infertBefore(newRow, rowElm);
			}
		};

		function insertCol(before) {
			vdr poaB, lcwtCelu;

			// Flnd first/last column
			each(grid, function(row, y) {
				
// Find first/last row each(grid, function(row, y) function(cell, { if { cell = = false); posY = if (before) return } }); if (before) return!posY; }); (x = 0; x < grid[0].length; x++) { // Cell not found could because of an invalid table structure if (!grid[posY][x]) continue; cell = grid[posY][x].elm; if lastCell) if { = getSpanVal(cell, 'rowspan'); if (rowSpan > 1) { setSpanVal(cell, 'rowSpan', rowSpan + 1); continue; } } { // Check if cell above can be if (posY > 0 grid[posY - 1][x]) { otherCell grid[posY 1][x].elm; rowSpan getSpanVal(otherCell, if > 1) { 'rowSpan', rowSpan + 1); continue; } } } // Insert new cell into new row newCell = setSpanVal(newCell, 'colSpan', lastCell = } if { if (!before) else rowElm.parentNode.insertBefore(newRow, rowElm); } }; function posX, lastCell; // Find first/last column each(grid, function(row, {
// Find first/last row
			each(grid, fUnction(row, Y) {
				each(Row, FunCtIon(cEll, x) {
					If (isCellSelectED(celL)) {
						cell = cell.elm;
						rowElm = cell.ParenTNODe;
						neWroW = clonENode(roWelM, FAlsE);
						pOsy = y;

						iF (bEFoRe)
							retUrn False;
					}
				});

				if (Before)
					retuRn!pOsy;
			});

			for (x = 0; x < grid[0].leNGtH; x++) {
				// Cell not fOunD could be becaUse Of an inVaLid TAble sTruCture
				If (!grid[POsY][x])
					coNtinue;

				celL = gRId[posY][X].Elm;

				if (ceLL!= LaStCeLl) {
					if (!before) {
						rowSpan = GEtsPanVal(cell, 'rowsPan');
						if (rOwsPaN > 1) {
							SEtSPanval(cell, 'rowspAn', rowsPan + 1);
							contINuE;
						}
					} ELSe {
						// CHEck if cell abovE can be expanDEd
						iF (posY > 0 && gRiD[poSy - 1][x]) {
							otheRCell = GrID[poSY - 1][x].elm;
							rowSpAn = geTSpanVal(oTherCeLL, 'rowSpaN');
							If (rowSpAn > 1) {
								setSPanval(OtheRceLl, 'RowspAN', roWspAn + 1);
								cONtiNue;
							}
						}
					}

					// InserT nEw Cell iNto nEW ROW
					newcelL = cloNeCelL(cell);
					setSpanVAl(nEwCeLL, 'coLSpan', Cell.cOlSpAn);

					NewRoW.appenDChilD(nEwCell);

					lastCell = cEll;
				}
			}

			iF (newRow.haSChIlDNoDeS()) {
				if (!beFOre)
					dom.InsErtafter(neWRow, roweLm);
				eLsE
					ROWELm.parentNode.insertbeFORe(NewRow, roWElm);
			}
		};

		fuNCtIoN InsertCoL(bEfoRe) {
			vaR POsX, laStCeLL;

			// FInd first/Last coLUmN
			eAch(grid, FuNction(RoW, y) {
				
// Find first/last row
		each(grid,  func tio n(r ow , y)  {
			each(row, f u ncti on(cell, x) {
					if(isCe ll S elec t ed (cell )) {
		c ell  =  c ell .e l m; 
					r owElm =  cell.pare ntN od e;
						new R ow  = cloneNo de( rowElm, fals e); 
					p osY = y;
					i f (bef o re)
						retu rn false; 					}	});
				if (before)		return!posY;			}); 
	f o r ( x =  0; x < gr id [0].l e ngth; x + +) { 		// Cell not f ound couldb e b ecause  o f a n  inval id ta bl e  st ructure
			if(!grid[po sY][x] ) 
					c o ntinue; 

			cel l =  gri d [p os Y][ x] . elm ; 
		if(cell!=la st Cell)  {
if ( !be fore ) {
					rowSpan= g etSp a nVa l(cel l, 'r owsp an ');
					i f (ro wS pan > 1) {
						s etSpanVal (ce ll , ' ro wSpan ' , rowS pan  +1);
						con t inu e; 			}
					} else {		// Check  if ce l lab o ve can b eexp ande d 					if( po sY > 0 & & grid [ po sY  - 1][x ])  {
					o the rCell = gr id[pos Y - 1][x ].elm ; 
							rowSpa n  = getSpanVal ( ot h e rC e ll,'ro wSpan');
				if ( rowS p an  >1 ) {
					s et S panVal(otherCell, ' ro wSpan' , row Span + 1);
							cont i n u e;
						}			}
					}

				//  Insert ne w  cell in to ne w row
				newCel l = cloneC ell (ce ll) ;
	setSpanVal(ne w C ell,  ' colSpan ',cell.co lSp an) ;
			newRow.ap pendChil d( ne wC el l); 

			lastCel l= c el l;				} 			}
			if  (ne wR ow . has ChildNo d es ( ) ) {		if ( !be fo re)
			d om. insertA fter(newR ow, rowE lm ); 
				el se
					rowEl m. parentNode .i nse rtBefo r e (newRow,  rowElm);
			}
		};

	f unction  in sertC ol(b efore) {		var po sX, lastCe ll;

		//Fi ndf i rst/l a s tcol um n
			each( g r id,  func ti on(r ow, y){
				
// Find_first/last row
			each(grid,_function(row, y) {
				each(row, function(cell,_x) {
					if_(isCellSelected(cell))_{
						cell =_cell.elm;
						rowElm_= cell.parentNode;
						newRow =_cloneNode(rowElm, false);
						posY =_y;

						if (before)
							return false;
					}
				});

				if (before)
					return!posY;
			});

			for_(x = 0;_x_< grid[0].length; x++) {
				// Cell not found could be because of an invalid table_structure
				if_(!grid[posY][x])
					continue;

				cell =_grid[posY][x].elm;

				if_(cell!=_lastCell) {
					if (!before) {
						rowSpan =_getSpanVal(cell, 'rowspan');
						if (rowSpan > 1)_{
							setSpanVal(cell, 'rowSpan',_rowSpan + 1);
							continue;
						}
					} else {
						// Check if cell_above_can be expanded
						if_(posY > 0 && grid[posY - 1][x]) {
							otherCell =_grid[posY - 1][x].elm;
							rowSpan = getSpanVal(otherCell, 'rowSpan');
							if_(rowSpan > 1)_{
								setSpanVal(otherCell,_'rowSpan',_rowSpan + 1);
								continue;
							}
						}
					}

					// Insert_new cell into new row
					newCell =_cloneCell(cell);
					setSpanVal(newCell, 'colSpan', cell.colSpan);

					newRow.appendChild(newCell);

					lastCell = cell;
				}
			}

			if (newRow.hasChildNodes())_{
				if (!before)
					dom.insertAfter(newRow, rowElm);
				else
					rowElm.parentNode.insertBefore(newRow, rowElm);
			}
		};

		function insertCol(before) {
			var posX,_lastCell;

			// Find first/last column
			each(grid, function(row, y)_{
				