/*================================================================================*/
/*                                                                                */
/*             BW2Technologies.Web.JScript.Framework (Alpha V1.0.0.0)             */
/*                                                                                */
/*                                    Web-ListView                                */
/*                                                                                */
/*              Copyright © 2006-2009 by BW2Technologies (HP. Lassnig)            */
/*                           mail to : hansi@lassnig.ch                           */
/*                                                                                */
/*================================================================================*/

var _oListViews = new Array();
var _oListView = null;

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/


/*================================================================================*/
/* <Function> ListView Object </Function>
/*================================================================================*/
function __bw2ListView(strListViewID, eViewStyle, fAjax) {

         /*--- Base-Object ---*/
         this.Ajax = fAjax;
         this.ID = strListViewID;

         this.ListView = __bw2GetElementById(strListViewID); 
         this.ListView.Type = 'listview';
         this.ListView.ViewStyle = eViewStyle;
         this.ListView.Content = __bw2GetElementById(strListViewID + '__Content');
         this.ListView.Head = __bw2GetElementById(strListViewID + '__Head');
         this.ListView.Body = __bw2GetElementById(strListViewID + '__Body');
         this.ListView.PanelBottom = __bw2GetElementById(strListViewID + '__PanelBottom');
         this.ListView.PanelTop = __bw2GetElementById(strListViewID + '__PanelTop');
         this.ListView.Resize = _bw2ListViewResizeFn;

         if (_fIE) {
            __bw2AddEventListener(this.ListView, 'resize', _bw2ListViewResizeEv, false);
         } else {
            __bw2ListViewResize(null, strListViewID);
         }

/*--------------------------------------------------------------------------------*/

         function _bw2ListViewResizeEv(oEvent) {
                  if (oEvent == null) return;
                  var oListView = __bw2EventSource(oEvent);
                  if (oListView) __bw2ListViewResize(oEvent, oListView.id); 
         }

/*--------------------------------------------------------------------------------*/

         function _bw2ListViewResizeFn(oObj) {
                  if (oObj) {
                     __bw2ListViewResize(null, oObj.id); 
                  } else {
                     __bw2ListViewResize(null, this.id); 
                  }  
         }
}
/*================================================================================*/
/* <Function> ListView-Item Event (Event-Handeler) </Function>
/*================================================================================*/
function __bw2ListViewItemEvent(oEvent, oItem, strType, strID, fAjax) {
         if (oItem == null) return;

         if (fAjax) {
            __bw2AjaxObjOnEvent(oEvent, oItem, strType, 'ID=' + strID);
         } else {
            __doPostBack(oItem.id, 'ITEMCLICK');
         }
}

/*================================================================================*/
/* <Function> ListView Scroll </Function>
/*================================================================================*/
function __bw2ListViewResize(oEvent, strListViewID) {
         try {
             var oObj = __bw2GetElementById(strListViewID);

             with (oObj) {
                  var oST = null;  
                  var nT = 0;  
                  var nH = offsetHeight;  
                  var nPH = 1;
                  var nPW = 1;

                  oST = __bw2GetStyle(oObj, 'padding-top'); if (oST) nPH += __bw2GetNumber(oST);
                  oST = __bw2GetStyle(oObj, 'padding-bottom'); if (oST) nPH += __bw2GetNumber(oST);
                  oST = __bw2GetStyle(oObj, 'padding-left'); if (oST) nPW += __bw2GetNumber(oST);
                  oST = __bw2GetStyle(oObj, 'padding-right'); if (oST) nPW += __bw2GetNumber(oST);

                  oST = __bw2GetStyle(oObj, 'border-top-width'); if (oST) nPH += __bw2GetNumber(oST);
                  oST = __bw2GetStyle(oObj, 'border-bottom-width'); if (oST) nPH += __bw2GetNumber(oST);
                  oST = __bw2GetStyle(oObj, 'border-left-width'); if (oST) nPW += __bw2GetNumber(oST);
                  oST = __bw2GetStyle(oObj, 'border-right-width'); if (oST) nPW += __bw2GetNumber(oST);

                  /*--- ToolStrips neu anordnen ---*/ 
                  if (PanelTop) {
                     PanelTop.style.width = offsetWidth - nPW;
                     __bw2ReorderContent(PanelTop);
                     nT = PanelTop.offsetHeight;
                     nH -= nT;
                  }

                  if (PanelBottom) {
                     PanelBottom.style.width = offsetWidth - nPW;
                     __bw2ReorderContent(PanelBottom);
                     nH -= PanelBottom.offsetHeight;
                  }

                  if (Content) {
                     Content.style.Top = nT;
                     Content.style.width = offsetWidth - nPW;
                     Content.style.height = nH - nPH;
                  } else if ((Head) && (Body)) {
                     Head.style.Top = nT;
                     Head.style.width = offsetWidth - nPW;
                     Body.style.top = Head.offsetHeight + nT + 1;
                     Body.style.width = offsetWidth - nPW;
                     Body.style.height = nH - Head.offsetHeight - nPH;
                  }

                  __bw2Debug('__bw2ListViewResize : ' + Body.offsetHeight);
             }
         } catch (e) {
             __bw2Debug('__bw2ListViewResize Exception : ' + e);
        }
}

/*================================================================================*/
/* <Function> ListView load </Function>
/*================================================================================*/
function __bw2ListViewLoad(strListViewID, fNewLoad, fAsync) {
         try {
             with (_oListViews[strListViewID]){
                  __bw2Loading(true); 
                  
                  if (Ajax) {
                     if (fAsync) {
                        __bw2AjaxRequest(strListViewID, 'ListView', fNewLoad, 'onload', __bw2ListViewLoadAsyncResponse);
                     } else {    
                        __bw2AjaxRequest(strListViewID, 'ListView', fNewLoad, 'onload');
                     }
                  }  
             }
         } catch (e) {
             this.error = new __bw2FrameworkError(e.name, e.description, e.number);
             alert('__bw2ListViewLoad Exception : ' + this.error);
         }
}

/*================================================================================*/
/* <Function> ListView load response </Function>
/*================================================================================*/
function __bw2ListViewLoadAsyncResponse(oRequest) {
         try {
             //with (_oListViews[oRequest.context]){
                  //ListView.Body.innerHTML += oRequest.value;   
             //}
         } catch (e) {
             this.error = new __bw2FrameworkError(e.name, e.description, e.number);
             alert('__bw2ListViewLoadResponse Exception : ' + this.error);
         }
}

/*================================================================================*/
/* <Function> ListView Scroll </Function>
/*================================================================================*/
function __bw2ListViewScroll(oEvent, strListViewID) {
         try {
             var oHead = __bw2GetElementById(strListViewID + '__Head');
             var oBody = __bw2GetElementById(strListViewID + '__Body');
             var oScroll = __bw2GetElementById(strListViewID + '_SCP');

             oHead.scrollLeft = oBody.scrollLeft;
             oScroll.value = oBody.scrollTop + ',' + oBody.scrollLeft;
         } catch (e) {
             this.error = new __bw2FrameworkError(e.name, e.description, e.number);
             alert('__bw2ListViewScroll Exception : ' + this.error);
         }
}

/*================================================================================*/
/* <Function> ListView Sort </Function>
/*================================================================================*/
function __bw2ListViewSort(oEvent, oObject, strListViewID, strSort) {
         try {
             //__bw2Loading(true);

             var oBody = __bw2GetElementById(strListViewID + '__Body');
             var oScroll = __bw2GetElementById(strListViewID + '_SCP');

             oScroll.value = oBody.scrollTop + ',' + oBody.scrollLeft;

             with (_oListViews[strListViewID]){
                  if (Ajax) {
                     if (oEvent.ctrlKey == true) {
                        __bw2AjaxObjOnEvent(oEvent, strListViewID, 'onsort_+' + strSort, oObject.id, true);
                     } else {
                        __bw2AjaxObjOnEvent(oEvent, strListViewID, '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('__bw2ListViewSort : ' + this.error);
         }
}

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/

