function renderRichTextButtons( item )
{
	document.write("<img alt=\"Geselecteerde tekst kopieren\" src=\"images/textAreaImages/ed_copy.gif\" onclick=\"copyTxt('" + item + "');\" />");
	document.write("<img alt=\"Geselecteerde tekst knippen\" src=\"images/textAreaImages/ed_cut.gif\" onclick=\"cutTxt('" + item + "');\" />");
	document.write("<img alt=\"tekst plakken\" src=\"images/textAreaImages/ed_paste.gif\" onclick=\"pasteTxt('" + item + "');\" />");
	document.write("<img alt=\"Geselecteerde tekst verwijderen\" src=\"images/textAreaImages/ed_delete.gif\" onclick=\"deleteTxt('" + item + "');\" />");
	document.write("<img alt=\"Geselecteerde tekst dikdrukken\" src=\"images/textAreaImages/ed_format_bold.gif\" onclick=\"AddTag('" + item + "', 'bold');\" />");
	document.write("<img alt=\"Geselecteerde tekst schuinzetten\" src=\"images/textAreaImages/ed_format_italic.gif\" onclick=\"AddTag('" + item + "', 'italic');\" />");
	document.write("<img alt=\"Geselecteerde tekst onderstrepen\" src=\"images/textAreaImages/ed_format_underline.gif\" onclick=\"AddTag('" + item + "', 'underline');\" />");
//	document.write("<img alt=\"Plaatje toevoegen\" src=\"images/textAreaImages/ed_image.gif\" onclick=\"AddTag('" + item + "', 'img');\" />");
	document.write("<img alt=\"Link toevoegen\" src=\"images/textAreaImages/ed_link.gif\" onclick=\"AddTag('" + item + "', 'url');\" />");
//	document.write("<img alt=\"Lijstitem toevoegen\" src=\"images/textAreaImages/ed_list_num.gif\" onclick=\"AddTag('" + item + "', 'listbullet');\" />");
	document.write("<br />");
}

function copyTxt( item )
{
	var selectedText = document.selection;
	if (selectedText.type == 'Text')
	{
		var CopiedTxt = selectedText.createRange();
		CopiedTxt.execCommand("Copy");
	}
}

function cutTxt( item )
{
	var selectedText = document.selection;
	if (selectedText.type == 'Text')
	{
		var CopiedTxt = selectedText.createRange();
		CopiedTxt.execCommand("Cut");
	}
}

function deleteTxt( item )
{
	var selectedText = document.selection;
	if (selectedText.type == 'Text')
	{
		var CopiedTxt = selectedText.createRange();
		CopiedTxt.execCommand("Delete");
	}
}

function pasteTxt( item )
{ 
   document.all[item].focus();

   PastedText = document.all[item].createTextRange();

   txt = PastedText.execCommand("Paste");
   
   document.all[item].value += txt;
} 

function $$() {
	var elements = new Array();
	for (var il = 0; il < arguments.length; il++) {
		var element = arguments[il];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function shortkey(e)
{
	if (!e) {e = event;}

	var akey = 0;
	if (e.KeyCode) {key = e.KeyCode;}
	else if (e.which) {akey = e.which - 32;}

	if (e.ctrlKey && !e.shiftKey)
	{
		switch (akey)
		{
			case 66:
				putExt('bold');
				return cancelEvent(e);
			case 73:
				putExt('italic');
				return cancelEvent(e);
			case 83:
				putExt('strike');
				return cancelEvent(e);
			case 85:
				putExt('underline');
				return cancelEvent(e);
		}
	}

	return true;
}

function storeCursor()
{
	this.cursorPos = document.selection.createRange().duplicate();
}

function AddTag(item, type)
{
	atarget = $$(item);
	if (atarget !== null)
	{
		atarget.focus();
		if (typeof atarget.createTextRange != 'undefined')
		{
			atarget.onkeydown = shortkey;
			atarget.onkeyup = storeCursor;
			atarget.onclick = storeCursor;
			atarget.onselect = storeCursor;
			atarget.onselect();
		}
		else
		{
			atarget.onkeypress = shortkey;
		}
	}
	
	if (atarget !== null)
	{
		if (typeof atarget.cursorPos != 'undefined')
		{
			var cursorPos = atarget.cursorPos;
			if (type != 'plain') {text = cursorPos.text;}
			cursorPos.text = det_replace(type, text);
		}
		else if (typeof atarget.selectionStart != 'undefined')
		{
			// remember scrollposition
			var scrollTop = atarget.scrollTop;

			var sStart = atarget.selectionStart;
			var sEnd = atarget.selectionEnd;
			if (type != 'plain') {text = atarget.value.substring(sStart, sEnd);}
			text = det_replace(type, text);
			atarget.value = atarget.value.substr(0, sStart) + text + atarget.value.substr(sEnd);
			var nStart = sStart == sEnd ? sStart + text.length : sStart;
			var nEnd = sStart + text.length;
			atarget.setSelectionRange(nStart, nEnd);

			// reset scrollposition
			atarget.scrollTop = scrollTop;
		}
		else
		{
			if (type != 'plain') {text = '';}
			atarget.value += det_replace(type, text);
		}

		atarget.focus();
		if (typeof atarget.cursorPos != 'undefined') {atarget.onselect();}
	}
}

function det_replace(type, text)
{
	var aval = '';
	switch (type)
	{
		case 'plain':
			break;
		case 'bold':
			text = '[b]'+text+'[/b]';
			break;
		case 'italic':
			text = '[i]'+text+'[/i]';
			break;
		case 'underline':
			text = '[u]'+text+'[/u]';
			break;
		case 'strike':
			text = '[s]'+text+'[/s]';
			break;
		case 'sub':
			text = '[sub]'+text+'[/sub]';
			break;
		case 'sup':
			text = '[sup]'+text+'[/sup]';
			break;
		case 'spoiler':
			text = '[spoiler]'+text+'[/spoiler]';
			break;
		case 'code':
			text = '[code]'+text+'[/code]';
			break;
		case 'php':
			text = '[php]'+text+'[/php]';
			break;
		case 'quote':
			text = '[quote]'+text+'[/quote]';
			break;
		case 'me':
			text = '[me='+thisuser+']'+text+'[/me]';
			break;
		case 'listbullet':
			//text = '\r\n[*]'+(text.split(/\r?\n/).join('\r\n[*]'))+'\r\n';
			text = '\r\n[*]'+(text.split(/\r?\n/).join('\r\n[*]'));
			break;
		case 'url':
			if (/^(http:\/\/|www\.)/i.test(text))
			{
				aval = prompt('Voer omschrijving in:', text);
				if (aval !== null && aval !== '') {text = '[url='+text+']'+aval+'[/url]';}
			}
			else
			{
				aval = prompt('Voer de URL in:','http:\/\/');
				if (aval !== null && aval != 'http:\/\/')
				{
					if (text === '') {text = '[url]'+aval+'[/url]';}
					else {text = '[url='+aval+']'+text+'[/url]';}
				}
			}
			break;
		case 'img':
			if (text === '')
			{
				aval = prompt('Voer de URL in:','http:\/\/');
				if (aval !== null && aval != 'http:\/\/') {text = '[img]'+aval+'[/img]';}
			}
			else
			{
				text = '[img]'+text+'[/img]';
			}
			break;
		case 'quotesplits':
			text += '[/quote]\r\n[quote]';
			break;
	}

	return text;
}
