//alert(navigator.userAgent);
//alert(navigator.appName);
//alert(navigator.appVersion);

function getLeft(targetObject)
{
/*
	Info: Gibt die absolute x_Position eines Objektes im Dokument zurŸck (DOM 2)
	Autor: Thomas BŸchler
	Erstellt: 05.02.2004
	Letzte €nderung: 05.02.2004
	
*/
	if (targetObject.offsetParent) return (targetObject.offsetLeft + getLeft(targetObject.offsetParent));
	else return (targetObject.offsetLeft);
}


function getTop(targetObject)
{
/*
	Info: Gibt die absolute y_Position eines Objektes im Dokument zurŸck (DOM 2)
	Autor: Thomas BŸchler
	Erstellt: 05.02.2004
	Letzte €nderung: 05.02.2004
	
*/

	if (targetObject.offsetParent) return (targetObject.offsetTop + getTop(targetObject.offsetParent));
	else return (targetObject.offsetTop);
}

function setDivpos(targetDiv, parentDiv, divDirection, balanceX, balanceY)
{

/*
	Richtet targetDiv an parentDiv abhŠngig von divdirection aus
	
	divDirection:
	topW = rechts/oberkante von Parent
	bottomX	= unten/Startposition von Parent
	
*/	
	parentDiv = document.getElementById(parentDiv);
	targetDiv = document.getElementById(targetDiv);
	
	parentDivX = getLeft(parentDiv);
	parentDivY = getTop(parentDiv);
	parentDivW = parentDivX + parentDiv.offsetWidth;
	parentDivH = parentDivY + parentDiv.offsetHeight;


	if (divDirection == "topW")
	{
		targetDiv.style.left = parentDivW;
		targetDiv.style.top = parentDivY;
	}
	else if (divDirection == "bottomX")
	{
		targetDiv.style.left = parentDivX - balanceX;
		targetDiv.style.top = parentDivH + balanceY;
	}
	else
	{
		alert("divDirection ungŸltig");
	}
	
	return true;
}

function testMousepos(targetDiv)		// Testet, ob sich der Mauszeiger innerhalb des targetDiv befindet
{
	targetDiv = document.getElementById(targetDiv);
		
	targetDivX = getLeft(targetDiv);
	targetDivY = getTop(targetDiv);
	targetDivW = targetDivX + targetDiv.offsetWidth;
	targetDivH = targetDivY + targetDiv.offsetHeight;
	
	var browsertyp=navigator.userAgent.toLowerCase();
	
	
	if((browsertyp.indexOf("netscape") != -1 || browsertyp.appName == "Netscape" || browsertyp.indexOf("mozilla") != -1) && browsertyp.indexOf("opera") == -1 && browsertyp.indexOf("msie") == -1)
	{		
		function handleMove(pos)
		{
			x=pos.pageX;
			y=pos.pageY;
		}
		document.addEventListener("mousemove", handleMove, true);
	}
	else if(browsertyp.indexOf("msie") != -1 && browsertyp.indexOf("opera") == -1)
	{
		x = window.event.x;
		y = window.event.y;	
	}
	
	if(!((x <= targetDivW) && (y <= targetDivH) && (x >= targetDivX) && (y >= targetDivY)))
	{
		return false;
	}
	else
	{
		//alert(x+" =>"+targetDivW+"\n"+y+" =>"+targetDivH+"\n"+x+" =>"+targetDivX+"\n"+y+" =>"+targetDivY);
		
		return true;
	}
}

function blende()		// †berwacht die Mausposition / Sichtbarkeit der Layer
{

if(!window.noloop)	// PrŸft Browser-Version
{
	if(navigator.appName == "Netscape" || navigator.userAgent.indexOf("mozilla") != -1)
	{
		if(navigator.appVersion.substring(0,1) > "4")
		{
			window.layerOK = 1;
			window.noloop = 1;
		}
	}
	else
	{
		if(navigator.appVersion.substring(0,1) >= "4")
		{
			window.layerOK = 1;
			window.noloop = 1;
		}
	}				
}

if(window.layerOK)
{
	
	if (window.currentlyVisiblePopup  && !window.blocker)
	{
		
		if (!testMousepos(window.currentlyVisibleParent))
		{
			if (!testMousepos(window.currentlyVisiblePopup))
			{
				hideCurrentPopup(window.currentlyVisiblePopup);
				
				window.currentlyVisiblePopup = false;
				window.currentlyVisibleParent = false;
								
				if(open_sel_button_ > "")// --- Wird gesetzt wenn ein MenŸ wegen einem offenen Layer nicht deselektiert werden konnte. Wird jetzt nachgeholt
				{
					Desel(open_sel_button_);
					open_sel_button_="";
				}
			}
		}
	}
	
	if(window.blocker)
	{
		//	PrŸfung, ob Mauszeiger Ÿber gŸltigen Layern ist
		
		if (!testMousepos(window.currentlyVisiblecontainerLayer) && !testMousepos(window.currentlyVisibleSubPopup) && testMousepos(window.currentlyVisibleParent))
		{
			hideCurrentPopup(window.currentlyVisibleSubPopup);
			window.currentlyVisibleSubPopup = false;
			window.blocker = false;
			window.currentlyVisiblePopup = window.currentlyVisiblecontainerLayer;
		}
		else if (!testMousepos(window.currentlyVisiblecontainerLayer) && !testMousepos(window.currentlyVisibleSubPopup) && !testMousepos(window.currentlyVisibleParent))
		{
		
			hideCurrentPopup(window.currentlyVisibleSubPopup);
			window.currentlyVisibleSubPopup = false;
			
			hideCurrentPopup(window.currentlyVisiblecontainerLayer);
			window.currentlyVisiblecontainerLayer = false;
			
			window.blocker = false;

		}	
	}
}

} // Blende


function hidesubLayer()		// Blendet aktuelles Sublayer aus
{
	if (window.blocker)
	{
		hideCurrentPopup(window.currentlyVisibleSubPopup);
		window.currentlyVisibleSubPopup = false;
		window.blocker = false;
		window.currentlyVisiblePopup = window.currentlyVisiblecontainerLayer;
	}
}


function getStyleObject(objectId) {
/*  
	cross-browser-funktion um das Style-Objekt eines Objektes anzusprechen
*/
    if(document.getElementById && document.getElementById(objectId)) {
    // W3C (IE6 & Netscape 6 & 7 )
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// IE 4
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// Netscape 4
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // Setzt Sichtbarkeit am Objekt
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	
	return true;
    } else {
	return false;
    }
} // changeObjectVisibility


function showPopup (targetObject, targetParent, poppos, balanceX, balanceY) 
{
		


if(window.layerOK)
{	

	if(window.currentlyVisiblePopup)
	{
		hideCurrentPopup(window.currentlyVisiblePopup);
	}
	
	if(window.currentlyVisibleSubPopup)
	{
		hideCurrentPopup(window.currentlyVisibleSubPopup);
	}
	
	if(changeObjectVisibility(targetObject, 'visible') )
	{
		if(setDivpos(targetObject, targetParent, poppos, balanceX, balanceY))
		{
			window.currentlyVisiblePopup = targetObject;
			window.currentlyVisibleParent = targetParent;
			//alert("HALLO1");
		}
	}
	
}   
    
} // showPopup

function showSubPopup (targetObject, targetParent, targetSubParent, poppos)	// 'subsubmenue1','Ebene1','drucker1','topW 
{	

if(window.layerOK)
{	

	if(window.currentlyVisibleSubPopup)
	{
		hideCurrentPopup(window.currentlyVisibleSubPopup);
	}
	
	if(changeObjectVisibility(targetObject, 'visible') )
	{
	
		if(setDivpos(targetObject, targetSubParent, poppos))
		{
			window.currentlyVisibleSubPopup = targetObject;			//Unter-Layer
			window.currentlyVisibleSubParent = targetSubParent;		//Eltern-Image
			
			window.currentlyVisiblecontainerLayer = targetParent; //Eltern-Layer (enthŠlt Eltern-Image)		
			
			window.blocker = 1;		//Schalter fŸr 2te MenueEbene
		}
	}
}   
    
} // showPopup


function hideCurrentPopup(targetPopup) {
    changeObjectVisibility(targetPopup, 'hidden');
	window.currentlyVisiblePopup = false;
   
} // hideCurrentPopup


// Mac IE 5 resizeFix
window.onload = initializeHacks;

// Ausblenden eventuell eingeblendeter Layer bei Mausklick


document.onclick = function () {

	if (window.currentlyVisiblePopup) {
	
		hideCurrentPopup(window.currentlyVisiblePopup);
				
		window.currentlyVisiblePopup = false;
		window.currentlyVisibleParent = false;
	}
	
	if (window.blocker) {
	
		hideCurrentPopup(window.currentlyVisibleSubPopup);
		hideCurrentPopup(window.currentlyVisiblecontainerLayer);
		window.currentlyVisiblecontainerLayer = false;
		window.currentlyVisibleSubPopup = false;
		window.blocker = false;
		window.currentlyVisiblePopup = false;
	}
	
}

function initializeHacks() {
    // Mac IE 5 resizeFix
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    // Fake-Objekt fŸr Šltere Browser
    createFakeEventObj();
}

function createFakeEventObj() {
    // Fake-Objekt fŸr Šltere Browser
    if (!window.event) {
	window.event = false;
    }
} // createFakeEventObj

function resizeBlankDiv() {
    // Mac IE 5 resizeFix
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function explorerMacResizeFix () {
    location.reload(false);
}