/* Funktionen openWindow (neu) und OpenWindow (alt) */

/*
function openWindow (winUrl, winWidth, winHeight, winX, winY, winName, winPropsEnable, winPropsDisable)

Öffnet ein neues Fenster mit den angegebenen Eigenschaften. Dabei werden die Rechenfehler des IE weit gehend ausgeglichen. 
Zudem soll das Fenster nie über den Bildschirmrand hinausgehen, wird also ggf. kleiner geöffnet als angegeben.

Beispielaufruf:
<a href="seite.htm" onclick="return openWindow (this, 400, 500, 20, 20, 'winNew', wSetFocus + wDependent, wResizable);">

Anleitung:
- Alles ab dem nächsten /* ins Javascript des Webs kopieren
- In winPropsEnable alle Eigenschaften des zu öffnenden Fensters geben, die es unbedingt haben soll
- In winPropsDisable alle Eigenschaften des zu öffnenden Fensters geben, die es auf keinen Fall haben soll
- Nicht übergebene Eigenschaften besitzt das Fenster abhängig von den Grundeinstellungen des anzeigenden Browsers
*/

/*
function openWindow (winUrl, winWidth, winHeight, winX, winY, winName, winPropsEnable, winPropsDisable)

(c) 2002 whe Kittelberger media solutions GmbH, www.kittelberger.de

2002-08-22 whe  Version 0.5 in EW Advertising Pool Green eingebaut
2003-01-17 whe  Version 1 auf \\enterprise\www\_javascript veröffentlicht

*/

var wReturnWinHandle = 1;
var wSetFocus = 2;
var wDependent = 4;
var wResizable = 8;
var wScrollbars = 16;
var wMenubar = 32;
var wToolbar = 64;
var wLocationbar = 128;
var wStatusbar = 256;
var wBookmarks = 512;
var wHotkeys = 1024;

function openWindow (winUrl, winWidth, winHeight, winX, winY, winName, winPropsEnable, winPropsDisable) {

	// Default-Werte für Zahlenvariablen setzen, wenn Parameter nicht oder falsch übergeben wurden. Variablen auf numerischen Typ festlegen
	winWidth = (!winWidth || isNaN (winWidth)) ? 400 : parseInt (winWidth);
	winHeight = (!winHeight || isNaN (winHeight)) ? 400 : parseInt (winHeight);
	winX = (!winX || isNaN (winX)) ? 20 : parseInt (winX);
	winY = (!winY || isNaN (winY)) ? 20 : parseInt (winY);

	// Fenster verkleinern, wenn größer als darstellbarer Bereich
	if ( (winWidth + winX) > (screen.availWidth - 10) ) winWidth = screen.availWidth - winX - 10;
	if ( (winHeight + winY) > (screen.availHeight - 30) ) winHeight = screen.availHeight - winY - 30;
	
	// Dreistatus-Attribute (An/Aus/Unbestimmt) in Variablen definieren
  var winDependent = (winPropsEnable & wDependent) ? 'dependent=yes,' : ( (winPropsDisable & wDependent) ? 'dependent=no,' : '' );
  var winResizable = (winPropsEnable & wResizable) ? 'resizable=yes,' : ( (winPropsDisable & wResizable) ? 'resizable=no,' : '' );
  var winScrollbars = (winPropsEnable & wScrollbars) ? 'scrollbars=yes,' : ( (winPropsDisable & wScrollbars) ? 'scrollbars=no,' : '' );
  var winMenubar = (winPropsEnable & wMenubar) ? 'menubar=yes,' : ( (winPropsDisable & wMenubar) ? 'menubar=no,' : '' );
	var winToolbar = (winPropsEnable & wToolbar) ? 'toolbar=yes,' : ( (winPropsDisable & wToolbar) ? 'toolbar=no,' : '' );
  var winLocationbar = (winPropsEnable & wLocationbar) ? 'location=yes,' : ( (winPropsDisable & wLocationbar) ? 'location=no,' : '' );
  var winStatusbar = (winPropsEnable & wStatusbar) ? 'status=yes,' : ( (winPropsDisable & wStatusbar) ? 'status=no,' : '' );
	var winBookmarks = (winPropsEnable & wBookmarks) ? 'directories=yes,' : ( (winPropsDisable & wBookmarks) ? 'directories=no,' : '' );
	var winHotkeys = (winPropsEnable & wHotkeys) ? 'hotkeys=yes,' : ( (winPropsDisable & wHotkeys) ? 'hotkeys=no,' : '' );

	// IE verändert die Fenstergröße ganz speziell ... deswegen wieder "von Hand" zurückberechnen
	if (document.all) {

		winWidth = (winPropsEnable & wScrollbars) ? winWidth + 16 : winWidth;

		winWidth = ( (winPropsEnable & wMenubar) 
			&& (winPropsEnable & wToolbar) 
			&& (winPropsEnable & wLocationbar) 
			&& (winPropsEnable & wStatusbar)
			&& (winPropsEnable & wBookmarks)
			&& (winPropsEnable & wResizable) ) 
			? winWidth + 12 : winWidth;
			
		winWidth = ( (winPropsEnable & wMenubar) 
			&& (winPropsEnable & wToolbar) 
			&& (winPropsEnable & wLocationbar) 
			&& (winPropsEnable & wStatusbar)
			&& (winPropsEnable & wBookmarks)
			&& ( (winPropsDisable & wResizable) || !(winPropsEnable & wResizable) ) )
			? winWidth + 10 : winWidth;

		winHeight = (winPropsEnable & wMenubar) ? winHeight - 19 : winHeight;

		winHeight = ( (winPropsEnable & wMenubar) 
			&& (winPropsEnable & wToolbar) 
			&& (winPropsEnable & wLocationbar) 
			&& (winPropsEnable & wStatusbar) 
			&& (winPropsEnable & wBookmarks)
			&& (winPropsEnable & wResizable) ) 
			? winHeight + 171 : winHeight;

		winHeight = ( (winPropsEnable & wMenubar) 
			&& (winPropsEnable & wToolbar) 
			&& (winPropsEnable & wLocationbar) 
			&& (winPropsEnable & wStatusbar) 
			&& (winPropsEnable & wBookmarks)
			&& ( (winPropsDisable & wResizable) || !(winPropsEnable & wResizable) ) )
			? winHeight + 169 : winHeight;

		// Nach der IE-Neuberechnung wieder auf maximale Größe reduzieren, wenn notwendig
		if ( (winWidth + winX) > (screen.availWidth - 10) ) winWidth = screen.availWidth - winX - 10;
		if ( (winHeight + winY) > (screen.availHeight - 30) ) winHeight = screen.availHeight - winY - 30;

	} // if (document.all)

  // Fenster öffnen
  newWin = window.open (winUrl, winName, 
  	'left=' + winX + 
  	',top=' + winY + 
  	',width=' + winWidth + 
  	',height=' + winHeight + 
  	',' + winDependent + winResizable + winScrollbars + winMenubar + winToolbar 
  	+ winLocationbar + winStatusbar + winBookmarks + winHotkeys);

	if (winPropsDisable ^ wSetFocus) newWin.focus();
  return (winPropsEnable & wReturnWinHandle) ? newWin : false;

} // function openWindow


// V3

function OpenWindow (URL, Width, Height, Left, Top, Name, Resizable, ScrollBars, MenuBar, ToolBar, LocationBar, BookmarkBar, StatusBar, Dependent, HotKeys) {

	// Vorsicht bei NN: Wird die MenuBar angezeigt, wird ab Breiten kleiner 303 die Fensterhöhe vom NN falsch berechnet.

	// Testen, ob Positions- und Größen-Parameter angegeben und nicht zu groß sind
	if ( (Top == null) || isNaN (Top) ) Top = 20;
	if ( (Left == null) || isNaN (Left) ) Left = 20;
	if ( (Height == null) || isNaN (Height) || (Height + Top > screen.availHeight - 10) ) Height = screen.availHeight - 10 - Top;
	if ( (Width == null) || isNaN (Width) || (Width + Left > screen.availWidth - 10) ) Width = screen.availWidth - 10 - Left;
	Name = (Name == null) ? '' : Name; // Name = Leerstring, wenn kein Name angegeben ist
	// Testen, ob alle Parameter vorhanden sind, sonst Default-Werte vergeben

	Resizable = ((Resizable == null) || (Resizable == true)) ? 'yes' : 'no';
	ScrollBars = ((ScrollBars == null) || (ScrollBars == true)) ? 'yes' : 'no';
	MenuBar = ((MenuBar == null) || (MenuBar == false)) ? 'no' : 'yes';
	ToolBar = ((ToolBar == null) || (ToolBar == false)) ? 'no' : 'yes';
	LocationBar = ((LocationBar == null) || (LocationBar == false)) ? 'no' : 'yes';
	BookmarkBar = ((BookmarkBar == null) || (BookmarkBar == false)) ? 'no' : 'yes';
	StatusBar = ((StatusBar == null) || (StatusBar == true)) ? 'yes' : 'no';
	Dependent = ((Dependent == null) || (Dependent == true)) ? 'yes' : 'no';
	HotKeys = ((HotKeys == null) || (HotKeys == true)) ? 'yes' : 'no';

	// Für IE Fenstergrößen extra berechnen, da IE "innerWidth" und "InnerHeight" nicht beachtet.
	if (document.all) {
		Height += 31; // 31 Pixel höher für Fensterrahmen und Titelleiste des Fensters
		Width = Width + 12; // 12 Pixel breiter für den Fensterrahmen
		Height = (Resizable == 'no') ? Height - 2 : Height; // Der Fensterrahmen von Nicht-"Resizable"-Fenstern ist 2 Pixel schmaler.
		Width = (Resizable == 'no') ? Width - 2 : Width; // dto.
		Width = (ScrollBars == 'yes') ? Width + 16 : Width;
		Height = (MenuBar == 'yes') ? Height + 29 : Height;
		Height = (ToolBar == 'yes') ? Height + 47 : Height;
		Height = (LocationBar == 'yes') ? Height + 29 : Height; 
		var BarCompensation = (MenuBar == 'yes') ? 1 : 0; // je "Bar"-Paar werden wiederum 5 Pixel eingespart
		BarCompensation = (ToolBar == 'yes') ? BarCompensation + 1 : BarCompensation;
		BarCompensation = (LocationBar == 'yes') ? BarCompensation + 1 : BarCompensation;
		BarCompensation = (BarCompensation < 1) ? 1 : BarCompensation;
		Height -= ( (BarCompensation - 1) * 5);
		Height = (StatusBar == 'yes') ? Height + 20 : Height;
		// Fenster wieder verkleinern, falls es jetzt wieder zu groß ist
		if (!Width || isNaN (Width) || (Width > screen.availWidth - 10)) Width = screen.availWidth - 10;
		if (!Height || isNaN (Height) || (Height > screen.availHeight - 10)) Height = screen.availHeight - 10;
	}
	
	// Fenster mit den gegebenen Parametern öffnen
	NewWindow = window.open(URL, Name, 'screenX=' + Left + ',screenY=' + Top 
	+ ',height=' + Height + ',width=' + Width + ',innerHeight=' + Height + ',innerWidth=' + Width
	+ ',resizable=' + Resizable + ',scrollbars=' + ScrollBars + ',menubar=' + MenuBar 
	+ ',toolbar=' + ToolBar + ',location=' + LocationBar + ',directories=' + BookmarkBar 
	+ ',status=' + StatusBar + ',dependent=' + Dependent);

	if (navigator.appVersion.indexOf ('MSIE 5.0')) NewWindow.focus (); // IE 5.0 bricht hier sonst ab

	URL += ''; // IE versteht die URL nur so als String ...

	// Für IE muss extra positioniert. Der Fenster-Zugriff wird aber verweigert, wenn eine 
	// komplette HTTP-Adresse aufgerufen wird ...

	if (!NewWindow.innerWidth && (URL.indexOf ('http://') < 0)) {
		NewWindow.moveTo (Left, Top);
	}

	NewWindow.focus (); // Fenster ganz nach vorn stellen, also Focus auf das Fenster

	return false; // damit der HREF-Link nicht ausgeführt wird
	
} // function OpenWindow

function closeWindow() {   
	window.parent.close();
}