
function fett() {
	var textfield = document.getElementsByTagName('textarea')[0];
	if (textfield.selectionStart || textfield.selectionStart == '0') {
		textfield.focus();
		var startPos = textfield.selectionStart;		var endPos = textfield.selectionEnd;
		strSelection = "[b]" + textfield.value.substring(startPos, endPos)+ "[/b]";
		textfield.value = textfield.value.substring(0, startPos) + strSelection + textfield.value.substring(endPos, textfield.value.length);
	}
	else if (document.selection && document.selection.createRange().text != '') {document.selection.createRange().text = "[b]" + document.selection.createRange().text + "[/b]";}
	else {
		if (document.getElementById('fett').style.fontWeight=="bolder") {	textfield.value += "[b]";		document.getElementById('fett').style.fontWeight="normal";}
		else {																textfield.value += "[/b]";		document.getElementById('fett').style.fontWeight="bolder";}
	}
}
function italic() {
	var textfield = document.getElementsByTagName('textarea')[0];
	if (textfield.selectionStart || textfield.selectionStart == '0') {
		textfield.focus();
		var startPos = textfield.selectionStart;		var endPos = textfield.selectionEnd;
		strSelection = "[i]" + textfield.value.substring(startPos, endPos)+ "[/i]";
		textfield.value = textfield.value.substring(0, startPos) + strSelection + textfield.value.substring(endPos, textfield.value.length);
	}
	else if (document.selection && document.selection.createRange().text != '') {document.selection.createRange().text = "[i]" + document.selection.createRange().text + "[/i]";}
	else {
		if (document.getElementById('italic').style.fontStyle=="italic") {	textfield.value += "[i]";		document.getElementById('italic').style.fontStyle="normal";}
		else {																textfield.value += "[/i]";		document.getElementById('italic').style.fontStyle="italic";}
	}
}
function uline() {
	var textfield = document.getElementsByTagName('textarea')[0];
	if (textfield.selectionStart || textfield.selectionStart == '0') {
		textfield.focus();	var startPos = textfield.selectionStart;	var endPos = textfield.selectionEnd;
		strSelection = "[u]" + textfield.value.substring(startPos, endPos)+ "[/u]";
		textfield.value = textfield.value.substring(0, startPos) + strSelection + textfield.value.substring(endPos, textfield.value.length);
	}
	else 
	if (document.selection && document.selection.createRange().text != '') {
		document.selection.createRange().text = "[u]" + document.selection.createRange().text + "[/u]";
	}
	else {
		if (document.getElementById('uline')) {	textfield.value += "[u]";	document.getElementById('uline').setAttribute('id','line');	document.getElementById('line').className = 'noline';}
		else {									textfield.value += "[/u]";	document.getElementById('line').className = 'uline';		document.getElementById('line').setAttribute('id','uline');
		}
	}
}
