/**
 *	Klasse um eine Nachrichtenbox zu erzeugen.
 *
 * @author			 	Christian Matyas
 * @param oMessage 		Nachricht, die im Fenster erscheinen soll 
 * @param oButton		Element das bei onclick die Nachrichtenbox sichtbar werden lässt
 * @param oFollowMouse	Soll die Box der Maus folgen oder nicht, wenn nicht erscheint sie unterhalb des Knopfes 
 */

function MessageBox(oMessage, oButton, oFollowMouse){
	this.button = oButton;
	this.message = oMessage;
	this.xPos = 0;
	this.yPos = 0;
	this.messageBox = null;
	
	if(oFollowMouse)
		this.followMouse = oFollowMouse;
	else
		this.followMouse = false;
		
	this.init();
}

MessageBox.prototype.init = function(){
	if(this.followMouse)
		this.initMouse();
	
	oThis = this;
	
	this.button.onclick = function (oEvent){
		if(!oEvent){
			oEvent = window.event;
		}
		oThis.show(oEvent);
	}
	
	this.messageBox = document.createElement("div");
	this.messageBox.className = "infotable";
	this.messageBox.style.visibility = "hidden";
	this.messageBox.style.position = "absolute";
	this.messageBox.style.display = "none";
	this.messageBox.style.padding = "4px";
	this.messageBox.style.width = "200px";
	this.messageBox.innerHTML = '<img src="./dateien/wait.gif" style="float:left; padding:10px;">'+this.message;
	
	var left = this.getLeft();
	var top = this.getTop()+this.button.offsetHeight;
	
	this.messageBox.style.left = left+"px";
	this.messageBox.style.top = top+"px";
	
	document.body.appendChild(this.messageBox);
};
	
MessageBox.prototype.move = function (event){
  	var mausx,mausy;

	/* MSIE, Konqueror, Opera : */
	  if (document.all)
	  {
	    mausx=event.clientX;
	    mausy=event.clientY;
	    if (document.body.scrollLeft)
	      mausx+=document.body.scrollLeft;
	    if (document.body.scrollTop)
	      mausy+=document.body.scrollTop;
	  }
	
	/* Netscape, Mozilla : */
	  else
	  {
	    mausx=event.pageX;
	    mausy=event.pageY;
	  }
	
	/* Vom Cursor wegrücken */  
	mausx += 15;
	mausy += 15; 
	
	/* Auswertung : */
	this.messageBox.style.left = mausx+"px";
	this.messageBox.style.top = mausy+"px";
};


/* Initialisierung der Mausueberwachung */
MessageBox.prototype.initMouse = function()
{
	oThis = this;
	
	
	var IE = ( document.all && document.getElementById && !window.opera );
    var FF = (!document.all && document.getElementById && !window.opera);
    var OP = (document.all && document.getElementById && window.opera);
    
    
    if ( FF || OP ) {
        document.addEventListener('mousemove', function(oEvent){if(!oEvent){oEvent = window.event;}oThis.move(oEvent);}, false);
    }

    if ( IE ) {
        document.attachEvent('onmousemove', function(oEvent){if(!oEvent){oEvent = window.event;}oThis.move(oEvent);});
    }
	
    /*
	// MSIE, Konqueror, Opera : 
	if (document.all)
	    window.onmousemove = function(oEvent){
	    	if(!oEvent){
				oEvent = window.event;
			}
	    	oThis.move(oEvent);
	    }
	
	// Netscape, Mozilla : 
	else
	{
	
		// Netscape6, Mozilla : 
		if (typeof(document.addEventListener)=="function")
			document.addEventListener("mousemove",function(oEvent){if(!oEvent){oEvent = window.event;}oThis.move(oEvent);},true);
		
		// Netscape4 : 
		else
		{
	    	window.captureEvents(Event.MOUSEMOVE);
	    	window.onmousemove = function(oEvent){
		    	if(!oEvent){
					oEvent = window.event;
				}
		    	oThis.move(oEvent);
			}
	    }
	}
	*/
};
    
MessageBox.prototype.show = function()
{
	this.messageBox.style.visibility = "visible";
	this.messageBox.style.display = "block";
};
   

/* Hilffunctionen zur Positionierung*/
MessageBox.prototype.getLeft = function(){
	var oNode = this.button;
	var iLeft = 0;
	
	while(oNode.tagName != 'BODY'){
		iLeft += oNode.offsetLeft;
		oNode = oNode.offsetParent;
	}
	
	return iLeft;
};


MessageBox.prototype.getTop = function(){
	var oNode = this.button;
	var iTop = 0;
	
	while(oNode.tagName != 'BODY'){
		iTop += oNode.offsetTop;
		oNode = oNode.offsetParent;
	}
	
	return iTop;
};