/*================================================================================*/
/*                                                                                */
/*             BW2Technologies.Web.JScript.Framework (Alpha V1.0.0.0)             */
/*                                                                                */
/*                                    Web-Grid                                    */
/*                                                                                */
/*              Copyright © 2006-2009 by BW2Technologies (HP. Lassnig)            */
/*                           mail to : hansi@lassnig.ch                           */
/*                                                                                */
/*================================================================================*/

var _oGrids = new Array();
var _oGrid = null;
var _oGridColumn = null;
var _oGridColumnResizing = null;

var _fGridLockEvents = false;
var _fOnColumnResizing = false;

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/


/*================================================================================*/
/* <Function> Grid Object </Function>
/*================================================================================*/
function __bw2Grid(strGrid , fAjax) {
         this.Ajax = fAjax;
         this.ID = strGrid;
         
         this.Refresh = _bw2GridRefresh;

         /*--- Grid Object ---*/   
         this.Grid = __bw2GetElementById(strGrid);
         this.Grid.ParentObject = this;
         this.Grid.Type = 'grid';
         this.Grid.ReadedRow = null;
         this.Grid.ReadedTimeout = null;
         this.Grid.SelectedRow = null;
         this.Grid.SelectedRows = new Array();
         this.Grid.OldSelectedRow = null;

         this.Grid.ClassRow = _oSkinCssClasses['GRID_BODY'];
         this.Grid.ClassRowOnOver = _oSkinCssClasses['GRID_ROW_ONOVER'];
         this.Grid.ClassRowSelected = _oSkinCssClasses['GRID_ROW_SELECTED'];
         this.Grid.ClassRowMultiSelected = _oSkinCssClasses['GRID_ROW_MULTISELECTED'];
         this.Grid.ClassRowEven = _oSkinCssClasses['GRID_ROW_EVEN'];
         this.Grid.ClassRowOdd = _oSkinCssClasses['GRID_ROW_ODD'];
         this.Grid.ClassCell = _oSkinCssClasses['GRID_CELL'];
         this.Grid.ClassCellLink = _oSkinCssClasses['GRID_CELL_LINK'];
         this.Grid.ClassColumnHeader = _oSkinCssClasses['GRID_COLUMN_HEADER'];
         this.Grid.ClassColumnHeaderSortIndex = _oSkinCssClasses['GRID_COLUMN_HEADER_SORTINDEX'];

         this.Grid.Resize = _bw2GridResizeFn;
         this.Grid.onmousedown = _bw2Grid_OnMouseDown;
         this.Grid.onmouseup = _bw2Grid_OnMouseUp;
         this.Grid.onmousemove = _bw2Grid_OnMouseMove;

         /*--- ToolStrip-Panels Objects ---*/   
         this.Grid.PanelTop = __bw2GetElementById(strGrid + '__PanelTop');
         this.Grid.PanelBottom = __bw2GetElementById(strGrid + '__PanelBot');

         /*--- Grid-Header Object ---*/   
         this.Grid.Head = __bw2GetElementById(strGrid + '__Head');
         this.Grid.Head.ParentObject = this.Grid;
         this.Grid.Head.Cols = new Array(); 
         this.Grid.Head.ColsWidth = _bw2GridHeader_ColsWidth;
    
         this.Grid.Head.onmousedown = _bw2GridHeader_OnMouseDown;
         this.Grid.Head.onmouseup = _bw2GridHeader_OnMouseUp;
         this.Grid.Head.onmousemove = _bw2GridHeader_OnMouseMove;

         /*--- Grid-Body Object ---*/   
         this.Grid.Body = __bw2GetElementById(strGrid + '__Body');
         this.Grid.Body.ParentObject = this.Grid;
         this.Grid.Body.HasAllRows = false;
         this.Grid.Body.ScrollV = 0;
         this.Grid.Body.ScrollH = 0;

         this.Grid.Body.onscroll = _bw2GridBody_OnScroll;
         this.Grid.Body.onkeydown = _bw2GridBody_OnKeyDown;

         if (_fIE) {
            __bw2AddEventListener(this.Grid, 'resize', _bw2GridResizeEv, false);
         } else {
            __bw2AddEventListener(this.Grid, 'resize', __bw2GridResizeObject, false);
         }

         this.Grid.Resize();
         //__bw2GridResize(null, strGrid);

/*--------------------------------------------------------------------------------*/

         function _bw2GridRefresh() {
                  try {
                      __bw2GetElementById(this.Grid.Head.id + '_Table').style.left = - this.Grid.Body.scrollLeft;
                     if (this.Grid.Head.children) this.Grid.Head.Cols = __bw2GridColumns(this.Grid.Head.children[0]);
                  } catch (e) {}          
         }

/*--------------------------------------------------------------------------------*/

         function _bw2Grid_OnMouseDown(oEvent) {
                  if (oEvent == null) oEvent = window.event;

         }

/*--------------------------------------------------------------------------------*/

         function _bw2Grid_OnMouseUp(oEvent) {
                  if (oEvent == null) oEvent = window.event;

                  if (_oGridColumnResizing != null) {
                     _oGridColumnResizing.Dispose();
                     _fOnColumnResizing = false;
                  } 
         }

/*--------------------------------------------------------------------------------*/

         function _bw2Grid_OnMouseMove(oEvent) {
                  if ((_fOnColumnResizing) || (this.Head == null)) { __bw2Unselect(); return; }
                  if (oEvent == null) oEvent = window.event;

                  var nMY = __bw2EventClientY(oEvent) - __bw2ObjectOffsetTop(this.Head);

                  if ((nMY > 0) && (nMY < this.Head.offsetHeight)) {   
                     if (_fIE) this.style.cursor = 'hand'; else this.style.cursor = 'pointer';
                  } else {  
                     this.style.cursor = 'default';
                  }
         }

/*--------------------------------------------------------------------------------*/

         function _bw2GridBody_OnKeyDown(oEvent) {
                  if (oEvent == null) oEvent = window.event;
                  if (oEvent.keyCode == 16) return;
                  if (oEvent.keyCode == 17) return;
                  if (oEvent.keyCode == 18) return;
                  
                  var nOK = __bw2GetEventKeyOptions(oEvent);
                  var strQ = 'KeyCode=' + oEvent.keyCode; 
                  strQ += '&KeyOptions=' + nOK;
                  strQ += '&ScrollTop=' + this.scrollTop;
                  strQ += '&ScrollHeight=' + this.scrollHeight;
                  strQ += '&ScrollHeightView=' + this.offsetHeight;
                                    
                  __bw2AjaxRequest(this.ParentObject.id, 'GRID', strQ, 'onkeydown', null, nOK);
                  
                  oEvent.returnValue = false;
         }   

/*--------------------------------------------------------------------------------*/

         function _bw2GridBody_OnScroll(oEvent) {
                  if (oEvent == null) oEvent = window.event;

                  //__bw2GetElementById(this.ParentObject.id + '_SCP').value = this.scrollTop + ',' + this.scrollLeft;

                  /*--- Verticlal Scroll for Reload ---*/
                  if (this.ScrollV != this.scrollTop) {
                     this.ScrollV = this.scrollTop;

                     /*--- On Scroll-End Send next Datablock ---*/   
                     if ((!this.HasAllRows) && (this.scrollTop >= (this.scrollHeight - this.offsetHeight))) {
                        __bw2AjaxRequest(this.ParentObject.id, 'GRID', null, 'onscrolldown');
                     }
                     
                  /*--- Horizontal Scroll ---*/
                  } else if (this.ScrollH != this.scrollLeft) {
                     this.ScrollH = this.scrollLeft; 

                     //if (_fIE) {
                        __bw2GetElementById(this.ParentObject.id + '__Head_Table').style.left = - this.scrollLeft;
                     //} else {
                     //   __bw2GetElementById(this.ParentObject.id + '__Head_Table').style.left = - this.scrollLeft + 1;
                     //}                     
                  }
         }

/*--------------------------------------------------------------------------------*/

         function _bw2GridResizeEv(oEvent) {
                  if ((_fGridLockEvents) || (oEvent == null)) return;
                  var oGrid = __bw2EventSource(oEvent);
                  if (oGrid) __bw2GridResize(oEvent, oGrid.id); 
         }

/*--------------------------------------------------------------------------------*/

         function _bw2GridResizeFn(oObj) {
                  if (oObj) {
                     __bw2GridResize(null, oObj.id); 
                  } else {
                     __bw2GridResize(null, this.id); 
                  }  
         }

/*--------------------------------------------------------------------------------*/

         function _bw2GridHeader_ColsWidth() {
                  if (this.Cols.length == 0) return 0;  

                  var nW = 0;
                    
                  for (nI = 0; nI < this.Cols.length - 1; nI++) {
                      nW += this.Cols[nI].Width;  
                  }

                  return nW;
         }

/*--------------------------------------------------------------------------------*/

         function _bw2GridHeader_OnMouseDown(oEvent) {
                  if (oEvent == null) oEvent = window.event;
                         
                  if (this.SelectedCol > -1) {
                     if (_oGridColumnResizing != null) _oGridColumnResizing.Dispose();
                     _oGridColumnResizing = new __bw2GridSplitLine(this.ParentObject); 
                  } 
         }

/*--------------------------------------------------------------------------------*/

         function _bw2GridHeader_OnMouseUp(oEvent) {
                  if (oEvent == null) oEvent = window.event;

                  if (_oGridColumnResizing != null) {
                     _oGridColumnResizing.Dispose();
                  } 
         }

/*--------------------------------------------------------------------------------*/

         function _bw2GridHeader_OnMouseMove(oEvent) {
                  if (oEvent == null) oEvent = window.event;

                  var nMX = __bw2EventClientX(oEvent) - __bw2ObjectOffsetLeft(this) + this.ParentObject.Body.scrollLeft;

                  __bw2Unselect();

                  /*--- Check for Column-Resizing ---*/
                  if ((this.Cols != null) && (_oGridColumnResizing == null)) {
                     this.SelectedCol = -1;
                     _fOnColumnResizing = false;
         
                     for (nI = 0; nI < this.Cols.length; nI++) {
                         var nC = this.Cols[nI].Pos;
                           
                         if ((nMX > nC - 2) && (nMX < nC + 6)) {
                            if (_fIE) this.ParentObject.style.cursor = 'col-resize'; else this.ParentObject.style.cursor = 'e-resize';
                            this.SelectedCol = nI;
                            _fOnColumnResizing = true;
                            return;  
                         } 
                     }
                  }
         }
}

/*================================================================================*/
/* <Function> Dashboard Raster-Line Object </Function>
/*================================================================================*/
function __bw2GridSplitLine(oParent) {
         this.ID = oParent.id + '_SplitLine';
         this.ParentObject = oParent;

         this.Dispose = _bw2GridSplitLineDispose; 

         /*--- Create Split-Line Object ---*/
         this.Line = document.createElement('DIV'); oParent.appendChild(this.Line);
         this.Line.ParentObject = this;
         this.Line.Grid = oParent;

         this.Line.id = this.ID;
         this.Line.style.zIndex = 2;
         this.Line.style.display = 'block';
         this.Line.style.visibility = 'visible';
         this.Line.style.marginRightWidth = '2';
         this.Line.style.borderRightWidth = '1';
         this.Line.style.borderRightStyle = 'dotted';
         this.Line.style.borderRightColor = _oSkinColors['GRID_SPLITLINE'];

         var nX = oParent.Head.Cols[oParent.Head.SelectedCol].Pos;

         if (_fIE) {
            nX -= 3
            this.Line.style.cursor = 'col-resize';
         } else {
            nX -= 4
            this.Line.style.cursor = 'e-resize';
         }

         this.Line.style.position = 'absolute';
         this.Line.style.width = '4';
         this.Line.style.height = oParent.Head.offsetHeight + oParent.Body.offsetHeight;
         this.Line.style.left = nX - oParent.Body.scrollLeft;;
         this.Line.style.top = oParent.Head.offsetTop;

         /*--- Add Event-Handlers ---*/
         __bw2AddEventListener(oParent, 'mousemove', _bw2GridSplitLine_DragMove, false);

/*--------------------------------------------------------------------------------*/

         function _bw2GridSplitLineDispose() {

                  /*--- Remove Event-Handlers ---*/
                  __bw2RemoveEventListener(this.ParentObject, 'mousemove', _bw2GridSplitLine_DragMove, false);

                  /*--- Remove from Container ---*/
                  try { this.ParentObject.removeChild(this.Line); } catch (e) {}

                  /*--- Post Column-Size infos ---*/  
                  if ((_oGridColumn) && (this.ParentObject.ParentObject.Ajax)) {  
                     if (_fIE) {
                        __bw2AjaxRequest(_oGridColumn.id, 'GRID', _oGridColumn.offsetWidth, 'oncolumnresized');
                     } else if (_fSf) {
                        __bw2AjaxRequest(_oGridColumn.id, 'GRID', _oGridColumn.offsetWidth, 'oncolumnresized');
                     } else {
                        __bw2AjaxRequest(_oGridColumn.id, 'GRID', _oGridColumn.offsetWidth - 5, 'oncolumnresized');
                     }
                  }

                  /*--- Resize Column ---*/
                  _bw2GridSplitLineColumnResize(this.ParentObject);
                  
                  /*--- Destroy Objects ---*/
                  _oGridColumnResizing = null;
                  _oGridColumn = null;

                  __bw2Unselect();
         }

/*--------------------------------------------------------------------------------*/

         function _bw2GridSplitLineColumnResize(oGrid) {
                  try {
                      var oTables = oGrid.Body.children;

                      oGrid.Head.Cols = __bw2GridColumns(oGrid.Head.children[0]);

                      for (nT = 0; nT < oTables.length; nT++) {
                          for (nR = 0; nR < oTables[nT].rows.length; nR++) {
                              var oRow = oTables[nT].rows[nR];
                              var nC = _oGridColumn.cellIndex;

                              try {
                                  if (_fIE) {
                                     oRow.cells[nC].style.width = oGrid.Head.Cols[nC].Width;
                                  } else if (_fSf) {
                                     oRow.cells[nC].style.width = oGrid.Head.Cols[nC].Width;
                                  } else {
                                     oRow.cells[nC].style.width = oGrid.Head.Cols[nC].Width - 5;
                                  }
                              } catch (e) {
                                  var x = e;
                              }
                          }
                      }
                  } catch (e) {}
         }

/*--------------------------------------------------------------------------------*/

         function _bw2GridSplitLine_DragMove(oEvent) {
                  if ((oEvent == null) || (_oGridColumnResizing == null)) return;

                  var oH = _oGridColumnResizing.ParentObject.Head;  
                  var nMX = __bw2EventClientX(oEvent) - __bw2ObjectOffsetLeft(_oGridColumnResizing.ParentObject) + _oGridColumnResizing.ParentObject.Body.scrollLeft;      //- 5
                  var nMXL = 0;

                  _oGridColumn = __bw2GetElementById(oH.Cols[oH.SelectedCol].ID);

                  if (oH.SelectedCol == 0) {
                     if (nMX < 10) nMX = 10; 

                     if (_fIE) {
                        nMX -= 3;
                        nMXL = nMX - 3;
                     } else if (_fSf) {  
                        nMX -= 1;
                        nMXL = nMX - 4;
                     } else {
                        nMX -= 6;
                        nMXL = nMX + 1;
                     }

                     _oGridColumn.style.width = nMX;
                     
                  } else {
                     if (nMX < oH.Cols[oH.SelectedCol - 1].Pos + 10) nMX = oH.Cols[oH.SelectedCol - 1].Pos + 10; 

                     if (_fIE) {
                        nMX -= 3;
                        nMXL = nMX - 3;
                     } else if (_fSf) {  
                        nMX -= 1;
                        nMXL = nMX - 4;
                     } else {
                        nMX -= 6;
                        nMXL = nMX + 1;
                     }

                     _oGridColumn.style.width = nMX - oH.Cols[oH.SelectedCol - 1].Pos;
                  }
                    
                  _oGridColumnResizing.Line.style.left = nMXL - _oGridColumnResizing.ParentObject.Body.scrollLeft;
                  __bw2Unselect();
         }
}

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/


/*================================================================================*/
/* <Function> Grid-Column Object </Function>
/*================================================================================*/
function __bw2GridColumn(strID, nPos, nWidth) {
         this.ID = strID;
         this.Pos = nPos;
         this.Width = nWidth;
}

/*================================================================================*/
/* <Function> Grid get Columns </Function>
/*================================================================================*/
function __bw2GridColumns(oObj) {
         try {
             if (oObj.children.length == 0) return;

             _fGridLockEvents = true;

             var oR = oObj.children[0].children[0].children;
             var oCW = new Array();  
             var nCW = 0;
         
             for (nI = 0; nI < oR.length; nI++) {
                 nCW += oR[nI].offsetWidth;
                 oCW[nI] = new __bw2GridColumn(oR[nI].id, nCW, oR[nI].offsetWidth);  
             }

             _fGridLockEvents = false;
         
             return oCW;
         } catch (e) {
             _fGridLockEvents = false;
         }
}

/*================================================================================*/
/* <Function> Grid Resize </Function>
/*================================================================================*/
function __bw2GridResize(oEvent, strGrid) {
         try {
             var oObj = __bw2GetElementById(strGrid); if (!oObj) return;
         
             with (oObj) {
                  var oST = null;  
                  var nT = 0;  
                  var nH = offsetHeight;  
                  var nW = offsetWidth;  
                  var nPH = 3;
                  var nPW = 4;

                  if (_fIE) nPW++;

                  nPH += __bw2GetNumber(oObj.style.paddingTop);  
                  nPH += __bw2GetNumber(oObj.style.paddingBottom);  
                  nPW += __bw2GetNumber(oObj.style.paddingLeft);  
                  nPW += __bw2GetNumber(oObj.style.paddingRight);  

                  nPH += __bw2GetNumber(oObj.style.borderTopWidth);  
                  nPH += __bw2GetNumber(oObj.style.borderBottomWidth);  
                  nPW += __bw2GetNumber(oObj.style.borderLeftWidth);  
                  nPW += __bw2GetNumber(oObj.style.borderRightWidth);  

                  nH -= nPH;
                  nW -= nPW;

                  /*--- ToolStrips neu anordnen ---*/ 
                  if ((PanelTop) && (PanelTop.style.display != 'none')) {
                     PanelTop.style.left = 0;
                     PanelTop.style.top = 0;
                     PanelTop.style.width = nW;
                     nT = PanelTop.offsetHeight;
                     nH -= nT;
                  }

                  if ((PanelBottom) && (PanelBottom.style.display != 'none')) {
                     PanelBottom.style.left = 0;
                     PanelBottom.style.top = nH - PanelBottom.offsetHeight;
                     PanelBottom.style.width = nW;
                     nH -= PanelBottom.offsetHeight;
                  }

                  if ((Head) && (Body)) {
                     Head.style.Top = nT;
                     Head.style.width = nW;
                     if (Head.children) Head.Cols = __bw2GridColumns(Head.children[0]);
                     nT += Head.offsetHeight;
                     nH -= Head.offsetHeight;

                     Body.style.top = nT;
                     Body.style.width = nW;
                     Body.style.height = nH - 2;
                  }
             }
         } catch (e) {
             __bw2Debug('__bw2GridResize Exception : ' + e);
         }
}

/*--------------------------------------------------------------------------------*/

function __bw2GridResizeObject(oObj) {
         try {
             if (oObj) __bw2GridResize(null, oObj.id); 
         } catch (e) {}
}

/*================================================================================*/
/* <Function> Resize Grids </Function>
/*================================================================================*/
//function __bw2GridsResize() {
//         try {
//             for (strID in _oGrids) {
//                 if (_oGrids[strID] != null) _oGrids[strID].Resize();
//             }
//         } catch (e) {}
//}

/*================================================================================*/
/* <Function> Grid load </Function>
/*================================================================================*/
function __bw2GridLoad(strGrid, fNewLoad, fAsync) {
         try {
             if (fAsync) {
                __bw2AjaxRequest(strGrid, 'GRID', fNewLoad, 'onload', __bw2GridLoadAsyncResponse);
             } else {    
                __bw2AjaxRequest(strGrid, 'GRID', fNewLoad, 'onload');
             }
         } catch (e) {
             this.error = new __bw2FrameworkError(e.name, e.description, e.number);
             alert('__bw2GridLoad Exception : ' + strGrid + ', ' + this.error);
         }
}

/*================================================================================*/
/* <Function> Grid load response </Function>
/*================================================================================*/
function __bw2GridLoadAsyncResponse(oRequest) {
         try {
             //with (_oGrids[oRequest.context]){
                  //Grid.Body.innerHTML += oRequest.value;   
             //}
         } catch (e) {
             this.error = new __bw2FrameworkError(e.name, e.description, e.number);
             alert('__bw2GridLoadResponse Exception : ' + this.error);
         }
}

/*================================================================================*/
/* <Function> Grid Row-Readed handler </Function>
/*================================================================================*/
function __bw2GridReadedHandler(strGrid) {
         try {
             var oGrid = __bw2GetElementById(strGrid);
             if (oGrid == null) return; 

             if (oGrid.ReadedRow = oGrid.SelectedRow) {
                var strRowID = oGrid.ReadedRow.getAttribute('RowID');

                /*--- Ajax-Post ---*/
                __bw2AjaxRequest(strGrid, 'GRID', strRowID, 'onreaded');

                oGrid.ReadedRow.setAttribute('RowReaded', null);
                oGrid.ReadedRow = null;
                oGrid.ReadedTimeout = null;
            }
         } catch (e) { }
}

/*================================================================================*/
/* <Function> Grid Row-Click </Function>
/*================================================================================*/
function __bw2GridRowClick(oEvent, oObject, strGrid) {
         try {
             if (oEvent == null) oEvent = window.event;

             var oGrid = __bw2GetElementById(strGrid);
             
             oGrid.SelectedRow = oObject;

             /*--- Get real Row-ID ---*/   
             var strRowID = oObject.getAttribute('RowID');
                      
             /*--- Check for Multi-Select ---*/
             if (oEvent.ctrlKey) { strRowID += '&MS=1'; oEvent.cancelBubble = true; }

             /*--- Ajax-Post ---*/
             __bw2AjaxObjOnEvent(oEvent, strGrid, 'onclick', 'ID=' + strRowID, true);   
             __bw2ToolStripsDestroy();
         } catch (e) {}
}

/*================================================================================*/
/* <Function> Grid Row-DblClick </Function>
/*================================================================================*/
function __bw2GridRowDblClick(oEvent, oObject, strGrid) {
         try {
             var strR = oObject.getAttribute('RowID');
             __bw2AjaxObjOnEvent(oEvent, strGrid, 'ondblclick', 'ID=' + strR, true);   
         } catch (e) {}
}

/*================================================================================*/
/* <Function> Grid Row-Selection </Function>
/*================================================================================*/
function __bw2GridRowSelection(strGrid, nRowID, nOldRowID, fAdd, fContextMenu, fEvenOdd, strClassName) {
         try {
             var oGrid = __bw2GetElementById(strGrid); if (oGrid == null) return; 

             /*--- Reset old Selected-Row ---*/
             if ((nOldRowID != null) && (nOldRowID != nRowID)) {
                oGrid.OldSelectedRow = __bw2GetElementById(strGrid + '_Row_' + nOldRowID);

                if (oGrid.OldSelectedRow) {
                   var strCB = oGrid.ClassRow;
                   
                   if (fEvenOdd) {
                      if ((nOldRowID % 2) == 0) {
                         strCB = oGrid.ClassRowEven;
                      } else {
                         strCB = oGrid.ClassRowOdd;
                      }
                   }

                   oGrid.OldSelectedRow.className = strCB;

                   /*--- Set OnOver-Style ---*/
                   if (oGrid.ClassRowOnOver) {
                      oGrid.OldSelectedRow.onmouseout = function() {this.className = strCB;}
                      oGrid.OldSelectedRow.onmouseover = function() {this.className = oGrid.ClassRowOnOver;}
                   }
                }
             }

             /*--- Set old Selected-Row ---*/
             if (oGrid.SelectedRow) oGrid.OldSelectedRow = oGrid.SelectedRow;

             /*--- Set Selected-Row ---*/
             oGrid.SelectedRow = __bw2GetElementById(strGrid + '_Row_' + nRowID); if (oGrid.SelectedRow == null) return; 

             /*--- Context-Menu Handler ---*/   
             if (fContextMenu) oGrid.SelectedRow.oncontextmenu = __bw2GridOnContextMenu;

             /*--- Stop Readed-Timer ---*/
             if (oGrid.ReadedTimeout) {
                clearTimeout(oGrid.ReadedTimeout);
                oGrid.ReadedTimeout = null;
             }

             /*--- Init Row-Readed handler ---*/
             var strRH = oGrid.SelectedRow.getAttribute('RowReaded');

             if (strRH) {
                oGrid.ReadedRow = oGrid.SelectedRow;
                oGrid.ReadedTimeout = setTimeout('__bw2GridReadedHandler("' + strGrid + '")', strRH);                 
             }
             
             /*--- Set Selected-Style ---*/   
             if (strClassName) {
                oGrid.SelectedRow.className = strClassName;
             } else {
                oGrid.SelectedRow.className = oGrid.ClassRowSelected;
             }   
             
             /*--- Set OnOver-Style ---*/
             if (oGrid.ClassRowOnOver) {
                oGrid.SelectedRow.onmouseout = function() {this.className = oGrid.SelectedRow.className;}
                oGrid.SelectedRow.onmouseover = function() {this.className = oGrid.SelectedRow.className;}
             }
         } catch (e) {}
}

/*================================================================================*/
/* <Function> Grid Sort </Function>
/*================================================================================*/
function __bw2GridSort(oEvent, oObject, strGrid, strSort) {
         if (_fOnColumnResizing) return;
          
         try {
             with (_oGrids[strGrid]){
                  if (Ajax) {
                     if ((oEvent.ctrlKey == true) || (oEvent.altKey == true)) {
                        __bw2AjaxObjOnEvent(oEvent, strGrid, 'onsort_+' + strSort, oObject.id, true);
                     } else {
                        __bw2AjaxObjOnEvent(oEvent, strGrid, 'onsort_' + strSort, oObject.id, true);
                     }
                  } else {  
                     if (oEvent.ctrlKey == true) {
                        __doPostBack(oObject.id, 'SORT_+' + strSort);
                     } else {
                        __doPostBack(oObject.id, 'SORT_' + strSort);
                     }
                  }  
             }
         } catch (e) {
             this.error = new __bw2FrameworkError(e.name, e.description, e.number);
             alert('__bw2GridSort : ' + this.error);
         }
}

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/


/*================================================================================*/
/* <Function> Grid Context-Menu </Function>
/*================================================================================*/
function __bw2GridOnContextMenu(oEvent, strObjID) {
         if (_fIE) oEvent = window.event;
                      
         try {
             oEvent.cancelBubble = true;

             /*--- Get Cursor-Pos ---*/
             var oCP = __bw2GetCursorPosition(oEvent);
             
             /*--- Load Context-Menu ---*/
             __bw2AjaxObjOnEvent(oEvent, this, 'oncontextmenu', 'MX=' + oCP.X + '&MY=' + oCP.Y);
         } catch (e) {
         }

         return false;
}

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
