/*================================================================================*/
/*                                                                                */
/*             BW2Technologies.Web.JScript.Framework (Alpha V1.0.0.0)             */
/*                                                                                */
/*                                 Web-TreeView                                   */
/*                                                                                */
/*              Copyright © 2006-2010 by BW2Technologies (HP. Lassnig)            */
/*                           mail to : hansi@lassnig.ch                           */
/*                                                                                */
/*================================================================================*/

var _oTreeView = null;
var _oTreeViews = new Array();
var _oNode = null;
var _oNodeTimer = null;

var _fNodeAjax = false;
var _fNodeCancel = false;
var _nNodeHeight1 = 0;
var _nNodeHeight2 = 0;

var _strCompactImg;   //'Images/TreeView/XP-Cmp-16.gif'
var _strCompactImg;   //'Images/TreeView/XP-Cmp-16.gif'
var _strCompactText;  //'Schliessen'
var _strExpandImg;    //'Images/TreeView/XP-Exp-16.gif'
var _strExpandText;   //'Öffnen'

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/


/*================================================================================*/
/* <Function> TreeView Object </Function>
/*================================================================================*/
function __bw2TreeView(strTreeView, strSelected, strCssClassNode, strCssClassNodeSelected, fAjax) {
         this.Ajax = fAjax;
         this.ID = strTreeView;
         
         this.CssClassNode = strCssClassNode;
         this.CssClassNodeSelected = strCssClassNodeSelected;

         this.TreeView = __bw2GetElementById(strTreeView);
         this.Selected = null;
         this.Scroll = __bw2GetElementById('SCR_' + strTreeView);

         try {
             if (strSelected) {
                this.Selected = __bw2GetElementById(strTreeView + '_' + strSelected);
             }
         } catch (e) {
         }
}

/*================================================================================*/
/* <Function> Node Click </Function>
/*================================================================================*/
function __bw2NodeClick(oEvent, strTreeView, strNodeKey, fAjax, fAsync) {
         if (_fNodeCancel == true) { _fNodeCancel = false; return; }

         if (fAsync != null) {
            __bw2Loading(true);
         } else {
            fAsync = false;
         }
  
         try {
             with (_oTreeViews[strTreeView]) {
                  if (TreeView != null) {
                     __bw2SetActiveObject(TreeView);
                     Scroll.value = TreeView.scrollTop;
                  }   

                  var strQuery = 'SEL=' + strNodeKey + '&SCV=' + TreeView.scrollTop; 
                  if ((oEvent) && (oEvent.ctrlKey == true)) strQuery += '&KEY=CTRL'; 

                  if (fAjax) {
                     if (fAsync) {
                        __bw2AjaxRequest(strTreeView, null, strQuery, 'onnodeclick', _bw2NodeClick);
                     } else {
                        __bw2AjaxRequest(strTreeView, null, strQuery, 'onnodeclick', null);
                     }
                  } else {
                     __doPostBack(strTreeView, 'SEL=' + strTreeView + '_' + strNodeKey);
                  }
             }
         } catch (e) {
         }

/*--------------------------------------------------------------------------------*/

         function _bw2NodeClick() {
                  __bw2Loading(false);  
         }
}

/*================================================================================*/
/* <Function> Ladet Child-Nodes dynamisch nach </Function>
/*================================================================================*/
function __bw2NodeLoadDynamic(oEvent, strTreeView, strNodeKey, fAsync) {
         if ((_oNode == null) || ((_oNode.innerHTML != '') && (_oNode.innerHTML.search(/</) > -1))) {
            _oNode.style.display = 'block';

            if (!_fOp) {
               _nNodeHeight1 = _oNode.offsetHeight;
               _nNodeHeight2 = 1;
               _oNode.style.height = _nNodeHeight2;
               _oNode.style.visibility = 'visible';
               __bw2NodeSlideOpen();
            }

            return;
         }

         if (fAsync != null) {
            __bw2Loading(true);
         } else {
            fAsync = false;
         }

         try {
             with (_oTreeViews[strTreeView]) {
                  if (TreeView != null) {
                     __bw2SetActiveObject(TreeView);
                     Scroll.value = TreeView.scrollTop;
                  }   

                  var strQuery = 'SEL=' + strNodeKey + '&SCV=' + Scroll.value;

                  if (fAsync) {
                     __bw2AjaxRequest(strTreeView, null, strQuery, 'onnodeexpandload', _bw2NodeLoadDynamic);
                  } else {
                     __bw2AjaxRequest(strTreeView, null, strQuery, 'onnodeexpandload', null);
                     _oNode.style.display = 'block';
                     
                     if (!_fOp) {
                        _nNodeHeight1 = _oNode.offsetHeight;
                        _nNodeHeight2 = 1;
                        _oNode.style.height = _nNodeHeight2;
                        _oNode.style.visibility = 'visible';
                        __bw2NodeSlideOpen();
                     }
                  }
             }
         } catch (e) {
         }

/*--------------------------------------------------------------------------------*/

         function _bw2NodeLoadDynamic() {
                  if (_oNode == null) return;
         
                  _oNode.style.display = 'block';

                  if (!_fOp) {
                     _nNodeHeight1 = _oNode.offsetHeight;
                     _nNodeHeight2 = 1;
                     _oNode.style.height = _nNodeHeight2;
                     _oNode.style.visibility = 'visible';
                     __bw2NodeSlideOpen();
                  }
                    
                  __bw2Loading(false);  
         }
}

/*================================================================================*/
/* <Function> Node Expand by Posted </Function>
/*================================================================================*/
function __bw2NodeExpPost(strTreeView, strNodeKey) {
         var strNK = strTreeView + "_" + strNodeKey;
         var oHid = document.getElementById('ECS_' + strNK);

         try {
             if (oHid != null) oHid.value = '1';
         } catch (e) {
         }

         __doPostBack(strTreeView, 'EXP=' + strNK);
}

/*================================================================================*/
/* <Function> Open Node (Slide) </Function> 
/*================================================================================*/
function __bw2NodeSlideOpen() {
         if (_oNode) {    
            var nS = _nNodeHeight1 / 10;

            if (nS < 1) nS = 1;
            _nNodeHeight2 += nS;

            if (_nNodeHeight2 < _nNodeHeight1) {
               _oNode.style.height = _nNodeHeight2;
               _oNodeTimer = setTimeout('__bw2NodeSlideOpen()', 10);
            } else {
               _oNode.style.height = null;
               if ((_fNodeAjax) && (_oNode.TreeView != null)) __bw2AjaxRequest(_oNode.TreeView, null, _oNode.id, 'onnodeexpand');
               _oNode = null;
            }
         }
}

/*================================================================================*/
/* <Function> Close Node (Slide) </Function>
/*================================================================================*/
function __bw2NodeSlideClose() {
         if (_oNode) {    
            var nS = _nNodeHeight1 / 10;

            if (nS < 1) nS = 1;
            _nNodeHeight2 -= nS;

            if (_nNodeHeight2 > 0) {
               _oNode.style.height = _nNodeHeight2;
               _oNodeTimer = setTimeout('__bw2NodeSlideClose()', 10);
            } else {
               _oNode.style.display = 'none';
               _oNode.style.visibility = 'hidden';
               _oNode.style.height = null;
               if ((_fNodeAjax) && (_oNode.TreeView != null)) __bw2AjaxRequest(_oNode.TreeView, null, _oNode.id, 'onnodecollaps');
               _oNode = null;
            }   
         }
}

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
