size_text = "Textgrösse ändern [SIZE]";
font_text = "Schriftart ändern [FONT]";
color_text = "Schriftfarbe ändern [COLOR]";
b_text = "FETTEN Text einfügen [B]";
i_text = "KURSIVEN Text einfügen [I]";
u_text = "UNTERSTRICHENEN Text einfügen [U]";
url_text = "Internetadresse einfügen [URL]";
email_text = "eMail-Link einfügen [EMAIL]";
img_text = "Grafik einfügen [IMG]";
code_text = "Code einfügen [CODE]";
php_text = "PHP Code farbig hervorheben [PHP]";
list_text = "Geordnete Liste einfügen [LIST]";
quote_text = "Zitat einfügen [QUOTE]";
center_text = "Mittig ausgerichteten Text einfügen [CENTER]";
norm_text = "In den Normalen Modus wechseln";
enha_text = "Erweiterter Modus: erlaubt Tag-Verschachtelung";
closecurrent_text = "Aktuelles xpCode Tag schliessen";
closeall_text = "Alle offenen xpCode Tags schliessen";
enhanced_only_text = "<< Nur im erweiterten Modus benutzbar >>";
no_tags_text = "<< Keine offenen xpCode Tags gefunden. >>";
already_open_text = "<< Es gibt schon ein offenes Tag dieser Art >>";
tag_prompt = "Zu formatierenden Text eingeben:";
font_formatter_prompt = "Zu formatierenden Text eingeben mit der angegebenen";
link_text_prompt = "Beschreibungstext für den Link eingeben (optional)";
link_url_prompt = "Komplette URL für den Link eingeben";
link_email_prompt = "eMail-Adresse für den Link eingeben";
list_type_prompt = "Welcher Art soll die Liste sein? '1' eingeben, für eine numerierte Liste, 'a' eingeben, für eine alphabetische Liste oder leer lassen, für eine ungeordnete Liste.";
list_item_prompt = "Einen Listen Eintrag eingeben.\nFeld leer lassen oder 'Cancel' drücken, um die Listenerstellung zu beenden.";

tags = new Array();

function closetag(theform) {
	if (normalmode(theform))
		stat('enhanced_only');
	else
		if (tags[0]) {
			theform.text.value += "[/"+ arraypop(tags) +"]";
			}
		else {
			stat('no_tags');
			}
	theform.text.focus();
}

function closeall(theform) {
	if (normalmode(theform))
		stat('enhanced_only');
	else {
		if (tags[0]) {
			while (tags[0]) {
				theform.text.value += "[/"+ arraypop(tags) +"]";
				}
			theform.text.value += " ";
			}
		else {
			stat('no_tags');
			}
		}
	theform.text.focus();
}

function xpcode(theform,xpcode,prompttext) {
	if ((normalmode(theform)) || (xpcode=="IMG")) {
		inserttext = prompt(tag_prompt+"\n["+xpcode+"]xxx[/"+xpcode+"]",prompttext);
		if ((inserttext != null) && (inserttext != ""))
			theform.text.value += "["+xpcode+"]"+inserttext+"[/"+xpcode+"] ";
		}
	else {
		donotinsert = false;
		for (i = 0; i < tags.length; i++) {
			if (tags[i] == xpcode)
				donotinsert = true;
			}
		if (donotinsert)
			stat("already_open");
		else {
			theform.text.value += "["+xpcode+"]";
			arraypush(tags,xpcode);
			}
		}
	theform.text.focus();
}

function fontformat(theform,thevalue,thetype) {
	if (normalmode(theform)) {
		if (thevalue != 0) {
			inserttext = prompt(font_formatter_prompt+" "+thetype,"");
			if ((inserttext != null) && (inserttext != ""))
				theform.text.value += "["+thetype+"="+thevalue+"]"+inserttext+"[/"+thetype+"] ";
			}
		}
	else {
		theform.text.value += "["+thetype+"="+thevalue+"]";
		arraypush(tags,thetype);
		}
	theform.text.focus();
}

function namedlink(theform,thetype) {
	linktext = prompt(link_text_prompt,"");
		var prompttext;
		if (thetype == "URL") {
			prompt_text = link_url_prompt;
			prompt_contents = "http://";
			}
		else {
			prompt_text = link_email_prompt;
			prompt_contents = "";
			}
	linkurl = prompt(prompt_text,prompt_contents);
	if ((linkurl != null) && (linkurl != "")) {
		if ((linktext != null) && (linktext != ""))
			theform.text.value += "["+thetype+"="+linkurl+"]"+linktext+"[/"+thetype+"] ";
		else
			theform.text.value += "["+thetype+"]"+linkurl+"[/"+thetype+"] ";
		}
	theform.text.focus();
}

function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

function arraypush(thearray,value) {
	thearraysize = getarraysize(thearray);
	thearray[thearraysize] = value;
}

function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function setmode(modevalue) {
	document.cookie = "xpcodemode="+modevalue+"; path=/; expires=Wed, 1 Jan 2020 00:00:00 GMT;";
}

function smiliemode(modevalue) {
	document.cookie = "xpsmiliemode="+modevalue+"; path=/; expires=Wed, 1 Jan 2020 00:00:00 GMT;";
}

function normalmode(theform) {
	if (theform.mode[0].checked) return true;
	else return false;
}

function stat(thevalue) {
	document.xpform.status.value = eval(thevalue+"_text");
}

function dolist(theform) {
	listtype = prompt(list_type_prompt, "");
	if ((listtype == "a") || (listtype == "1")) {
		thelist = "[list="+listtype+"]\n";
		listend = "[/list="+listtype+"] ";
		}
	else {
		thelist = "[list]\n";
		listend = "[/list] ";
		}
	listentry = "initial";
	while ((listentry != "") && (listentry != null)) {
		listentry = prompt(list_item_prompt, "");
		if ((listentry != "") && (listentry != null))
			thelist = thelist+"[*]"+listentry+"\n";
		}
	theform.text.value += thelist+listend;
	theform.text.focus();
}

function smilie(thesmilie) {
	opener.document.xpform.text.value += thesmilie+" ";
	opener.document.xpform.text.focus();
}

function smilie2(thesmilie) {
	document.xpform.text.value += thesmilie+" ";
	document.xpform.text.focus();
}

function laenge(theform,maxlength) {
	alert("Dein Beitrag hat "+theform.text.value.length+" Zeichen.\nMaximale Anzahl der Zeichen beträgt "+maxlength+" Zeichen.");
}

function smilies(boardid)	{
  window.open("showsmilies.php?boardid="+boardid+"","SmilieLegende","Toolbar=no,resizeable=yes,scrollbars=yes,width=320,height=500");
}
function themenbox(boardid)	{
  window.open("themenbox.php?boardid="+boardid+"","Themenbox","Toolbar=no,resizeable=yes,scrollbars=yes,width=250,height=300");
}
function buddy(boardid)	{
  window.open("buddylist.php?boardid="+boardid+"","Buddyliste","Toolbar=no,resizeable=yes,scrollbars=yes,width=250,height=300");
}
function showxpcode(boardid)	{
  window.open("showcodes.php?boardid="+boardid+"","xpCode","Toolbar=no,resizeable=yes,scrollbars=yes,width=500,height=500");
}
function confirmLink(theLink, theMSG)
{
    if (typeof(window.opera) != 'undefined') {
        return true;
    }
    var is_confirmed = confirm(theMSG);
    return is_confirmed;
}
function CheckAll() {
	for (var i=0;i<document.form.elements.length;i++) {
		var e = document.form.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox')) {
			e.checked = document.form.allbox.checked;
		}
	}
}
function CheckCheckAll() {
	var TotalBoxes = 0;
	var TotalOn = 0;
	for (var i=0;i<document.form.elements.length;i++) {
		var e = document.form.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox')) {
			TotalBoxes++;
			if (e.checked) {
				TotalOn++;
			}
		}
	}
	if (TotalBoxes==TotalOn) {
		document.form.allbox.checked=true;
	} else {
		document.form.allbox.checked=false;
	}
}

function logexit()
{
	var theUrl = "http://www.xpbulletin.de/exit.php?ref="+escape(document.referrer)+"&location="+escape(document.location);
	var clickImage = new Image();
	clickImage.src = theUrl;
}

function toggle(layer) 
{
	var div = document.getElementById(layer);
	var img = document.getElementById(layer+'-img')
	if (div.style.display == 'none') 
	{
		document.cookie = "xp_collapse-"+layer+"=1; path=/; expires=Wed, 1 Jan 2020 00:00:00 GMT;";
		div.style.display = '';
		img.src = 'gfx/up.gif';
	} else {
		document.cookie = "xp_collapse-"+layer+"=; path=/; expires=Fri, 1 Jan 1999 00:00:00 GMT;";
		div.style.display = 'none';
		img.src = 'gfx/down.gif';
	}
}
