InfoDefaultDivName = 'InfoDiv';
InfoPositionHLeft = 1;
InfoPositionHRight = 2;
InfoPositionHCenter = 4;

InfoPositionVTop = 1;
InfoPositionVBottom = 2;
InfoPositionVCenter = 4;

function InfoDiv(strDivName) {
    if(!(strDivName)) {
       strDivName = InfoDefaultDivName;
    }
    if(!(document.getElementById(strDivName))) {
        createInfoLayer(strDivName);
    }
    this.objInfoDiv = document.getElementById(strDivName);
    this.divName = strDivName;
    this.show = showInfoLayer;
    this.hide = hideInfoLayer;
    this.move = moveInfoLayer;
    this.setPosition = setLayerPosition;
    this.enableFollowMouse = enableInfoLayerFollowMouse;
    this.moveVisible = moveVisibleInfoLayer;
    this.calcPosition = calcInfoLayerPosition;
    this.handleOverlap = handleInfoLayerOverlap;
    this.setOverlapHandling = setInfoLayerOverlapHandling;
    this.setClipping = setInfoLayerClipping;
    this.m_lngInfoHPosition = 0;
    this.m_lngInfoVPosition = 0;
    this.m_lngMouseXPosition = 0;
    this.m_lngMouseYPosition = 0;
    this.m_lngInfoPositionXMin = -1;
    this.m_lngInfoPositionYMin = -1;
    this.m_lngInfoPositionXMax = -1;
    this.m_lngInfoPositionYMax = -1;
    this.m_strOverlappedElements = '';
    this.m_strOverlapElements = '';
    this.m_blnHandleOverLap = true;
    this.blnMove = true;
    this.m_lngMoveCount = 0;

    i=0;
    this.m_strOverlapElements = '';
	el = document.forms[0].elements[i];
	while(el) {
		if(el.type == 'select-one' || el.type == 'select-multiple')
		{
			if(el.name!='undefined') {
				this.m_strOverlapElements += ';' + el.name
		    }
		}
		i++;
		el = document.forms[0].elements[i];
	}
    this.m_strOverlapElements = this.m_strOverlapElements.substr(1,this.m_strOverlapElements.length-1);
}

function setInfoLayerOverlapHandling(blnHandleOverlap){
    if(blnHandleOverlap == true || blnHandleOverlap == false)this.m_blnHandleOverLap = blnHandleOverlap;
}

function createInfoLayer(id) {
	if (document.all && !document.getElementById) {
		document.body.insertAdjacentHTML('BeforeEnd','<DIV ID=\"' + id + '\">');
		objDiv = document.all[id];
	} else {
		objDiv = document.createElement('DIV');
        objDiv.id = id;
		document.body.appendChild(objDiv);
	}
	with (objDiv.style) {
		position = 'absolute';
		left = '0px';
		top = '0px';
		display = 'none';
	}
    return eval(objDiv);
}

function enableInfoLayerFollowMouse(blnFollow)
{
    if(blnFollow == true || blnFollow == false)this.blnMove = blnFollow;
}

function setInfoLayerClipping(lngXMin, lngYMin, lngXMax, lngYMax) {
    this.m_lngInfoPositionXMin = lngXMin;
    this.m_lngInfoPositionYMin = lngYMin;
    this.m_lngInfoPositionXMax = lngXMax;
    this.m_lngInfoPositionYMax = lngYMax;
}

function showInfoLayer(strID, lngHPosition, lngVPosition, blnMove)
{
    if(document.getElementById(strID)) {
        if(blnMove == true || blnMove == false)this.blnMove = blnMove;
        this.objInfoDiv = document.getElementById(strID);
        this.m_lngInfoHPosition = lngHPosition;
        this.m_lngInfoVPosition = lngVPosition;
        this.m_divName = strID;
        this.objInfoDiv.style.display = 'block';
        this.calcPosition(this.m_lngInfoHPosition, this.m_lngInfoVPosition);
        if(this.m_blnHandleOverLap == true)this.handleOverlap(false);
    }
}

function hideInfoLayer()
{
    this.objInfoDiv.style.display = 'none';
    if(this.m_blnHandleOverLap == true)this.handleOverlap(true);
}

function calcInfoLayerPosition(lngHPosition, lngVPosition)
{
    var lngXOffset = 0;
    var lngYOffset = 0;
    var containerOffsetX = 0;
    var containerOffsetY = 0;
    var intDIVWidth;
    var intDIVWidthTemp;
    var intDIVHeight;
    var lngX = 0;
    var lngY = 0;

    if(this.blnMove) {
	    intDIVWidth = this.objInfoDiv.offsetWidth;
	    intDIVWidthTemp = intDIVWidth;
	    intDIVHeight = this.objInfoDiv.offsetHeight;

	    switch(lngHPosition) {
	        case InfoPositionHLeft:
	            lngXOffset = lngXOffset - intDIVWidth -5;
	            break;
	        case InfoPositionHRight:
	            lngXOffset = +15;
	            break;
	        case InfoPositionHCenter:
	            lngXOffset = (lngXOffset - intDIVWidth) / 2;
	            break;
	        default:
	            lngXOffset = -15;
	            break;
	    }
	    switch(lngVPosition) {
	        case InfoPositionVTop:
	            lngYOffset = lngYOffset - intDIVHeight - 5;
	            break;
	        case InfoPositionVBottom:
	            lngYOffset = 25;
	            break;
	        case InfoPositionVCenter:
	            lngYOffset = (lngYOffset - intDIVHeight) / 2 ;
	            break;
	        default:
	            lngYOffset = 25;
	            break;
	    }

        if(this.objInfoDiv.offsetParent)
        {
	      containerOffsetX = getRealLeft(this.objInfoDiv.offsetParent);
	      containerOffsetY = getRealTop(this.objInfoDiv.offsetParent);
	    }
	    lngX = this.m_lngMouseXPosition - containerOffsetX + lngXOffset;
	    lngY = this.m_lngMouseYPosition - containerOffsetY + lngYOffset;
	    if(this.m_lngInfoPositionXMax - this.m_lngInfoPositionXMin <= intDIVWidth && this.m_lngInfoPositionXMax != -1 && this.m_lngInfoPositionXMin != -1)intDIVWidthTemp = this.m_lngInfoPositionXMax - this.m_lngInfoPositionXMin - 10;
	    if(lngX < this.m_lngInfoPositionXMin && this.m_lngInfoPositionXMin != -1) lngX = this.m_lngInfoPositionXMin;
	    if(lngY < this.m_lngInfoPositionYMin && this.m_lngInfoPositionYMin != -1) lngY = this.m_lngInfoPositionYMin;
	    if(lngX + intDIVWidth > this.m_lngInfoPositionXMax && this.m_lngInfoPositionXMax != -1) lngX = this.m_lngInfoPositionXMax - intDIVWidth;
	    if(lngY + intDIVHeight > this.m_lngInfoPositionYMax && this.m_lngInfoPositionYMax != -1) lngY = this.m_lngInfoPositionYMax - intDIVHeight;
	    this.objInfoDiv.style.left = lngX  + "px";
	    this.objInfoDiv.style.top = lngY + "px";
	    if(intDIVWidth != intDIVWidthTemp )this.objInfoDiv.style.width = intDIVWidthTemp + "px";
    }
}

function moveInfoLayer(lngX,lngY)
{
    this.m_lngMouseXPosition = lngX;
    this.m_lngMouseYPosition = lngY;
    if(this.blnMove = true) {
        this.calcPosition(this.m_lngInfoHPosition, this.m_lngInfoVPosition);
        if(this.m_blnHandleOverLap == true)this.handleOverlap(false);
    }
}

function setLayerPosition(strLayerName, lngX, lngY)
{
    var objDiv = document.getElementById(strLayerName);
    if(objDiv) {
        objDiv.style.left = lngX + 'px';
        objDiv.style.top = lngY + 'px';
    }
}

function moveVisibleInfoLayer(lngX,lngY)
{
    this.m_lngMouseXPosition = lngX;
    this.m_lngMouseYPosition = lngY;
    if(this.objInfoDiv) {
        if(this.objInfoDiv.style.display == 'block' && this.blnMove == true)
        {
            this.m_lngMoveCount++;
            this.calcPosition(this.m_lngInfoHPosition, this.m_lngInfoVPosition);
            if(this.m_lngMoveCount >= 5) {
                if(this.m_blnHandleOverLap == true)this.handleOverlap(true);
                if(this.m_blnHandleOverLap == true)this.handleOverlap(false);
                this.m_lngMoveCount = 0;
            }
        }
    }
}

function handleInfoLayerOverlap(blnModeShow)
{
    // only IE and Netscape 7 has the selectbox z-index bug
    if((navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.toLowerCase().indexOf("opera") == -1)||navigator.userAgent.toLowerCase().indexOf("netscape\/7") >0) {
	    if(blnModeShow == false) {
  	        var containerOffsetX = 0;
    	    var containerOffsetY = 0;
            
            if(this.objInfoDiv.offsetParent)
            {
    	      containerOffsetX = getRealLeft(this.objInfoDiv.offsetParent);
    	      containerOffsetY = getRealTop(this.objInfoDiv.offsetParent);
    	    }
	    	intDIVLeft = this.objInfoDiv.style.left;
	    	intDIVLeft = parseInt(intDIVLeft.replace(/px/,''));
	    	if(isNaN(intDIVLeft))intDIVLeft = getRealLeft(this.objInfoDiv);
	    	intDIVTop = this.objInfoDiv.style.top;
	    	intDIVTop = parseInt(intDIVTop.replace(/px/,''));
	    	if(isNaN(intDIVTop))intDIVTop = getRealTop(this.objInfoDiv);
            intDIVLeft += containerOffsetX;
            //intDIVTop += containerOffsetY;
	    	intDIVWidth = this.objInfoDiv.offsetWidth;
	    	intDIVHeight = this.objInfoDiv.offsetHeight;
	    	arrOverlapElements = this.m_strOverlapElements.split(';')
	    	for(i=0;i < arrOverlapElements.length;i++) {
                el = document.forms[0].elements[arrOverlapElements[i]];
    			if(isElementOverlapped(el, intDIVLeft, intDIVTop, intDIVWidth, intDIVHeight))
    			{
					if(el.name!='undefined') {
						this.m_strOverlappedElements += ';' + el.name
						el.style.visibility = 'hidden';
				    }
    			}
    		}
	    } else {
	    	arrOverlappedElements = this.m_strOverlappedElements.split(';')
	    	for(i=0;i <= arrOverlappedElements.length;i++) {
	    		if(document.forms[0].elements[arrOverlappedElements[i]])
	    		{
                    if(this.objInfoDiv.style.display == 'none') {
	    			    document.forms[0].elements[arrOverlappedElements[i]].style.visibility = 'visible';
                        this.m_strOverlappedElements.replace('/' + arrOverlappedElements[i] + ';/','')
                    } else {
                        if(isElementOverlapped(document.forms[0].elements[arrOverlappedElements[i]], intDIVLeft, intDIVTop, intDIVWidth, intDIVHeight)==false ) {
    	    			    document.forms[0].elements[arrOverlappedElements[i]].style.visibility = 'visible';
                            this.m_strOverlappedElements.replace('/' + arrOverlappedElements[i] + ';/','')
                        }
	                }
	    		}
	    	}
	    }
    }
}

function isElementOverlapped(objElement,lngLeft,lngTop, lngWidth, lngHeight)
{
	var blnReturn = false;
  if(objElement)
  {
  	intelementLeft = getRealLeft(objElement);
  	intelementTop = getRealTop(objElement);
  	intelementWidth = objElement.offsetWidth;
  	intelementHeight = objElement.offsetHeight;
  
  	hideX1 = false;
  	hideX2 = false;
  	hideY1 = false;
  	hideY2 = false;
  	if(intDIVLeft >= intelementLeft && intDIVLeft <= intelementLeft + intelementWidth)hideX1=true;
  	if(intDIVLeft <= intelementLeft && intelementLeft <= intDIVLeft + intDIVWidth)hideX2=true;
  	if(intDIVTop <= intelementTop && intelementTop <= intDIVTop + intDIVHeight)hideY1=true;
  	if(intDIVTop >= intelementTop && intDIVTop <= intelementTop + intelementHeight)hideY2=true;
  
  	if((hideX1 || hideX2) && (hideY1 || hideY2))
  	{
          blnReturn = true;
  	}
  }
  return blnReturn;
}

//****************************************************************************************

//Beispiel für die Verwendung der InfoBox Funktion. Durch die Verwendung des Events kann
//die Box der Maus folgen.
/*
if (document.layers) {
    document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = moveDiv;

function moveDiv(e)
{
    var eventX = (document.all) ? event.clientX : e.pageX;
    var eventY = (document.all) ? event.clientY : e.pageY;
    if(document.all) {
		eventX += getScrollLeft()
		eventY += getScrollTop()
    }
    info.moveVisible(eventX, eventY)
}
*/

function getScrollLeft()
{
	var returnValue = 0;

	if ( getIsStandard() )
	    returnValue = document.documentElement.scrollLeft;
	else
	    returnValue = document.body.scrollLeft;

	return returnValue;
}

function getScrollTop()
{
	var returnValue = 0;

	if ( getIsStandard() )
	    returnValue = document.documentElement.scrollTop;
	else
	    returnValue = document.body.scrollTop;

	return returnValue;
}

function getRealLeft(el) {
  if(el)
  {
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
  }
  else
  {
    xPos = 0;
  }
  return xPos;
}

function getRealTop(el) {
  if(el)
  {
    xPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
  }
  else
  {
    xPos = 0;
  }
  return xPos;
}

function getIsStandard()
{
    return (document.compatMode == "CSS1Compat");
}

