
/**
 * Klasse SwitchPane
 * definiert einen Reiter mit zugehörigem Inhalt
 * headerActiveId     Id der aktiven Reiter-Version
 * headerInactiveId   Id der inaktiven Reiter-Version
 * paneId             Id des Inhalt-tragenden Block-Elements
 * displayHeader      Display-Level des aktiven Reiters
 *                    z.B. 'block' oder 'inline', default='block'
 * displayPane        Display-Level des aktiven Inhalt-tragenden Block-Elements
 *                    z.B. 'block' oder 'inline', default='block'
 */
function SwitchPane(
	headerActiveId, headerInactiveId,
	paneId,
	displayHeader, displayPane) {
	
    this.headerActiveId = headerActiveId;
    this.headerInactiveId = headerInactiveId;
    this.paneId = paneId;
    this.displayHeader = displayHeader;
    this.displayPane = displayPane;
    if (this.displayHeader == null) {
    	this.displayHeader = 'block';
    }
    if (this.displayPane == null) {
    	this.displayPane = 'block';
    }
    this.headerActiveElement = document.getElementById(headerActiveId);
    this.headerInactiveElement = document.getElementById(headerInactiveId);
    this.paneElement = document.getElementById(paneId);
    this.enable = SwitchPane_enable;
    this.disable = SwitchPane_disable;
}

function SwitchPane_enable() {
	this.headerActiveElement.style.display = this.displayHeader;
	this.headerInactiveElement.style.display = 'none';
	this.paneElement.style.display = this.displayPane;
}

function SwitchPane_disable() {
	this.headerActiveElement.style.display = 'none';
	this.headerInactiveElement.style.display = this.displayHeader;
	this.paneElement.style.display = 'none';
}


/**
 * Klasse SwitchPaneByClass
 * definiert einen Reiter mit zugehörigem Inhalt, die Steuerung der
 * Inhalt-tragenden Block-Elemente geschieht per Style-Klasse
 *
 * headerActiveId     Id der aktiven Reiter-Version
 * headerInactiveId   Id der inaktiven Reiter-Version
 * paneId             Id des Inhalt-tragenden Block-Elements
 */
function SwitchPaneByClass(
	headerActiveId, headerInactiveId,
	paneId) {

    this.headerActiveId = headerActiveId;
    this.headerInactiveId = headerInactiveId;
    this.paneId = paneId;
    this.headerActiveElement = document.getElementById(headerActiveId);
    this.headerInactiveElement = document.getElementById(headerInactiveId);
    this.paneElement = document.getElementById(paneId);
    this.enable = SwitchPaneByClass_enable;
    this.disable = SwitchPaneByClass_disable;
}

function SwitchPaneByClass_enable() {
	this.headerActiveElement.style.display = 'block';
	this.headerInactiveElement.style.display = 'none';
	
	var clazz = this.paneElement.className;
	clazz = clazz.replace(/unsichtbar/gi,'');
	this.paneElement.className = clazz;
}

function SwitchPaneByClass_disable() {
	this.headerActiveElement.style.display = 'none';
	this.headerInactiveElement.style.display = 'block';
	
	var clazz = this.paneElement.className;
	if (clazz.indexOf('unsichtbar') == -1) {
		clazz += ' unsichtbar';
		this.paneElement.className = clazz;
	}
}


/**
 * Klasse SwitchPanes
 * definiert eine Gruppe von Objekten des Typs SwitchPane
 */
function SwitchPanes() {
    this.panes = new Array();
    this.add = SwitchPanes_add;
    this.switchPane = SwitchPanes_switchPane;
}

/**
 * fügt der Gruppe ein Objekt des Typs SwitchPane hinzu
 */
function SwitchPanes_add(pane) {
    this.panes[pane.headerActiveId] = pane;
}

/**
 * Aktiviert einen Reiter. Parameter ist die ID der aktiven Version
 * des Reiters.
 */
function SwitchPanes_switchPane(headerActiveId) {
    for (var id in this.panes) {
        var pane = this.panes[id];
        if (pane == null)
            continue;
        if (pane.headerActiveId == headerActiveId) {
            pane.enable();
		}
		else {
		    pane.disable();
		}
	}
}

