1 define(['jquery', 'require','Collections','DomObjects'], 
  2     function ( $, require, Collections,DomObjects) {
  3    		/**
  4 		 * A Class to handle the User Inteface of Cells in Worksheet/Grid 
  5 		 * @name GridView
  6 		 * @class WorkBook
  7 		 * @example require('GridView')
  8 		 * @exports GridView
  9 		 * @version 1.0
 10 		 * @module GridView
 11 		 * @augments jquery
 12 		 * @augments DomObjects
 13 		 * @augments Collections
 14 		 **/
 15         var GridView = {
 16 			KEY:$.key,
 17 			editorTextFieldDiv:'',
 18 			lastHighlighedTD:'',
 19 			sibUp:'',
 20 			sibLeft:'',
 21 			selectedCell:new Object(),// Object ROW, COL Will maintain teh Current Selected CELL
 22 			highlightedGroupId:Collections.Set(),// Keep the Track of Last highlighted group.
 23 			/**
 24 			 * @name getViewRows
 25 			 * @memberOf GridView
 26 			 * @method 
 27 			 * @return {Integer} rows The number of rows can be shown in the current view.
 28 			 * @description Depends on the Browser Size, the Visible Rows Size are different, It returns the Maximum Number of Rows That can present in Current View. 
 29 			 * @function
 30 			 */
 31 			getViewRows:function(){
 32 				return parseInt($('div.dataTableDiv').height()/20)+10;
 33 			},
 34 			/**
 35 			 * @name setSize
 36 			 * @memberOf GridView
 37 			 * @method 
 38 			 * @description sets the size of teh GridView with respect to the Windowsize. 
 39 			 * @function
 40 			 */
 41 			setSize:function(){
 42 				$('div.content').width($( window ).width()-25);
 43 				$('div.content').height($( window ).height()-25);
 44 			},
 45 			/**
 46 			 * @name cancelCellEdit
 47 			 * @memberOf GridView
 48 			 * @method 
 49 			 * @param {Object} cell
 50 			 * @description This method will cancell the cell edit, by removing editCellDiv from DOM, and updates the cell value. It will be called once the user select another while editing the cell, hence the cell value need to be saved. 
 51 			 * @function
 52 			 */
 53 			cancelCellEdit:function(cell){
 54 				GridView = require("GridView");
 55 				if(GridView.editorTextFieldDiv && !cell){
 56 					var currentCellObj = GridView.getHighlightedCellObj();
 57 					GridView.updateCell(currentCellObj.getSheetId(), parseInt(currentCellObj.getRow())-1, parseInt(currentCellObj.getColumn())-1, currentCellObj.getValue() ,$(GridView.editorTextFieldDiv).find('input').val());
 58 				}
 59 				$(GridView.editorTextFieldDiv).remove();
 60 				GridView.editorTextFieldDiv=null;
 61 				if(HANDLER.CELL_DRAG_HANDLER.TARGET)
 62 					GridView.CELL_DRAG.positionSelectionCornerDiv(HANDLER.CELL_DRAG_HANDLER.TARGET);
 63 			},
 64 
 65 			/**
 66 			 * @name clearArea
 67 			 * @memberOf GridView
 68 			 * @method 
 69 			 * @param {Object} selection Selection Object should be {}
 70 			 * @description It clears the the Area provided if there is no Group formula found. 
 71 			 * @function
 72 			 */
 73 			clearArea:function(selection){
 74 				GridView = require("GridView");
 75 				WorkBook = require('WorkBook');
 76 				NexcelUI = require("NexcelUI");
 77 				var updatedCellList = Collections.ArrayList();
 78 				NexcelCellList = require("NexcelCellList");
 79 				var sheetId = WorkBook.ACTIVE_SHEET_ID;
 80 				var trList = $('#dataTable tr');
 81 				var cellFormula;
 82 				for(row=parseInt(selection.START_ROW);row<=parseInt(selection.CURR_ROW);row++){
 83 					for(col=parseInt(selection.START_COL);col<=parseInt(selection.CURR_COL);col++){
 84 						if(GridView.isCellAssociatedWithGroupWithFormula((row+1), (col+1), GridView.ACTIVE_SHEET_ID))
 85 							continue;
 86 						var nCell = NexcelCellList.isExist(sheetId, (row+1), (col+1));
 87 						try{
 88 							$($(trList[row]).find('td')[col]).html('');// Just Updating teh value in GRID_VIEW. Need to Update the TD_LIST as well
 89 						}catch(e){}
 90 						if(nCell){
 91 							nCell.setValue('');
 92 							nCell.setFormula(cellFormula);// Making as Null
 93 						}
 94 						else
 95 							nCell = NexcelCellList.addCellWithDetails(sheetId, (row+1), (col+1), cellFormula, '');
 96 						updatedCellList.add(nCell);
 97 					}
 98 				}
 99 				NexcelUI.CELL.DATA.updateListOfCells(updatedCellList);
100 				require(['DependencyGraphController'],function(dependencyGraphController){
101 					var _CXT = new Object();
102 					_CXT.formulaList = [];
103 					_CXT.valueList = [];
104 					var cellList = [];
105 					var dependencyTable = require('DependencyTableController').getDependencyTable();
106 					for(var i=0; i<updatedCellList.size(); i++){
107 						var cell = updatedCellList.get(i);
108 						var cellName = require('GridView').getCellFullName(cell.getSheetId(), cell.getRow(), cell.getColumn());
109 						var groupList = require('GridView').getGroupsOnCell(cell.getSheetId(), cell.getRow(), cell.getColumn());
110 						for(var j=0; j<groupList.length; j++)
111 							dependencyTable.push([3001, cellName, 3002, groupList[j].name]);
112 						cellList.push(cellName);
113 					}
114 					require('NexcelDependencyEvaluationController').evaluateDependency(dependencyTable, require('CONSTANT').DEP_SOURCE_TYPE.CELL, cellList, _CXT);
115 					require('NexcelUI').updateCalculatedDependents(_CXT.valueList);
116 					///dependencyGraphController.evaluateCellDependents(calculatedCellObj);
117 				});
118 				//require('DependencyGraphController').evaluateCellListDependents(updatedCellList);
119 			},
120 
121 			/**
122 			 * @name clearRow
123 			 * @memberOf GridView
124 			 * @method 
125 			 * @description Clears the complete row if the cell is not associted a group with a formula. the row number is calculated from the selection happened earlier by the user. 
126 			 * @function
127 			 */
128 			clearRow : function(){
129 				GridView = require("GridView");
130 				GridView.clearArea(HANDLER.SELECTION_HANDLER);
131 			},
132 
133 			/**
134 			 * @name clearColumn
135 			 * @memberOf GridView
136 			 * @method 
137 			 * @description Clears the complete column if the cell is not associted a group with a formula. the row number is calculated from the selection happened earlier by the user. 
138 			 * @function
139 			 */
140 			clearColumn:function(){
141 				GridView = require("GridView");
142 				GridView.clearArea(HANDLER.SELECTION_HANDLER);
143 			},
144 			/**
145 			 * GridView Add or Remove Row or Column based functions comes under this Sub Class
146 			 * @name ADD_REM_ROW_COL
147 			 * @class ADD_REM_ROW_COL
148 			 * @example require('GridView').ADD_REM_ROW_COL
149 			 * @exports ADD_REM_ROW_COL
150 			 * @version 1.0
151 			 * @module GridView
152 			 * @memberOf GridView
153 			 **/
154 			ADD_REM_ROW_COL:{
155 
156 				/**
157 				 * @name moveGroupOnRowAdd
158 				 * @memberOf GridView.ADD_REM_ROW_COL
159 				 * @method 
160 				 * @description This method simply reposition group position values in group Object 
161 				 * @param {Integer} sheetId
162 				 * @param {Integer} pos which position the row is inserted or deleted.
163 				 * @param {Integer} rows Number of rows, if deleted, then the value will be negative.
164 				 * @function
165 				 */
166 				moveGroupOnRowAdd:function(sheetId, pos, rows){
167 					var groupList = require('NexcelGroupList').getGroupObjListOnSheet(sheetId);
168 					for(var i=0; i<groupList.size(); i++){
169 						var group = groupList.get(i);
170 						var changed = false;
171 						if(group.rowStart>= pos){
172 							group.rowStart = parseInt(group.rowStart) + parseInt(rows);
173 							group.rowEnd = parseInt(group.rowEnd) + parseInt(rows);
174 							changed = true; 
175 						}else if(group.rowEnd>= pos){
176 							group.rowEnd = parseInt(group.rowEnd) + parseInt(rows);
177 							changed = true; 
178 						}	
179 						if(changed){
180 							require('NexcelUIDataService').updateGroupSize(group);
181 						}
182 						
183 					}
184 				},
185 
186 				/**
187 				 * @name moveGroupOnColAdd
188 				 * @memberOf GridView.ADD_REM_ROW_COL
189 				 * @method 
190 				 * @param {Integer} sheetId
191 				 * @param {Integer} pos which position the row is inserted or deleted.
192 				 * @param {Integer} columns Number of columns, if deleted, then the value will be negative.
193 				 * @description This method simply reposition group position.  Columns can be -ve value -> -2 means two columns deleted +2 means added 2 columns 
194 				 * @function
195 				 */
196 				moveGroupOnColAdd:function(sheetId, pos, columns){
197 					var groupList = require('NexcelGroupList').getGroupObjListOnSheet(sheetId);
198 					for(var i=0; i<groupList.size(); i++){
199 						var group = groupList.get(i);
200 						var changed = false;
201 						if(group.colStart>= pos){
202 							group.colStart = parseInt(group.colStart) + parseInt(columns);
203 							group.colEnd = parseInt(group.colEnd) + parseInt(columns); 
204 							changed = true; 
205 						}else if(group.colEnd>= pos){
206 							group.colSize = parseInt(group.colSize) + parseInt(columns); 
207 							group.colEnd = parseInt(group.colEnd) + parseInt(columns);
208 							changed = true; 
209 						} 
210 						if(changed){
211 							require('NexcelUIDataService').updateGroupSize(group);
212 						}
213 					}
214 				},
215 				/**
216 				 * @name addRowAbove
217 				 * @memberOf GridView.ADD_REM_ROW_COL
218 				 * @method 
219 				 * @description This method will add a row above the current selection row, It will validate whether a row can be inserted or not.If it will add a row in a group with formula, then the group value will be filtered to avoid the blank values in group result.
220 				 * As the row added, then the refering expressions row and column will be calculated and updated with relative formula. 
221 				 * @function
222 				 */
223 				addRowAbove:function(){
224 					var GridView = require("GridView");
225 					var WorkBook = require('WorkBook');
226 					var MouseListener =  require('MouseListener');
227 					var canInsert = GridView.ADD_REM_ROW_COL.checkForRowInsert(GridView.ACTIVE_SHEET_ID,(HANDLER.SELECTION_HANDLER.START_ROW));
228 					if(!canInsert.INSERT){
229 						modal({
230 							type  : 'alert',
231 							title : 'Warning! Cannot Insert row above',
232 							text  : canInsert.reason
233 						});
234 						return false;
235 					}
236 					//Remove Exisiting Highlight.
237 					GridView.highlightSelectionArea(MouseListener.getOrderedSelectionPos(HANDLER.SELECTION_HANDLER), DomObjects.defaultBorderCol);
238 					var row = $('#dataTable tr')[HANDLER.SELECTION_HANDLER.START_ROW];
239 					console.log('Row is :'+row);
240 					var columns = $(row).find('td').length;
241 					var rowStr = "<tr>";
242 					for(var i=0; i< columns; i++){
243 						if(i==0)
244 							rowStr = rowStr + '<td><img src="img/w1px.png"/></td>';
245 						else
246 							rowStr = rowStr + "<td></td>";
247 					}
248 					rowStr = rowStr + "</tr>";
249 					var newRow = $(rowStr).insertBefore($(row));
250 					$(newRow).find('td').each(function(){
251 						MouseListener.setCellListener(this);
252 						require('KeyListener').setCellListener(this);
253 					});
254 					NexcelCellList = require('NexcelCellList');
255 					NexcelCellList.moveRow(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_ROW+1, 1);
256 					workBookDataService.addRow(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_ROW+1, 1);
257 					GridView.ADD_REM_ROW_COL.moveGroupOnRowAdd(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_ROW+1, 1);
258 					
259 					var startCell = GridView.getCellName(HANDLER.SELECTION_HANDLER.START_ROW+1, 1);
260 					var cellList = NexcelCellList.getListOfCellWithFormula(WorkBook.ACTIVE_SHEET_ID,{row:(HANDLER.SELECTION_HANDLER.START_ROW+1),col:1});
261 					GridView.ADD_REM_ROW_COL.updateCellFormulaOnRowColAdd(cellList, startCell, 1, 0);
262 					GridView.ADD_REM_ROW_COL.updateGroupFormulaOnRowColAdd(WorkBook.ACTIVE_SHEET_ID, startCell, 1, 0);
263 					GridView.ADD_REM_ROW_COL.removeEmptyRowsInGroupWithFormulaOnRowAdd(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_ROW+1, HANDLER.SELECTION_HANDLER.END_ROW+1);
264 					
265 					//Highlight the old One.
266 					GridView.highlightSelectionArea(MouseListener.getOrderedSelectionPos(HANDLER.SELECTION_HANDLER), DomObjects.selectionAreaBorderColor);
267 					HANDLER.SELECTION_HANDLER.ROW_SELECTION_STARTED = false;
268 				},
269 				/**
270 				 * @name addRowBelow
271 				 * @memberOf GridView.ADD_REM_ROW_COL
272 				 * @method 
273 				 * @description This method will add a row below the current selection row, It will validate whether a row can be inserted or not.If it will add a row in a group with formula, then the group value will be filtered to avoid the blank values in group result.
274 				 * As the row added, then the refering expressions row and column will be calculated and updated with relative formula. 
275 				 * @function
276 				 */
277 				addRowBelow:function(){
278 					GridView = require("GridView");
279 					var WorkBook = require('WorkBook');
280 					var MouseListener =  require('MouseListener');
281 					var canInsert = GridView.ADD_REM_ROW_COL.checkForRowInsert(GridView.ACTIVE_SHEET_ID,(HANDLER.SELECTION_HANDLER.START_ROW+1));
282 					if(!canInsert.INSERT){
283 						modal({
284 							type  : 'alert',
285 							title : 'Warning! Cannot Insert row below',
286 							text  : canInsert.reason
287 						});
288 						return false;
289 					}
290 					//Remove Exisiting Highlight.
291 					GridView.highlightSelectionArea(MouseListener.getOrderedSelectionPos(HANDLER.SELECTION_HANDLER), DomObjects.defaultBorderCol);
292 					var row = $('#dataTable tr')[HANDLER.SELECTION_HANDLER.START_ROW];
293 					var columns = $(row).find('td').length;
294 					var rowStr = "<tr>";
295 					for(var i=0; i< columns; i++){
296 						if(i==0)
297 							rowStr = rowStr + '<td><img src="img/w1px.png"/></td>';
298 						else
299 							rowStr = rowStr + "<td></td>";
300 					}
301 					rowStr = rowStr + "</tr>";
302 					var newRow = $(rowStr).insertAfter($(row));
303 					$(newRow).find('td').each(function(){
304 						MouseListener.setCellListener(this);
305 						require('KeyListener').setCellListener(this);
306 					});
307 					nexcelCellList = require("NexcelCellList");
308 					nexcelCellList.moveRow(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_ROW+2, 1);
309 					workBookDataService.addRow(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_ROW+2, 1);
310 					GridView.ADD_REM_ROW_COL.moveGroupOnRowAdd(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_ROW+2, 1);
311 					
312 					var startCell = GridView.getCellName(HANDLER.SELECTION_HANDLER.START_ROW+2, 1);
313 					var cellList = nexcelCellList.getListOfCellWithFormula(WorkBook.ACTIVE_SHEET_ID,{row:(HANDLER.SELECTION_HANDLER.START_ROW+2),col:1});
314 					GridView.ADD_REM_ROW_COL.updateCellFormulaOnRowColAdd(cellList, startCell, 1, 0);
315 					GridView.ADD_REM_ROW_COL.updateGroupFormulaOnRowColAdd(WorkBook.ACTIVE_SHEET_ID, startCell, 1, 0);
316 					GridView.ADD_REM_ROW_COL.removeEmptyRowsInGroupWithFormulaOnRowAdd(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_ROW+2, HANDLER.SELECTION_HANDLER.END_ROW+2);
317 					//Highlight the old One.
318 					GridView.highlightSelectionArea(MouseListener.getOrderedSelectionPos(HANDLER.SELECTION_HANDLER), DomObjects.selectionAreaBorderColor);
319 					HANDLER.SELECTION_HANDLER.ROW_SELECTION_STARTED = false;
320 				},
321 				
322 				/**
323 				 *	GridView.ADD_REM_ROW_COL.checkForRowInsert
324 				 *  Checks whether i can add a row above or below.
325 				 *  we are checking whether can insert after the row provided. 
326 				 */
327 				/**
328 				 * @name checkForRowInsert
329 				 * @memberOf GridView.ADD_REM_ROW_COL
330 				 * @param {Integer} sheetId
331 				 * @param {Integer} row 
332 				 * @return {boolean} whether a row can be inserted
333 				 * @method 
334 				 * @description It will check whether a row can be inserted on the provided row of the sheetId provided.It will deny if try to insert a row between Group name and column names. 
335 				 * @function
336 				 */
337 				checkForRowInsert:function(sheetId, row){
338 					
339 					var result =new Object();
340 					result.INSERT = true;
341 					var groupList = require('NexcelGroupList').getGroupObjListWithGroupFormula(sheetId);
342 					for(var i=0; i<groupList.size(); i++){
343 						var group = groupList.get(i);
344 						if(group.colNameAvailable && group.groupTitle){
345 							if(group.rowStart == row){
346 								result.reason = group.name+" : Cannot insert row in header";
347 								result.INSERT = false;
348 								return result;
349 							}				
350 						}
351 					}
352 					return result;			
353 				},
354 				/**
355 				 * @name addColumnRight
356 				 * @memberOf GridView.ADD_REM_ROW_COL
357 				 * @method 
358 				 * @description This method will add a column right to the current selection column, It will validate whether a row can be inserted or not.If it will add a row in a group with formula, then the group value will be filtered to avoid the blank values in group result.
359 				 * As the row added, then the refering expressions row and column will be calculated and updated with relative formula. 
360 				 * @function
361 				 */
362 				addColumnRight:function(){
363 					GridView = require("GridView");
364 					var WorkBook = require('WorkBook');
365 					var MouseListener =  require('MouseListener');
366 					//Remove Exisiting Highlight.
367 					GridView.highlightSelectionArea(MouseListener.getOrderedSelectionPos(HANDLER.SELECTION_HANDLER), DomObjects.defaultBorderCol);
368 					var rows = $('#dataTable tr');
369 					for(var i=0; i< rows.length; i++){
370 						var td = $('<td/>');
371 						var row = rows[i];
372 						var column = $(row).find('td')[HANDLER.SELECTION_HANDLER.START_COL];
373 						$(td).insertAfter($(column));
374 						MouseListener.setCellListener($(td));
375 						require('KeyListener').setCellListener($(td));
376 					}
377 					nexcelCellList = require("NexcelCellList");
378 					nexcelCellList.moveColumn(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_COL+2, 1);
379 					workBookDataService.addColumn(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_COL+2, 1);
380 					GridView.ADD_REM_ROW_COL.moveGroupOnColAdd(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_COL+2, 1);
381 					
382 					var startCell = GridView.getCellName(1, HANDLER.SELECTION_HANDLER.START_COL+2);
383 					var cellList = nexcelCellList.getListOfCellWithFormula(WorkBook.ACTIVE_SHEET_ID,{row:1, col:(HANDLER.SELECTION_HANDLER.START_COL+2)});
384 					GridView.ADD_REM_ROW_COL.updateCellFormulaOnRowColAdd(cellList, startCell, 0, 1);
385 					GridView.ADD_REM_ROW_COL.updateGroupFormulaOnRowColAdd(WorkBook.ACTIVE_SHEET_ID, startCell, 0,1);
386 					GridView.ADD_REM_ROW_COL.addColumnFieldInFormulaForColumnAdd(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_COL+2);
387 					GridView.highlightSelectionArea(MouseListener.getOrderedSelectionPos(HANDLER.SELECTION_HANDLER), DomObjects.selectionAreaBorderColor);
388 					HANDLER.SELECTION_HANDLER.ROW_SELECTION_STARTED = false;
389 				},
390 				
391 				/**
392 				 * @name addColumnLeft
393 				 * @memberOf GridView.ADD_REM_ROW_COL
394 				 * @method 
395 				 * @description This method will add a column left to the current selection column, It will validate whether a row can be inserted or not.If it will add a row in a group with formula, then the group value will be filtered to avoid the blank values in group result.
396 				 * As the row added, then the refering expressions row and column will be calculated and updated with relative formula. 
397 				 * @function
398 				 */
399 				addColumnLeft:function(){
400 					GridView = require("GridView");
401 					var WorkBook = require('WorkBook');
402 					var MouseListener =  require('MouseListener');
403 					GridView.highlightSelectionArea(MouseListener.getOrderedSelectionPos(HANDLER.SELECTION_HANDLER), DomObjects.defaultBorderCol);
404 					var rows = $('#dataTable tr');
405 					for(var i=0; i< rows.length; i++){
406 						var td = $('<td/>');
407 						if(HANDLER.SELECTION_HANDLER.START_COL==0)
408 							td = $('<td><img src="img/w1px.png"/></td>');
409 						var row = rows[i];
410 						var column = $(row).find('td')[HANDLER.SELECTION_HANDLER.START_COL];
411 						$(td).insertBefore($(column));
412 						MouseListener.setCellListener($(td));
413 						require('KeyListener').setCellListener($(td));
414 					}
415 					nexcelCellList = require("NexcelCellList");
416 					nexcelCellList.moveColumn(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_COL+1, 1);
417 					workBookDataService.addColumn(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_COL+1, 1);
418 					GridView.ADD_REM_ROW_COL.moveGroupOnColAdd(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_COL+1, 1);
419 					
420 					var startCell = GridView.getCellName(1, HANDLER.SELECTION_HANDLER.START_COL+1);
421 					var cellList = nexcelCellList.getListOfCellWithFormula(WorkBook.ACTIVE_SHEET_ID,{row:1, col:(HANDLER.SELECTION_HANDLER.START_COL+1)});
422 					GridView.ADD_REM_ROW_COL.updateCellFormulaOnRowColAdd(cellList, startCell, 0, 1);
423 					GridView.ADD_REM_ROW_COL.updateGroupFormulaOnRowColAdd(WorkBook.ACTIVE_SHEET_ID, startCell, 0,1);
424 					GridView.ADD_REM_ROW_COL.addColumnFieldInFormulaForColumnAdd(WorkBook.ACTIVE_SHEET_ID, HANDLER.SELECTION_HANDLER.START_COL+1);
425 					GridView.highlightSelectionArea(MouseListener.getOrderedSelectionPos(HANDLER.SELECTION_HANDLER), DomObjects.selectionAreaBorderColor);
426 					HANDLER.SELECTION_HANDLER.ROW_SELECTION_STARTED = false;
427 				},
428 				
429 				/**
430 				 * @name updateCellFormulaOnRowColAdd
431 				 * @memberOf GridView.ADD_REM_ROW_COL
432 				 * @method 
433 				 * @param {Collection.ArrayList} cellList The list of cell with the formula
434 				 * @param {String} startCell @example A1 or C10 etc..
435 				 * @param {Integer} rows number of rows added.
436 				 * @param {Integer} columns Number of columns added
437 				 * @description This method will iterate through the cellList provided, and update the cell formula with the relative formula using @RelativeFormulaController. 
438 				 * @function
439 				 */
440 				updateCellFormulaOnRowColAdd:function(cellList, startCell, rows, cols){
441 					GridView = require("GridView");
442 					for(var i=0; i<cellList.size(); i++){
443 						var cell = cellList.get(i);
444 						var newFormula = "="+relativeFormulaController.applyRelativeFormulaForRowColAdd(cell.getFormula(), startCell, rows, cols);
445 						GridView.saveCell(cell.getSheetId(), cell.getRow(), cell.getColumn(), newFormula, cell.getValue());
446 					}
447 				},
448 				
449 				/**
450 				 * @name updateGroupFormulaOnRowColAdd
451 				 * @memberOf GridView.ADD_REM_ROW_COL
452 				 * @method 
453 				 * @param {Integer} sheetId The sheet in which the row or column added
454 				 * @param {String} startCell @example A1 or C10 etc..
455 				 * @param {Integer} rows number of rows added.
456 				 * @param {Integer} columns Number of columns added
457 				 * @description This method will iterate through the groups in the Sheet provided and update the group formula with the relative formula using @RelativeFormulaController. 
458 				 * @function
459 				 */
460 				updateGroupFormulaOnRowColAdd:function(sheetId, startCell, rows, cols){
461 					var groupList = require('NexcelGroupList').getGroupObjListWithGroupFormula(sheetId);
462 					for(var i=0; i<groupList.size(); i++){
463 						var group = groupList.get(i);
464 						var newFormula = relativeFormulaController.applyRelativeFormulaForRowColAdd(group.formula, startCell, rows, cols);
465 						group.formula = newFormula;
466 						require('NexcelUIDataService').updateGroupFormula(group.id, newFormula);
467 					}
468 				},
469 				
470 				 //TODO  On Row Addition, it can create empty spaces groups, In groups empty rows between is not allowed,  need to be removed.
471 				/**
472 				 * @name removeEmptyRowsInGroupWithFormulaOnRowAdd
473 				 * @memberOf GridView.ADD_REM_ROW_COL
474 				 * @method 
475 				 * @param {Integer} sheetId The sheet in which the row or column added
476 				 * @param {Integer} startRow 
477 				 * @param {Integer} endRow 
478 				 * @description The method will remove empty rows in the Group with formula while a row is added in the group. 
479 				 * @function
480 				 */
481 				removeEmptyRowsInGroupWithFormulaOnRowAdd:function(sheetId, startRow, endRow){
482 					NexcelUI = require("NexcelUI");
483 					var groupList = require('NexcelGroupList').getGroupObjListWithGroupFormula(sheetId);
484 					for(var i=0; i<groupList.size(); i++){
485 						var group = groupList.get(i);
486 						if(parseInt(group.rowStart)<startRow && parseInt(group.rowEnd)>=startRow && group.formula){
487 							var data = NexcelUI.GROUP.DATA.getGroupData(group.name);
488 							data = evaluationHelper.removeEmptyRows(data);
489 							NexcelUI.updateGroupResult(group.id, data, group.formula);
490 						}
491 					}
492 				},
493 
494 				/**
495 				 * @name addColumnFieldInFormulaForColumnAdd
496 				 * @memberOf GridView.ADD_REM_ROW_COL
497 				 * @method 
498 				 * @param {Integer} sheetId The sheet in which the row or column added
499 				 * @param {Integer} columns 
500 				 * @description Once a new column is added, if it breaks any group which is reffered by any nexcel expression, a new column in expression need to be added so that it will not effect the result already generated. 
501 				 * @function
502 				 */
503 				addColumnFieldInFormulaForColumnAdd:function(sheetId, col){
504 					var modifiedGroup = Collections.ArrayList();
505 					var groupInColumnList = require('NexcelGroupList').getGroupObjListOnSheet(sheetId);
506 					for(var i=0; i<groupInColumnList.size(); i++){
507 						var group = groupInColumnList.get(i);
508 						if(parseInt(group.colStart)<col && parseInt(group.colEnd)>=col){
509 							modifiedGroup.add(group);
510 							console.log('Group is under changes :'+group.name);
511 							//group.colEnd = parseInt(group.colEnd)+1;
512 							//group.colSize = parseInt(group.colSize)+1; 
513 							//require('NexcelUIDataService').updateGroupColumnResize(group.id, 1); // Currently it supports only one columns.
514 						}
515 					}
516 					var groupList = require('NexcelGroupList').getGroupObjListWithGroupFormula();
517 					for(var i=0; i<groupList.size(); i++){
518 						var group = groupList.get(i);
519 						var newFormula = relativeFormulaController.addTempVariableInGroupFormulaFact(group.formula, modifiedGroup, col);
520 						if(StringUtil.removeSpaces(group.formula) != StringUtil.removeSpaces(newFormula)){
521 							group.formula = newFormula;
522 							require('NexcelUIDataService').updateGroupFormula(group.id, newFormula);
523 						}
524 					}
525 				},
526 			
527 			},
528 			
529 			/**
530 			 * @name saveCell
531 			 * @memberOf GridView
532 			 * @method 
533 			 * @param {Integer} sheetId The sheet in which the row or column added
534 			 * @param {Integer} row
535 			 * @param {Integer} column
536 			 * @param {String} formula If there is no formula associated then the value will be null.
537 			 * @param {String} value The result value.
538 			 * @description Once the Cell Edit happened & User Accept the Value, excluding ESC Button event. Need to Update in the Sheet. 
539 			 *  row=1 means first Row, Similar in Column
540 			 * 	First CellA1=> row=1: col=1 
541 			 * 
542 			 * It will check whether the cell is already existing in the system @nexcelCellList, if not will create a new one. Then it will update in the View, and do an Ajax request to update in the server.
543 			 * @function
544 			 */
545 			saveCell:function(sheetId, row, col, formula, value){
546 				console.log('Update Cell');
547 				var nexcelCellList = require("NexcelCellList");
548 				var cell = nexcelCellList.isExist(sheetId, row, col);
549 				if(cell){
550 					cell.setValue(value);
551 					cell.setFormula(formula);
552 				}else
553 					cell = nexcelCellList.addCellWithDetails(sheetId, row, col, formula, value);
554 				var updatedCellList = Collections.ArrayList();
555 				updatedCellList.add(cell);
556 				$($($('#dataTable tr')[row-1]).find('td')[col-1]).html(value);
557 				require(['WorkBookDataService'],function(workBookDataService){
558 					workBookDataService.updateListOfCells(updatedCellList.json());	
559 				});
560 				require('GridView').setViewRowHeight();
561 				return cell;
562 			},
563 			/**
564 			 * @name getScrollBarWidth
565 			 * @memberOf GridView
566 			 * @method 
567 			 * @description Scroll Bar Width will be Different in Different browsers, It will return the Scroll Bar Size. 
568 			 * @function
569 			 */
570 			getScrollBarWidth:function(){
571 				var a,b,c;
572 				if(c===undefined){a=$('<div style="width:50px;height:50px;overflow:auto"><div/></div>').appendTo('body');
573 					b=a.children();c=b.innerWidth()-b.height(99).innerWidth();a.remove();};
574 				return c;
575 			},
576 			/**
577 			 * @name editCell
578 			 * @memberOf GridView
579 			 * @method 
580 			 * @param {Object} cell
581 			 * @param {Event} event
582 			 * @description If user try to edit a cell by double clicking on the cell, this method will be called Refer MouseListener.If the cell is a part of any group with formula is associated it will popup with Editor to 
583 			 * updated the formula.other wise editTextFieldDiv will be created with an input Object and the values will be populated. 
584 			 * @function
585 			 */
586 			editCell:function(cell, event){
587 				GridView = require("GridView");
588 				var WorkBook = require('WorkBook');
589 				if(cell.type && cell.type=='dblclick') {
590 					cell.preventDefault();
591 					cell = cell.target;
592 				}
593 				var row = $(cell).parent().index()+1;//data('row');
594 				var col = $(cell).index()+1;//data('col');
595 				//if(GridView.isCellIsHeader(WorkBook.ACTIVE_SHEET_ID, row, col))
596 				//	return;
597 				var groupWithFormula = GridView.isCellAssociatedWithGroupWithFormula(row, col, WorkBook.ACTIVE_SHEET_ID);
598 				if(!groupWithFormula){
599 					var groupList = GridView.getGroupsOnCell(WorkBook.ACTIVE_SHEET_ID, row, col);
600 					$(DomObjects.editTxtFieldDiv).remove();
601 					GridView.editorTextFieldDiv = $('<div id="editTxtFieldDiv" class="editTxtFieldDiv" />');
602 					var txtField = $('<input type="text" class="cellEditInput"/>');
603 					var cellObj = require("NexcelCellList").isExist(WorkBook.ACTIVE_SHEET_ID, row, col);
604 					if(cellObj && cellObj.getFormula() && cellObj.getFormula() !='null'){
605 						$(txtField).val(cellObj.getFormula());	
606 					}else if(cellObj){
607 						$(txtField).val(cellObj.getValue());
608 						if(event && event.charCode == 13)
609 							$(txtField).val(cellObj.getValue());
610 						else if(event && event.charCode != 0)
611 							$(txtField).val(''+String.fromCharCode(event.charCode));
612 						else if(event)
613 							$(txtField).val(cellObj.getValue()+''+String.fromCharCode(event.charCode));
614 					}else if(event && event.charCode != 0){
615 						$(txtField).val(''+String.fromCharCode(event.charCode));
616 					}
617 					if(event && event.key){// Only for Mozilla //TODO require('is').firefox()
618 						if(event.key == 'Escape'){
619 								//console.log('Escape pressed.');
620 								event.preventDefault();
621 								event.stopPropagation();
622 								GridView.cancelCellEdit(event.target);
623 						}else if(event && event.keyCode == 13)
624 							$(txtField).val(''+cellObj.getValue());
625 					}
626 					/*$(txtField).blur(function(){
627 						console.log('Blurring existing Txt field...');
628 						//$(DomObjects.editTxtFieldDiv).remove();
629 						GridView.cancelCellEdit();
630 					});*/
631 					
632 					$(txtField).css('font-size',$(cell).css('font-size'));
633 					$(txtField).css('font-family',$(cell).css('font-family'));
634 					$(txtField).css('border-radius','0px');
635 					if(require('is').firefox())
636 						$(txtField).css({width:$(cell).width(), height:$(cell).height()});
637 					else
638 						$(txtField).css({width:$(cell).width()+1, height:$(cell).height()+2});
639 					
640 					var editorDivTop = $(DomObjects.dataTableDiv).scrollTop() + $(cell).offset().top - $(DomObjects.dataTableDiv).offset().top;
641 					var editorDivLeft = $(DomObjects.dataTableDiv).scrollLeft() + $(cell).offset().left-$(DomObjects.dataTableDiv).offset().left+1;
642 					if(require('is').firefox())
643 						$(GridView.editorTextFieldDiv).css({'z-index':12,position:"absolute", left:(editorDivLeft-1),top:(editorDivTop),width:$(cell).outerWidth(), height:$(cell).outerHeight(), border: '1px dotted #4285F4;', 'background-color':'#EEEEEE;'});
644 					else
645 						$(GridView.editorTextFieldDiv).css({'z-index':12,position:"absolute", left:editorDivLeft,top:editorDivTop,width:$(cell).outerWidth(), height:$(cell).outerHeight(), border: '1px dotted #4285F4;', 'background-color':'#EEEEEE;'});
646 					
647 					$('#selectionCornerDiv').css({'left':editorDivLeft,'top':editorDivTop, position:"absolute"});
648 					
649 					$(txtField).appendTo($(GridView.editorTextFieldDiv));
650 					$(GridView.editorTextFieldDiv).appendTo($(DomObjects.dataTableDiv));
651 					$(txtField).focus().setCursorPosition($(txtField).val().length);
652 					$(txtField).keypress(require('KeyListener').textFieldKeyPress);
653 					$(txtField).keydown(require('KeyListener').textFieldKeyDown);
654 					//console.log('Key Code :'+event.keyCode );
655 					$(txtField).on('keyup',function(e){
656 						console.log('Text Field key up.....');
657 						//$(this).val($(this).val()+String.fromCharCode(e.keyCode));
658 						$('.formulaBarText').val($(this).val());
659 						//e.stopPropagation();
660 						//e.preventDefault();
661 					});
662 				}else{
663 					//TODO View the Formula Edit Model Panel.
664 					require(['EditorController'],function(EditorController){
665 						EditorController.openEditor(groupWithFormula.id, groupWithFormula);
666 					});
667 				}
668 			},
669 			/**
670 			 * @name isCellIsHeader
671 			 * @memberOf GridView
672 			 * @method 
673 			 * @param {Integer} wsId
674 			 * @param {Integer} row
675 			 * @param {Integer} col
676 			 * @description Check whether the given cell is the part of any header like column header of range name header.
677 			 * @function
678 			 */
679 			isCellIsHeader:function(wsId, row, col){
680 				var groupList = require('GridView').getGroupsOnCell(wsId, row, col);
681 				for(var i=0; i< groupList.length; i++){
682 					var group = groupList[i];
683 					if((group.colNameAvailable &&  group.colNameAvailable !="0")|| (group.groupTitle && group.groupTitle !="0")){
684 						if(row == group.rowStart && col >=group.colStart && col<=(parseInt(group.colStart)+parseInt(group.colSize)))
685 							return true;
686 						if((group.colNameAvailable &&  group.colNameAvailable !="0")&& (group.groupTitle && group.groupTitle !="0")){
687 							if(row == parseInt(group.rowStart)+1 && col >=group.colStart && col<=(parseInt(group.colStart)+parseInt(group.colSize)))
688 								return true;
689 						}
690 					}
691 				}
692 				return false;
693 			},
694 
695 			/**
696 			 * @name updateCellByEvent
697 			 * @memberOf GridView
698 			 * @method 
699 			 * @param {Event} event
700 			 * @description save a Cell Associated with teh Editing textField. The function can be called only through an event.
701 			 * @function
702 			 */
703 			updateCellByEvent:function(e){
704 				WorkBook = require("WorkBook");
705 				console.log(" -- updateCellByEvent --");
706 				var newVal = $(e.target).val();
707 				var oldVal = "";
708 				var gridCol = $(GridView.lastHighlighedTD).index();
709 				var gridRow = $(GridView.lastHighlighedTD).parent().index();
710 				var cell = require("NexcelCellList").isExist(WorkBook.ACTIVE_SHEET_ID, gridRow+1, gridCol+1);
711 				if(cell)
712 					oldVal = cell.getValue();
713 				var checkCircularDependency = true;
714 				var calculatedCellObj = GridView.updateCell(WorkBook.ACTIVE_SHEET_ID, gridRow, gridCol, oldVal, newVal);
715 				$(GridView.editorTextFieldDiv).remove();
716 				GridView.editorTextFieldDiv=null;
717 				
718 				return calculatedCellObj;
719 			},
720 			/**
721 			 * @name updateCell
722 			 * @memberOf GridView
723 			 * @method 
724 			 * @param {Integer} sheetId
725 			 * @param {Integer} row
726 			 * @param {Integer} column
727 			 * @param {Integer} OldValue
728 			 * @param {Integer} newValue
729 			 * @description This function can be called through programmatically to save a cell with a value, it need to pass old value and new value, it will do calculation if formula available and update it, if it is calculated it required to update the dependencies.
730 			 * A1=> row:0, col:0
731 			 * @function
732 			 */
733 			updateCell:function(sheetId, row, col, oldVal, newVal){
734 				var checkCircularDependency = true;
735 				var calculatedCellObj = GridView.calculateCell(sheetId, row, col, oldVal, newVal, checkCircularDependency);
736 				if(calculatedCellObj)
737 					require(['DependencyGraphController'],function(dependencyGraphController){
738 						var _CXT = new Object();
739 						_CXT.formulaList = [];
740 						_CXT.valueList = [];
741 						var cellName = require('GridView').getCellFullName(sheetId, row+1, col+1);
742 						var dependencyTable = require('DependencyTableController').getDependencyTable();
743 						var groupList = require('GridView').getGroupsOnCell(sheetId, row+1, col+1);
744 						for(var i=0; i<groupList.length; i++)
745 							dependencyTable.push([3001, cellName, 3002, groupList[i].name]);
746 						var cellList = [cellName];
747 						require('NexcelDependencyEvaluationController').evaluateDependency(dependencyTable, require('CONSTANT').DEP_SOURCE_TYPE.CELL, cellList, _CXT);
748 						require('NexcelUI').updateCalculatedDependents(_CXT.valueList);
749 						///dependencyGraphController.evaluateCellDependents(calculatedCellObj);
750 					});
751 				return calculatedCellObj;
752 			},
753 
754 			/**
755 			 * @name calculateCell
756 			 * @memberOf GridView
757 			 * @method 
758 			 * @param {Integer} sheetId
759 			 * @param {Integer} row
760 			 * @param {Integer} column
761 			 * @param {String} OldValue
762 			 * @param {String} newValue if user applies a formula, then the newValue will be the formula. 
763 			 * @param {Boolean} checkCircularDependency if it is true, then it required to check teh dircular dependancy with the cell formula.
764 			 * @description This function can be called through programmatically to calculate the cell and call saveCell to save teh values to Database.
765 			 * A1=> row:0, col:0
766 			 * @function
767 			 */
768 			calculateCell:function(sheetId, row, col, oldVal, newVal, checkCircularDependency){
769 				GridView = require("GridView");
770 				console.log("CALC-"+sheetId+":"+row+":"+col+"--"+newVal);
771 				var formula;
772 				programs=[];
773 				if(newVal.charAt(0) == '='){// Check whether New Value is a Formula.
774 					var cellName = GridView.getCellName(row+1,col+1);
775 					try{
776 						var sheetObj = require('WorkBook').getSheetObj(sheetId);
777 						var sourceName = sheetObj.name+"!"+cellName;
778 						var dependencyTable = require('DependencyTableController').getDependencyTable();
779 						var sourceNotEqual = require('TreeGenerationHelper').setBinRelDetails(require('CONSTANT').BinOperation.OP_NOT_EQUAL, new TREEObjects.EXPRESSION(ObjectType.EXP_VAR, 'Source'), new TREEObjects.CONSTANT(ObjectType.CONSTANT_NAM, sourceName));
780 						var filteredTable = require('EvaluationHelper').applyConstrRelOnRange(dependencyTable, [sourceNotEqual]);
781 						require('ParsingController').parseFormula(newVal);
782 						var sourceType=require('CONSTANT').DEP_SOURCE_TYPE.CELL;
783 						var DependencyTableController = require('DependencyTableController');
784 						var updatedTable = DependencyTableController.getDependency(programs, sourceType, sourceName, filteredTable);
785 						var inDirectTable = require('GraphBasedEvaluationHelper').getInDirectDependency(updatedTable);
786 						programs=[];
787 						if(require('GraphBasedEvaluationHelper').isCellCreatesCircularDependency(inDirectTable, sourceName))
788 							throw "Circular Dependency."
789 					}catch(e){
790 						modal({
791 							type  : 'alert',
792 							title : 'Alert',
793 							text  : "Circular dependency found with cell "+cellName+" !"
794 						});
795 						return false;
796 					}
797 
798 					formula= newVal;
799 					var resultObj  = require('ParsingController').parseAndEvaluateFormula(newVal);
800 					if(!resultObj)//It must have some error happened or No result created then the value will be false.
801 						return;
802 					newVal = resultObj.groupValue;
803 				}
804 				if(newVal == oldVal && !formula)
805 					return;
806 				var oldFormula;
807 				if(formula){
808 					var cell = require("NexcelCellList").isExist(sheetId, row+1, col+1);
809 					if(cell)
810 						oldFormula = cell.getFormula();
811 					if(formula == oldFormula && newVal == oldVal)
812 						return false;
813 				}
814 				return GridView.saveCell(sheetId, row+1, col+1, formula, newVal);
815 			},
816 			/**
817 			 * @name calculateGroup
818 			 * @memberOf GridView
819 			 * @method 
820 			 * @param {Integer} groupId the group which need to be calculated
821 			 * @description This function will recalculate the group result with the existing group formula.
822 			 * @function
823 			 */
824 			calculateGroup:function(groupId){
825 				console.log('Calculating Group :'+groupId);
826 				NexcelUI = require("NexcelUI");
827 				var formula = require('NexcelGroupList').getGroupObjById(groupId).formula;
828 				NexcelUI.updateGroupFormula(groupId, formula);
829 			},
830 
831 			/**
832 			 * @name loadRowData
833 			 * @memberOf GridView
834 			 * @method 
835 			 * @param {Integer} diff the number of rows need to be loaded.
836 			 * @description This function will create the cell to the sheet where the user is scrolling for. The data is already loaded through Ajax initially.It also apply all the vent listener like KeyListener and MouseListener to the cells.
837 			 * @function
838 			 */	
839 			loadRowData:function(diff){
840 				if(diff<0){
841 					var GridView = require('GridView');
842 					var WorkBook = require('WorkBook');
843 					var tableRows = $('#dataTable tr');
844 					var sheetObj = WorkBook.getSheetObj(WorkBook.ACTIVE_SHEET_ID);
845 					var size =  rowCount = tableRows.length;
846 					if(size>sheetObj.rows) return;
847 					var max = -1*(diff/100 )+10+rowCount;
848 					if(max > sheetObj.rows)
849 						max =sheetObj.rows;
850 					for(row=rowCount;row<max ; row++){
851 					//	var tr=$(GridView.TABLE_ROW_HTML[GridView.ACTIVE_SHEET_ID][row]);
852 						var rowHtml = GridView.getRowHtml(WorkBook.ACTIVE_SHEET_ID, row+1);
853 					//	$('#dataTable').append(tr);
854 						$('#dataTable').append(rowHtml);
855 						var MouseListener = require('MouseListener');
856 						var KeyListener = require('KeyListener');
857 						$(rowHtml).find('td').each (function() {
858 							MouseListener.setCellListener(this);
859 							KeyListener.setCellListener(this);
860 						});
861 					}
862 					GridView.setUserRowHeight(rowCount);
863 					GridView.setViewRowHeight();
864 				}
865 			},
866 			/**
867 			 * @name getRowHtml
868 			 * @memberOf GridView
869 			 * @method 
870 			 * @param {Integer} sheetId
871 			 * @param {Integer} row the row number which required.
872 			 * @return {String} String format of teh HTML Row data.
873 			 * @description This function will create String object of the html row with the cell data.
874 			 * @function
875 			 */	
876 			getRowHtml:function(sheetId, row){
877 				WorkBook = require('WorkBook');
878 				var sheetObj = WorkBook.getSheetObj(sheetId);
879 				var tr =$('<tr></tr>');
880 				for(var col=1; col<= sheetObj.cols; col++){
881 					var cell = require("NexcelCellList").isExist(sheetObj.id, row, col);
882 					var td;
883 					if(cell){
884 						if(col==1 && cell.getValue().toString().trim().length ==0)
885 							td = $('<td data-row="'+row+'" data-col="'+col+'"></td>');
886 						else
887 							td = $('<td data-row="'+row+'" data-col="'+col+'">'+cell.getValue()+'</td>');
888 					}else if(col==1)
889 						td = $('<td data-row="'+row+'" data-col="'+col+'"></td>');
890 					else
891 						td=$('<td data-row="'+row+'" data-col="'+col+'"></td>');
892 					$(tr).append(td);
893 				}	
894 				return tr;
895 			},
896 			/**
897 			 *	Nexcel.GRID_VIEW 
898 			 */
899 			setUpRowNum:function(rows){
900 				$('#rowNumTable tr').remove();
901 				for(var i=0; i< rows; i++)
902 					$('#rowNumTable').append("<tr><td>"+(i+1)+"</td></tr>");
903 				$('#rowNumTable td').each(function() {
904 								Nexcel.MOUSE_LISTENER.ROW.setRowCellListener(this);
905 							});
906 			},
907 			colIndexToString:function(cols, str) {
908 				if(!str) str='';
909 				var char = String.fromCharCode(65+(cols-1)%26);
910 				str = char+str;
911 				cols = parseInt((cols-1)/26);
912 				if(cols>0)
913 					str =require('GridView').colIndexToString(cols, str);
914 				return str;
915 			},
916 			/**
917 			 *	1:1=>A1 
918 			 */
919 			rowColNumToCellName:function(row, col){
920 				return require('GridView').colIndexToString(col)+row;
921 			},
922 			/**
923 			 *	Nexcel.GRID_VIEW 
924 			 */
925 			setUpColumns:function(cols){
926 				var tds='<th style="min-width:43px;max-width: 43px;"></th>';
927 				$('#columnNameTable tr').remove();
928 				for(var i=1; i<=cols; i++){
929 					var colLbl = require('GridView').colIndexToString(i);
930 					tds=tds+"<th>"+colLbl+"</th>";
931 				}
932 				var WorkBook = require('WorkBook');
933 				tds=tds+'<th style="min-width:'+WorkBook.SCROLLBAR_WIDTH+'px;max-width: '+WorkBook.SCROLLBAR_WIDTH+'px;"></th>';
934 				if($('div.dataTableDiv').width()<$('#dataTable').width())// Scroll Bar Available
935 					$('div.rowNumTableDiv').css('margin-bottom',(WorkBook.SCROLLBAR_WIDTH+40)+'px'); // dataTableDiv padding-bottom : 40px
936 				else	
937 					$('div.rowNumTableDiv').css('margin-bottom','40px'); // dataTableDiv padding-bottom : 40px
938 				$('#columnNameTable').append("<tr>"+tds+"</tr>");
939 				$('#columnNameTable th').each(function() {
940 								require('MouseListener').COL.setColCellListener(this);
941 							});
942 	//			 $("#columnNameTable").simpleResizableTable(); 
943 			},
944 
945 			/**
946 			 * Nexcel.GRID_VIEW 
947 			 */
948 			setUserColWidth:function(){
949 			//	console.log('Setting Column User Size....'+ arguments.callee.caller);
950 				var GridView = require('GridView');
951 				var WorkBook = require('WorkBook');
952 				var dataTableRows = $('#dataTable tr');
953 				var columnHeaderDiv = $('div.colsHeaderDiv').find('.colDiv');
954 				var dataTableTDs = $(dataTableRows[0]).find('td');
955 				var sheetId = WorkBook.ACTIVE_SHEET_ID;
956 				var sheetCols = WorkBook.getSheetObj(sheetId).cols;
957 				for(var col=0; col< parseInt(sheetCols); col++){
958 					var TD = dataTableTDs[col];
959 					if(WorkBook.WB_COL_WIDTH[sheetId] && WorkBook.WB_COL_WIDTH[sheetId][col]){
960 						var width = WorkBook.WB_COL_WIDTH[sheetId][col];
961 						$(TD).css('min-width', width+'px');
962 						$(TD).css('max-width', width+'px');
963 						$(columnHeaderDiv[col]).css('min-width', width+'px');
964 						$(columnHeaderDiv[col]).css('max-width', width+'px');
965 					}else{
966 						$(TD).css('min-width', '100px');
967 						$(TD).css('max-width', '100px');
968 						$(columnHeaderDiv[col]).css('min-width', '100px');
969 						$(columnHeaderDiv[col]).css('max-width', '100px');
970 					}
971 				}
972 			},
973 			/**
974 			 * Nexcel.GRID_VIEW 
975 			 * Updating the user defined row height to the view.
976 			 */
977 			setUserRowHeight:function(minRow){
978 				var WorkBook = require('WorkBook');
979 				var dataTableRows = $('#dataTable tr');
980 				var rowDivList = $('.rowDiv');
981 				var rowHeaderDivList = $('div.rowTableDiv').find('.rowDiv');
982 				if(!minRow) minRow=0;
983 				var sheetId = WorkBook.ACTIVE_SHEET_ID;
984 				var sheetRows = WorkBook.getSheetObj(sheetId).rows;
985 				for(var row=0; row< parseInt(sheetRows); row++){
986 					var TR = dataTableRows[row];
987 					if(WorkBook.WB_ROW_HEIGHT[sheetId] && WorkBook.WB_ROW_HEIGHT[sheetId][row]){
988 						var height = WorkBook.WB_ROW_HEIGHT[sheetId][row];
989 						$(TR).css('min-height', height+'px');
990 						$(TR).css('max-height', height+'px');
991 						$(TR).css('height', height+'px');
992 						$(rowHeaderDivList[row]).css('min-height', height+'px');
993 						$(rowHeaderDivList[row]).css('max-height', height+'px');
994 					}else{
995 						$(TR).css('min-height', '21px');
996 						$(TR).css('max-height', '21px');
997 						$(TR).css('height', '21px');
998 						$(rowHeaderDivList[row]).css('min-height', '21px');
999 						$(rowHeaderDivList[row]).css('max-height', '21px');
1000 					}
1001 				}
1002 			},
1003 						/**
1004 			 * Nexcel.GRID_VIEW 
1005 			 * Updating the cell row height to the Row number div.
1006 			 */
1007 			setViewRowHeight:function(minRow){
1008 				var WorkBook = require('WorkBook');
1009 				var dataTableRows = $('#dataTable tr');
1010 				var rowDivList = $('.rowDiv');
1011 				var rowHeaderDivList = $('.rowDiv');
1012 				if(!minRow) minRow=0;
1013 				var sheetId = WorkBook.ACTIVE_SHEET_ID;
1014 				var sheetRows = WorkBook.getSheetObj(sheetId).rows;
1015 				for(var row=minRow; row< parseInt(sheetRows); row++){
1016 					var TR = dataTableRows[row];
1017 					var height = $(TR).css('height');
1018 					$(rowHeaderDivList[row]).css('min-height', height);
1019 					$(rowHeaderDivList[row]).css('max-height', height);
1020 				}
1021 			},
1022 
1023 			/**
1024 			 *	Nexcel.GRID_VIEW 
1025 			 */
1026 			highlightCell:function(cell, cellOnView){
1027 				var GridView = require('GridView');
1028 				$(GridView.lastHighlighedTD).css('border','1pt solid #DADADA');
1029 				$(GridView.sibUp).css('border-bottom','1pt solid #DADADA');
1030 				$(GridView.sibLeft).css('border-right','1pt solid #DADADA');
1031 				if(!cell){
1032 					cell = $($($('#dataTable tr')[0]).find('td')[0]);
1033 					if(cell && cell.length){ // When the first cell is selected , make the dragger available. Refer Nexcel.js line -2199
1034 						require('MouseListener').setSelectionHandler(0,0,0,0);
1035 						HANDLER.CELL_DRAG_HANDLER = new Object();
1036 						HANDLER.CELL_DRAG_HANDLER.TARGET = cell;
1037 					}
1038 				}
1039 				
1040 				if(cellOnView)
1041 					GridView.placeCellOnView(cell);
1042 				var colIndex = $(cell).index();
1043 				$(cell).css('border','1pt solid #4285F4');
1044 				GridView.sibLeft = $(cell).siblings('td')[colIndex-1];
1045 				$(GridView.sibLeft).css("border-right","1px #4285F4");
1046 				var rowIndex = $(cell).parent('tr').index();
1047 				
1048 				if(rowIndex){
1049 					var sibRow =$(cell).closest('tr').siblings('tr')[rowIndex-1];
1050 					GridView.sibUp = $(sibRow).find('td')[colIndex];
1051 					$(GridView.sibUp).css("border-bottom","1px #4285F4");
1052 				}
1053 				if(require('GridView').lastHighlighedTD != cell){
1054 					GridView.lastHighlighedTD = $(cell);
1055 					GridView.updateFormulaBar(cell);
1056 				}
1057 			},
1058 			/**
1059 			 *	Nexcel.GRID_VIEW
1060 			 * 	The give cell is the TD object of teh highlighted cell. 
1061 			 */
1062 			updateFormulaBar:function(cell){
1063 				var GridView = require('GridView');
1064 				var col = $(cell).index();
1065 				var row = $(cell).parent().index();
1066 				var WorkBook = require('WorkBook');
1067 				var nexcelCellList = require("NexcelCellList");
1068 				var cellObj = nexcelCellList.isExist(WorkBook.ACTIVE_SHEET_ID, row+1, col+1);
1069 				if(cellObj){
1070 					if(cellObj.getFormula() && cellObj.getFormula() != 'null' )
1071 						$('.formulaBarText').val(cellObj.getFormula());
1072 					else if(!cellObj.getValue() || cellObj.getValue() == 'null'){
1073 						$('.formulaBarText').val('');
1074 					}else
1075 						$('.formulaBarText').val(cellObj.getValue());
1076 				}else{ 
1077 					$('.formulaBarText').val('');
1078 				}
1079 				
1080 				var groupWithFormula = GridView.isCellAssociatedWithGroupWithFormula(row+1, col+1, WorkBook.ACTIVE_SHEET_ID);
1081 				if(groupWithFormula)
1082 					$('.formulaBarText').attr('disabled',true);
1083 				else
1084 					$('.formulaBarText').attr('disabled',false);
1085 				$('#activeCellName').html(GridView.rowColNumToCellName(row+1, col+1));
1086 			},
1087 			/**
1088 			*	Nexcel.GRID_VIEW
1089 			* 	Function to Activate the Next cell with Respect to the KEY_PRESSED.
1090 			*/
1091 			highlightNextCell:function(key, row, col){
1092 				GridView = require("GridView");
1093 				var gridCol = $(GridView.lastHighlighedTD).index();
1094 				var gridRow = $(GridView.lastHighlighedTD).parent().index();
1095 				var tableRows = $('#dataTable tr');
1096 				var cols = $(tableRows[0]).find('td');
1097 				if((gridCol ==0 && key ==  KEY.LEFT )|| (gridRow==0 && key ==  KEY.UP) || (gridRow+1) == tableRows.length && key == KEY.DOWN || (gridCol+1)==cols.length && key == KEY.RIGHT ) //TODO Implement for Last Row & Col
1098 					return false;
1099 				var nextCell;
1100 				if(key ==  KEY.UP)
1101 					nextCell = $(tableRows[gridRow-1]).find('td')[gridCol];
1102 				else if(key ==  KEY.DOWN)
1103 					nextCell = $(tableRows[gridRow+1]).find('td')[gridCol];
1104 				else if(key ==  KEY.RIGHT)
1105 					nextCell = $(tableRows[gridRow]).find('td')[gridCol+1];
1106 				else if(key ==  KEY.LEFT)
1107 					nextCell = $(tableRows[gridRow]).find('td')[gridCol-1]; 
1108 				else if(key == KEY.ENTER)
1109 					nextCell = $(tableRows[row]).find('td')[col];
1110 				GridView.highlightCell(nextCell, true);
1111 				GridView.CELL_DRAG.positionSelectionCornerDiv(nextCell);
1112 			},
1113 			
1114 			/**
1115 			 *	Nexcel.GRID_VIEW
1116 			 * 	Highlight All the Groups in the SheetNo Provided.. 
1117 			 */
1118 			highlightGroupsNearToSelection:function(){
1119 				GridView = require("GridView");
1120 				var SEL = require('MouseListener').getOrderedSelectionPos(HANDLER.SELECTION_HANDLER);
1121 				var AREA = new Object();
1122 				AREA.START_ROW = (SEL.START_ROW-3)<1 ?1: (SEL.START_ROW-3);
1123 				AREA.CURR_ROW = SEL.CURR_ROW + 3;
1124 				AREA.START_COL = (SEL.START_COL-1)<1 ?1: (SEL.START_COL-1);
1125 				AREA.CURR_COL = SEL.CURR_COL + 2;
1126 				var groupList = require('NexcelGroupList').getGroupObjListOnSheet(GridView.ACTIVE_SHEET_ID);
1127 				for(var i=0; i< groupList.size(); i++){
1128 					var group = groupList.get(i);
1129 					if(((group.rowStart <= AREA.START_ROW && AREA.START_ROW <= group.rowEnd) || 
1130 						(group.rowStart <= AREA.CURR_ROW  && AREA.CURR_ROW <= group.rowEnd)  ||  
1131 						(group.rowStart >= AREA.START_ROW  &&  group.rowEnd <= AREA.CURR_ROW)) &&
1132 					   ((group.colStart <= AREA.START_COL &&  AREA.START_COL <= group.colEnd )|| 
1133 						(group.colStart <= AREA.CURR_COL && AREA.CURR_COL <= group.colEnd ) ||  
1134 						(group.colStart >= AREA.START_COL  &&  group.colEnd <= AREA.CURR_COL)))
1135 						GridView.highlighGroupByGroupObj(group, group.color);
1136 				}
1137 			},
1138 			/**
1139 			 *	Nexcel.GRID_VIEW
1140 			 * 	Highlight All the Groups in the SheetNo Provided.. 
1141 			 */
1142 			highlightGroupsOnSheet:function(sheetId){
1143 				var groupList = require('NexcelGroupList').getGroupObjListOnSheet(sheetId);
1144 				for(var i=0; i< groupList.size(); i++){
1145 					require('GridView').highlighGroupByGroupObj(groupList.get(i));
1146 				}
1147 			},
1148 			/**
1149 			 *	Nexcel.GRID_VIEW
1150 			 * 	Highlight Group. 
1151 			 */
1152 			highlightGroup:function(row, col, mouseEvent){
1153 				var WorkBook = require("WorkBook");
1154 				var MouseListener = require('MouseListener');
1155 				var sheetId = WorkBook.ACTIVE_SHEET_ID;
1156 				var groups=GridView.getGroupsOnCell(sheetId, row, col);
1157 				for(var i=0; i<groups.length;i++){
1158 					var groupObj = groups[i];
1159 					if(mouseEvent == MouseListener.MOUSE_OVER)
1160 						GridView.highlighGroupByGroupObj(groupObj, groupObj.color);
1161 					else{
1162 						GridView.removeHighlightByGroupObj(groupObj);
1163 					}
1164 				}
1165 			},
1166 			/**
1167 			 *	Nexcel.GRID_VIEW 
1168 			 */
1169 			highlighGroupByGroupObj:function(groupObj, color){
1170 				var GridView = require('GridView');
1171 				if(groupObj.headerPinned){
1172 					GridView.enlargeHeader(groupObj.id);
1173 				}else if(DomObjects.defaultBorderCol != color){
1174 					GridView.shortenHeader(groupObj.id);
1175 				}
1176 				var WorkBook = require('WorkBook'); 
1177 				var sheetId = WorkBook.ACTIVE_SHEET_ID;
1178 				if(sheetId != groupObj.sheetId)
1179 					return;// No Need to consider other sheet Highlighting.
1180 				if(color)
1181 					require('NexcelGroupList').highlightGroup(groupObj.id);
1182 				var endRow = groupObj.rowEnd;
1183 				if(groupObj.rowEnd==-1 && WorkBook.getSheetObj(sheetId))
1184 					endRow = WorkBook.getSheetObj(sheetId).rows;
1185 				GridView.applyStyleToGroupTitleAndColName(groupObj);
1186 				var SELECTION_AREA = new Object();
1187 				SELECTION_AREA.START_ROW=(groupObj.rowStart-1);
1188 				SELECTION_AREA.CURR_ROW=(endRow-1);
1189 				SELECTION_AREA.START_COL=(groupObj.colStart-1);
1190 				SELECTION_AREA.CURR_COL=(groupObj.colEnd-1); 
1191 				GridView.highlightSelectionArea(SELECTION_AREA, color);
1192 			},
1193 			removeHighlightByGroupObj:function(groupObj){
1194 				var GridView = require('GridView'); 
1195 				require('NexcelGroupList').removeGroupHighlight(groupObj.id);
1196 				GridView.hideHeader(groupObj.id);
1197 				GridView.highlighGroupByGroupObj(groupObj, DomObjects.defaultBorderCol);
1198 			},
1199 			/**
1200 			*
1201 			*/
1202 			applyStyleToGroupOnActiveSheet:function(){
1203 				var groupList = require('NexcelGroupList').getGroupObjListOnSheet(require("WorkBook").ACTIVE_SHEET_ID);
1204 				for(var i=0; i< groupList.size(); i++)
1205 					this.applyStyleToGroupTitleAndColName(groupList.get(i));
1206 					this.setUpGroupHeader(groupList.get(i));
1207 			},
1208 			/**
1209 			 *	Nexcel.GRID_VIEW
1210 			 * 	Apply Style to Group Header and Title 
1211 			 */
1212 			applyStyleToGroupTitleAndColName:function(groupObj){
1213 
1214 			/*
1215 			 * == Old code start here
1216 				NexcelUI = require("NexcelUI");
1217 				var titleRow = parseInt(groupObj.rowStart)-1;
1218 				if(groupObj.groupTitle == '1'){
1219 					var headerCell;
1220 					var width=0;
1221 					for(var i=0; i<groupObj.colSize; i++){
1222 						var row = parseInt(groupObj.rowStart-1);
1223 						var col = parseInt(groupObj.colStart)+i-1;
1224 						var cell  = $($($('#dataTable tr')[row]).find('td')[col]);
1225 						$(cell).css("font-size", "13px;");
1226 						$(cell).css("font-family", "arial, snas-serif;");
1227 						//$(cell).css("font-weight", "bold");
1228 						//$(cell).css("background", "#C9CACA");
1229 						$(cell).attr('align', 'center');
1230 						$(cell).css('text-align','center');
1231 						width = width + $(cell).width();
1232 						if(i==0){
1233 							$(cell).attr('colspan',groupObj.colSize);
1234 							$(cell).css('border-right-color',groupObj.color);
1235 							headerCell = $(cell); 
1236 						}
1237 						else	
1238 							$(cell).css("display", "none");
1239 					}
1240 				//	$(headerCell).css('min-width',width+'px');
1241 				//	$(headerCell).css('max-width',width+'px');
1242 					titleRow = titleRow+1;
1243 				}
1244 //				var divName = "groupNameDiv"+groupObj.id;
1245 //				var selectionCornerDiv = $('<div id="'+divName+'" class="groupNameDiv" />');
1246 //				$(selectionCornerDiv).appendTo($(DomObjects.dataTableDiv));
1247 				
1248 				if(groupObj.colNameAvailable =='1'){
1249 					for(var i=0;i<groupObj.colSize; i++){
1250 						var col = parseInt(groupObj.colStart)+i-1;
1251 						var cell  = $($($('#dataTable tr')[titleRow]).find('td')[col]);
1252 						//$(cell).css("font-weight", "bold");
1253 						$(cell).css("font-size", "13px;");
1254 						$(cell).css("font-family", "arial, snas-serif;");
1255 						//$(cell).css("background", "#C9CACA");
1256 						$(cell).attr('align', 'center');
1257 						$(cell).css('text-align','center');	
1258 						$(cell).data('groupId', groupObj.id);
1259 						$(cell).data('colIndex', i);
1260 						$(cell).data('colName', $(cell).html());
1261 						$(cell).mouseover(function(){
1262 							if(!groupObj) return; //TODO Deleted group object
1263 							var groupObj = require('NexcelGroupList').getGroupObjById($(this).data('groupId'));
1264 							var row = parseInt(groupObj.rowStart);
1265 							if(groupObj.groupTitle)
1266 								row++;
1267 							var cellData = NexcelUI.CELL.DATA.getSheetCellValue(groupObj.sheetId, row, parseInt(groupObj.colStart)+parseInt($(this).data('colIndex')));
1268 							//TODO How to set the ASC/DESC Sorting functionality here.
1269 							
1270 						/*	var sortDiv = $('<div style="float: right;"/>');
1271 							if(groupObj.sorted == 1 && groupObj.sortedCol == i){
1272 								$('<img src="img/sortAsc.gif"/>').appendTo($(sortDiv));
1273 							}else if(groupObj.sorted == -1 && groupObj.sortedCol == i){
1274 								$('<img src="img/sortDsc.gif"/>').appendTo($(sortDiv));
1275 							}else{
1276 								$('<img src="img/sortNil.gif"/>').appendTo($(sortDiv));
1277 							}
1278 							var div =$('<div/>');
1279 							var headDiv = $('<div style="float:center">'+cellData+'</div>');
1280 							$(headDiv).appendTo($(div));
1281 							$(sortDiv).appendTo($(headDiv));
1282 							
1283 							$(sortDiv).click(function(){console.log('Clicked....');});
1284 							$(sortDiv).css('cursor','pointer');
1285 							
1286 							$('<div style="clear:both"/>').appendTo($(div));
1287 							$(this).html($(div));*/
1288 						/*});
1289 						$(cell).mouseout(function(){
1290 							var groupObj = require('NexcelGroupList').getGroupObjById($(this).data('groupId'));
1291 							if(!groupObj) return;//TODO Deleted group object
1292 							var row = parseInt(groupObj.rowStart);
1293 							if(groupObj.groupTitle)
1294 								row++;
1295 							var cellData = NexcelUI.CELL.DATA.getSheetCellValue(groupObj.sheetId, row, parseInt(groupObj.colStart)+parseInt($(this).data('colIndex')));
1296 							$(this).html(cellData);
1297 						});
1298 					}
1299 				}  == End of old code*/
1300 			},
1301 			setUpGroupHeader:function(groupObj){
1302 				if(!groupObj)
1303 					return;
1304 				var hexColor = require('UIUtil').colorToHex(groupObj.color);
1305 				var bgColor = require('UIUtil').lightenDarkenColor(groupObj.color,150);
1306 				var lightColor = require('UIUtil').lightenColor(groupObj.color);
1307 				var divName = "groupNameDiv"+groupObj.id;
1308 				var groupNameDiv = $('<div id="'+divName+'" class="groupNameDiv" />');
1309 				$(groupNameDiv).data('groupId', groupObj.id);
1310 				$(groupNameDiv).mouseover(function(){
1311 					require('GridView').enlargeHeader($(this).data('groupId'));
1312 				});
1313 				$(groupNameDiv).mouseout(function(){
1314 					var groupObj = require('NexcelGroupList').getGroupObjById($(this).data('groupId'));
1315 					if(!groupObj.headerPinned)
1316 						require('GridView').hideHeader($(this).data('groupId'));
1317 					//require('GridView').shortenHeader($(this).data('groupId'));
1318 				});
1319 				var heading = $('<div class="Heading"  ></div>');
1320 				$(heading).css('background',lightColor);
1321 				var dataDiv = $('<div class="Table"><div class="Title"><p>'+groupObj.name+'</p></div></div>');
1322 				$(heading).appendTo(dataDiv);
1323 				$(dataDiv).appendTo(groupNameDiv);
1324 				$(dataDiv).find('.Title').each(function(id, obj){
1325 					$(obj).css('background',lightColor);
1326 				});
1327 				$(groupNameDiv).css('background',lightColor);
1328 				var header = '<div class="jsPanel-hdr-r"><div class="jsPanel-btn-min" style="background-image: none;"><span class="jsglyph jsglyph-minimize" onclick="require(\'GridView\').pinGroupHeaderOnClick(this)" style="background-image: none;"></span></div><div class="jsPanel-btn-small" style="display:none; background-image: none;"><span class="jsglyph jsglyph-chevron-up" onclick="require(\'GridView\').groupHeaderMaximizeOnClick(this)" style="background-image: none;"></span></div></div>';
1329 				$(groupNameDiv).data('groupName',groupObj.name);
1330 				$(header).appendTo($(groupNameDiv));
1331 				if(groupObj.rowStart<3)
1332 					$(groupNameDiv).appendTo($('body'));
1333 				else
1334 					$(groupNameDiv).appendTo(DomObjects.dataTableDiv);
1335 				var colAdded = false;
1336 				var headerHeight = $('#'+divName).height();
1337 				var WorkBook = require('WorkBook');
1338 				if(groupObj.colNameAvailable == '1'){
1339 					var columnsDiv = $('<div class="jsPanel-hdr-toolbar jsPanel-clearfix groupColumnNameDiv"></div>');
1340 					$(columnsDiv).appendTo(groupNameDiv);
1341 					var columnList = groupObj.colNameList;
1342 					for(var j=0; j<groupObj.colSize && columnList[j]; j++){
1343 						var width = 100;
1344 						if(WorkBook.WB_COL_WIDTH[WorkBook.ACTIVE_SHEET_ID] && WorkBook.WB_COL_WIDTH[WorkBook.ACTIVE_SHEET_ID][j+1])
1345 							width = WorkBook.WB_COL_WIDTH[WorkBook.ACTIVE_SHEET_ID][j+1];
1346 						//var colDiv = $('<div style="min-width: '+width+'px;max-width: '+width+'px; padding: 0px 0px; float: left;" class="ColName">Column '+j+'</div>');
1347 						var colDiv = $('<div class="Cell"><p style="margin:1px;">'+columnList[j].name+'</p></div>');
1348 						$(colDiv).appendTo($(heading));
1349 						$(colDiv).css('width',width);
1350 						$(colDiv).css('background',require('UIUtil').lightenColor(lightColor));
1351 					}
1352 				}
1353 				var td = $($($('#dataTable tr')[parseInt(groupObj.rowStart)-1]).find('td')[parseInt(groupObj.colStart)-1])[0];
1354 				$(groupNameDiv).find('.Table').mouseout(function(){
1355 					console.log('Table Out....'+$(event.target).html())
1356 				});
1357 				require('GridView').setUpGroupHeaderWidth('#'+divName, groupObj);
1358 				if(!groupObj.headerPinned)
1359 					require('GridView').hideHeader(groupObj.id);
1360 				return divName;
1361 			},
1362 			/**
1363 			 *	Nexcel.GRID_VIEW
1364 			 * 	Apply Style to Group Header and Title 
1365 			 *  @description Deleted function.
1366 			 */
1367 			setUpGroupHeaderWidth:function(divName, groupObj){
1368 				var navHeight =0;
1369 				$('nav').each(function(){navHeight+=$(this).height() || 0;});
1370 				var left = 0;
1371 				var width = 0;
1372 				var colDivList = $('div.colsHeaderDiv').find('.colDiv');
1373 				var trList = $('#dataTable tr');
1374 				if(parseInt(groupObj.rowStart) > trList.length)
1375 					return;
1376 				var firstTd = $($(trList[parseInt(groupObj.rowStart)-1]).find('td')[parseInt(groupObj.colStart)-1])[0];
1377 				var columnDiv = $(divName).find('.Cell');
1378 				for(var j=0; j<parseInt(groupObj.colSize); j++){
1379 					 w=$(colDivList[parseInt(groupObj.colStart)-1+j]).width()+2;//$(td).width()+2;
1380 					 $(columnDiv[j]).css('min-width',w+'px');
1381 					 $(columnDiv[j]).css('max-width',w+'px');
1382 					 width += w;
1383 				}
1384 				var divHeight = $(divName).height();
1385 				var colHeight = $(divName).find('.Cell').height();
1386 				var parent = $(divName).parent();
1387 				var top = 0; 
1388 				if( parent[0] && parent[0].tagName== 'BODY'){
1389 					top = navHeight - divHeight - colHeight ;//- divHeight - colHeight + require('WorkBook').LAST_TOP
1390 					left = $(firstTd).offset().left  //+$(DomObjects.dataTableDiv).offset().left ;//require('WorkBook').LAST_LEFT;
1391 				}else{
1392 					top = $(firstTd).offset().top - divHeight - colHeight - navHeight +require('WorkBook').LAST_TOP-3;//- divHeight - colHeight + require('WorkBook').LAST_TOP
1393 					left =  $(firstTd).offset().left  - $(DomObjects.dataTableDiv).offset().left +require('WorkBook').LAST_LEFT+1;
1394 				}	
1395 				var divLeft = left-1  ;
1396 				//$('#'+divName).css({'left':divLeft,'top':divTop});
1397 				$(divName).css({'min-width':(width-2)+'px','max-width':(width-2)+'px','top':top,'left':divLeft});
1398 			},
1399 			/**
1400 			 * Nexcel.GRID_VIEW
1401 			 * It reposition the group header with the screen move or col resize.
1402 			 */
1403 			rePositionGroupHeaderDiv:function(){
1404 				$('.groupNameDiv').each(function(id, div){
1405 					var navHeight =0;
1406 					$('nav').each(function(){navHeight+=$(this).height() || 0;});
1407 					var trList = $('#dataTable tr');
1408 					var groupName = $(div).data('groupName');
1409 					var groupObj = require('NexcelGroupList').getGroupObjByName(groupName);
1410 					if(parseInt(groupObj.rowStart) > trList.length)
1411 						return;
1412 					var firstTd = $($($('#dataTable tr')[parseInt(groupObj.rowStart)-1]).find('td')[parseInt(groupObj.colStart)-1])[0];
1413 					if(!firstTd)
1414 						return;
1415 					if($(div).parent().is('body')){
1416 						top = navHeight - $(div).height() - $(div).find('.Cell').height() ;//- divHeight - colHeight + require('WorkBook').LAST_TOP
1417 						left = $(firstTd).offset().left   //+$(DomObjects.dataTableDiv).offset().left ;//require('WorkBook').LAST_LEFT;
1418 					}else{
1419 						var top = $(firstTd).offset().top -  $(div).height() - $(div).find('.Cell').height() - navHeight +require('WorkBook').LAST_TOP-3;;//+ require('WorkBook').LAST_TOP
1420 						var left = $(firstTd).offset().left - $(DomObjects.dataTableDiv).offset().left + require('WorkBook').LAST_LEFT;
1421 					}
1422 					$(div).css('left', (left-1)+'px');
1423 					$(div).css('top', top+'px');
1424 				});
1425 			},
1426 			enlargeHeader:function(groupId){
1427 				var divName = '#groupNameDiv'+groupId;
1428 				$(divName).show();
1429 				$(divName).find('.jsPanel-btn-min').show();
1430 				$(divName).find('.groupColumnNameDiv').show();
1431 				$(divName).find('.jsPanel-btn-small').hide();
1432 				$(divName).find('.Heading').show();
1433 				var groupObj = require('NexcelGroupList').getGroupObjById(groupId);
1434 				if(groupObj){
1435 					$(divName).find('.Title').css({'border': 'solid','border-width': 'thin','border-bottom': '0px'});
1436 					this.setUpGroupHeaderWidth(divName, groupObj);
1437 					var width = $(divName).width()-3;
1438 					$(divName).css({'min-width':width+'px','max-width':width+'px'});
1439 				}
1440 			},
1441 			shortenHeader:function(groupId){
1442 				
1443 				var navHeight =0;
1444 				$('nav').each(function(){navHeight+=$(this).height() || 0;});
1445 				var divName = '#groupNameDiv'+groupId;
1446 				$(divName).show();
1447 				$(divName).find('.jsPanel-btn-small').hide();
1448 				$(divName).find('.jsPanel-btn-min').hide();
1449 				$(divName).find('.groupColumnNameDiv').hide();
1450 				$(divName).find('.Title').css({'border': '0px'});
1451 				var groupObj = require('NexcelGroupList').getGroupObjById(groupId);
1452 				if(!groupObj)
1453 					return;
1454 				//var top = $($($($('#dataTable tr')[parseInt(groupObj.rowStart)-1]).find('td')[parseInt(groupObj.colStart)-1+0])[0]).offset().top - $(parentDiv).height();
1455 				var divHeight = $(divName).height();
1456 				var colHeight = $($(divName).find('.Cell')[0]).height();
1457 				var width = groupObj.name.length *20;
1458 				var firstTd = $($($('#dataTable tr')[parseInt(groupObj.rowStart)-1]).find('td')[parseInt(groupObj.colStart)-1])[0];
1459 				if(!firstTd)
1460 					return;
1461 				if($(divName).parent().is('body')){
1462 					top = navHeight - $(divName).height() - $(divName).find('.Cell').height() ;//- divHeight - colHeight + require('WorkBook').LAST_TOP
1463 					left = $(firstTd).offset().left ;//+$(DomObjects.dataTableDiv).offset().left ;//- require('WorkBook').LAST_LEFT;
1464 				}else{
1465 					var top = $(firstTd).offset().top -  $(divName).height() - navHeight +require('WorkBook').LAST_TOP-3;//+ require('WorkBook').LAST_TOP
1466 					var left = $(firstTd).offset().left - $(DomObjects.dataTableDiv).offset().left + require('WorkBook').LAST_LEFT;;
1467 				}
1468 				width = (width+3)+'px'
1469 				$(divName).css({'top':top});
1470 				$(divName).find('.Heading').hide();
1471 			},
1472 			hideHeader:function(groupId){
1473 				var divName = '#groupNameDiv'+groupId;
1474 				$(divName).hide();
1475 			},
1476 			/**
1477 			 * 
1478 			 */
1479 			pinGroupHeaderOnClick:function(icon){
1480 				var parentDiv = $(icon).parent().parent();
1481 				var groupName = $(parentDiv).parent().data('groupName');
1482 				var groupObj = require('NexcelGroupList').getGroupObjByName(groupName);
1483 				if(groupObj.headerPinned)
1484 					groupObj.headerPinned = false;
1485 				else
1486 					groupObj.headerPinned = true;
1487 				require('NexcelUIDataService').pinGroupHeader(groupObj);
1488 				require('GridView').enlargeHeader(groupObj.id);
1489 			},
1490 			/**
1491 			 *	Nexcel.GRID_VIEW
1492 			 * 	Apply Style to Group Header and Title 
1493 			 */
1494 			groupHeaderMinimizeOnClick:function(icon){
1495 				var navHeight =0;
1496 				$('nav').each(function(){navHeight+=$(this).height() || 0;});
1497 				var parentDiv = $(icon).parent().parent();
1498 				var groupName = $(parentDiv).parent().data('groupName');
1499 				var groupId = require('NexcelGroupList').getGroupObjByName(groupName).id
1500 				$(parentDiv).find('.jsPanel-btn-small').show();
1501 				$(parentDiv).parent().find('.groupColumnNameDiv').hide();
1502 				var groupObj = require('NexcelGroupList').getGroupObjByName(groupName);
1503 				//var top = $($($($('#dataTable tr')[parseInt(groupObj.rowStart)-1]).find('td')[parseInt(groupObj.colStart)-1+0])[0]).offset().top - $(parentDiv).height();
1504 				$(icon).parent().hide();
1505 				var divHeight = $('#groupNameDiv'+groupId).height();
1506 				var colHeight = $($('#groupNameDiv'+groupId).find('.Cell')[0]).height();
1507 				var width = groupObj.name.length *20;
1508 				var firstTd = $($($('#dataTable tr')[parseInt(groupObj.rowStart)-1]).find('td')[parseInt(groupObj.colStart)-1])[0];
1509 				if($(icon).is('.dataTableDiv *')){
1510 					var top = $(firstTd).offset().top - divHeight - navHeight;
1511 				}else{
1512 					var top = $(firstTd).offset().top - divHeight ;
1513 				}
1514 				$($(parentDiv).parent()).css({'min-width':(width+3)+'px','max-width':(width+3)+'px','top':top});
1515 				
1516 				$($(parentDiv).parent()).find('.Heading').hide();
1517 				//$($(parentDiv).parent()).find('.Title').hide();
1518 			},
1519 			/**
1520 			 *	Nexcel.GRID_VIEW
1521 			 * 	Apply Style to Group Header and Title 
1522 			 */
1523 			groupHeaderMaximizeOnClick:function(icon){
1524 				var parentDiv = $(icon).parent().parent();
1525 				var groupName = $(parentDiv).parent().data('groupName');
1526 				var groupObj = require('NexcelGroupList').getGroupObjByName(groupName);
1527 				$(parentDiv).find('.jsPanel-btn-min').show();
1528 				$(parentDiv).parent().find('.groupColumnNameDiv').show();
1529 				$(icon).parent().hide();
1530 				var divName = $($(parentDiv).parent()).attr('id');
1531 				$($(parentDiv).parent()).find('.Heading').show();
1532 				//$($(parentDiv).parent()).find('.Title').show();
1533 				this.setUpGroupHeaderWidth('#'+divName, groupObj);
1534 			},
1535 			/**
1536 			 *	Nexcel.GRID_VIEW
1537 			 * 	Apply Style to Group Header and Title 
1538 			 */
1539 			removeStyleToGroupTitleAndColName:function(groupObj){
1540 				var titleRow = parseInt(groupObj.rowStart)-1;
1541 				if(groupObj.groupTitle == '1'){
1542 					for(var i=0; i<groupObj.colSize; i++){
1543 						var row = parseInt(groupObj.rowStart-1);
1544 						var col = parseInt(groupObj.colStart)+i-1;
1545 						var cell  = $($($('#dataTable tr')[row]).find('td')[col]);
1546 						$(cell).removeAttr('style');
1547 						if(i==0){
1548 							$(cell).attr('colspan','1');
1549 						}
1550 					}
1551 					titleRow = titleRow+1;
1552 				}
1553 				if(groupObj.colNameAvailable =='1'){
1554 					for(var i=0;i<groupObj.colSize; i++){
1555 						var col = parseInt(groupObj.colStart)+i-1;
1556 						var cell  = $($($('#dataTable tr')[titleRow]).find('td')[col]);
1557 						$(cell).removeAttr('style');
1558 						$(cell).unbind('mouseover mouseout');
1559 					}
1560 				}
1561 			},
1562 			clearGroupTitleAndColNameCellValues:function(groupObj){
1563 				var titleRow = parseInt(groupObj.rowStart)-1;
1564 				if(groupObj.groupTitle == '1'){
1565 					for(var i=0; i<groupObj.colSize; i++){
1566 						var row = parseInt(groupObj.rowStart-1);
1567 						var col = parseInt(groupObj.colStart)+i-1;
1568 						var cell  = $($($('#dataTable tr')[row]).find('td')[col]);
1569 						$(cell).html('');
1570 						GridView.saveCell(groupObj.sheetId, titleRow+1, col+1, '', '');
1571 					}
1572 					titleRow = titleRow+1;
1573 				}
1574 				if(groupObj.colNameAvailable =='1'){
1575 					for(var i=0;i<groupObj.colSize; i++){
1576 						var col = parseInt(groupObj.colStart)+i-1;
1577 						var cell  = $($($('#dataTable tr')[titleRow]).find('td')[col]);
1578 						$(cell).html('');
1579 						GridView.saveCell(groupObj.sheetId, titleRow+1, col+1, '', '');
1580 					}
1581 				}
1582 			},
1583 			/**
1584 			 *	Nexcel.GRID_VIEW
1585 			 * 	On Sheet Switch the Group Headers Should be setup. 
1586 			 */
1587 			setUpgroupHeaderOnSheet:function(sheetNo){
1588 				$('.groupNameDiv').remove();//Remove all existing group header div.
1589 				var groupList = require('NexcelGroupList').getGroupObjListOnSheet(sheetNo);
1590 				var GridView = require('GridView');
1591 				for(var i=0; i< groupList.size(); i++){
1592 					GridView.applyStyleToGroupTitleAndColName(groupList.get(i));
1593 					GridView.createSortDivOnColHeader(groupList.get(i));
1594 					GridView.setUpGroupHeader(groupList.get(i));
1595 				}
1596 				GridView.rePositionGroupHeaderDiv();
1597 			},
1598 			/**
1599 			 * 	Nexcel.GRID_VIEW
1600 			 * 	Sorting Functionality DIV Available on Columns.
1601 			 */
1602 			createSortDivOnColHeader:function(groupObj){
1603 				return;
1604 				var row= parseInt(groupObj.rowStart);
1605 				if(groupObj.groupTitle == '1'){
1606 					row ++;
1607 				}
1608 				if(groupObj.colNameAvailable =='1'){
1609 					NexcelUI = require("NexcelUI");
1610 					var tableRow= $('#dataTable tr');
1611 					for(var col=groupObj.colStart;col<=groupObj.colEnd; col++){
1612 						
1613 						var cell = $(tableRow[row-1]).find('td')[col];
1614 						$(cell).css("font-size", "45px;");
1615 						$(cell).css("font-family", "arial, snas-serif;");
1616 						//$(cell).css("font-weight", "bold");
1617 						$(cell).css("background", "#B5C3C7");
1618 						$(cell).attr('align', 'center');	
1619 						//TODO Add the Sorting Functionality here.
1620 						var div = $('<div class="ui-state-default jSBarHelper" style="padding-left: 477.55556535720825px; display: block;"></div>');//<span class="ui-icon ui-icon-triangle-dn"></span>
1621 						var span ;
1622 						if(groupObj.sorted && groupObj.sorted == SORTING.ASC && groupObj.sortedCol == col){
1623 							span = NexcelUI.GROUP.UI.getSortAscSpan();
1624 							$(div).data('sorting', SORTING.ASC);
1625 						}
1626 						else if(groupObj.sorted && groupObj.sorted == SORTING.DESC && groupObj.sortedCol == col){
1627 							span = NexcelUI.GROUP.UI.getSortDscSpan();
1628 							$(div).data('sorting', SORTING.DESC);
1629 						}
1630 						else{ 
1631 							span = NexcelUI.GROUP.UI.getNoSortingSpan();
1632 							$(div).data('sorting', SORTING.NO);
1633 						}
1634 						$(span).appendTo($(div));
1635 						$(div).data('groupName', groupObj.name);
1636 						$(div).data('columnName', $($(cell)[0]).html());
1637 						$(div).appendTo($(cell));
1638 						$(div).click(function(){
1639 							var sorting = $(this).data('sorting');
1640 							var span = $(this).children()[0];
1641 							$(span).remove();
1642 							console.log($(this).data('groupName')+" Group Sorting :"+sorting);
1643 							if(sorting == SORTING.ASC){
1644 								NexcelUI.GROUP.DATA.SORTDSC($(this).data('groupName'), $(this).data('columnName'));
1645 							}
1646 							else{
1647 								NexcelUI.GROUP.DATA.SORTASC($(this).data('groupName'), $(this).data('columnName'));
1648 							}
1649 						});
1650 					}
1651 				}
1652 			},
1653 			
1654 			/**
1655 			 *	Nexcel.GRID_VIEW
1656 			 * 	row=1 means first Row, Similar in Column 
1657 			 * 	First Cell row=1: col=1
1658 			 */
1659 			getGroupsOnCell:function(sheetId, row, col){
1660 				var WorkBook = require('WorkBook');
1661 				var groups=[];
1662 				var groupsOnSheet = require('NexcelGroupList').getGroupObjListOnSheet(sheetId);
1663 				for(var i=0; i<groupsOnSheet.size();i++){
1664 					var groupObj = groupsOnSheet.get(i);
1665 					var endRow = groupObj.rowEnd;
1666 					if(groupObj.rowEnd==-1 && WorkBook.getSheetObj(sheetId))
1667 						endRow = WorkBook.getSheetObj(sheetId).rows;
1668 					if(groupObj.rowStart <= row && endRow>= row && groupObj.colStart<= col && groupObj.colEnd>=col){
1669 						groups.push(groupObj);
1670 					}
1671 				}
1672 				return groups;
1673 			},
1674 
1675 			/**
1676 			 *	Nexcel.GRID_VIEW
1677 			 *  Selection Area will have the CURR_ROW CURR_COL START_ROW START_COL but not necessary START_ROW<CURR_ROW and for col as well.
1678 			 * 	row=1 means first Row, Similar in Column 
1679 			 * 	First Cell row=1: col=1
1680 			 */
1681 			getGroupsOnSelectionArea:function(sheetId, selectionArea){
1682 				var WorkBook = require('WorkBook');
1683 				var AREA = require('MouseListener').getOrderedSelectionPos(selectionArea);
1684 				var groups=[];
1685 				var groupList = require('NexcelGroupList').getGroupObjListOnSheet(sheetId);
1686 				for(var i=0; i< groupList.size(); i++){
1687 					var group = groupList.get(i);
1688 					var endRow = group.rowEnd;
1689 					if(group.rowEnd==-1 && WorkBook.getSheetObj(sheetId))
1690 						endRow = WorkBook.getSheetObj(sheetId).rows;
1691 					if(((group.rowStart <= AREA.START_ROW+1 && AREA.START_ROW+1 <= endRow) || 
1692 						(group.rowStart <= AREA.CURR_ROW+1  && AREA.CURR_ROW+1 <= endRow)  ||  
1693 						(group.rowStart >= AREA.START_ROW+1  &&  endRow <= AREA.CURR_ROW+1)) &&
1694 					   ((group.colStart <= AREA.START_COL+1 &&  AREA.START_COL+1 <= group.colEnd )|| 
1695 						(group.colStart <= AREA.CURR_COL+1 && AREA.CURR_COL+1 <= group.colEnd ) ||  
1696 						(group.colStart >= AREA.START_COL+1  &&  group.colEnd <= AREA.CURR_COL+1)))
1697 						groups.push(group);
1698 				}
1699 				return groups;
1700 			},
1701 			
1702 			/**
1703 			 *	Nexcel.GRID_VIEW
1704 			 * 	A Cell can be a part of one Group with Formula. 
1705 			 *  row=1 means first Row, Similar in Column
1706 			 * 	First Cell A1=> row=1: col=1
1707 			 */
1708 			isCellAssociatedWithGroupWithFormula:function(row, col, sheetId){
1709 				var groupsAssociated = require('GridView').getGroupsOnCell(sheetId, row, col);
1710 				var groupWithFormula;
1711 				for(var i=0; i< groupsAssociated.length; i++){
1712 					groupObj = groupsAssociated[i];
1713 					if(groupObj.formula){
1714 						groupWithFormula = groupObj;
1715 					}
1716 				}
1717 				return groupWithFormula;
1718 			},
1719 			/**
1720 			 *	Nexcel.GRID_VIEW
1721 			 * 	Scroll the View So that the Cell will come in View 
1722 			 */
1723 			placeCellOnView:function(cell){
1724 				var hDiff = 2*parseInt($(cell).width())+parseInt($(cell).position().left)-parseInt($('div.dataTableDiv').width());
1725 				if(hDiff>0){
1726 					$('div.dataTableDiv').scrollLeft(hDiff+$('div.dataTableDiv').scrollLeft());
1727 				}
1728 				if($(cell).position().left<0){
1729 					$('div.dataTableDiv').scrollLeft($(cell).position().left+$('div.dataTableDiv').scrollLeft());
1730 				}
1731 				var vDiff = 2*parseInt($(cell).height())+parseInt($(cell).position().top)-parseInt($('div.dataTableDiv').height());
1732 				if(vDiff>0){
1733 					$('div.dataTableDiv').scrollTop(vDiff+$('div.dataTableDiv').scrollTop()+$(cell).height());
1734 				}
1735 				if($(cell).position().top<0){
1736 					$('div.dataTableDiv').scrollTop($(cell).position().top+$('div.dataTableDiv').scrollTop());
1737 				}
1738 			},
1739 			
1740 			
1741 			highlightSelectionArea:function (SELECTION_AREA, color){
1742 				var GridView = require('GridView');
1743 				var NexcelUI=require('NexcelUI');
1744 				if(!SELECTION_AREA) return;
1745 				var trList = $('#dataTable tr');
1746 				var border=new Object();
1747 				var lastTD;
1748 				var totalCell = (SELECTION_AREA.CURR_ROW - SELECTION_AREA.START_ROW +1)*(SELECTION_AREA.CURR_COL-SELECTION_AREA.START_COL+1);
1749 				for(var i=SELECTION_AREA.START_ROW;i<=SELECTION_AREA.CURR_ROW; i++){
1750 					if(i==SELECTION_AREA.START_ROW)
1751 						border.TOP=true;
1752 					else
1753 						border.TOP=false;
1754 					if(i==SELECTION_AREA.CURR_ROW)
1755 						border.BOTTOM=true;
1756 					else
1757 						border.BOTTOM=false;
1758 					var tr = trList[i];
1759 					var tdList = $(tr).find('td');
1760 					for(var j=SELECTION_AREA.START_COL;j<=SELECTION_AREA.CURR_COL; j++){
1761 						var td= lastTD =tdList[j];
1762 						if(j==SELECTION_AREA.START_COL)
1763 							border.LEFT=true;
1764 						else
1765 							border.LEFT=false;
1766 						if(j==SELECTION_AREA.CURR_COL)
1767 							border.RIGHT=true;
1768 						else
1769 							border.RIGHT=false;
1770 						GridView.drawCellBorder(td, border, color);
1771 						if(SELECTION_AREA.TYPE && !NexcelUI.isPartOfAnyGroupHeader($(td), GridView.ACTIVE_SHEET_ID) ){
1772 							if(color == DomObjects.defaultBorderCol || totalCell == 1) 
1773 								$(td).css('background-color', '');
1774 							else  
1775 								$(td).css('background-color', '#ECF3FF');
1776 						}
1777 					}
1778 				}
1779 				GridView.highlightCell(GridView.lastHighlighedTD, false);
1780 			},
1781 			/**
1782 			 *	Nexcel.GRID_VIEW
1783 			 * 	Method to highlight the row & column header highlighting. 
1784 			 */
1785 			highlightRowColHeader:function(SELECTION_AREA, color){
1786 				$('.colDiv').each(function(){$(this).css('background-color','');});
1787 				$('.rowDiv').each(function(){$(this).css('background-color','');});
1788 				var colHeaderDiv = $('.colDiv');
1789 				var rowHeaderDiv = $('.rowDiv'); 
1790 				if(color){
1791 					for(var i=SELECTION_AREA.START_ROW;i<=SELECTION_AREA.CURR_ROW; i++){
1792 						$(rowHeaderDiv[i]).css('background-color', color);
1793 					}
1794 					for(var j=SELECTION_AREA.START_COL;j<=SELECTION_AREA.CURR_COL; j++){
1795 						$(colHeaderDiv[j]).css('background-color', color);	
1796 					}
1797 				}
1798 			},
1799 			/**
1800 			 * Nexcel.GRID_VIEW
1801 			 * @param {Object} cell	It is teh TD 
1802 			 * @param {Object} border where border is an Object with LEFT,TOP,RIGHT,BOTTOM values will be set.
1803 			 */
1804 			drawCellBorder:function(cell, border, color){
1805 				if(border.RIGHT && border.BOTTOM)
1806 					$(cell).css('border','1pt solid '+color);
1807 				else if(border.RIGHT)
1808 					$(cell).css('border-right','1pt solid '+color);
1809 				else if(border.BOTTOM)
1810 					$(cell).css('border-bottom','1pt solid '+color);
1811 				var colIndex = $(cell).index();
1812 				if(border.LEFT){
1813 					
1814 					var sibLeft = $(cell).siblings('td')[colIndex-1];
1815 					if(sibLeft)
1816 						$(sibLeft).css("border-right","1px solid "+color);
1817 					else	$(cell).css('border-left','1pt solid '+color);
1818 					
1819 				}
1820 				if(border.TOP){
1821 					var rowIndex = $(cell).parent('tr').index();
1822 					var sibRow =$(cell).closest('tr').siblings('tr')[rowIndex-1];
1823 					var sibUp = $(sibRow).find('td')[colIndex];
1824 					if(!sibRow || ! sibUp)
1825 						$(cell).css("border-top","1px solid "+color);
1826 					$(sibUp).css("border-bottom","1px solid "+color);
1827 				}
1828 			},
1829 		
1830 		
1831 			/**
1832 			 * Nexcel.GRID_VIEW
1833 			 * Parse a cell name to it's location
1834 			 * @param {String} locStr, "A1" = {row: 1, col: 1}
1835 			 * @return {Object} {row: 1, col: 1}
1836 			 * @methodOf Nexcel.GRID_VIEW
1837 			 * @name parseLocation
1838 			 */
1839 			parseLocation:function (locStr) {
1840 				for (var firstNum = 0; firstNum < locStr.length; firstNum++) {
1841 					if (locStr.charCodeAt(firstNum) <= 57 && locStr.charAt(firstNum) != '$') {// 57 == '9'
1842 						break;
1843 					}
1844 				}
1845 				var rowStr = locStr.substring(firstNum);
1846 				var colStr = locStr.substring(0, firstNum);
1847 				var rowAbsolute = false;
1848 				var colAbsolute = false;
1849 				if(colStr.charAt(colStr.length-1)=='$'){
1850 					rowAbsolute = true;
1851 					colStr = colStr.substr(0, colStr.length-1);
1852 				}
1853 				if(colStr.charAt(0)=='$'){
1854 					colAbsolute = true;
1855 					colStr = colStr.substr(1);
1856 				}
1857 				
1858 				return {
1859 					row:parseInt(rowStr),
1860 					col:this.columnLabelIndex(colStr),
1861 					ABS_ROW: rowAbsolute,
1862 					ABS_COL: colAbsolute
1863 				};
1864 			},
1865 			/**
1866 			 *	row:1, col:1 =>A1 
1867 			 *  colAbsolute true/false $A$15
1868 			 *  rowAbsolute true/false
1869 			 */
1870 			getCellName:function(row, col,rowAbsolute, colAbsolute){
1871 				var cellName ="";
1872 				if(colAbsolute)
1873 					cellName = "$"+this.getColumnName(col, 1);
1874 				else cellName = this.getColumnName(col, 1);
1875 				
1876 				if(rowAbsolute)
1877 					cellName = cellName+"$"+row;
1878 				else cellName = cellName+row;
1879 				return cellName;
1880 			},
1881 			/**
1882 			 *	It returns the Sheet Name and the Row, col  like TestSheet!A1
1883 			 */
1884 			getCellFullName:function(sheetId, row, col){
1885 				var sheetObj = require('WorkBook').getSheetObj(sheetId);
1886 				return sheetObj.name + '!'+this.getCellName(row, col);
1887 			},
1888 			getColumnName:function(colNum){
1889 				if(colNum<27)
1890 					return this.columnLabels[colNum-1];
1891 				var x= parseInt(colNum/26);
1892 				var y= colNum%26;
1893 				if(y==0) {
1894 					y=26; x--;
1895 				}
1896 				console.log(x+" : "+y);
1897 				return this.getColumnName(x)+""+this.columnLabels[y-1];
1898 			},
1899 			
1900 			/**
1901 			 * Available labels, used for their index
1902 			 * @memberOf jQuery.sheet.engine
1903 			 * @name columnLabels
1904 			 */
1905 			columnLabels:'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
1906 		
1907 			/**
1908 			 * Get index of a column label
1909 			 * @param {String} str, A to 1, B to 2, Z to 26, AA to 27
1910 			 * @return {Number}
1911 			 * @methodOf jQuery.sheet.engine
1912 			 * @name columnLabelIndex
1913 			 */
1914 			columnLabelIndex:function (str) {
1915 				var num = 0,
1916 					str = str.toUpperCase();
1917 		
1918 				for (var i = 0; i < str.length; i++) {
1919 					var digit = this.columnLabels.indexOf(str[i]) + 1;
1920 					num = (num * 26) + digit;
1921 	//				console.log('Num :'+num+" STR:"+str[i]);
1922 				}
1923 				return (num >= 0 ? num : 0);
1924 			},
1925 			/**
1926 			 *	Nexcel.GRID_VIEW
1927 			 * 	returns cellObj associated with the highlighted td. 
1928 			 */
1929 			getHighlightedCellObj:function(){
1930 				var GridView = require('GridView');
1931 				var gridCol = $(GridView.lastHighlighedTD).index();
1932 				var gridRow = $(GridView.lastHighlighedTD).parent().index();
1933 				var nexcelCellList = require('NexcelCellList');
1934 				var WorkBook = require('WorkBook');
1935 				var cell = nexcelCellList.isExist(WorkBook.ACTIVE_SHEET_ID, gridRow+1, gridCol+1);
1936 				if(!cell)
1937 					cell = nexcelCellList.addCellWithDetails(WorkBook.ACTIVE_SHEET_ID, gridRow+1, gridCol+1, "", "");
1938 				return cell;
1939 			},
1940 			/**
1941 			 *	GridView.jsPanelTipsy
1942 			 * 	Set the tipsy for all the open jsPanel. 
1943 			 */
1944 			/*jsPanelTipsy:function(){
1945 				$('span.jsglyph-remove').tipsy({title:function(){return "Close";}});
1946 				$('span.jsglyph-maximize').tipsy({title:function(){return "Maximise";}});
1947 				$('span.jsglyph-normalize').tipsy({title:function(){return "Restore Down";}});
1948 				$('span.jsglyph-minimize').tipsy({title:function(){return "Minimise";}});
1949 				$('span.jsglyph-chevron-up').tipsy({title:function(){return "Collapse";}});
1950 			},*/
1951 			
1952 			/**
1953 			 *	All Dragging related functions comes here, cell bottom corner drag 
1954 			 * GridView.CELL_DRAG 
1955 			 */
1956 			CELL_DRAG : {
1957 				
1958 				init:function(){
1959 					var GridView = require('GridView');
1960 					var selectionCornerDiv = $('<div id="selectionCornerDiv" class="selectionCornerDiv" />');
1961 					$(selectionCornerDiv).appendTo($(DomObjects.dataTableDiv));
1962 					$(selectionCornerDiv).draggable({
1963 							  drag: function( event, ui ) {
1964 								return false;
1965 							  }
1966 							});
1967 					$(selectionCornerDiv).mousedown(GridView.CELL_DRAG.mouseDown);
1968 					$(selectionCornerDiv).mouseup(GridView.CELL_DRAG.mouseUp);
1969 					//$(selectionCornerDiv).mouseover(GridView.CELL_DRAG.mouseOver);
1970 					require(['HANDLER'],function(HANDLER){
1971 						HANDLER.CELL_DRAG_HANDLER = new Object();
1972 						HANDLER.CELL_DRAG_HANDLER.STARTED =false;	
1973 					});
1974 					
1975 				},
1976 				/**
1977 				 *	RePosition the Cell Dragg selection Div in the provided TD bottom right corner. 
1978 				 */
1979 				positionSelectionCornerDiv:function(td){
1980 					var top = $(DomObjects.dataTableDiv).scrollTop() + $(td).offset().top +$(td).height()  - 3 - $(DomObjects.dataTableDiv).offset().top;
1981 					var left = $(DomObjects.dataTableDiv).scrollLeft() + $(td).offset().left +$(td).width() - 3 - $(DomObjects.dataTableDiv).offset().left+1;
1982 	//				console.log(top+" : "+left);
1983 					$('#selectionCornerDiv').css({'left':left,'top':top});
1984 				},
1985 				positionSelectionCornerDivWithRowCol:function(row, col){
1986 					var td = $($($('#dataTable tr')[parseInt(row)-1]).find('td')[parseInt(col)-1])[0];
1987 					var top = $(DomObjects.dataTableDiv).scrollTop() + $(td).offset().top +$(td).height()  - 3 - $(DomObjects.dataTableDiv).offset().top;
1988 					var left = $(DomObjects.dataTableDiv).scrollLeft() + $(td).offset().left +$(td).width() - 3 - $(DomObjects.dataTableDiv).offset().left+1;
1989 	//				console.log(top+" : "+left);
1990 					$('#selectionCornerDiv').css({'left':left,'top':top});
1991 				},
1992 				mouseDown:function(){
1993 					HANDLER.CELL_DRAG_HANDLER.INITIAL_SELECTION = HANDLER.SELECTION_HANDLER;
1994 					console.log('DRAG---Mouse DN');
1995 					HANDLER.CELL_DRAG_HANDLER.STARTED =true;
1996 				},
1997 				mouseOver:function(){
1998 					
1999 				},
2000 				mouseUp:function(){
2001 					console.log('DRAG---Mouse UP');
2002 					HANDLER.CELL_DRAG_HANDLER.STARTED =false;
2003 				}
2004 			},
2005 			/**
2006 			 * 
2007 			 */
2008 			//TODO Bug fixes on Col resize .. Some more perfection required.
2009 			VIEW_RESIZE:{
2010 				COL_RESIZE:false,
2011 				ROW_RESIZE:false,
2012 				ROW_TARGET:false,
2013 				COL_TARGET:false,
2014 				COL_START_POINT:false,
2015 				ROW_START_POINT:false,
2016 				/**
2017 				 * Nexcel.VIEW_RESIZE.init
2018 				 * Initializes all the resize related functionalities.
2019 				 */
2020 				init:function(){
2021 					require('GridView').VIEW_RESIZE.rowColResizeInit();
2022 				},
2023 				/**
2024 				 *	Nexcel.VIEW_RESIZE.rowColResizeInit
2025 				 * 	Refer : Nexcel.MOUSE_LISTENER.COL.setColCellListener
2026 				 */
2027 				rowColResizeInit:function(){
2028 					$( ".col-resize-div" ).draggable({ axis: "x" });
2029 					$( ".row-resize-div" ).draggable({ axis: "y" });
2030 
2031 					$( ".row-resize-div" ).mousedown(function(){
2032 						require('GridView').VIEW_RESIZE.ROW_RESIZE=true;
2033 						require('GridView').VIEW_RESIZE.ROW_START_POINT = $( ".row-resize-div" ).offset().top;
2034 					});
2035 					$( ".row-resize-div" ).mouseup(function(){
2036 						var GridView = require('GridView');
2037 						GridView.VIEW_RESIZE.ROW_RESIZE=false;
2038 						if(GridView.VIEW_RESIZE.ROW_TARGET){
2039 							rowResizeFunc();
2040 						}
2041 						//GridView.setHeaderRowColumnSize();
2042 						//GridView.CELL_DRAG.positionSelectionCornerDiv(HANDLER.CELL_DRAG_HANDLER.TARGET);
2043 					});
2044 					$( ".row-resize-div" ).mousemove(function(){
2045 						var GridView = require('GridView');
2046 						var maxTop =  parseInt($('.row-resize-div').data('max-top')+10);
2047 					//	console.log('Mouse MOVE.... DIV'+maxTop);
2048 						if(GridView.VIEW_RESIZE.ROW_RESIZE){
2049 							if(parseInt($('.row-resize-div').css('top')) < parseInt($('.row-resize-div').data('max-top'))+10){
2050 								$('.row-resize-div').css('top',maxTop);
2051 								rowResizeFunc();
2052 							}
2053 						}
2054 					});
2055 					var colResizeFunc = function(){
2056 						var GridView = require('GridView');
2057 						var diff = $( ".col-resize-div" ).offset().left  - GridView.VIEW_RESIZE.COL_START_POINT;  
2058 						var width = $(GridView.VIEW_RESIZE.COL_TARGET).width()+diff;
2059 						var index=$(GridView.VIEW_RESIZE.COL_TARGET).index();
2060 						var trList = $('.dataTable tr');
2061 						$($(trList[0]).find('td')[index]).css('min-width',width).css('max-width',width);
2062 						$($(trList[1]).find('td')[index]).css('min-width',width).css('max-width',width);
2063 						$($(trList[2]).find('td')[index]).css('min-width',width).css('max-width',width);
2064 						//TODO Check colspan of row 1, if it is morethan 1, it should a row which have colspan 1.
2065 						width = $($(trList[1]).find('td')[index]).width();
2066 						$(GridView.VIEW_RESIZE.COL_TARGET).css('min-width',width+1).css('max-width',width+1);
2067 						var WorkBook = require('WorkBook');
2068 						if(!WorkBook.WB_COL_WIDTH[WorkBook.ACTIVE_SHEET_ID])
2069 							WorkBook.WB_COL_WIDTH[WorkBook.ACTIVE_SHEET_ID] = [];
2070 						WorkBook.WB_COL_WIDTH[WorkBook.ACTIVE_SHEET_ID][index] = width;
2071 						require('GridView').rePositionGroupHeaderDiv();
2072 						require('GridView').setViewRowHeight();
2073 						require('WorkBookDataService').updateColumnSize(require('WorkBook').ACTIVE_SHEET_ID, index, width);
2074 					};
2075 					var rowResizeFunc = function(){
2076 						var GridView = require('GridView');
2077 						var diff = $( ".row-resize-div" ).offset().top - GridView.VIEW_RESIZE.ROW_START_POINT;  
2078 						var height = $(GridView.VIEW_RESIZE.ROW_TARGET).height()+diff;
2079 						var index=$(GridView.VIEW_RESIZE.ROW_TARGET).parent().index();
2080 						var trList = $('#dataTable tr');
2081 						$($(trList[index])).css('min-height',height).css('max-height',height);
2082 						$($(trList[index]).find('td')).each(function(){$(this).css('min-height',height).css('max-height',height).css('height',height);});
2083 						//height = $($($('#dataTable tr')[1]).find('td')[index-1]).width();
2084 						$(GridView.VIEW_RESIZE.ROW_TARGET).css('min-height',height).css('max-height',height);
2085 						if(!require('WorkBook').WB_ROW_HEIGHT[require('WorkBook').ACTIVE_SHEET_ID])
2086 							require('WorkBook').WB_ROW_HEIGHT[require('WorkBook').ACTIVE_SHEET_ID]=[];
2087 						require('WorkBook').WB_ROW_HEIGHT[require('WorkBook').ACTIVE_SHEET_ID][index] = height;
2088 						require('WorkBookDataService').updateRowSize(require('WorkBook').ACTIVE_SHEET_ID, index+1, height);
2089 					};
2090 					$( ".col-resize-div" ).mousedown(function(){
2091 						var GridView = require('GridView');
2092 						GridView.VIEW_RESIZE.COL_START_POINT = $( ".col-resize-div" ).offset().left;
2093 						GridView.VIEW_RESIZE.COL_RESIZE=true;
2094 					});
2095 					$( ".col-resize-div" ).mouseup(function(){
2096 						var GridView = require('GridView');
2097 						GridView.VIEW_RESIZE.COL_RESIZE=false;
2098 						if(GridView.VIEW_RESIZE.COL_TARGET){
2099 							colResizeFunc();
2100 						}
2101 						//GridView.setHeaderRowColumnSize();
2102 						//GridView.CELL_DRAG.positionSelectionCornerDiv(HANDLER.CELL_DRAG_HANDLER.TARGET);
2103 					});
2104 					$( ".col-resize-div" ).mousemove(function(){
2105 						var GridView = require('GridView');
2106 						var maxLeft =  parseInt($('#col-resize-div').data('max-left')+20);
2107 						if(GridView.VIEW_RESIZE.COL_RESIZE){
2108 							if(parseInt($('#col-resize-div').css('left')) < parseInt($('#col-resize-div').data('max-left'))+80){
2109 								$('#col-resize-div').css('left',maxLeft);
2110 								//Nexcel.VIEW_RESIZE.COL_RESIZE = false;
2111 								//Nexcel.VIEW_RESIZE.COL_TARGET = false;
2112 								colResizeFunc();
2113 							}
2114 						}
2115 					});
2116 				},
2117 			},
2118 		};
2119         return GridView;
2120 });