/*================================================================================*/
/*                                                                                */
/*        BW2Technologies.Web.JScript.Framework.Inputs (Alpha V1.0.0.0)           */
/*                                                                                */
/*                  Copyright © 2006-2007 by BW2Technologies HPL                  */
/*                                                                                */
/*================================================================================*/

var _oDropDowns = new Array();
var _oDropDown = null;
var _oSelectedListItem = null;
var strLastID = '';

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/


/*================================================================================*/
/* <Function> Set Style of BW2-InputControls </Function>
/*================================================================================*/
function __bw2InputSetStyle(strObject, strClass, strColor, fFocus) {
         var oObj = null;
         
         //if (strObject == strLastID) return;

//__bw2Debug('__bw2InputSetStyle : ' + strObject);

         try {
             oObj = __bw2GetElementById(strObject);
             oObj.className = strClass;
             //strLastID = strObject;
             __bw2SetActiveObject(oObj);
             if (fFocus == true) oObj.focus();
         } catch (ex) {
         }
   
         try {
             oObj = __bw2GetElementById(strObject + '_Label');
             oObj.style.borderBottom = '1px solid ' + strColor;
   
         } catch (e) {
         }
   
         try {
             oObj = __bw2GetElementById(strObject + '_Image');
             oObj.className = strClass;
             oObj.style.borderBottom = '1px solid ' + strColor;
         } catch (e) {
         }
   
         try {
             oObj = __bw2GetElementById(strObject + '_Input');
             oObj.className = strClass;
             oObj.style.borderBottom = '1px solid ' + strColor;
         } catch (e) {
         }
   
         try {
             oObj = __bw2GetElementById(strObject + '_Arrow');
             oObj.className = strClass;
             oObj.style.borderBottom = '1px solid ' + strColor;
         } catch (e) {
         }
   
         try {
             oObj = __bw2GetElementById(strObject + '_Controls');
             oObj.className = strClass;
             oObj.style.borderBottom = '1px solid ' + strColor;
         } catch (e) {
         }
   
         try {
             oObj = __bw2GetElementById(strObject + '2');
             oObj.className = strClass;
         } catch (e) {
         }
   
         try {
             oObj = eval(strObject + '_Input2');
             oObj.className = strClass;
             oObj.style.borderBottom = '1px solid ' + strColor;
         } catch (e) {
         }
}

/*================================================================================*/
/* <Function> Define DropDown </Function>
/*================================================================================*/
function __bw2CheckBoxCheck(strObject, strImg, strImgChecked) {
         try {  
             var oI = __bw2GetElementById(strObject + '_IMG');
             var oH = __bw2GetElementById(strObject + '_CHK');

             if ((oI != null) && (oH != null)) {
                if (oH.value == 0) {
                   oI.src = strImgChecked;
                   oH.value = 1; 
                } else {
                   oI.src = strImg;
                   oH.value = '0'; 
                }
             } 
         } catch (e) {
             alert(e.description);
         }
}

/*================================================================================*/
/* <Function> Define DropDown </Function>
/*================================================================================*/
function __bw2DropDown(strObject, strDropDown, nWidth, nHeight, nOffset, strCssClass, nType, fAjax) {
         if (fAjax) _CreateDropDown(strDropDown, strCssClass);  
         
         this.Ajax = fAjax;
         this.AjaxLoaded = false;
         this.ID = strObject;
         this.Type = nType;
         this.Width = nWidth;
         this.Height = nHeight;
         this.Offset = nOffset;
         this.State = 0;
         this.DropDown = __bw2GetElementById(strDropDown);
         this.Obj = __bw2GetElementById(strObject + '_Obj');
         this.ObjImage = __bw2GetElementById(strObject + '_Image');
         this.ObjInput = __bw2GetElementById(strObject + '_Input');
         this.ObjArrow = __bw2GetElementById(strObject + '_Arrow');

         /*--- DropDown --*/
         if (this.Type == 0) {
            __bw2AddEventListener(this.ObjImage, 'mousedown', __bw2DropDownOpen, false);
            __bw2AddEventListener(this.ObjInput, 'mousedown', __bw2DropDownOpen, false);
            __bw2AddEventListener(this.ObjArrow, 'mousedown', __bw2DropDownOpen, false);

         /*--- DropDown-Input --*/
         } else {
            __bw2AddEventListener(this.ObjImage, 'mousedown', __bw2DropDownOpen, false);
            __bw2AddEventListener(this.ObjArrow, 'mousedown', __bw2DropDownOpen, false);
         }
         
         /*--- Create Dynamic-DropDown for Ajax ---*/         
         function _CreateDropDown(strID, strCssClass) {
                  var oForm = document.getElementsByTagName("FORM")[0];
                  var oDD = document.createElement('DIV');

                  oDD.id = strID;
                  oDD.innerHTML = 'Loading ...'
                  oDD.className = strCssClass;
                  oDD.style.display = 'none';
                  oDD.style.overflow = 'auto';
                  oDD.style.position = 'absolute';

                  if (_fIE) oDD.style.filter = 'progid:dximagetransform.microsoft.shadow(direction=150, strength=3, color=#a0a0a0)';

                  __bw2AddEventListener(oDD, 'mouseover', __bw2DropDownOnMouseOver, false);
                  __bw2AddEventListener(oDD, 'mouseout', __bw2DropDownOnMouseOut, false);
    

                  oForm.appendChild(oDD);
         }
}

/*================================================================================*/
/* <Function> Open DropDown </Function>
/*================================================================================*/
function __bw2DropDownOpen(oEvent) {
         if (oEvent == null) return;
         if (_oDropDown != null) { __bw2DropDownClose(oEvent); return; }
   
         var oObj = __bw2EventSource(oEvent).parentNode;
         var strID = oObj.id.split(/_/)[0];

         _oDropDown = _oDropDowns[strID];
         if (_oDropDown == null) return;
         
         with (_oDropDown) {
              var nL, nW = Width;
              var nT = __bw2ObjectOffsetTop(Obj) + Offset;

              if (ObjImage) {
                 nL = __bw2ObjectOffsetLeft(ObjImage);
              } else {
                 nL = __bw2ObjectOffsetLeft(ObjInput);
              }

              if (_fIE) {
                 nW += 3;
              } else {
                 nW -= 1;
              }

              DropDown.scrollTop = 0;
              DropDown.style.left = nL;
              DropDown.style.top = nT;
              DropDown.style.width = nW;
                            
              if ((Ajax && !AjaxLoaded) || Type == 1) {
                 DropDown.innerHTML = 'Loading ...';
                 DropDown.style.display = '';
                 //__bw2AjaxRequest(strID, 'DIV', _strAjaxURL, null, 'ondropdown', _AjaxResponse);
                 _AjaxResponse(__bw2AjaxRequest(strID, 'DIV', _strAjaxURL, null, 'ondropdown', null));
                 AjaxLoaded = true;
              } else {
                 DropDown.style.height = Height;
                 DropDown.style.display = '';
              }
              
              State = 1;
         }

         function _AjaxResponse(oRequest) {
//alert('Show : ' + oRequest.value);                 
                  if (oRequest.value) {
                     _oDropDown.DropDown.innerHTML = oRequest.value; 
                     _oDropDown.DropDown.style.height = _oDropDown.Height;
                  }   
         }
}

/*================================================================================*/
/* <Function> Close DropDown </Function>
/*================================================================================*/
function __bw2DropDownClose(oEvent) {
         if (_oDropDown == null) return;

         __bw2RemoveEventListener(_oDropDown.DropDown, 'mousemove', __bw2DropDownOnMouseMove, false);
         __bw2RemoveEventListener(_oDropDown.DropDown, 'mousedown', __bw2DropDownOnMouseDown, false);

         _oDropDown.DropDown.style.display = 'none';
         _oDropDown = null;
         _oSelectedListItem = null;
}

/*================================================================================*/
/* <Function> Handling DropDown-Events </Function>
/*================================================================================*/
function __bw2DropDownOnEvents(oEvent) {
         if (_oDropDown == null) return;
         if (_oDropDown.State < 2) { _oDropDown.State = 2; return; }
         
         __bw2DropDownClose();
}

/*================================================================================*/
/* <Function> DropDown [OnMouseOver] </Function>
/*================================================================================*/
function __bw2DropDownOnMouseDown(oEvent) {
         if (!_oDropDown) return;
         if (!_oSelectedListItem) return;

         try {         
             var strID = _oSelectedListItem.id.substring(4);
             var nP = strID.indexOf('_');
             var strObject = strID.substring(0, nP);
            
             __bw2GetElementById('__ACTIVEOBJECT').value = strObject;
             
             if (_oDropDown.Ajax) {
                __bw2AjaxRequest(strObject, 'DIV', _strAjaxURL, strID, 'onlistitemselected', _AjaxResponse);
             } else {
                __doPostBack(strObject, 'SEL=' + strID);
                __bw2DropDownClose();
             }
         } catch (e) {
             __bw2Debug(e.description); 
         }

         /*--- Item Selection-Response ---*/ 
         function _AjaxResponse(oRequest) {
                  if (!_oDropDown) return;
                  if (!oRequest.value) return;

                  try {
                      eval(oRequest.value);
                      __bw2GetElementById(oResponse.InputID).value = oResponse.Text;
                      __bw2GetElementById(oResponse.InputID + '_IMG').src = oResponse.Image;

                  } catch (e) {
                      //this.error = new __bw2FrameworkError(e.name, e.description, e.number);
                      //alert('__bw2DropDownOnMouseDown._AjaxResponse : ' + this.error)
                  }   

                   __bw2DropDownClose();
         }
}

/*================================================================================*/
/* <Function> DropDown [OnMouseOver] </Function>
/*================================================================================*/
function __bw2DropDownOnMouseOver(oEvent) {
         if (!_oDropDown) return;
         if (_oDropDown != null) _oDropDown.State = 1;

         __bw2AddEventListener(_oDropDown.DropDown, 'mousemove', __bw2DropDownOnMouseMove, false);
         __bw2AddEventListener(_oDropDown.DropDown, 'mousedown', __bw2DropDownOnMouseDown, false);
         
__bw2Debug('__bw2DropDownOnMouseOver');         
}

/*================================================================================*/
/* <Function> DropDown [OnMouseOut] </Function>
/*================================================================================*/
function __bw2DropDownOnMouseOut(oEvent) {
         if (!_oDropDown) return;
         if (_oDropDown != null) _oDropDown.State = 2;
         __bw2RemoveEventListener(_oDropDown.DropDown, 'mousemove', __bw2DropDownOnMouseMove, false);
         __bw2RemoveEventListener(_oDropDown.DropDown, 'mousedown', __bw2DropDownOnMouseDown, false);

__bw2Debug('__bw2DropDownOnMouseOut');         
}

/*================================================================================*/
/* <Function> DropDown [OnMouseMove] </Function>
/*================================================================================*/
function __bw2DropDownOnMouseMove(oEvent) {
         if (_oDropDown == null) return;

         var oSrc = __bw2EventSource(oEvent); 
         
         if (oSrc.id == _oDropDown.DropDown.id) {
            _oSelectedListItem = null;
         } else {
            _oSelectedListItem = oSrc;
         }
__bw2Debug('__bw2DropDownOnMouseMove : ' + oSrc.id);         
}

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/



/*
function __bw2InputDropDown(strObject, strDropDown, nWidth, nHeight, nOnType) {
            try {
                var oDropDown = __bw2GetElementById(strDropDown);
                var oObj = null;
                var nW = 0;
                var nWi = 0;
                var nWt = 0;
   
                
   
                try {
                    oObj = __bw2GetElementById(strObject + '_Image');
                    nWi = oObj.offsetWidth;
                } catch (ex) {
                }
                try {
                    oObj = __bw2GetElementById(strObject + '_Input');
                    nWt = oObj.offsetWidth;
                    if (nOnType == null) nW = nWi + nWt;
                } catch (ex) {
                    return;
                }
               
                if (oDropDown.style.display == 'none') {
                   //var aPos = __bw2GetCursorPosition(window.event)
                   var nLeft = event.clientX - event.offsetX - nW - 2;
                   var nTop = event.clientY - event.offsetY + oObj.clientHeight - 2;

alert(oObj.id + ', ' + nLeft + ', ' + nTop);
   
                   if (nOnType != null) {
                      if (nOnType == 1) {
                         nLeft = event.clientX - event.offsetX - nWi - 4;
                         nW = nWi + 16;
                      } else if (nOnType == 2) {
                         nLeft = event.clientX - event.offsetX - 2;
                         nW = nWt + 16;
                      }
                   }
                   oDropDown.DropDown = true;
                   oDropDown.Closing = true;
                   oDropDown.style.left = nLeft;
                   oDropDown.style.top = nTop;
                   oDropDown.style.display = '';
   
                   try {
                       __bw2SetActiveObject(oDropDown);
                   } catch (ex) {
                   }
   
                   try {
                       var nH = oDropDown.firstChild.clientHeight;
                       if (nH < nHeight) nHeight = 0;
                       oDropDown.scrollTop = 0;
                   } catch (ex) {
                   }
   
                   if (nWidth != null) {
                      oDropDown.style.pixelWidth = nWidth;
                   } else {
                      oDropDown.style.pixelWidth = event.srcElement.style.pixelWidth + nW + 2;
                   } 
   
                   if (nHeight != null) oDropDown.style.pixelHeight = nHeight;
                } else {
                   oDropDown.style.display = 'none';
                }
            } catch (ex) {
               alert(ex);
            }
}
*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
