/**
 * Window
 * Beschreibt ein Fenster und bietet Zugriffsmöglichkeiten auf dieses.
 * Die PHP-Klasse Window beschreibt, wie ein Window-Element aufgebaut sein muss.
 * 
 * Folgende Events werden an dem Div dieses Elements ausgelöst:
 *  Window::show					- Wenn das Fenster eingeblendet wird
 *  Window::hide					- Wenn das Fenster ausgeblendet wird
 *  Window::bringToFront			- Wenn das Fenster an die höchste z-index Position gebracht wird
 *  Window::destroy					- Wenn das Fenster zerstört wird
 *  Window::propertyChanged			- Wenn das Fenster eine Eigenschaft ändert
 * 
 * Ausgelöst durch document:
 *  Window::addInstance				- Wenn der Fenster-Instanzensammlung eine Instanz angefügt wird
 *  Window::removeInstance			- Wenn der Fenster-Instanzensammlung eine Instanz genommen wird
 *  Window::correctZIndex			- Wenn der Z-Index der Fenster neu durchnummeriert wird
 * 
 * @author Martin Kuckert
 * @version $Revision: 1.15.2.1 $  $Date: 2009/12/18 14:24:33 $
 * @package JS.Window
 * @since 22.11.2007
 */
var IMWindow = Class.create();
Object.extend( IMWindow.prototype, {
	/**
	 * @var Element Referenz auf das Haupt-DIV dieser Fensters
	 */
	divRef: null,
	/**
	 * @var Element Referenz auf die Titlebar dieses Fensters
	 */
	TitleBar: null,
	/**
	 * @var Element Referenz auf den Hauptbereich dieses Fensters
	 */
	Main: null,
	/**
	 * @var Element Referenz auf den Fußbereich dieses Fensters
	 */
	Footer: null,
	/**
	 * @var string ID dieses Fensters
	 */
	id: null,
	/**
	 * @var boolean Flag, ob dies ein Resizable-Fenster ist
	 */
	isResizable: false,
	/**
	 * @var float Modifizierwert für die Bewegungsgeschwindigkeit
	 */
	moveSpeedModifier: 1.0,
	/**
	 * @var boolean true, wenn dieses Fenster aktuell modal sichtbar ist.
	 */
	isModal: false,
    /**
     * @var IMWindow null, wenn dieses Fenster kein Unterfenster zu einem modalen Fenster ist.
     */
    modalParentWindow: null,
	/**
	 * Konstruktor
	 * 
	 * @param string/Element Ein bereits vorhandenes Fenster, welches durch diese Klasse
	 * verwaltet werden soll oder die ID für dieses Fenster
	 */
	initialize: function() {
		if( arguments.length>0 ) {
			var a = arguments[0];
			if( Object.isString( a ) ){
				this.id = a;
			}
			else {
				a = $( a );
				this.adoptWindow( a );
				this.id = a.readAttribute( 'id' );
			}
		}
		if( !this.divRef ) {
			this.createWindow();
		}
		if( !this.id ) {
			this.id = this.divRef.identify();
		}
		this.divRef.writeAttribute( 'id', this.id );
		
		this.divRef.windowHandle = this;
		
		IMWindow.addInstance( this );
		
		this.setToStoredPosition();
	},
	/**
	 * Zerstört dieses Fenster
	 * 
	 * @return void
	 */
	destroy: function() {
		this.divRef.remove();
		IMWindow.removeInstance( this );
		this.id = null;
	},
	/** 
	 * Erstellt das DOM dieses Fensters und fügt dies in den Dokumentbaum ein
	 * 
	 * @return void
	 */
	createWindow: function() {
		this.divRef = document.createElement( 'div' );
		this.divRef.addClassName( 'Window' );
		this.divRef.setStyle( {
			display:		'none',
			left:			'10px',
			top:			'10px'
		} );
		
		this.TitleBar = this.divRef.appendChild( document.createElement( 'div' ) );
		this.TitleBar.addClassName( 'WindowTitlebar' );
		
		var icon = IMLib.Icon.getIcon( 'window_application' );
		this.TitleBar.Icon = this.TitleBar.appendChild( icon );
		var title = document.createElement( 'span' );
		title.appendChild( document.createTextNode( '' ) );
		this.TitleBar.Title = this.TitleBar.appendChild( title );
		
		this.Main = this.divRef.appendChild( document.createElement( 'div' ) );
		this.Main.addClassName( 'WindowMain' );
		
		var mainContent = this.Main.appendChild( document.createElement( 'div' ) );
		mainContent.addClassName( 'WindowMainContent' );
		mainContent.appendChild( document.createTextNode( '' ) );
		this.Main.Content = mainContent;
		
		this.Footer = this.divRef.appendChild( document.createElement( 'div' ) );
		this.Footer.addClassName( 'WindowFooter' );
		this.makeDraggable();
		
		$$( 'body' )[0].appendChild( this.divRef );
	},
	/** 
	 * Adoptiert ein bereits gerendertes Fenster.
	 * 
	 * @return void
	 */
	adoptWindow: function( win ) {
		this.divRef = win;
		
		this.TitleBar = this.divRef.down( '.WindowTitlebar' );
		if( this.TitleBar ) {
			this.TitleBar.Icon = this.TitleBar.down( 'img' );
			if( this.TitleBar.Icon ) {
				this.TitleBar.Title = this.TitleBar.Icon.nextSibling;
			}
			else {
				this.TitleBar.Title = this.TitleBar.down();
			}
		}
		
		this.Main = this.divRef.down( '.WindowMain' );
		
		var mainContent = this.Main.down( 'WindowMainContent' );
		this.Main.Content = mainContent;
		
		this.Footer = this.divRef.down( '.WindowFooter' );
		
		this.makeDraggable();
	},
	/**
	 * Erstellt das Draggable für dieses Fenster
	 * 
	 * @return void
	 */
	makeDraggable: function() {
		if( !this.divRef.observingBringToFront ) {
			this.divRef.observe( 'click', function() {
				this.bringToFront();
			}.bindAsEventListener( this ) );
			this.divRef.observingBringToFront = true;
		}
		var div = this.divRef;
		div.draggable = new Draggable( div,
			{
				handle:					this.TitleBar,
				onEnd:					function() {
					this.storePosition();
				}.bindAsEventListener( this ),
				scroll:					window,
				starteffect:			Prototype.emptyFunction,
				endeffect:				Prototype.emptyFunction,
				snap:					function( x, y, draggable ) {
					return( [x<0?0:x,y<0?0:y] );
				}
			}
		);
	},
	/**
	 * Gibt den Status zurück, ob dieses Fenster in der Größe veränderbar ist
	 * 
	 * @return boolean
	 */
	getResizable: function() {
		return( this.isResizable );
	},
	/**
	 * Setzt den Status, ob dieses Fenster in der Größe veränderbar ist
	 * 
	 * @return void
	 * @param boolean
	 */
	setResizable: function( set ) {
		if( set ) {
			this.makeResizable();
		}
		else {
			this.makeFixed();
		}
	},
	/**
	 * Erstellt das Resizable für dieses Fenster
	 * 
	 * @return void
	 * @param integer Zu verwendende Höhe für den WindowMain-Bereich
	 */
	makeResizable: function() {
		if( this.isResizable ) {
			return;
		}
		
		this.divRef.resizable = new Resizable( this.Main,
			{
				handle:					this.Footer,
				constraint:				'vertical',
				min:					[0,15],
				starteffect:			Prototype.emptyFunction,
				endeffect:				Prototype.emptyFunction,
				onStart:				function() {
					this.bringToFront();
				}.bind( this )
			}
		);
		this.divRef.addClassName( 'ResizableWindow' );
		
		if( arguments.length>0 && arguments[0]>=15 ) {
			this.Main.setStyle( {
				height:				arguments[0]
			} );
		}
		
		this.isResizable = true;
	},
	/**
	 * Entfernt das Resizable dieses Fensters
	 * 
	 * @return void
	 */
	makeFixed: function() {
		if( !this.isResizable ) {
			return;
		}
		
		this.divRef.resizable.destroy();
		this.divRef.resizable = null;
		this.divRef.removeClassName( 'ResizableWindow' );
		
		this.isResizable = false;
	},
		
	/**
	 * Gibt den Text für die Titlebar des Fensters zurück
	 * 
	 * @return string
	 */
	getTitle: function() {
		return( this.TitleBar.Title );
	},
	/**
	 * Setzt den Text für die Titlebar des Fensters
	 * 
	 * @return void
	 * @param string
	 */
	setTitle: function( title ) {
		if( this.TitleBar.Title.nodeType==3 ) {
			this.TitleBar.Title.nodeValue = title;
		}
		else {
			this.TitleBar.Title.innerHTML = title;
		}
	},
	/**
	 * Gibt den Namen des Titel-Icons dieses Fensters zurück
	 * 
	 * @return string
	 */
	getTitleIcon: function() {
		return( IMLib.Icon.getName( this.TitleBar.Icon.readAttribute( 'src' ) ) );
	},
	/**
	 * Setzt den Namen des Titel-Icons dieses Fensters. Mit null kann die Ausgabe eines Icons
	 * unterdrückt werden.
	 * 
	 * @return void
	 * @param string
	 */
	setTitleIcon: function( icon ) {
		if( icon===null ) {
			this.TitleBar.Icon.hide();
		}
		else {
			this.TitleBar.Icon.writeAttribute( 'src', IMLib.Icon.getPath( icon ) );
			this.TitleBar.Icon.show();
		}
	},
	/**
	 * Blendet dieses Fenster ein
	 * 
	 * @return void
	 * @param boolean true, wenn das Fenster automatisch zentriert werden soll
	 * @param boolean true, wenn das Fenster modal angezeigt werden soll
		 */
show: function() {
		if( arguments.length>0 && arguments[0]==true ) {
			this.center();
		}
		if( arguments.length>1 && arguments[1]==true && !this.isShown() ) {
			IMLib.Element.Modal.show();
			this.isModal = true;
			$( 'Modal' ).style.zIndex=90;
		}
		
		this.bringToFront();
		
		new Effect.Appear( this.divRef,
			{
				duration:			0.5,
				queue:
					{
						position:			'end',
						scope:				'Window'+this.id,
						limit:				1
					}
			}
		);
	},
    /**
     * Übeprüft, ob dieses Fenster bereits sichtbar ist.
     * 
     * @return boolean
     */
    isShown: function() {
    	return this.divRef.visible();
	},
    /**
     * Blendet diese Fenster modal zu einem anderen bereits geöffneten (modalen oder nichtmodalen) Fenster ein
     * @return void
     * @param mixed IMWindow oder string (id) des "Eltern"fensters
     */
    showSubmodalTo: function( target) {
        if( !( target instanceof IMWindow ) ) 
            target = IMWindow.find( target );
        if( target.isModal ) { 
            this.modalParentWindow = target;
            //target.isModal = false;
            target.divRef.style.zIndex=80;
        }
        this.show(true,true);
        this.bringToFront.bind(this).delay(0.25);

    },
	/**
	 * Blendet dieses Fenster aus
	 * 
	 * return void
	 */
	hide: function() {
		if( this.isModal ) {
			IMLib.Element.Modal.hide();
		}
        if (this.modalParentWindow) {
            this.modalParentWindow.bringToFront.bind(this.modalParentWindow).delay(0.25);
        }
		
		new Effect.Fade( this.divRef,
			{
				duration:			0.5,
				queue:
					{
						position:			'end',
						scope:				'Window'+this.id,
						limit:				1
					}
			}
		);
	},
	/**
	 * Lässt dieses Fenster aufblinken
	 * 
	 * return void
	 */
	blink: function() {
		new Effect.Shake( this.divRef, 100 );
	},
	/**
	 * Zentriert das Fenster
	 * 
	 * @return void
	 */
	center: function() {
		var left = ( document.viewport.getWidth() - this.divRef.getWidth() ) / 2;
		var top = ( document.viewport.getHeight() - this.divRef.getHeight() ) / 2;
		this.divRef.setStyle( {
			left:	left+'px',
			top:	top+'px'
		} );
	},
	/**
	 * Überprüft, ob das Kontextmenü momentan sichtbar ist
	 * 
	 * @return boolean
	 */
	visible: function() {
		return( this.divRef.visible() );
	},
	/**
	 * Bringt dieses Fenster an den höchsten z-index
	 * 
	 * @return void
	 */
	bringToFront: function() {
		//if( IMWindow.topMostWindow!=this ) {
			IMWindow.correctZIndex();
			
			this.divRef.style.zIndex = 100;
			if( this.divRef.draggable ) {
				this.divRef.draggable.originalZ = 100;
			}
			
			IMWindow.topMostWindow = this;
		//}
	},
	/**
	 * Bewegt dieses Fenster an die übergebene Position
	 * 
	 * @return void
	 * @param integer X oder [X,Y]
	 * @param integer Y wenn X kein Array ist
	 */
	moveTo: function( x, y ) {
		if( x instanceof Array ) {
			y = x[1];
			x = x[0];
		}
		
		var left = parseInt( this.divRef.getStyle( 'left' ) );
		var top = parseInt( this.divRef.getStyle( 'top' ) );
		
		var l = Math.abs( left - x );
		var t = Math.abs( top - y );
		
		var duration = Math.sqrt( l * l + t * t ) / ( 1000 * this.moveSpeedModifier );
		
		new Effect.Move( this.divRef,
			{
				x:			x,
				y:			y,
				mode:		'absolute',
				duration:	duration
			}
		);
	},
	/**
	 * Bewegt dieses Fenster an die gespeicherte Position
	 * 
	 * @return void
	 */
	moveToStoredPosition: function() {
		var pos = this.loadPosition();
		if( pos==null ) {
			return;
		}
		this.moveTo( pos );
	},
	/**
	 * Setzt dieses Fenster an die gespeicherte Position
	 * 
	 * @return void
	 */
	setToStoredPosition: function() {
		var pos = this.loadPosition();
		if( pos==null ) {
			return;
		}
		this.divRef.setStyle( {
			left:			pos[0]+'px',
			top:			pos[1]+'px'
		} );
	},
	/**
	 * Speichert die Position dieses Fensters in einem Cookie
	 * 
	 * @return void
	 */
	storePosition: function() {
		if( typeof Cookie == "undefined" ) return;
		var pos = parseInt( this.divRef.getStyle( 'left' ) )+'|'+parseInt( this.divRef.getStyle( 'top' ) );
		Cookie.set( 'WindowPosition_'+this.id, pos );
	},
	/**
	 * Lädt die Position dieses Fensters aus einem Cookie
	 * 
	 * @return [x,y] oder null
	 */
	loadPosition: function() {
		if( typeof Cookie == "undefined" ) return null;
		var cookie = Cookie.get( 'WindowPosition_'+this.id );
		if( !cookie ) {
			return null;
		}
		
		var split = cookie.split( '|' );
		if( split.length!=2 ) {
			return null;
		}
		
		return( split );
	},
	/**
	 * Zeigt den Loading-Indicator in der Titelleiste des Fensters an
	 * 
	 * @return void
	 */
	showLoadingIndicator: function() {
		if( this.loading ) {
			return;
		}
		
		this.divRef.down( '.WindowLoading' ).show();
		this.loading = true;
	},
	/**
	 * Entfernt den Loading-Indicator in der Titelleiste des Fensters
	 * 
	 * @return void
	 */
	hideLoadingIndicator: function() {
		if( !this.loading ) {
			return;
		}
		
		this.divRef.down( '.WindowLoading' ).hide();
		this.loading = false;
	}
} );
/**
 * Statische Eigenschaften und Funktionen der Fensterklasse
 */
Object.extend( IMWindow, {
	/**
	 * @var Hash Array aller Fenster
	 */
	instances: new Hash(),
	/**
	 * @var Window Das oberste Fenster
	 */
	topMostWindow: null,
	/**
	 * Blendet alle Fenster ein
	 * 
	 * @return void
	 * @param boolean true, wenn das Fenster automatisch zentriert werden soll
	 */
	showAll: function() {
		var center = false;
		if( arguments.length>0 && arguments[0]==true ) {
			center = true;
		}
		
		IMWindow.instances.each( function( w ) {
			if( !w.value.visible() ) {
				w.value.show( center );
			}
		} );
	},
	/**
	 * Blendet alle Fenster aus
	 * 
	 * @return void
	 */
	hideAll: function() {
		IMWindow.instances.each( function( w ) {
			if( w.value.visible() ) {
				w.value.hide();
			}
		} );
	},
	/**
	 * Blendet ein Fenster ein
	 * 
	 * @return void
	 * @param string|Element
	 * @param boolean true, wenn das Fenster nicht automatisch zentriert werden soll
	 */
	show: function( el ) {
		var center = false;
		if( arguments.length>=1 && arguments[1]==true ) {
			center = true;
		}
		
		if( !( el instanceof IMWindow ) ) {
			el = IMWindow.find( el );
			if( !el ) {
				throw new Error( "Window "+el+" not found!" );
			}
		}
		
		el.show( center );
	},
	/**
	 * Blendet ein Fenster aus
	 * 
	 * return void
	 * @param string|Element
	 */
	hide: function( el ) {
		if( !( el instanceof IMWindow ) ) {
			el = IMWindow.find( el );
			if( !el ) {
				throw new Error( "Window "+el+" not found!" );
			}
		}
		
		el.hide();
	},
	/**
	 * Fügt der Sammlung aller Instanzen eine Instanz hinzu
	 * 
	 * @return void
	 * @param Window
	 */
	addInstance: function( win ) {
		IMWindow.instances.set(win.id, win);
	},
	/**
	 * Entfert eine Instanz aus der Sammlung
	 * 
	 * @return void
	 * @param Window
	 */
	removeInstance: function( win ) {
		if( IMWindow.instances.get(win.id)==undefined ) {
			return;
		}
		IMWindow.instances.unset(win.id);
	},
	/**
	 * Nummeriert den Z-Index aller Fenster neu durch
	 * 
	 * @return void
	 */
	correctZIndex: function() {
		var wins = IMWindow.instances.values();
		
		wins.sortBy( function( item ) {
			return item.divRef.style.zIndex;
		} );
		
		var zIndex = 1;
		wins.each( function( item ) {
			item.divRef.style.zIndex = zIndex;
			zIndex++;
		} );
	},
	/**
	 * Sucht anhand der übergebenen ID nach einem Fenster
	 * 
	 * @return Window|null
	 * @param string
	 */
	find: function( id ) {
		if( IMWindow.instances.get(id)!=undefined ) {
			return( IMWindow.instances.get(id) );
		}
		else {
			return( null );
		}
	},
	/**
	 * Sucht nach einem Window-Objekt eines Elternelementes des übergebenen Elementes
	 * 
	 * @return Window oder null
	 * @param Element
	 */
	findHandle: function( element ) {
		element = $( element );
		
		do {
			if( !element ) {
				return( null );
			}
			if( element.windowHandle ) {
				return( element.windowHandle );
			}
		}
		while( ( element = element.up() ) != null );
		return( null );
	},
	/**
	 * Erstellt aus einem Fenster-DIV ein Window-Objekt passenden Typs
	 * 
	 * @return Window
	 * @param Element
	 */
	factory: function( el ) {
		if( el.hasClassName( 'SmallWindow' ) ) {
			return( new SmallWindow( el ) );
		}
		else if( el.hasClassName( 'WizardWindow' ) ) {
			return( new WizardWindow( el ) );
		}
		else {
			return( new IMWindow( el ) );
		}
	},
	/**
	 * Adoptiert ein DIV als Window-Objekt
	 * 
	 * @return void
	 * @param string
	 */
	adoptById: function( id ) {
		var el=$(id);
		if(!el) {
			IMLib.Alert('Element '+id+' not found!');
		}
		IMWindow.factory(el);
	}
} );

/**
 * SmallWindow
 * Beschreibt ein etwas schmaleres Fenster und bietet Zugriffsmöglichkeiten auf dieses.
 * 
 * @author Martin Kuckert
 * @version $Revision: 1.15.2.1 $  $Date: 2009/12/18 14:24:33 $
 * @package JS.Window
 * @since 22.11.2007
 * @see Window
 */
var SmallWindow = Class.create( IMWindow );
var tmp = SmallWindow.prototype.createWindow;
Object.extend( SmallWindow.prototype, {
	__createWindow: tmp,
	/** 
	 * Erstellt das DOM dieses Fensters und fügt dies in den Dokumentbaum ein
	 * 
	 * @return void
	 */
	createWindow: function() {
		this.__createWindow.apply( this );
		this.divRef.addClassName( 'SmallWindow' );
	}
} );

/**
 * AlertWindow
 * Stellt ein Fenster für Fehlermeldungen dar
 * 
 * @author Martin Kuckert
 * @version $Revision: 1.15.2.1 $  $Date: 2009/12/18 14:24:33 $
 * @package JS.Window
 * @since 12.12.2007
 * @see Window
 */
var AlertWindow = Class.create( SmallWindow );
var tmp = AlertWindow.prototype.createWindow;
Object.extend( AlertWindow.prototype, {
	/**
	 * @var Element Das Label mit der Fehlermeldung
	 */
	ErrorLabel: null,
	/**
	 * @var Element Das Icon neben der Fehlermeldung
	 */
	ErrorIcon: null,
	/**
	 * @var string Der Typ dieses Fensters
	 */
	Type: 'error',
	___createWindow: tmp,
	/** 
	 * Erstellt das DOM dieses Fensters und fügt dies in den Dokumentbaum ein
	 * 
	 * @return void
	 */
	createWindow: function() {
		this.___createWindow.apply( this );
		this.divRef.addClassName( 'AlertWindow' );
		
		var img = document.createElement( 'img' );
		img.writeAttribute( 'src', '' );
		img.addClassName( 'ErrorIcon' );
		this.Main.Content.appendChild( img );
		
		this.ErrorIcon = img;
		
		var err = document.createElement( 'span' );
		err.addClassName( 'ErrorLabel' );
		this.Main.Content.appendChild( err );
		
		this.ErrorLabel = err;
		
		var btnDiv = document.createElement( 'div' );
		btnDiv.addClassName( 'button-container' );
		
		var btn = document.createElement( 'button' );
		btn.onclick = function() {
			IMWindow.findHandle( this ).hide();
		}
		btn.appendChild( document.createTextNode( 'OK' ) );
		btnDiv.appendChild( btn );
		
		this.Main.Content.appendChild( btnDiv );
		
		this.setType( 'error' );
		
		this.center();
	},
	/**
	 * Gibt die Fehlermeldung zurück
	 * 
	 * @return string
	 */
	getMsg: function() {
		return( this.ErrorLabel.innerHTML );
	},
	/**
	 * Setzt die Fehlermeldung
	 * 
	 * @return void
	 * @param string
	 */
	setMsg: function( msg ) {
		this.ErrorLabel.update( msg );
	},
	/**
	 * Gibt den Namen des Message-Icons zurück
	 * 
	 * @return string
	 */
	getMsgIcon: function() {
		return( IMLib.Icon.getName( this.ErrorIcon.readAttribute( 'src' ) ) );
	},
	/**
	 * Setzt das Message-Icon
	 * 
	 * @return void
	 * @param string
	 */
	setMsgIcon: function( icon ) {
		this.ErrorIcon.writeAttribute( 'src', IMLib.Icon.getPath( icon ) );
	},
	/**
	 * Gibt den Typ dieses Fensters zurück
	 * 
	 * @return void
	 * @param string
	 */
	getType: function() {
		return( this.Type );
	},
	/**
	 * Setzt den Typ dieses Fensters
	 * 
	 * @return void
	 * @param string (error|warning|notice)
	 */
	setType: function( type ) {
		switch( type ) {
			case 'error':
				this.setTitle( 'Error' );
				this.setTitleIcon( 'error' );
				this.setMsgIcon( 'error_24' );
				break;
			case 'warning':
				this.setTitle( 'Warning' );
				this.setTitleIcon( 'warning' );
				this.setMsgIcon( 'warning_24' );
				break;
			case 'notice':
				this.setTitle( 'Notice' );
				this.setTitleIcon( 'about' );
				this.setMsgIcon( 'about_24' );
				break;
			default:
				throw new Error( 'Unknown type '+type );
		}
		this.Type = type;
	},
	/**
	 * Blendet dieses Fenster aus und zerstört es
	 * 
	 * @return void
	 * @see destroy
	 */
	hide: function() {
		new Effect.Fade( this.divRef,
			{
				duration:			0.5,
				queue:
					{
						position:			'end',
						scope:				'Window'+this.id,
						limit:				1
					},
				afterFinish:		this.destroy.bind( this )
			}
		);
	}
} );

/**
 * WizardWindow
 * Beschreibt ein Assistenten-Fenster und bietet Zugriffsmöglichkeiten auf dieses.
 * 
 * @author Martin Kuckert
 * @version $Revision: 1.15.2.1 $  $Date: 2009/12/18 14:24:33 $
 * @package JS.Window
 * @since 22.11.2007
 * @see Window
 */
var WizardWindow = Class.create( IMWindow );
var tmp = WizardWindow.prototype.createWindow;
var shw_tmp = WizardWindow.prototype.show;
Object.extend( WizardWindow.prototype, {
	submit_button: undefined,
	__createWindow: tmp,
	
	
	/** 
	 * Erstellt das DOM dieses Fensters und fügt dies in den Dokumentbaum ein
	 * 
	 * @return void
	 */
	createWindow: function() {
		this.__createWindow.apply( this );
		this.divRef.addClassName( 'WizardWindow' );
		// finde Submit-Button
		/*findSubmitButton = function () { 
			inputs = this.getElementsByTagName( 'input' );
			for(button in inputs){
				if (button.type == 'submit') {
					if (/SendButton$/.match(button.name))
						submit_button = button;
				}
			}
		}
		findSubmitButton();
		activateSubmitButton(); */		
	} //,
	
// die folgenden Passagen sollen eine Buttondeaktivierung implementieren.
// Der Submit-Button soll dabei deaktiviert werden, sobald er einmal angeklickt wurde
// und beim Zeigen des Fensters wieder aktiviert
	/**
	 *  Setzt den Submit-Button auf 'aktiv' und fuegt ein JavaScript-
	 *  Skript ein, um den Button zu aktivieren.  
	 * @author Dominik Abraham
	 * @return void
	 */
	/* activateSubmitButton: function() {
		// Binde das Skript an den SubmitButton, das den Button beim Anklicken
		// deaktiviert
		submit_button.disabled = false;
		submit_button.onclick = function() { 
			submit_button.disabled = true;
			return true;
		};
	}, // */
	
	/**
	 * Ueberschreibt die Methode show, indem beim Anzeigen der Submit-Button
	 * aktiviert wird. Ansonsten alles wie gehabt
	 */
	/*show: function() {
		submit_button.disabled = false;
		shw_tmp();
	} // */
} );

