function fctCountdown( )
{
	startDatum = new Date( ); // Aktuelles Datum
	var objDocText = document.getElementById( "countdown" );	// Hier kommt der Text rein

	// Countdown berechnen und anzeigen, bis Ziel-Datum erreicht ist
	if( startDatum <= zielDatum ) 
	{
	
		var jahre = 0
		var monate = 0
		var tage = 0
		var stunden = 0
		var minuten = 0
		var sekunden = 0;

		// Tage
		restTage = Math.floor( ( zielDatum - startDatum ) / ( 24 * 60 * 60 * 1000 ) );
		// Die abgezählten Tage zum startDatum dazuzählen, dass nur noch mit dem Rest weitergerechnet wird
		startDatum.setTime( startDatum.getTime( ) + restTage * 24 * 60 * 60 * 1000 );
		tage += restTage;

		// Stunden
		stunden = Math.floor( ( zielDatum - startDatum ) / ( 60 * 60 * 1000 ) );
		// Die abgezählten Stunden zum startDatum dazuzählen, dass nur noch mit dem Rest weitergerechnet wird
		startDatum.setTime( startDatum.getTime( ) + stunden * 60 * 60 * 1000 );

		// Minuten
		minuten = Math.floor( ( zielDatum - startDatum ) / ( 60 * 1000 ) );
		// Die abgezählten Minuten zum startDatum dazuzählen, dass nur noch mit dem Rest weitergerechnet wird
		startDatum.setTime( startDatum.getTime( ) + minuten * 60 * 1000 );

		// Sekunden
		sekunden = Math.floor( ( zielDatum - startDatum ) / 1000 );

		// Anzeige formatieren
		if (tage != 1)
		{
			tage = tage + " Tage, ";
		}
		else
		{
			tage = tage + " Tag, ";
		}

		if(stunden < 10)
		{
			stunden ="0" + stunden;
		}													
		stunden = stunden + " h ";

		if(minuten < 10)
		{
			minuten ="0" + minuten;
		}													
		minuten = minuten + " min ";

		if(sekunden < 10) 
		{
			sekunden = "0" + sekunden;
		}
		sekunden = sekunden + " sec";
		
		if (objDocText)
		{
			objDocText.innerHTML = tage + stunden + minuten + sekunden + "<br />bis zur LAN-Party!";
		}

		setTimeout( "fctCountdown()", 200 );
	}
	// Anderenfalls alles auf Null setzen
	else
	{
		if (objDocText)
		{
			objDocText.innerHTML = "Die LAN-Party hat begonnen!";
		}
	}
}

var g_StartTime = "08:00";
var g_EndTime = "12:00";

function fctFillWholeDay( p_Checkbox, p_FieldStart, p_FieldEnd )
{
	var objFieldStart = document.getElementsByName( p_FieldStart )[ 0 ];
	var objFieldEnd = document.getElementsByName( p_FieldEnd )[ 0 ];
	var objDate = null;

	if( objFieldStart != null && objFieldEnd != null )
	{		
		if( p_Checkbox.checked == true )
		{
			g_StartTime = objFieldStart.value;
			g_EndTime = objFieldEnd.value;
			objFieldStart.value = "00:00";
			objFieldEnd.value = "23:59";		
			objFieldStart.readOnly = true;
			objFieldEnd.readOnly = true;
		}
		else
		{
			objFieldStart.value = g_StartTime;
			objFieldEnd.value = g_EndTime;		
			objFieldStart.readOnly = false;
			objFieldEnd.readOnly = false;
		}
	}
}

function fctMarkRecipients( p_type, p_checked )
{
	/*
	all = alle
	none = keine
	payed = definitiv angemeldete
	signed = angemeldete ( nicht definitiv )
	signedpayed = definitiv angemeldete und nur angemeldete
	registered = nur registrierte
	active = aktive user
	*/
	var objarrCheckboxes = document.getElementsByName( "lst_user_mail_check" + p_type );
	
	for( var i = 0; i < objarrCheckboxes.length; i ++ )
	{
		if( p_checked == "all" )
		{
			objarrCheckboxes[ i ].checked = true;	
		}
		else if( p_checked == "none" )
		{
			objarrCheckboxes[ i ].checked = false;	
		}
		else if( p_checked == "payed" )
		{
			if( objarrCheckboxes[ i ].getAttribute( "user_payed" ) == "1" )
			{
				objarrCheckboxes[ i ].checked = true;	
			}
			else
			{
				objarrCheckboxes[ i ].checked = false;
			}
		}
		else if( p_checked == "signed" )
		{
			if( objarrCheckboxes[ i ].getAttribute( "user_role" ) == "signedin" && objarrCheckboxes[ i ].getAttribute( "user_payed" ) == "0" )
			{
				objarrCheckboxes[ i ].checked = true;	
			}
			else
			{
				objarrCheckboxes[ i ].checked = false;
			}
		}
		else if( p_checked == "signedpayed" )
		{
			if( objarrCheckboxes[ i ].getAttribute( "user_role" ) == "signedin" )
			{
				objarrCheckboxes[ i ].checked = true;		
			}
			else
			{
				objarrCheckboxes[ i ].checked = false;
			}
		}
		else if( p_checked == "registered" )
		{
			if( objarrCheckboxes[ i ].getAttribute( "user_role" ) == "registered" && objarrCheckboxes[ i ].getAttribute( "user_active" ) == "1" )
			{
				objarrCheckboxes[ i ].checked = true;	
			}
			else
			{
				objarrCheckboxes[ i ].checked = false;	
			}
		}
		else if( p_checked == "active" )
		{
			if( objarrCheckboxes[ i ].getAttribute( "user_active" ) == "1" )
			{
				objarrCheckboxes[ i ].checked = true;	
			}
			else
			{
				objarrCheckboxes[ i ].checked = false;
			}
		}
	}
}

function fctHandleMailGreetingsDisplay( )
{
	var objField = document.getElementsByName( "greetings" )[ 0 ];	
	
	if( objField != null && objField.checked == true )
	{
		fctShowObjectByID( "greetings_display" );	
	}
	else
	{
		fctHideObjectByID( "greetings_display" );	
	}
}

function fctHandleMailSignatureDisplay( )
{
	var objField = document.getElementsByName( "signature" )[ 0 ];
	
	if( objField != null && objField.checked == true )
	{
		fctShowObjectByID( "signature_display" );	
	}
	else
	{
		fctHideObjectByID( "signature_display" );	
	}
}

function fctMailLoad( )
{
	// Empfänger
	var objRecipient = null;
	var objLink = null;
	var objRecipientDisplay = null;
	var arrRecipientsToShow = null;
	var arrTemp = new Array( );
	var arrRecipientUserIds = new Array( );
	var strRecipientDisplay = "";
	var strAddRecipientType = "";
	var blnShowCC 			= false;
	var blnShowBCC			= false;
	
	// Text
	var objTextId = null;
	var objTxtDisplay = null;
	
	// -------------------------------------------------------------------------------------
	// Empfänger
	
	strRecipientDisplay = "";
	arrRecipientsToShow = new Array( "", "_cc", "_bcc" );

	// anzuzeigende Recipients anzeigen
	for( var i = 0; i < arrRecipientsToShow.length; i ++ )
	{
		// namen der ausgewählten empfänger aus der user db anzeigen
		objRecipient = document.getElementsByName( "recipient_user_ids" + arrRecipientsToShow[ i ] )[ 0 ];
		strRecipientDisplay = "";
		blnShowCC = false;
		blnShowBCC = false;
		
		if( objRecipient != null )
		{
			if( objRecipient.value != "" )
			{
				arrRecipientUserIds = objRecipient.value.split( ";" );
				
				// alle namen zu den user_ids holen und zum anzeigen vorbereiten
				for( var j = 0; j < arrRecipientUserIds.length; j ++ )
				{
					arrTemp = g_arrUser[ arrRecipientUserIds[ j ] ].split( "##" );
					arrTemp[ 1 ] = "<span class=\"description_text\">( " + arrTemp[ 1 ] + " )</span>";
					strRecipientDisplay += arrTemp[ 0 ] + " " + arrTemp[ 1 ] + ", ";
				}
				
				if( strRecipientDisplay != "" )
				{
					// das letzte ", " abschneiden
					strRecipientDisplay = strRecipientDisplay.substring( 0, strRecipientDisplay.length - 2 );
					
					objRecipientDisplay = document.getElementById( "user_mail_display" + arrRecipientsToShow[ i ] );
					
					// namen der user_ids anzeigen
					if( objRecipientDisplay != null )
					{
						objRecipientDisplay.innerHTML = strRecipientDisplay;	
					}
						
					if( arrRecipientsToShow[ i ] == "_cc" )
					{
						blnShowCC = true;
					}
					else if( arrRecipientsToShow[ i ] == "_bcc" )
					{
						blnShowBCC = true;
					}
				}
			}
		}
		
		// e-mail adresse anzeigen, die der erfasser selbst eingegeben hat
		objRecipient = document.getElementsByName( "recipient_email" + arrRecipientsToShow[ i ] )[ 0 ];
		
		if( objRecipient != null )
		{
			if( objRecipient.value != "" )
			{
				if( arrRecipientsToShow[ i ] == "_cc" )
				{
					blnShowCC = true;
				}
				else if( arrRecipientsToShow[ i ] == "_bcc" )
				{
					blnShowBCC = true;
				}
			}
		}
		
		// CC + BCC Empfänger einblenden
		if( arrRecipientsToShow[ i ] != "" )
		{
			if( arrRecipientsToShow[ i ] == "_cc" )
			{
				strAddRecipientType = "cc";
			}
			else if( arrRecipientsToShow[ i ] == "_bcc" )
			{
				strAddRecipientType = "bcc";
			}
			
			if( ( arrRecipientsToShow[ i ] == "_cc" && blnShowCC == true ) || ( arrRecipientsToShow[ i ] == "_bcc" && blnShowBCC == true ) )
			{
				objRecipient = document.getElementById( strAddRecipientType + "_recipient_frm" );
				objLink = document.getElementById( strAddRecipientType + "_link" );
				
				if( objRecipient != null && objLink != null )
				{
					objRecipient.style.display = "";
					objLink.innerHTML = strAddRecipientType.toUpperCase( ) + " Empfänger entfernen";
				}
			}
		}
	}	
	
	// -----------------------------------------------------------------------------------------
	// Text
	
	objTextId = document.getElementsByName( "text_id" )[ 0 ];
	objTxtDisplay = document.getElementById( "txt_db_display" );
	
	if( objTextId != null )
	{
		if( objTextId.value != "" && objTextId.value > -1 )
		{
			if( g_arrText[ objTextId.value ] != "" )
			{
				if( g_arrText[ objTextId.value ].length > 100 )
				{
					objTxtDisplay.innerHTML = "( <a href=\"?section=showtext&title=Mail&subtitle=Textvorschau&text_id=" + objTextId.value + "\" target=\"_blank\">Vorschau</a> )<br>" + g_arrText[ objTextId.value ].substring( 0, 100 ) + "...";
				}
				else
				{
					objTxtDisplay.innerHTML = g_arrText[ objTextId.value ];
				}		
			}
		}
	}
}

function fctCheckMailSaveSend( )
{
	var objRad = document.getElementsByName( "sendsave" );
	var objSubmit = document.getElementById( "mailsubmitbutton" );
	
	if( objSubmit != null )
	{
		for( var i = 0; i < objRad.length; i ++ )
		{
			if( objRad[ i ].checked == true )
			{
				if( objRad[ i ].value == "send" )
				{
					objSubmit.value = "Senden";
				}
				else if( objRad[ i ].value == "save" )
				{
					objSubmit.value = "Speichern";
				}
			}
		}
	}
}

function fctCommitTextID( )
{
	var objarrRad = null;
	var objTxtId = null;
	var objTxtDisplay = null;
	
	objarrRad = document.getElementsByName( "text_list_rad" );
	objTxtId = document.getElementsByName( "text_id" )[ 0 ];
	objTxtDisplay = document.getElementById( "txt_db_display" );
	
	// Test_id in hidden field abfüllen
	if( objTxtId != null )
	{
		for( var i = 0; i < objarrRad.length; i ++ )
		{
			if( objarrRad[ i ].checked == true )
			{
				objTxtId.value = objarrRad[ i ].value;
				i = objarrRad.length;
			}
		}
	}
	
	if( objTxtDisplay != null )
	{
		if( g_arrText[ objTxtId.value ].length > 100 )
		{
			objTxtDisplay.innerHTML = "( <a href=\"?section=showtext&title=Mail&subtitle=Textvorschau&text_id=" + objTxtId.value + "\" target=\"_blank\">Vorschau</a> )<br>" + g_arrText[ objTxtId.value ].substring( 0, 100 ) + "...";
			//objTxtDisplay.onmouseover = fctShowTT( g_arrText[ objTxtId.value ] );
			//objTxtDisplay.onmouseout = fctHideTT( );
		}
		else
		{
			objTxtDisplay.innerHTML = g_arrText[ objTxtId.value ];
		}
	}
	
	fctSwitchVisibilityByID( new Array( 'frm_mail', 'lst_text' ) );
}

function fctShowMailTxtList( )
{
	var objarrRad = null;
	var objTxtId = null;
	
	objarrRad = document.getElementsByName( "text_list_rad" );
	objTxtId = document.getElementById( "text_id" );
	
	if( objTxtId != null && objTxtId.value != "" )
	{
		for( var i = 0; i < objarrRad.length; i ++ )
		{
			if( objarrRad[ i ].value == objTxtId.value )
			{
				objarrRad[ i ].checked = true;	
			}
			else
			{
				objarrRad[ i ].checked = false;	
			}
		}
	}
	
	fctSwitchVisibilityByID( new Array( 'frm_mail', 'lst_text' ) );	
}

function fctHandleText( p_Field )
{
	var objTextUserDef = null;
	var objTextDB = null;
	
	objTextUserDef = document.getElementById( "text_user_def_display" );
	objTextDB = document.getElementById( "text_from_db_display" );
	
	if( p_Field.checked == true )
	{
		fctHideObject( objTextDB );
		fctShowObject( objTextUserDef );
	}
	else
	{
		fctHideObject( objTextUserDef );
		fctShowObject( objTextDB );
	}
}

function fctRemoveAttachment( p_Nr )
{
	var objTBody = null;
	var objAttToRemove = null;
	var objLinkToDisplay = null;
	var objAttachmentCount = null;
	
	g_AttachmentCount --;
	
	objAttachmentCount = document.getElementsByName( "attachment_count" )[ 0 ];
	if( objAttachmentCount != null )
	{
		objAttachmentCount = g_AttachmentCount;	
	}
	
	objTBody = document.getElementById( "attachment_table" );
	objAttToRemove = document.getElementById( "attachment_nr_" + p_Nr );
	
	objTBody.removeChild( objAttToRemove );
	
	if( p_Nr - 1 > 0 )
	{
		objLinkToDisplay = document.getElementById( "remove_link_" + ( p_Nr - 1 ) );
		objLinkToDisplay.style.display = "";
	}
}

function fctAddAttachment( )
{
	var objAttachmentTable = null;
	var objAttachmentCount = null;
	
	var objTr = null;
	var objTd1 = null;
	var objTd2 = null;
	var objInput = null;
	var objA = null;
	
	var objAText = null;
	
	var objOldRemoveLink = null;
	
	g_AttachmentCount ++;
	objAttachmentCount = document.getElementsByName( "attachment_count" )[ 0 ];
	
	if( objAttachmentCount != null )
	{
		objAttachmentCount.value = g_AttachmentCount;	
	}
	
	objAttachmentTable = document.getElementById( "attachment_table" );
	
	objTr = document.createElement( "tr" );
	objTd1 = document.createElement( "td" );
	objTd2 = document.createElement( "td" );
	objInput = document.createElement( "input" );
	objA = document.createElement( "a" );
	
	objAText = document.createTextNode( "entfernen" );
	
	objTr.id = "attachment_nr_" + g_AttachmentCount;
	
	objInput.type = "file";
	objInput.name = "attachment_" + g_AttachmentCount;
	objInput.style.width = "250px";
	
	objA.href = "javascript:fctRemoveAttachment( '" + g_AttachmentCount + "' );";
	objA.className = "description_text";
	objA.id = "remove_link_" + g_AttachmentCount;
	
	objA.appendChild( objAText );
	
	objTd2.appendChild( objInput );
	objTd2.appendChild( document.createTextNode( " " ) );
	objTd2.appendChild( objA );
	
	objTd1.appendChild( document.createTextNode( " " ) );

	objTr.appendChild( objTd1 );
	objTr.appendChild( objTd2 );
	
	objAttachmentTable.appendChild( objTr );
	
	objOldRemoveLink = document.getElementById( "remove_link_" + ( g_AttachmentCount - 1 ) );
	
	if( objOldRemoveLink != null )
	{
		objOldRemoveLink.style.display = "none";
	}
}

function fctHandleAddRecipient( p_Art )
{
	var objRecipient = document.getElementById( p_Art + "_recipient_frm" );
	var objLink = document.getElementById( p_Art + "_link" );
	var arrFieldsToEmpty = new Array( 'recipient_user_ids_', 'recipient_email_' );
	var objTemp = null;
	
	if( objRecipient != null && objLink != null )
	{
		if( objRecipient.style.display == "" )
		{
			// Felder leeren
			for( var i = 0; i < arrFieldsToEmpty.length; i ++ )
			{
				objTemp = document.getElementsByName( arrFieldsToEmpty[ i ] + p_Art )[ 0 ];
				
				if( objTemp != null )
				{
					objTemp.value = "";
				}
			}
			
			objTemp = document.getElementById( "user_mail_display_" + p_Art );
			
			if( objTemp != null )
			{
				objTemp.innerHTML = "";	
			}
			
			objRecipient.style.display = "none";
			objLink.innerHTML = p_Art.toUpperCase( ) + " Empfänger hinzufügen";
		}
		else
		{
			objRecipient.style.display = "";
			objLink.innerHTML = p_Art.toUpperCase( ) + " Empfänger entfernen";
		}
	}
}

function fctShowUserLstMail( p_Art )
{
	var arrIDs = document.getElementsByName( "recipient_user_ids" + p_Art )[ 0 ].value.split( ";" );
	var arrTmpCheckbox = new Array( );
	
	arrTmpCheckbox = document.getElementsByName( "lst_user_mail_check" + p_Art );
	
	// zuerst alle checkboxes deaktivieren
	for( var i = 0; i < arrTmpCheckbox.length; i ++ )
	{
		arrTmpCheckbox[ i ].checked = false;	
	}
	
	for( var i = 0; i < arrTmpCheckbox.length; i ++ )
	{
		for( var j = 0; j < arrIDs.length; j ++ )
		{
			if( arrTmpCheckbox[ i ].value == arrIDs[ j ] )
			{
				arrTmpCheckbox[ i ].checked = true;
				j = arrIDs.length;
			}
		}
	}
	
	fctSwitchVisibilityByID( new Array( 'frm_mail', 'lst_user_mail' + p_Art ) );	
}

function fctCommitUserEMail( p_Art )
{
	var objUserIDs = document.getElementsByName( "lst_user_mail_check" + p_Art );
	var strOutputDisplay = "";
	var strOutputHidden = "";
	var obField = null;
	var arrTemp = new Array( );
	
	for( var i = 0; i < objUserIDs.length; i ++ )
	{
		if( objUserIDs[ i ].checked == true )
		{
			strOutputHidden += objUserIDs[ i ].value + ";";
			
			arrTemp = g_arrUser[ objUserIDs[ i ].value ].split( "##" );
			arrTemp[ 1 ] = "<span class=\"description_text\">( " + arrTemp[ 1 ] + " )</span>";
			strOutputDisplay += arrTemp[ 0 ] + " " + arrTemp[ 1 ] + ", ";
		}
	}

	// letztes ; abschneiden
	if( strOutputHidden != "" )
	{
		strOutputHidden = strOutputHidden.substring( 0, strOutputHidden.length - 1 );
	}
	
	if( strOutputDisplay != "" )
	{
		strOutputDisplay = strOutputDisplay.substring( 0, strOutputDisplay.length - 2 );
	}
		
	// zurückschreiben
	objField = document.getElementsByName( "recipient_user_ids" + p_Art )[ 0 ];
	if( objField != null )
	{
		objField.value = strOutputHidden;	
	}
		
	objField = document.getElementById( "user_mail_display" + p_Art );
	if( objField != null )
	{
		objField.innerHTML = strOutputDisplay;	
	}
	
	fctSwitchVisibilityByID( new Array( 'frm_mail', 'lst_user_mail' + p_Art ) );
}

function fctOpenPopup( p_URL, p_width, p_height )
{
	var myPopup = window.open( p_URL, "_blank", "height=" + p_height + ", left=300, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, toolbar=no, top=300, width=" + p_width );
}

function fctChangeOrder( p_FieldName, p_Direction )
{
	var objList = document.getElementsByName( p_FieldName )[ 0 ];
	var intIndex = 0;
	var intArrayIndex = 0;
	var arrOptions = new Array( );
	var blnChanged = false;
	
	if( objList != null )
	{
		if( objList.selectedIndex != -1 )
		{
			intIndex = objList.selectedIndex;
			
			if( p_Direction == "up" )
			{
				if( intIndex > 0 )
				{
					blnChanged = true;
					
					for( var i = 0; i < objList.options.length; i ++ )
					{
						if( i + 1 == intIndex )
						{
							arrOptions[ i ] = objList.options[ i + 1 ];
							arrOptions[ i + 1 ] = objList.options[ i ];
							i ++;
						}
						else
						{
							arrOptions[ i ] = objList.options[ i ];
						}
					}
				}
			}
			else
			{
				if( intIndex < objList.options.length - 1 )
				{
					blnChanged = true;
					
					for( var i = objList.options.length - 1; i >= 0; i -- )
					{
						if( i - 1 == intIndex )
						{
							arrOptions[ i - 1 ] = objList.options[ i ];
							arrOptions[ i ] = objList.options[ i - 1 ];
							i --;
						}
						else
						{
							arrOptions[ i ] = objList.options[ i ];	
						}
					}
				}
			}
			
			if( blnChanged == true )
			{				
				for( var i = objList.options.length - 1; i >= 0; i -- )
				{
					objList.options[ i ] = null;	
				}
								
				for( var i = 0; i < arrOptions.length; i ++ )
				{
					objList.options[ objList.options.length ] = arrOptions[ i ];	
				}
			}
		}
	}
}

function fctPrepareChangeOrder( p_ListName )
{
	var objList = document.getElementsByName( p_ListName )[ 0 ];
	var strNewOrder = "";
	
	if( objList != null )
	{
		for( var i = 0; i < objList.options.length; i ++ )
		{
			strNewOrder+= objList.options[ i ].value + ", ";
		}
		
		strNewOrder = strNewOrder.substr( 0, strNewOrder.length - 2 );
		
		document.getElementsByName( "neworder" )[ 0 ].value = strNewOrder;
		
		//alert( document.getElementsByName( "neworder" )[ 0 ].value );
		return true;
	}
}

function fctInsertBBCode( p_AnfangsTag, p_EndTag, p_FieldName )
{
	var input = document.getElementsByName( p_FieldName )[ 0 ];
	input.focus( );
	
	if( typeof( document.selection ) != "undefined" )
	{
		/* für Internet Explorer */
		/* Einfügen des Formatierungscodes */
		var range = document.selection.createRange( );
		var insText = range.text;
		
		range.text = p_AnfangsTag + insText + p_EndTag;
		
		/* Anpassen der Cursorposition */
		range = document.selection.createRange( );
		
		if( insText.length == 0 )
		{
			range.moveStart( "character", - p_EndTag.length );
			range.moveEnd( "character", - p_EndTag.length );
		}
		else
		{
			range.moveStart( "character", p_AnfangsTag.length + insText.length + p_EndTag.length );      
		}
		
		range.select( );
	}
	else if( typeof( input.selectionStart ) != "undefined" )
	{
		/* für neuere auf Gecko basierende Browser */
		/* Einfügen des Formatierungscodes */
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring( start, end );
		
		input.value = input.value.substr( 0, start ) + p_AnfangsTag + insText + p_EndTag + input.value.substr( end );
		
		/* Anpassen der Cursorposition */
		var pos;
		if ( insText.length == 0 )
		{
			pos = start + p_AnfangsTag.length;
		}
		else
		{
			pos = start + p_AnfangsTag.length + insText.length + p_EndTag.length;
		}
		
		input.selectionStart = pos;
		input.selectionEnd = pos;
	}
	else
	{
		/* für die übrigen Browser */
		/* Abfrage der Einfügeposition */
		var pos;
		var re = new RegExp( '^[0-9]{0,3}$' );
		
		while( !re.test( pos ) )
		{
			pos = prompt( "Einfügen an Position (0.." + input.value.length + "):", "0" );
		}
		
		if( pos > input.value.length )
		{
			pos = input.value.length;
		}
		
		/* Einfügen des Formatierungscodes */
		var insText = prompt( "Bitte geben Sie den zu formatierenden Text ein:" );
		input.value = input.value.substr( 0, pos ) + p_AnfangsTag + insText + p_EndTag + input.value.substr( pos );
	}
}

function fctMail( p_strName )
{
	fctMailWithDomain( p_strName, "aarelan.ch" );
}

function fctMailWithDomain( p_strName, p_strDomain )
{
	var output = "ma";
	output += "ilto";
	output += ":";
	output += p_strName;
	output += "@";
	output += p_strDomain;
	
	location = output;
}

function fctVorgangVortsetzten( p_strUrl, p_strText )
{
	var blnAnswer = confirm( p_strText );
	
	if( blnAnswer == true )
	{
		window.location.href = p_strUrl;	
	}
}

function fctIsNumeric( p_Field )
{	
	if( p_Field != null )
	{
		if( p_Field.value != "" )
		{
			var arrAllowChar = new Array ( "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" );
			var intCountSuccess = 0;
			var strCurrentChar = "";
			
			// Alle Ziechen des Textfeldes durchloopen
			for( var i = 0; i < p_Field.value.length; i++ )
			{
				// Das aktuelle Ziechen
				strCurrentChar = p_Field.value.charAt( i );
				
				// Alle Elemente des Arrays durchloopen
				for( var j = 0; j < arrAllowChar.length; j++ )
				{	
					// Überprüfen ob das aktuelle Zeichen mit dem aktuellen Element des Arrays übereinstimmt
					if( strCurrentChar == arrAllowChar[ j ] )
					{
						// Wenn die Zeichen übereinstimmen, wird ein Counter hochgezählt
						intCountSuccess ++;
					}
				}
				
			}
			
			// Wenn alles richtig gelaufen ist, sollte der Counter so hoch sein, wie die Anzahl der Zeichen im Textfeld
			if( p_Field.value.length != intCountSuccess)
			{
				fctShowField( p_Field, "Nur Zahlen eingeben!" );
				return false;
			}
			else
			{
				return true;	
			}
		}
	}
}

function fctCheckFileType( p_Field, p_Type )
{	
	if( p_Field != null )
	{
		if( p_Field.value != "" )
		{
			if( p_Field.value.lastIndexOf( "." ) > -1 )
			{
				/* Position des letzten . im Dateipfad */
				var intPosition = p_Field.value.lastIndexOf( "." );
				/* Dateiname ausschneiden */
				var strType = p_Field.value.slice( intPosition + 1, p_Field.value.length );
				
				if ( strType.toLowerCase( ) != p_Type.toLowerCase( ) )
				{
					fctShowField( p_Field, "Bitte nur ." + p_Type + " Dateien auswählen" );
					return false;
				}
				else
				{
					return true;	
				}
			}
		}
	}
}

function fctCheckIsSameValue( p_FirstField, p_SecondField )
{	
	if( p_FirstField != null && p_SecondField != null )
	{
		if( p_FirstField.value != p_SecondField.value )
		{
			fctShowField( p_SecondField, "Die eingegebenen Werte müssen übereinstimmen!" );
			return false;
		}	
	}
}

// Object
function fctSwitchVisibility( p_arrObject )
{
	for( var i = 0; i < p_arrObject.length; i ++ )
	{
		fctHandleObjectVisible( p_arrObject[ i ] );	
	}
}

function fctHandleObjectVisible( p_Object )
{
	if( p_Object != null )
	{
		if( p_Object.style.display == "none" )
		{
			p_Object.style.display = ""; 		//einblenden
		}
		else
		{	
			p_Object.style.display = "none" 	//ausblenden	
		}
	}
}

function fctHideObject( p_Object )
{
	if( p_Object != null )
	{
		p_Object.style.display = "none";
	}
}

function fctShowObject( p_Object )
{
	if( p_Object != null )
	{
		p_Object.style.display = "";	
	}
}

// by Name
function fctSwitchVisibilityByName( p_arrName )
{
	for( var i = 0; i < p_arrName.length; i ++ )
	{
		fctHandleObjectVisible( fctGetObjectByName( p_arrName[ i ] ) );	
	}
}

function fctHandleObjectVisibleByName( p_Name )
{
	var objObject = fctGetObjectByName( p_Name );
	
	if( objObject != null )
	{
		if( objObject.style.display == "none" )
		{
			objObject.style.display = ""; 		//einblenden
		}
		else
		{	
			objObject.style.display = "none" 	//ausblenden	
		}
	}
}

function fctHideObjectByName( p_Name )
{
	var objObject = fctGetObjectByName( p_Name );
	
	if( objObject != null )
	{
		objObject.style.display = "none";
	}
}

function fctShowObjectByName( p_Name )
{
	var objObject = fctGetObjectByName( p_Name );
	
	if( objObject != null )
	{
		objObject.style.display = "";	
	}
}

function fctGetObjectByName( p_Name )
{
	return document.getElementsByName( p_Name )[ 0 ];	
}

// by ID
function fctSwitchVisibilityByID( p_arrID )
{
	for( var i = 0; i < p_arrID.length; i ++ )
	{
		fctHandleObjectVisible( fctGetObjectByID( p_arrID[ i ] ) );	
	}
}


function fctHandleObjectVisibleByID( p_ID )
{
	var objObject = fctGetObjectByID( p_ID );
	
	if( objObject != null )
	{
		if( objObject.style.display == "none" )
		{
			objObject.style.display = ""; 		//einblenden
		}
		else
		{	
			objObject.style.display = "none" 	//ausblenden	
		}
	}
}

function fctHideObjectByID( p_ID )
{
	var objObject = fctGetObjectByID( p_ID );
	
	if( objObject != null )
	{
		objObject.style.display = "none";
	}
}

function fctShowObjectByID( p_ID )
{
	var objObject = fctGetObjectByID( p_ID );
	
	if( objObject != null )
	{
		objObject.style.display = "";	
	}
}

function fctGetObjectByID( p_ID )
{
	return document.getElementById( p_ID );	
}

function fctCheckMinLength( p_Field, p_Length )
{	
	if( p_Field != null )
	{
		if( p_Field.value != "" )
		{
			if( p_Field.value.length < p_Length )
			{
				fctShowField( p_Field, "Bitte minimal " + p_Length + " Zeichen eingeben!" );
				return false;
			}
		}
		else
		{
			fctShowField( p_Field, "Bitte minimal " + p_Length + " Zeichen eingeben!" );
			return false;	
		}
	}
}

function fctCheckMaxLength( p_Field, p_Length )
{	
	if( p_Field != null )
	{
		if( p_Field.value != "" )
		{
			if( p_Field.value.length > p_Length )
			{
				fctShowField( p_Field.name, "Bitte nur maximal " + p_Length + " Zeichen eingeben!" );
				return false;
			}
		}
	}
}

function fctCheckMail( p_Field )
{
	if( p_Field != null )
	{
		if( p_Field.value != "" )
		{
			var strMail = p_Field.value;
			var strFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
			if ( strFilter.test( strMail ) == false )
			{
				fctShowField( p_Field, "Bitte gib eine gültige E-Mail Adresse ein!" );
				return false;
			}
		}
	}
}

function fctCheckWebSite( p_Field )
{
	var intPos = 0;
	
	if ( p_Field.value != "" )
	{
		intPos = p_Field.value.indexOf( "http://" );
		
		if ( intPos != -1 )
		{
			p_Field.value = p_Field.value.substring( intPos + 7, p_Field.value.length );
		}		
	}
}

function fctShowField( p_Field, p_Message )
{
	if( p_Field != null )
	{			
		//Styleänderungen
		p_Field.style.backgroundColor = "#BED5F1";	/* farbe von Navigation:hover */
		p_Field.style.borderColor = "#2F61C9";		/* Dunkles Blau des Logos */
		p_Field.style.borderWidth = "1px";
		p_Field.style.borderStyle = "solid";
		
		alert( p_Message );
		
		// Styleänderungen
		p_Field.style.backgroundColor = "#CDE5FF";	/* Helles Blau des Logos */
		p_Field.style.borderColor = "#2F61C9";		/* Dunkles Blau des Logos */
		p_Field.style.borderWidth = "1px";
		p_Field.style.borderStyle = "solid";
		
		if( p_Field.type != "file" )
		{
			// Wenn das Feld den typ Fiel hat, würde es in FireFox einen Endlos-Loop mit Alert-Boxes geben
			p_Field.focus( );
			p_Field.select( );
		}
	}	
}

function fctCheckListFilledField( p_arrFieldNames )
{
	var objField = null;
	
	for ( var i = 0; i < p_arrFieldNames.length; i++ )
	{
		objField = document.getElementsByName( p_arrFieldNames[ i ] )[0];
		
		if( objField != null && objField.value == "" )
		{
			fctShowField( objField, "Bitte füll dieses Feld aus!" );
			return false;
		}
		
		objField = null;
	}
}

function fctShowForumBBCodeDescr( p_DescrText )
{
	document.getElementById( "forum_bbcode_descr" ).innerHTML = p_DescrText;	
}

function fctCheckColor( p_Field, p_TargetFieldName )
{
	// herausfinden welches gechecked ist
	for( var i = 0; i < p_Field.options.length; i ++ )
	{
		if( p_Field.options[ i ].selected == true )
		{
			var intValue = p_Field.options[ i ].value;
		}
	}
	
	if( intValue != -1 )
	{
		fctInsertBBCode( '[color=' + intValue + ']', '[/color]', p_TargetFieldName )	
	}
}

function fctCheckSize( p_Field, p_TargetFieldName )
{
	// herausfinden welches gechecked ist
	for( var i = 0; i < p_Field.options.length; i ++ )
	{
		if( p_Field.options[ i ].selected == true )
		{
			var intValue = p_Field.options[ i ].value;
		}
	}
	
	if( intValue > -1 )
	{
		fctInsertBBCode( '[size=' + intValue + ']', '[/size]', p_TargetFieldName )	
	}
}

function fctCheckSubNavigation( )
{
	var arrFieldsToCheck = new Array( "link", "showname" );
	
	return fctCheckListFilledField( arrFieldsToCheck );
}

function fctCheckTexte( )
{
	var arrFieldsToCheck = new Array( "key", "text" );
	
	return fctCheckListFilledField( arrFieldsToCheck );
}

function fctHandlePicDel( p_CheckBox )
{
	var objFileField = document.getElementsByName( "pic" )[ 0 ];
	
	if( objFileField != null )
	{
		if( p_CheckBox.checked == true )
		{
			objFileField.style.display = "none";
		}
		else
		{
			objFileField.style.display = "";
		}
	}
}

function fctCheckSponsoren( )
{
	var arrFieldsToCheck = new Array( "name", "beschreibung" )
	
	return fctCheckListFilledField( arrFieldsToCheck );
}

function fctCheckTeam( )
{
	var arrFieldsToCheck = new Array( "name", "nick", "job", "bereich", "mail", "datum" );
	
	return fctCheckListFilledField( arrFieldsToCheck );
}

function fctCheckGalleryComment( )
{
	var arrFieldsToCheck = new Array( "nickname", "text", "captcha" );
	
	return fctCheckListFilledField( arrFieldsToCheck );
}

function fctCheckGallery( )
{
	var arrFieldsToCheck = new Array( "description", "date" );	
	
	return fctCheckListFilledField( arrFieldsToCheck );
}


function fctCheckCategory( )
{
	var arrFieldsToCheck = new Array( "description" );
	
	return fctCheckListFilledField( arrFieldsToCheck );
}

function fctCheckLANParty( )
{
	var arrFieldsToCheck = new Array( "description", "von", "bis" )
	
	return fctCheckListFilledField( arrFieldsToCheck );
}

function fctCheckNews( )
{
	var arrFieldsToCheck = new Array( "news_titel", "news_text" );
	
	return fctCheckListFilledField( arrFieldsToCheck );
}

function fctCheckLogin( )
{
	var arrFieldsToCheck = new Array( "username", "password" );
	
	return fctCheckListFilledField( arrFieldsToCheck );
}

function fctCheckKontaktMail( )
{
	var arrFieldsToCheck = new Array( "vorname", "name", "email", "inhalt", "captcha" );
	
	return fctCheckListFilledField( arrFieldsToCheck );
}