// ubb codes
var prompttext = new Array();
	prompttext['b'] = 'Vul dikgedrukte tekst in';
	prompttext['i'] = 'Vul schuingedrukte tekst in';
	prompttext['u'] = 'Vul onderstreepte tekst in';
	prompttext['larial'] = 'Vul tekst in voor lettertype Arial';
	prompttext['ltahoma'] = 'Vul tekst in voor lettertype Tahoma';
	prompttext['ltrebuchet'] = 'Vul tekst in voor lettertype Trebuchet';
	prompttext['ltnr'] = 'Vul tekst in voor lettertype Times New Roman';

var target = null;

function getTarget(el) {
	target = (document.getElementById) ? document.getElementById(el) : 0;
}

function storeCursor(el) {
	if (document.all && el.createTextRange) el.cursorPos = document.selection.createRange().duplicate();
}

function putStr(text) {
	if (target) {
		if (document.all && target.cursorPos) {
			target.cursorPos.text = text;
		} else if (typeof(target.selectionStart) != 'undefined') {
			var sStart = target.selectionStart;
			var sEnd = target.selectionEnd;
			target.value = target.value.substr(0, sStart) + text + target.value.substr(sEnd, target.value.length);
			target.selectionStart = (sStart == sEnd) ? sStart + text.length : sStart;
			target.selectionEnd = sStart + text.length;
		} else {
			target.value += text;
		}
		target.focus();
		storeCursor(target);
	}
}

function ubbApply(style) {
	if (target) {
		var selectedtext = '';

		if (document.all && target.cursorPos) {
			selectedtext = target.cursorPos.text;
		} else if (typeof(target.selectionStart) != 'undefined') {
			selectedtext = target.value.substr(target.selectionStart, target.selectionEnd - target.selectionStart);
		}

		if (!selectedtext) {
			selectedtext = prompt(prompttext[style], '');
		}

		if (!selectedtext) {
			target.focus();
			return;
		}

		if (style == 'url=') {
			var description = prompt(prompttext['urld'], '');
			if (!description) {
				target.focus();
				return;
			}
			selectedtext = '[url='+selectedtext+']'+description+'[/url]';
		} else {
			selectedtext = '['+style+']'+selectedtext+'[/'+style+'] ';
		}

		putStr(selectedtext);
	} 
}
