var lauftraining	= 5;		// In Jahren
var marathon		= 14;		// In Jahren
var half_marathon	= 10;		// In Jahren
var tenthousand		= 8;		// In Jahren
var dateObj			= new Date();
					// Leeres Element am Anfang um den
					// [0] Index zu überspringen
var months			= new Array("" , "Januar" , "Februar" , "März" , "April" , "Mai" , "Juni" , "Juli" , "August" , "September" , "Oktober" , "November" , "Dezember");


/**
 *
 *  Vergleicht die beiden übergebenen Zeitangaben und gibt -1 zurück,
 *  wenn A < B; 0, wenn A == B und 1 wenn A > B
 *
 *  @sample	time_compare(12, 00, 00, 09, 30, 00) --> 1
 *
 *  @param	int		Stundenangabe A
 *  @param	int		Minutenangabe A
 *  @param	int		Sekundenangabe A
 *  @param	int		Stundenangabe B
 *  @param	int		Minutenangabe B
 *  @param	int		Sekundenangabe B
 *  @return	int		Vergleichsergebnis
 *
***/
function time_compare(hh_a, mm_a, ss_a, hh_b, mm_b, ss_b)
{

	hh_a = parseInt(hh_a);
	mm_a = parseInt(mm_a);
	ss_a = parseInt(ss_a);
	hh_b = parseInt(hh_b);
	mm_b = parseInt(mm_b);
	ss_b = parseInt(ss_b);


	// Sind die beiden Stundenangaben identisch?
	if(hh_a == hh_b)
	{

		// Sind die beiden Minutenangaben identisch?
		if(mm_a == mm_b)
		{

			// Sind die beiden Sekundenangaben identisch?
			if(ss_a == ss_b)
			{
				return 0;
			}


			// Skundenangeben sind NICHT identisch
			else
			{
				return (ss_a > ss_b) ? 1 : -1 ;
			}

		}


		// Minutenangaben sind NICHT identisch
		else
		{
			return (mm_a > mm_b) ? 1 : -1 ;
		}

	}


	// Stundenangaben sind NICHT identisch
	else
	{
		return (hh_a > hh_b) ? 1 : -1 ;
	}

}



/**
 *
 *	Zeitangaben mit Minimalwerten initalisieren
 *
 * @param	string	ID der ComboBox zur Sekundenangabe
 * @return	void
 *
***/
function init_time(id)
{

	if(_id(id).selectedIndex <= 0)
	    _id(id).selectedIndex = 1;

}


/*
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * Combobbox, DOM Funktion
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 */


/**
 *
 *  Übergebene Formularelemente deaktvieren
 *
 *  @notice	Es können beliebig viele Formular Bezeichner übergeben werden
 *
 *  @param	string	Die ID des zu deaktivierenden Formular Elementes
 *  @param	string	...
 *  @return	void
 *
***/
function disable()
{
	// Durch die übergebenen Argumente iterieren
	for(var i = 0; i < arguments.length; i++)
	{
		_id(arguments[i]).disabled = true;
	}
}

/**
 *  Übergebene Formularelemente aktvieren
 *
 *  @notice	Es können beliebig viele Formular Bezeichner übergeben werden
 *
 *  @param	string	Die ID des zu aktivierenden Formular Elementes
 *  @param	string	...
 *  @return	void
***/
function enable()
{
	// Durch die übergebenen Argumente iterieren
	for(var i = 0; i < arguments.length; i++)
	{
		_id(arguments[i]).disabled = false;
	}
}

/**
 *  Übergebene Formularelemente de-/aktvieren, je nach aktuellem Status
 *
 *  @notice	Es können beliebig viele Formular Bezeichner übergeben werden
 *
 *  @param	string	Die ID des zu de-/aktivierenden Formular Elementes
 *  @param	string	...
 *  @return	void
***/
function change()
{
	for(var i = 0; i < arguments.length; i++)
	{
		_id(arguments[i]).disabled = !_id(arguments[i]).disabled;
	}
}


/*
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * Select, DOM Funktion
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 */


/**
 * Selektiert den der ID zugehörigen Wert, welcher aus dem versteckten
 * Feld übernommen wird.
 *
 * <select id="id_test" name="test">
 * ..
 * </select>
 * <input type="hidden" name="IN_test" id="IN_id_selectedtest" value="$#test#$" />
 *
 * @param	string	cboID ID der Combobx
 */
function selectInComboBox (cboID)
{
	// Referenz auf die Combobox
	var combo = _id(cboID);
	// Der Wert des der ID zugehörigen versteckten Feldes
	var value = _id('IN_' + cboID).value;

	for(var i = 0; i < combo.length; i++)
	{
		if(combo.options[i].value == value)
		{
			combo.options[i].selected = true;
			break;
		}
	}
}

/**
 * Selektiert den der ID zugehörigen Wert, welcher aus dem versteckten
 * Feld übernommen wird.
 *
 * <input type="radio" name="test" id="id_test_y" value="yes" />Ja
 * <input type="radio" name="test" id="id_test_n" value="no" />Nein
 * <input type="hidden" name="IN_test" id="IN_id_checkedtest" value="$#test#$" />
 *
 * @param	string	cboID ID der Combobx
 */
function selectInRadio(rdoName)
{
	// Referenz auf die Buttongruppe
	var radio = _name(rdoName);
	// Der Wert des dem Namen zugehörigen versteckten Feldes
	var value = _id('IN_id_' + rdoName).value;

	for(var i = 0; i < radio.length; i++)
	{
		if(radio[i].value == value)
		{
			radio[i].checked = true;
			break;
		}
	}
}

/**
 * Selektiert den der ID zugehörigen Wert, welcher aus dem versteckten
 * Feld übernommen wird.
 *
 * <input type="checkbox" name="test" id="id_test" value="Sportlich" />Sportlich
 * <input type="hidden" name="IN_test" id="IN_id_electedtest" value="$#test#$" />
 *
 * @param	string	cbkName ID der Checkbox
 */
function selectInCheckBox(cbkName)
{
	if(_id('IN_' + cbkName).value != '')
	{
		_id(cbkName).checked = true;
	}
	else
	{
		_id(cbkName).checked = false;
	}
}

/**
 * Konvertiert den Inhalt des Textfeldes von URL Kodierung in lesbare
 * Zeichen
 *
 * @param	string	txtName	Die ID des Textfelds
 */
function correctTextData(txtName)
{
	_id(txtName).value = decodeURIComponent(_id(txtName).value);
}


/*
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * Dynamische Inhalte, DOM Funktion
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 */


/**
 *  Jahresangeben der übergebenen DropDown Boxen ändern, dass
 *  nur Daten nach dem Geburtsdatum angegeben werden!
 *
 *  @notice	Es können beliebig viele Formular Bezeichner übergeben werden
 *
 *  @param	int		Kleiners Datum
 *  @param	int		Größeres Datum
 *  @param	bool	Von Klein nach Groß sortieren?
 *  @param	string	Die ID der zu aktualisierenden DropDown Box
 *  @param	string	...
 *  @return	void
***/
function createBoxContent()
{

	//
	// Prüfen, ob die Elemente aktualisiert werden können
	//
	if(create)
	{

		//
		// Es werden nicht alle notwendigen Funktionen zur
		// Aktualisierung des Formulars unterstützt.
		// Funktion verlassen!
		//
		return;

	}


	var obj = null, j = 0, i = 0, option = null, x;


	//
	// Für ALLE übergebenen Paramter
	//
	for(i = 0; i < (arguments.length - 3); i++)
	{

		//
		// Objekt holen
		//
		obj = _id(arguments[i + 3]);
		j = 0;


		//
		// ALLE Bestehende Elemente entfernen
		//
		for(j = obj.length; j > 0; j--)
		{

			obj.remove(0);

		}


		//
		// Leeres Feld zu Beginn der Liste
		//
		option = document.createElement('OPTION');
		option.text = '';
		option.value = 'empty';
		x = null;
		if(document.all) { x = 0; }
		obj.add(option, x);



		//
		// Neue Elemente hinzufügen
		//
		if(arguments[2])
		{

			//
			// Neue Elemente, beginnend beim Geburtsjahr
			// bis zum heutigen Jahr einfügen
			//
			for(j = parseInt(arguments[0]); j <= parseInt(arguments[1]); j++)
			{

				//
				// Altes <option...> Feld freigeben
				// und neues erstellen, danach die Werte
				// zuweisen
				//
				delete option;
				option = document.createElement('OPTION');
				option.text = j;
				option.value = j;


				x = null;
				//
				// IE Workaround:
				// Der IE erwartet als zweiten Parameter einen
				// Integer, welcher die Position für das einzufügende
				// Element angibt!
				// DOM konforme Browser erwarten als zweiten Parameter
				// eine Referenz auf das <option...> Objekt, hinter
				// welchem der neue Wert eingefügt werden soll!
				//
				if(document.all) { x = obj.length; }


				//
				// Objekt anhängen
				//
				obj.add(option, x);
			}

		}
		else
		{

			for(j = parseInt(arguments[1]); j >= parseInt(arguments[0]); j--)
			{

				delete option;
				option = document.createElement('OPTION');
				option.text = j;
				option.value = j;


				x = null;
				if(document.all) { x = obj.length; }


				obj.add(option, x);
			}

		}// if(arguments[2])...

	}

}


/*
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * Navigation und Fenster, DOM Funktion
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 */


/**
 *
 *  Öffnet ein neues Fenster
 *
 *  @param	string	Die URL der Zieldatei
 *  @param	string	Name des Fensters zur weiteren Verwendung
 *  @param	integer	Die Breite des Fenster in Pixel
 *  @param	integer	Die Höhe des Fenster in Pixel
 *  @param	integer	Der Abstand des Fenster vom linken Bildschirmrand in Pixel
 *  @param	integer	Der Abstand des Fenster vom oberen Bildschirmrand in Pixel
 *  @param	boolean	Fenster zentrieren (bei "true" werden die Angaben "left" und "top" ignoriert!)
 *  @param	string	Andere Paramter (menubar,status,toolbar...)
 *  @return	object	Das "Handle" des Fensters
 *
***/
function openWin(url, name, width, height, left, top, centered, params)
{
	//
	// Breite einstellen
	//
	params += ',width=' + width + ',height=' + height + ',';


	//
	// Zentrieren, wenn nötig
	// Andernfalls die Seitenabstände einstellen
	//
	if(centered)
	{
		params += 'left=' + ((screen.availWidth - width) / 2) + ',';
		params += 'top=' + (screen.availHeight - height) / 2;
	}
	else
	{
		params += 'left=' + left + ',top=' + top;
	}


	//
	// Fenster öffnen und in den Vordergrund holen
	//
	params += ',resizable=1';
	var win = window.open(url, name, params);
	win.focus();


	//
	// Fenster "Handle" zurückgeben
	//
	return win;

}

/**
 * Öffnet ein neues Fenster. Equivalent zu target=_blank, aber XHTML
 * kompatibel!
 * @param string Die URL der Zieldatei
 * @param string Name des Fensters zur weiteren Verwendung
 * @return object Das "Handle" des Fensters
 *
***/
function openFullWin(url, name)
{
	width = screen.width - 100;
	height = screen.height - 100;
	params = 'width=' + width + ',height=' + height;

	params += ',left=' + ((screen.availWidth - width) / 2);
	params += ',top=' + ((screen.availHeight - height) / 2);

	params += ',location=1,menubar=1,toolbar=1,status=1,scrollbars=1';

	win = window.open(url, name, params);
	win.focus();

	return win;
}



/**
 *
 *  Ändert die Sprache der aktuellen Seite
 *
 *  @param	string	Zieldatei
 *  @param	string	Sprache
 *  @return	void
 *
***/
function chgLocale(action, locale)
{

	_id('id_action').value = action;
	_id('id_locale').value = locale;
	document.forms[0].submit();

}

/**
 *
 * Leitet auf die übergebene Adresse weiter
 *
 *  @param	string	Die Zieladresse
 *  @return	void
 *
 */
function go(target)
{
	location.href = target;
}

/**
 *
 *  Springt zur angegebenen Seite OHNE Formularüberprüfung
 *
 *  @param	string	Zieldatei
 *  @return	void
 *
***/
function simpleGo(action)
{
	_id('id_action').value = action;
	document.forms[0].submit();

}


/**
 *
 *  Mail an die übergebene Adresse
 *
 *  @param	string	Top Level Domain
 *  @param	string	Name
 *  @param	string	Domain
 *  @return	void
 *
***/
function x(a, b, c)
{

	// S p A m   P r O t E c T i O n
	d = unescape('%6D%61%69') + unescape('%6C%74%6F%3A');
	f = b /* //*/ + /*  */ '%40' /* // */ + /* -- */ c;
	e = '%2E' /* ' */ + /* " */ a;

	win = window.open(d+f+e, null, null);
	win.close();

}


function calcWin(url, name, width, height)
{
	width  = screen.availWidth < width ? screen.availWidth * 0.9 : width;
	height = screen.availHeight < height ? screen.availHeight * 0.9 : height;

	var params = '';
	params +=  'width=' + parseInt(width);
	params += ',height=' + parseInt(height);
	params += ',left=' + parseInt((screen.availWidth - width) / 2);
	params += ',top=' + parseInt((screen.availHeight - height) / 2);
	params += ',location=0,menubar=0,toolbar=0,status=1,scrollbars=1,resizable=1';

	var sid = document.all
		? document.all['sid'].value
		: document.getElementsByName('sid')[0].value;

	var html = '';
	html += '<html>'
	html += '<head>';
	html += '<script type="text/javascript">history.forward(1);</script>';
	html += '</head>';
	html += '<body onload="document.forms[0].submit();">';
	html += '<form action="../pace-site/' + url + '" method="post">';
	html += '<input type="hidden" name="sid" id="sid" value="' + sid + '" />';
	html += '<input type="submit" value="Weiter" />';
	html += '</form>';
	html += '</body>';
	html += '</html>';

	win = window.open(null, name, params);
	win.blur();
	win.document.open();
	win.document.write(html);
	win.document.close();
	win.focus();

	return win;
}


function newsWin()
{
	width  = 920;
	height = 680;
	width  = screen.availWidth < width ? screen.availWidth * 0.9 : width;
	height = screen.availHeight < height ? screen.availHeight * 0.9 : height;

	var params = '';
	params +=  'width=' + parseInt(width);
	params += ',height=' + parseInt(height);
	params += ',left=' + parseInt((screen.availWidth - width) / 2);
	params += ',top=' + parseInt((screen.availHeight - height) / 2);
	params += ',location=0,menubar=0,toolbar=0,status=1,scrollbars=1,resizable=1';

	var locale = document.all
		? document.all['id_locale'].value
		: document.getElementById('id_locale').value;
	var sid = document.all
		? document.all['sid'].value
		: document.getElementsByName('sid')[0].value;
	var current = document.all
		? document.all['current'].value
		: document.getElementsByName('current')[0].value;

	var html = '';
	html += '<html>'
	html += '<head>';
	html += '<script type="text/javascript">history.forward(1);</script>';
	html += '</head>';
	html += '<body onload="document.forms[0].submit();">';
	html += '<form action="pace.dll" method="post">';
	html += '<input type="hidden" name="sid" id="id_sid" value="' + sid + '" />';
	html += '<input type="hidden" name="current" id="id_current" value="' + current + '" />';
	html += '<input type="hidden" name="locale" id="id_locale" value="' + locale + '" />';
	html += '<input type="hidden" name="action" id="id_action" value="news" />';
	html += '<input type="submit" value="Weiter" />';
	html += '</form>';
	html += '</body>';
	html += '</html>';

	win = window.open(null, name, params);
	win.blur();
	win.document.open();
	win.document.write(html);
	win.document.close();
	win.focus();

	return win;
}