﻿/*================================================================================*/
/*                                                                                */
/*      BW2Technologies.Web.JScript.Framework.BalloonTip (Alpha V1.0.0.0)         */
/*                                                                                */
/*                                Web-BalloonTips                                 */
/*                                                                                */
/*         Copyright Â© 2006-2010 by BW2Technologies (HP.Lassnig, S.Schmid)        */
/*                                                                                */
/*================================================================================*/

var _oBalloonTip = null;
var _oBalloonTips = new Array();

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/


/*================================================================================*/
/* <Function> BalloonTip Object </Function>
/*================================================================================*/
function __bw2BalloonTip(strBalloonTip, strContent, strTitle, eViewStyle, eClipControls, eArrowType, strImage,	eShowEffect, fAjax)	{
        this.Ajax = fAjax;
        this.ID = strBalloonTip;
        this.BaseObject = null;
        this.ClipControls = eClipControls;
        this.Content = strContent;
        this.Title = strTitle;
        this.Image = strImage;
        this.ShowEffect = eShowEffect;
        this.ViewStyle = eViewStyle;
        this.ArrowType = eArrowType;

        /*--- Create BalloonTip & Set Standard-Properties ---*/
        this.BalloonTip = document.createElement('DIV');
        this.BalloonTip.id = strBalloonTip;
        this.BalloonTip.className = _oSkinCssClasses['BALLOONTIP'];
        this.BalloonTip.style.position = 'absolute';
        this.BalloonTip.style.display = 'none';
        this.BalloonTip.style.overflow = 'hidden';
        this.BalloonTip.style.zIndex = 1;

        try {
            if (_fIE) this.BalloonTip.style.filter = 'progid:dximagetransform.microsoft.shadow(direction=150, strength=3, color=#a0a0a0)';
        } catch (e){
        }

        /*--- Set optional Properties ---*/
        this.BalloonTip.Ajax = fAjax;
        this.BalloonTip.ParentObject = this;
        this.BalloonTip.ArrowTopArea = null;
        this.BalloonTip.ArrowBottomArea = null;
        this.BalloonTip.Created = false;
        this.BalloonTip.Type = 'balloontip';

        /*--- Create BalloonTip-Content ---*/
        this.BalloonTip.Content = document.createElement('DIV');
        this.BalloonTip.Content.id = strBalloonTip + '_Content';
        //this.BalloonTip.Content.ParentObject = null;

        /*--- Define Functions ---*/
        this.Dispose = _bw2BalloonTipDestroy;

        this.BalloonTip.Close = _bw2BalloonTipClose;
        this.BalloonTip.Create = _bw2BalloonTipCreate;
        this.BalloonTip.Load = _bw2BalloonTipLoad;
        this.BalloonTip.Show = _bw2BalloonTipShow;
        this.BalloonTip.Title = _bw2BalloonTipTitle;
        this.BalloonTip.Visible = _bw2BalloonTipVisible;

        this.BalloonTip.Content.Create = _bw2BalloonTipContentCreate;

        /*--------------------------------------------------------------------------------*/

        function _bw2BalloonTipCreate() {
                if (this.Created) return;

                /*--- Add Click-Handler to Balloon-Tip ---*/
                __bw2AddEventListener(this, 'click', _bw2BalloonTipClick, false);

                /*--- Add BalloonTip to Main-Formular ---*/
                __bw2AppendChildElement(this);

                /*--- Arrow-Top ---*/
                this.ArrowTopArea = document.createElement('DIV');
                this.ArrowTopArea.id = this.id + '_ARROWTOPAREA';
                this.ArrowTopArea.style.display = 'none';
                this.ArrowTopArea.style.position = 'relative';
                this.ArrowTopArea.style.zIndex = 1;

                /*--- Arrow-Image-Top ---*/
                oArrowTopImage = document.createElement('IMG');
                oArrowTopImage.id = this.id + '_ARROWTOPIMG';
                oArrowTopImage.src = _oSkinImages['BALLOONTIP_ARROW_TOP_LEFT'].Image;
                oArrowTopImage.style.width = _oSkinImages['BALLOONTIP_ARROW_TOP_LEFT'].Width;
                oArrowTopImage.style.height = _oSkinImages['BALLOONTIP_ARROW_TOP_LEFT'].Height;
                oArrowTopImage.style.display = 'block';
                oArrowTopImage.style.position = 'relative';
                oArrowTopImage.style.top = 2;

                this.ArrowTopArea.appendChild(oArrowTopImage);
                this.ArrowTopArea.Arrow = oArrowTopImage;
                this.appendChild(this.ArrowTopArea);

                /*--- Content-Area ---*/
                this.Content.className = _oSkinCssClasses['BALLOONTIP_CONTENT'];
                //this.Content.width = '100%';
                //this.Content.height = '100%';
                this.Content.style.cursor = 'default';
                //this.Content.ParentObject = this;
                //this.Content.innerHTML = this.ParentObject.Content;

                /*--- Container-Grid ---*/
                var oTable = document.createElement('TABLE');
                this.appendChild(oTable);

                oTable.cellPading = 0;
                oTable.cellSpacing = 0;
                oTable.style.position = 'relative';

                var oRow = oTable.insertRow(-1);
                var oCel = oRow.insertCell(-1);

                /*--- Top-Row ---*/
                oCel.innerHTML = '&nbsp;';
                oCel.className = _oSkinCssClasses['BALLOONTIP_BORDER'];
                oCel.style.width = _oSkinImages['BALLOONTIP_BORDER_TOP_LEFT'].Width;
                oCel.style.height = _oSkinImages['BALLOONTIP_BORDER_TOP_LEFT'].Height;
                oCel.style.backgroundImage = 'url(' + _oSkinImages['BALLOONTIP_BORDER_TOP_LEFT'].Image + ')';
                oCel.style.backgroundRepeat = 'no-repeat';
                oCel.style.backgroundPosition = '2 0';

                oCel = oRow.insertCell(-1);
                oCel.innerHTML = '&nbsp;';
                oCel.className = _oSkinCssClasses['BALLOONTIP_BORDER'];
                oCel.style.height = _oSkinImages['BALLOONTIP_BORDER_TOP_MIDDLE'].Height;
                oCel.style.backgroundImage = 'url(' + _oSkinImages['BALLOONTIP_BORDER_TOP_MIDDLE'].Image + ')';
                oCel.style.backgroundRepeat = 'repeat-x';

                oCel = oRow.insertCell(-1);
                oCel.innerHTML = '&nbsp;';
                oCel.className = _oSkinCssClasses['BALLOONTIP_BORDER'];
                oCel.style.width = _oSkinImages['BALLOONTIP_BORDER_TOP_RIGHT'].Width;
                oCel.style.height = _oSkinImages['BALLOONTIP_BORDER_TOP_RIGHT'].Height;
                oCel.style.backgroundImage = 'url(' + _oSkinImages['BALLOONTIP_BORDER_TOP_RIGHT'].Image + ')';
                oCel.style.backgroundRepeat = 'no-repeat';

                /*--- Middle-Row ---*/
                oRow = oTable.insertRow(-1);
                oCel = oRow.insertCell(-1);
                oCel.innerHTML = '&nbsp;';
                oCel.className = _oSkinCssClasses['BALLOONTIP_BORDER'];
                oCel.style.width = _oSkinImages['BALLOONTIP_BORDER_MIDDLE_LEFT'].Width;
                oCel.style.backgroundImage = 'url(' + _oSkinImages['BALLOONTIP_BORDER_MIDDLE_LEFT'].Image + ')';
                oCel.style.backgroundRepeat = 'repeat-y';
                oCel.style.backgroundPosition = '2 0';

                oCel = oRow.insertCell(-1);
                oCel.appendChild(this.Content);
                oCel.noWrap = true;
                oCel.style.backgroundImage = 'url(' + _oSkinImages['BALLOONTIP_BORDER_MIDDLE_MIDDLE'].Image + ')';
                oCel.noWrap = true;

                oCel = oRow.insertCell(-1);
                oCel.innerHTML = '&nbsp;';
                oCel.className = _oSkinCssClasses['BALLOONTIP_BORDER'];
                oCel.style.width = _oSkinImages['BALLOONTIP_BORDER_MIDDLE_RIGHT'].Width;
                oCel.style.backgroundImage = 'url(' + _oSkinImages['BALLOONTIP_BORDER_MIDDLE_RIGHT'].Image + ')';
                oCel.style.backgroundRepeat = 'repeat-y';

                /*--- Bottom-Row ---*/
                oRow = oTable.insertRow(-1);
                oCel = oRow.insertCell(-1);
                oCel.innerHTML = '&nbsp;';
                oCel.className = _oSkinCssClasses['BALLOONTIP_BORDER'];
                oCel.style.width = _oSkinImages['BALLOONTIP_BORDER_BOTTOM_LEFT'].Width;
                oCel.style.height = _oSkinImages['BALLOONTIP_BORDER_BOTTOM_LEFT'].Height;
                oCel.style.backgroundImage = 'url(' + _oSkinImages['BALLOONTIP_BORDER_BOTTOM_LEFT'].Image + ')';
                oCel.style.backgroundRepeat = 'no-repeat';
                oCel.style.backgroundPosition = '2 0';

                oCel = oRow.insertCell(-1);
                oCel.innerHTML = '&nbsp;';
                oCel.className = _oSkinCssClasses['BALLOONTIP_BORDER'];
                oCel.style.height = _oSkinImages['BALLOONTIP_BORDER_BOTTOM_MIDDLE'].Height;
                oCel.style.backgroundImage = 'url(' + _oSkinImages['BALLOONTIP_BORDER_BOTTOM_MIDDLE'].Image + ')';
                oCel.style.backgroundRepeat = 'repeat-x';

                oCel = oRow.insertCell(-1);
                oCel.innerHTML = '&nbsp;';
                oCel.className = _oSkinCssClasses['BALLOONTIP_BORDER'];
                oCel.style.width = _oSkinImages['BALLOONTIP_BORDER_BOTTOM_RIGHT'].Width;
                oCel.style.height = _oSkinImages['BALLOONTIP_BORDER_BOTTOM_RIGHT'].Height;
                oCel.style.backgroundImage = 'url(' + _oSkinImages['BALLOONTIP_BORDER_BOTTOM_RIGHT'].Image + ')';
                oCel.style.backgroundRepeat = 'no-repeat';

                /*--- Arrow-Bottom Area ---*/
                this.ArrowBottomArea = document.createElement('DIV');
                this.ArrowBottomArea.id = this.id + '_ARROWBOTTOMAREA';
                this.ArrowBottomArea.style.display = 'none';
                this.ArrowBottomArea.style.position = 'relative';

                /*--- Arrow-Image-Bottom ---*/
                oArrowBottomImage = document.createElement('IMG');
                oArrowBottomImage.id = this.id + '_ARROWBOTTOMIMG';
                oArrowBottomImage.src = _oSkinImages['BALLOONTIP_ARROW_BOTTOM_LEFT'].Image;
                oArrowBottomImage.style.width = _oSkinImages['BALLOONTIP_ARROW_BOTTOM_LEFT'].Width;
                oArrowBottomImage.style.height = _oSkinImages['BALLOONTIP_ARROW_BOTTOM_LEFT'].Height;
                oArrowBottomImage.style.display = 'block';
                oArrowBottomImage.style.position = 'relative';

                this.ArrowBottomArea.appendChild(oArrowBottomImage);
                this.ArrowBottomArea.Arrow = oArrowBottomImage;
                this.appendChild(this.ArrowBottomArea);

                /*--- Balloon-Tip Control is created ---*/
                this.Created = true;
        }

        /*--------------------------------------------------------------------------------*/

        function _bw2BalloonTipContentCreate(strInnerHTML) {
                this.innerHTML = strInnerHTML;
        }

        /*--------------------------------------------------------------------------------*/

        function _bw2BalloonTipClick(oEvent) {
                try{
                  //var oObj = __bw2EventSource(oEvent);
                  //oObj.style.display = 'none';
                } catch (e){
                }
        }

        /*--------------------------------------------------------------------------------*/

        function _bw2BalloonTipDestroy() {
                if (!this.BalloonTip.Created) return;
                this.BaseObject = null;
        }

        /*--------------------------------------------------------------------------------*/

        function _bw2BalloonTipClose() {
        }

        /*--------------------------------------------------------------------------------*/

        function _bw2BalloonTipLoad(strContent, fShow) {

                 /*--- Create BalloonTip-Object ---*/
                 if (!this.Created) this.Create();

                 /*--- Create every new Content ---*/
                 this.Content.Create(strContent);

                 /*--- Set as current global BalloonTip ---*/
                 _oBalloonTip = this;

                 if (fShow != null) this.Visible(fShow);
        }

        /*--------------------------------------------------------------------------------*/

        function _bw2BalloonTipShow() {
                with (this.ParentObject) {
                    /*--- Check for reference BaseObject ---*/
                    if (!BaseObject) return;

                    /*--- Load & Create Content ---*/
                    this.Load(Content);

                    /*--- X/Y-Position berechnen ---*/
                    var nX = 0, nOX = __bw2ObjectOffsetLeft(BaseObject); // Get BaseObject X-Position as X-Offset reference
                    var nY = 0, nOY = __bw2ObjectOffsetTop(BaseObject);  // Get BaseObject Y-Position as Y-Offset reference
                    var nWW = __bw2WindowWidth();
                    var nWH = __bw2WindowHeight();
                    //var strAT = ArrowType;

                    this.style.display = 'block';
                    this.style.visibility = 'hidden';

                    /*--- Set BalloonTip viewsettings by predefined Arrow-Type ---*/
                    _bw2BalloonTipShow_ArrowType(this, ArrowType);

                    var fIsTop = true;

                    /*--- Evaluate startup position ---*/
                    switch (ArrowType) {
                          case 'BALLOONTIP_ARROW_BOTTOM_LEFT':
                          case 'BALLOONTIP_ARROW_TOP_LEFT':
                          default:
                                nX = nOX;
                                break;
        				    
                          case 'BALLOONTIP_ARROW_BOTTOM_MIDDLE':
                          case 'BALLOONTIP_ARROW_TOP_MIDDLE':
                                nX = nOX + ((BaseObject.offsetWidth - this.offsetWidth) / 2);
                                break;
        				    
                          case 'BALLOONTIP_ARROW_BOTTOM_RIGHT':
                          case 'BALLOONTIP_ARROW_TOP_RIGHT':
                                nX = nOX + (BaseObject.offsetWidth - this.offsetWidth);
                                break;
                    }

                    switch (ArrowType) {
                          case 'BALLOONTIP_ARROW_BOTTOM_LEFT':
                          case 'BALLOONTIP_ARROW_BOTTOM_MIDDLE':
                          case 'BALLOONTIP_ARROW_BOTTOM_RIGHT':
                          default:
	                              /*--- Check for intersection with top border ---*/
	                              nY = nOY - this.offsetHeight;

	                              if (nY < 1) {
		                              ArrowType = _bw2BalloonTipGetOppositeArrowType(ArrowType);
		                              _bw2BalloonTipShow_ArrowType(this, ArrowType);
		                              nY = nOY + BaseObject.offsetHeight;
		                              fIsTop = false;
		                            }
	                              break;

                          case 'BALLOONTIP_ARROW_TOP_LEFT':
                          case 'BALLOONTIP_ARROW_TOP_MIDDLE':
                          case 'BALLOONTIP_ARROW_TOP_RIGHT':
	                              /*--- Check for intersection with bottom border ---*/
	                              nY = nOY + BaseObject.offsetHeight;
	                              fIsTop = false;

	                              if (nY + this.offsetHeight > nWH) {
		                              ArrowType = _bw2BalloonTipGetOppositeArrowType(ArrowType);
		                              _bw2BalloonTipShow_ArrowType(this, ArrowType);
		                              nY = nOY - this.offsetHeight;
		                              fIsTop = true;
		                            }
	                              break;
                    }

                    /*--- Check for intersection with right border ---*/
                    if (nX + this.offsetWidth > nWW) {
                      if (fIsTop) {
		                     _bw2BalloonTipShow_ArrowType(this, 'BALLOONTIP_ARROW_BOTTOM_RIGHT');
	                    } else {
		                     _bw2BalloonTipShow_ArrowType(this, 'BALLOONTIP_ARROW_TOP_RIGHT');
	                    }
                      
                      nX = nOX - this.offsetWidth;

                    /*--- Check for intersection with left border ---*/
                    } else {
                      if (nX - this.offsetWidth < 1) {
	                      if (fIsTop) {
			                    _bw2BalloonTipShow_ArrowType(this, 'BALLOONTIP_ARROW_BOTTOM_LEFT');
		                    } else {
			                    _bw2BalloonTipShow_ArrowType(this, 'BALLOONTIP_ARROW_TOP_LEFT');
		                    }

	                      nX = nOX + BaseObject.offsetWidth;
	                    }
                    }

                    /*--- Set BalloonTip viewsettings by new Arrow-Type ---*/
                    //if (strAT != ArrowType) _bw2BalloonTipShow_ArrowType(this, strAT);

                    /*--- Set to X/Y-Position ---*/
                    this.style.left = nX;
                    this.style.top = nY;
                    this.Visible(true);

                    /*--- Clear reference to Base-Object ---*/
                    BaseObject = null;
                }
        }

        /*--------------------------------------------------------------------------------*/

        function _bw2BalloonTipGetOppositeArrowType(strArrowType) {
                switch (strArrowType) {
                      case 'BALLOONTIP_ARROW_BOTTOM_LEFT': return 'BALLOONTIP_ARROW_TOP_LEFT';
                      case 'BALLOONTIP_ARROW_BOTTOM_MIDDLE': return 'BALLOONTIP_ARROW_TOP_MIDDLE';
                      case 'BALLOONTIP_ARROW_BOTTOM_RIGHT': return 'BALLOONTIP_ARROW_TOP_RIGHT';
                      case 'BALLOONTIP_ARROW_TOP_LEFT': return 'BALLOONTIP_ARROW_BOTTOM_LEFT';
                      case 'BALLOONTIP_ARROW_TOP_MIDDLE': return 'BALLOONTIP_ARROW_BOTTOM_MIDDLE';
                      case 'BALLOONTIP_ARROW_TOP_RIGHT': return 'BALLOONTIP_ARROW_BOTTOM_RIGHT';
                      default: return 'BALLOONTIP_ARROW_BOTTOM_LEFT';
                }
        }

        /*--------------------------------------------------------------------------------*/

        function _bw2BalloonTipShow_ArrowType(oObj, strArrowType) {

                /*--- select given type ---*/
                switch (strArrowType) {
                      case 'BALLOONTIP_ARROW_BOTTOM_LEFT':
                          oObj.ArrowTopArea.style.display = 'none';
                          oObj.ArrowTopArea.Arrow.style.display = 'none';
                          oObj.ArrowBottomArea.style.display = 'block';
                          oObj.ArrowBottomArea.style.top = -2;
                          oObj.ArrowBottomArea.Arrow.style.display = 'block';
                          oObj.ArrowBottomArea.align = 'left';
                          oObj.ArrowBottomArea.Arrow.src = _oSkinImages['BALLOONTIP_ARROW_BOTTOM_LEFT'].Image;
                          break;

                      case 'BALLOONTIP_ARROW_BOTTOM_MIDDLE':
                          oObj.ArrowTopArea.style.display = 'none';
                          oObj.ArrowTopArea.Arrow.style.display = 'none';
                          oObj.ArrowBottomArea.style.display = 'block';
                          oObj.ArrowBottomArea.style.top = -2;
                          oObj.ArrowBottomArea.Arrow.style.display = 'block';
                          oObj.ArrowBottomArea.align = 'center';
                          oObj.ArrowBottomArea.Arrow.src = _oSkinImages['BALLOONTIP_ARROW_BOTTOM_MIDDLE'].Image;
                          break;

                      case 'BALLOONTIP_ARROW_BOTTOM_RIGHT':
                          oObj.ArrowTopArea.style.display = 'none';
                          oObj.ArrowTopArea.Arrow.style.display = 'none';
                          oObj.ArrowBottomArea.style.display = 'block';
                          oObj.ArrowBottomArea.style.top = -2;
                          oObj.ArrowBottomArea.Arrow.style.display = 'block';
                          oObj.ArrowBottomArea.align = 'right';
                          oObj.ArrowBottomArea.Arrow.src = _oSkinImages['BALLOONTIP_ARROW_BOTTOM_RIGHT'].Image;
                          break;

                      case 'BALLOONTIP_ARROW_TOP_LEFT':
                          oObj.ArrowBottomArea.style.display = 'none';
                          oObj.ArrowBottomArea.Arrow.style.display = 'none';
                          oObj.ArrowTopArea.style.display = 'block';
                          oObj.ArrowTopArea.Arrow.style.display = 'block';
                          oObj.ArrowTopArea.align = 'left';
                          oObj.ArrowTopArea.Arrow.src = _oSkinImages['BALLOONTIP_ARROW_TOP_LEFT'].Image;
                          break;

                      case 'BALLOONTIP_ARROW_TOP_MIDDLE':
                          oObj.ArrowBottomArea.style.display = 'none';
                          oObj.ArrowBottomArea.Arrow.style.display = 'none';
                          oObj.ArrowTopArea.style.display = 'block';
                          oObj.ArrowTopArea.Arrow.style.display = 'block';
                          oObj.ArrowTopArea.align = 'center';
                          oObj.ArrowTopArea.Arrow.src = _oSkinImages['BALLOONTIP_ARROW_TOP_MIDDLE'].Image;
                          break;

                      case 'BALLOONTIP_ARROW_TOP_RIGHT':
                          oObj.ArrowBottomArea.style.display = 'none';
                          oObj.ArrowBottomArea.Arrow.style.display = 'none';
                          oObj.ArrowTopArea.style.display = 'block';
                          oObj.ArrowTopArea.Arrow.style.display = 'block';
                          oObj.ArrowTopArea.align = 'right';
                          oObj.ArrowTopArea.Arrow.src = _oSkinImages['BALLOONTIP_ARROW_TOP_RIGHT'].Image;
                          break;

                      default:
                          oObj.ArrowTopArea.style.display = 'none';
                          oObj.ArrowTopArea.Arrow.style.display = 'none';
                          oObj.ArrowBottomArea.style.display = 'none';
                          oObj.ArrowBottomArea.Arrow.style.display = 'none';
                          break;
                      }
        }

        /*--------------------------------------------------------------------------------*/

        function _bw2BalloonTipTitle(strText) {
             /*
		                   if (strText) {
			                  this.ParentObject.Title = strText;
			                  if (this.Caption) this.Caption.innerHTML = strText;
		                   } else if (this.Caption) {
			                  return this.Caption.innerHTML;
		                   } 
             */
        }

        /*--------------------------------------------------------------------------------*/

        function _bw2BalloonTipVisible(fShow) {

                 /*--- Show ---*/
                 if (fShow) {
                    this.style.zIndex = __bw2ZIndex();
                    __bw2ObjectBlend(this, 20, 100, 700);

                    //$(this).animate({ width: "100%", opacity: 0.8, marginLeft: "0.2in", fontSize: "3em", borderWidth: "0px" }, 0 );

                 /*--- Hide ---*/
                 } else {
                    this.style.display = 'none';
                 }
        }
}

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/


/*================================================================================*/
/* <Function> BalloonTip Show </Function>
/*================================================================================*/
function __bw2BalloonTipShow(strBaseObject, strBalloonTip, strContent, strTitle, eViewStyle, eClipControls, eArrowType,	strImage, eShowEffect){
        try {
            if (_oBalloonTips[strBalloonTip] == null) return;

            with (_oBalloonTips[strBalloonTip]) {
                 if (strBaseObject) BaseObject = __bw2GetElementById(strBaseObject);
                 if (strContent) Content = strContent;
	             if (strTitle) Title = strTitle;
	             if (eViewStyle) ViewStyle = eViewStyle;
                 if (eClipControls) ClipControls = eClipControls;
	             if (strImage) Image = strImage;
	             if (eShowEffect) ShowEffect = eShowEffect;
	             if (eArrowType) ArrowType = eArrowType;

                 BalloonTip.Show();
            }
        } catch (e){
        }
}

/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
