// --- globale Variablen weil JavaScript keine ByRef Funktionen kennt...
var NS, IE;
var sW, sH, wX, wY, wW, wH, mX, mY;

// --- einfache Browserdefinition des aktuellen Clients..
NS = (document.all) ? 0 : 1; IE = (document.all) ? 1: 0;

function getMousePosDoc(e) {
	mY=(NS)?e.pageY:window.event.y + document.body.scrollTop;
	mX=(NS)?e.pageX:window.event.x + document.body.scrollLeft;
}

function getMousePosScreen(e) {
	mY=(NS)?e.screenY:window.event.screenY;
	mX=(NS)?e.screenX:window.event.screenX;
}

function getWindowDim() {
	sW = screen.availWidth; sH = screen.availHeight;
	if (NS) { wX = window.screenX; wY = window.screenY;} else {	wX = window.screenLeft; wY= window.screenTop; }
	if (NS) { wW = window.innerWidth; wH = window.innerHeight;} else {	wW = document.body.clientWidth; wH = document.body.clientHeight }
}

function openWindowPopup (oUrl, oName, oW, oH, flagScroll, flagResize, flagReset) {
	var wType, popupX, popupY;
	
	// negative oW, oH Werte sind relativ zur Screen Grösse
	if (oW < 0) {
		oW = screen.availWidth + oW;
		oH = screen.availHeight + oH;
	}
	
	wType = "dependent=yes,directories=no,menubar=no,personalbar=no,status=no,toolbar=no";
	if (flagScroll==0) { wType += ",scrollbars=no"; } else { wType += ",scrollbars=yes"; }
	if (flagResize==0) { wType += ",resizable=no"; } else { wType += ",resizable=yes"; }
	
	wType += ",width="+oW+",height="+oH;
	
	// Das neue Fenster soll in der Mitte des aktuellen Browser Fensters positioniert werden...
	// (falls dadurch Teile vom Fenster ausserhalb des sichtbaren Bereichs liegen, werden die Koordination angepasst)
	getWindowDim();

	popupX = parseInt(wX + (wW - oW) / 2); popupY = parseInt(wY + (wH - oH) / 2);
	if (parseInt(popupX + oW) > sW) popupX = sW - oW - 50 ; if (parseInt(popupY + oH) > sH) popupY = sH - oH - 50;	//- "50" ist Toleranz...
	if (popupX < 0) popupX = 0; if (popupY < 0) popupY = 0;

	// scrennX=NS, left=IE
	wType += ",screenX="+popupX+",left="+popupX+",screenY="+popupY+",top="+popupY;
	
	if (window['oW'+oName]) {
		if (window['oW'+oName].closed==false) {
			window['oW'+oName].document.location=oUrl; window['oW'+oName].focus();
		} else {
			if (flagReset==true) window['oW'+oName].close();
			window['oW'+oName] = window.open(oUrl, oName, wType); window['oW'+oName].focus();
		}
	} else {
		window['oW'+oName] = window.open(oUrl, oName, wType); window['oW'+oName].focus();
	}
	
	return window['oW'+oName];
}

