/** Bestandteil einer Grafik, der ein aktiviertes Symbol ausweist */
var ACTIVE_SYMBOL = "_f";
/** Nodetyp "Element" */
var NODETYPE_ELEMENT = 1;

/**
 * Wechselt eine Grafik
 * 
 * @param {Object} img Image-Element
 * @param {Boolean} activate Aktivieren oder Deaktivieren 
 */
function changeImg(img, activate)
{
	var ACTIVE_SYMBOL_LENGTH = ACTIVE_SYMBOL.length;
	
	var path		= img.src.slice(0, img.src.lastIndexOf("/") + 1);
	var file		= img.src.slice(img.src.lastIndexOf("/") + 1).split(".");
	var is_active	= (file[0].slice(file[0].length - ACTIVE_SYMBOL_LENGTH) == ACTIVE_SYMBOL);
	
	if (activate && !is_active)
		img.src = path + file[0] + ACTIVE_SYMBOL + "." + file[1];
	else if (!activate && is_active)
		img.src = path + file[0].slice(0, file[0].length - ACTIVE_SYMBOL_LENGTH) + "." + file[1];
}

/**
 * Tauscht eine Grafikdatei aus
 * 
 * @param {String} elm Name eines HTML-Elementes (IMG)
 * @param {String} img Name des zu setzenden Bildes
 */
function setImg(elm, img)
{
	getElm(elm).setImgSrc(getElm(elm).getImgSrc().replace(REGEXP_FILENAME, img));
}

/**
 * Ermittelt das Folgeelement in der aktuellen Ebene
 * 
 * @param {Object} elm Element
 * @return {Object}
 */
function getNextElm(elm)
{
	do {
		elm = elm.nextSibling;
	} 
	while (elm.nodeType != NODETYPE_ELEMENT)
	
	return elm;
}

/**
 * Ermittelt erste Kindelement eines Elements
 * 
 * @param {Object} elm Element
 * @return {Object}
 */
function getFirstChildElm(elm)
{
	var childs = elm.childNodes;
	
	for (var i = 0, ii = childs.length; i < ii; i++)
		if (childs[i].nodeType == NODETYPE_ELEMENT)
			return childs[i];
	
	return false;
}

/**
 * Klasse für Einstellungen
 * 
 * @param {String} key Name (Schlüsel) der Einstellung
 */
function Einstellung(key)
{
	/** Schlüssel dieser Einstellung, wie er im Cookie verwendet wird */
	this.key = key;
	
	/** Bezeichner für die Element-ID dieser Einstellung */
	this.prefix = (this.key == "ak")
		? "AK_"
		: (this.key == "bez")
			? "BEZ_"
			: "";
	 
	/** reg. Ausdruck zum Erkennen eines Elementes zu dieser Einstellung */
	this.regexp = new RegExp("^" + this.prefix);
	 
	/**
	 * Gibt das die Symbole dieser Einstellung 
	 * umschließende Element zurück
	 * 
	 * @return {Object}
	 */
	this.getContainerElm = function()
	{
		return getElm(
			(this.key == "ak")
				? "meineAltersklasse"
				: (this.key == "bez")
					? "meinBezirk"
					: ""
		);
	}

	/**
	 * Gibt das zu dieser Einstellung 
	 * aktuell gesetzte Element zurück
	 * 
	 * @return {Object}
	 */
	this.getCurrentElm = function()
	{
		return getElm(this.prefix + meinSTV.get(this.key));
	}

	/**
	 * individuelle alert()-Methode
	 * 
	 * @return {String}
	 */
	this.alert = function()
	{
		alert(
			"key\t\t= " + this.key +
			"\nprefix\t= " + this.prefix +
			"\nregexp\t= " + this.regexp +
			"\ncurrent\t= " + meinSTV.get(this.key)
		);
	}
}
	
