function set(text) {
	text = ' ' + text + ' ';
	if (document.p2form.nachricht.createTextRange && document.p2form.nachricht.caretPos) {
		var caretPos = document.p2form.nachricht.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.p2form.nachricht.focus();
	} else {
		document.p2form.nachricht.value  += text;
		document.p2form.nachricht.focus();
	}
}

function set_bb(aTag,eTag) {
	var myfeld = document.p2form.nachricht;
	myfeld.focus();
	if(typeof document.selection != 'undefined') {
		/* Einfügen des Formatierungscodes */
		var range = document.selection.createRange();
		var insText = range.text;
		range.text = aTag + insText + eTag;
		/* Anpassen der Cursorposition */
		range = document.selection.createRange();
		if (insText.length == 0) {
			range.move('character', -eTag.length);
		} else {
			range.moveStart('character', aTag.length + insText.length + eTag.length);
		}
		range.select();
	}
	/* für neuere auf Gecko basierende Browser */
else if(typeof myfeld.selectionStart != 'undefined')
{
	/* Einfügen des Formatierungscodes */
	var start = myfeld.selectionStart;
	var end = myfeld.selectionEnd;
	var insText = myfeld.value.substring(start, end);
	myfeld.value = myfeld.value.substr(0, start) + aTag + insText + eTag + myfeld.value.substr(end);
	/* Anpassen der Cursorposition */
	var pos;
	if (insText.length == 0) {
		pos = start + aTag.length;
	} else {
		pos = start + aTag.length + insText.length + eTag.length;
	}
	myfeld.selectionStart = pos;
	myfeld.selectionEnd = pos;
}

}
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function select_user(username) {

	opener.document.p2form.user.value = username;
	self.close();
}
var pm_status = false;
function pm_check() {
	u = document.pm.elements.length;
	if (pm_status == true) pm_status = false;
	else pm_status = true;
	for(i=0;i<=u;i++) {
		if (document.pm.elements[i] && document.pm.elements[i].name == "pmid[]") document.pm.elements[i].checked = pm_status;
	}
}
function goto2(){
	var auswahl, id;
	auswahl=document.gotoform.gotochoice.selectedIndex;
	id=document.gotoform.gotochoice.options[auswahl].value;
	if(id=="")
	{
		document.gotoform.submit.disabled=true;
		return false;
	}  else
		{
			document.gotoform.submit.disabled=false;
			location.href=id;
		}
	}

	function check_reply() {
		if (document.p2form.nachricht.value == "" || document.p2form.topic.value == "") {
			alert("Bitte füllen sie alle benötigten Felder aus!");
			return false;
		}

	else {
		return true;

	}


}

function check_split() {
	var zahl = document.form.thread_name.value;
	var zahl2 = Number(zahl);
	var thread_typ = document.form.thread_typ[1].checked;
	if(thread_typ == true && (zahl != zahl2 || !zahl)) {
		alert('Bitte geben sie eine Zahl an!!');
		return false;

	}
else return true;
}

function check_fusion() {
	var zahl = document.form.thread_fusion_id.value;
	var zahl2 = Number(zahl);
	if(zahl != zahl2 || !zahl) {
		alert('Bitte geben sie eine Zahl an!!');
		return false;

	}
else return true;
}

function check_formailer() {
	if (document.formmailer.betreff.value == "" || document.formmailer.nachricht.value == "") {
		alert("Bitte füllen sie Betreff und Nachricht Feld aus!");
		return false;
	}
else {
	return true;
}
}


var status = "";
function check_notify() {
	u = document.notify.elements.length;
	if (status == true) status = false;
else status = true;
for(i=0;i<u;i++) {
	if (document.notify.elements[i].name == "thread[]") document.notify.elements[i].checked = status;
}
}



function foobar() { alert(document.poll.answer.value); }
function hinzufuegen() {
	NeuerEintrag = new Option(document.poll.answer.value,document.poll.answer.value,false,false);
	if (document.poll.answer.value != "") {
		document.poll.votes.options[document.poll.votes.length] = NeuerEintrag;
		document.poll.answer.value = "";
		ids[ids.length] = "0";
	}
	document.poll.answer.focus();
}


function aendern() {
	NeuerEintrag = new Option(document.poll.answer.value,document.poll.answer.value,false,false);
	if (document.poll.answer.value != "") {
		document.poll.votes.options[document.poll.votes.selectedIndex] = NeuerEintrag;
		document.poll.answer.value = "";
	}
	document.poll.answer.focus();
}


function loeschen() {
	if (document.poll.votes.selectedIndex > -1) {
		var id2 = new Array();
		if (document.poll.votes.selectedIndex > 1) {
			id2 = ids.slice(0,document.poll.votes.selectedIndex);
			//alert(id2.join(" "));
		}
		ids = id2.concat(ids.slice(document.poll.votes.selectedIndex+1,ids.length));
		document.poll.votes.options[document.poll.votes.selectedIndex] = null;
		document.poll.answer.value = "";
	}
	document.poll.answer.focus();
}


function votesubmit() {
	if(document.poll.votes.length < 2) alert('Sie benötigen mindestens 2 Antwortmöglichkeiten!');
	else if(document.poll.frage.value == '') alert('Sie müssen eine Frage mit angeben!');
	else {
		for(i=0;i<document.poll.votes.length;i++) {
			if(document.poll.votes.options[i] != "") document.poll.pollanswers.value = document.poll.pollanswers.value + document.poll.votes.options[i].text + '%|%';
		}
		//alert(ids.join(" ")+' '+ids.length);
		document.poll.pollids.value = ids.join(",");
		document.poll.submit();
	}
}
function selectvote() {
	if(document.poll.votes.length > 0) {
		document.poll.answer.value=document.poll.votes.options[document.poll.votes.selectedIndex].text;
		document.poll.answer.focus();
		}
	else document.poll.answer.focus();
	}