/*================================================================================*/
/*                                                                                */
/*             BW2Technologies.Web.JScript.Framework (Alpha V1.0.0.0)             */
/*                                                                                */
/*                                    Web-TimePlan                                */
/*                                                                                */
/*              Copyright © 2006-2009 by BW2Technologies (HP. Lassnig)            */
/*                           mail to : hansi@lassnig.ch                           */
/*                                                                                */
/*================================================================================*/

var _oTimePlans = new Array();
var _oTimePlan = null;

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/


/*================================================================================*/
/* <Function> TimePlan Object </Function>
/*================================================================================*/
function __bw2TimePlan(strTimePlanID , fAjax) {
         var oTimePlan = __bw2GetElementById(strTimePlanID);
         var oObj = null;

         /*--- Base-Object ---*/
         this.Ajax = fAjax;
         this.ID = strTimePlanID;

         this.TimePlan = __bw2GetElementById(strTimePlanID); 
         this.TimePlan.Type = 'timeplan';
         this.TimePlan.Head = __bw2GetElementById(strTimePlanID + '__Head');
         this.TimePlan.Body = __bw2GetElementById(strTimePlanID + '__Body');
         this.TimePlan.PanelBottom = __bw2GetElementById(strTimePlanID + '__PanelBottom');
         this.TimePlan.PanelTop = __bw2GetElementById(strTimePlanID + '__PanelTop');
         this.TimePlan.Resize = _bw2TimePlanResizeFn;

         /*--- Bottom-ToolStrip ---*/ 
//         oObj = __bw2GetElementById(strTimePlanID + '__PanelBottom');
//         if (oObj) this.TimePlan.PanelBottom = oObj;

         /*--- Top-ToolStrip ---*/ 
//         oObj = __bw2GetElementById(strTimePlanID + '__PanelTop');
//         if (oObj) this.TimePlan.PanelTop = oObj;

         if (_fIE) {
            __bw2AddEventListener(this.TimePlan, 'resize', _bw2TimePlanResizeEv, false);
         } else {
            __bw2TimePlanResize(null, strTimePlanID);
         }

/*--------------------------------------------------------------------------------*/

         function _bw2TimePlanResizeEv(oEvent) {
                  if (oEvent == null) return;
                  var oTimePlan = __bw2EventSource(oEvent);
                  if (oTimePlan) __bw2TimePlanResize(oEvent, oTimePlan.id); 
         }

/*--------------------------------------------------------------------------------*/

         function _bw2TimePlanResizeFn(oObj) {
                  if (oObj) {
                     __bw2TimePlanResize(null, oObj.id); 
                  } else {
                     __bw2TimePlanResize(null, this.id); 
                  }  
         }
}

/*================================================================================*/
/* <Function> TimePlan Resize </Function>
/*================================================================================*/
function __bw2TimePlanResize(oEvent, strTimePlanID) {
         try {
             with (__bw2GetElementById(strTimePlanID)) {
                  var nT = 0;  

                  /*--- ToolStrips neu anordnen ---*/ 
                  if (PanelTop) {
                     PanelTop.style.width = offsetWidth - 3;
                     __bw2ReorderContent(PanelTop);
                     nT = PanelTop.offsetHeight;
                  }

                  if (PanelBottom) {
                     PanelBottom.style.width = offsetWidth - 3;
                     __bw2ReorderContent(PanelBottom);
                  }

                  Head.style.Top = nT;
                  Head.style.width = offsetWidth - 3;
                  Body.style.top = Head.offsetHeight + nT + 1;
                  Body.style.width = offsetWidth - 3;
                  Body.style.height = offsetHeight - Head.offsetHeight - nT - 3;
             }
         } catch (e) {
             __bw2Debug('__bw2TimePlanResize Exception : ' + e);
        }
}

/*================================================================================*/
/* <Function> TimePlan load </Function>
/*================================================================================*/
function __bw2TimePlanLoad(strTimePlanID, fNewLoad, fAjaxAsync) {
         try {
             with (_oTimePlans[strTimePlanID]){
                  if (Ajax) {
                     if (fAjaxAsync) {
                        __bw2AjaxRequest(strTimePlanID, 'TIMEPLAN', fNewLoad, 'onload', __bw2TimePlanLoadAsyncResponse);
                     } else {    
                        __bw2AjaxRequest(strTimePlanID, 'TIMEPLAN', fNewLoad, 'onload');
                     }
                  }  
             }
         } catch (e) {
             this.error = new __bw2FrameworkError(e.name, e.description, e.number);
             alert('__bw2TimePlanLoad Exception : ' + this.error);
         }
}

/*================================================================================*/
/* <Function> TimePlan load response </Function>
/*================================================================================*/
function __bw2TimePlanLoadAsyncResponse(oRequest) {
         try {
             with (_oTimePlans[oRequest.context]){
                  //TimePlan.Body.innerHTML += oRequest.value;   
             }
         } catch (e) {
             this.error = new __bw2FrameworkError(e.name, e.description, e.number);
             alert('__bw2TimePlanLoadResponse Exception : ' + this.error);
         }
}

/*================================================================================*/
/* <Function> TimePlan Scroll </Function>
/*================================================================================*/
function __bw2TimePlanScroll(oEvent, strTimePlanID) {
         try {
             var oHead = __bw2GetElementById(strTimePlanID + '__Head');
             var oBody = __bw2GetElementById(strTimePlanID + '__Body');
             var oScroll = __bw2GetElementById(strTimePlanID + '_SCP');

             oHead.scrollLeft = oBody.scrollLeft;
             oScroll.value = oBody.scrollTop + ',' + oBody.scrollLeft;
         } catch (e) {
             this.error = new __bw2FrameworkError(e.name, e.description, e.number);
             alert('__bw2TimePlanScroll Exception : ' + this.error);
         }
}

/*================================================================================*/
/* <Function> TimePlan Sort </Function>
/*================================================================================*/
function __bw2TimePlanSort(oEvent, oObject, strTimePlanID, strSort) {
         try {
             var oBody = __bw2GetElementById(strTimePlanID + '__Body');
             var oScroll = __bw2GetElementById(strTimePlanID + '_SCP');

             oScroll.value = oBody.scrollTop + ',' + oBody.scrollLeft;

             with (_oTimePlans[strTimePlanID]){
                  if (Ajax) {
                     if (oEvent.ctrlKey == true) {
                        __bw2AjaxObjOnEvent(oEvent, strTimePlanID, 'onsort_+' + strSort, oObject.id);
                     } else {
                        __bw2AjaxObjOnEvent(oEvent, strTimePlanID, 'onsort_' + strSort, oObject.id);
                     }
                  } 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('__bw2TimePlanSort : ' + this.error);
         }
}

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/

