function smileyPopup()
{
	window.open('smilies.html','Smilies','width=600, height=270, resizable=no, menubar=no, scrollbars=no, status=no, toolbar=no');
}

function emoticon(text)
{
	var txtarea = document.gastenboek.bericht;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos)
	{
		if (baseHeight != txtarea.caretPos.boundingHeight) {
			txtarea.focus();
			storeCaret(txtarea);
		}
		
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	}
	else if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
	{
		mozInsert(txtarea, text, "");
		return;
	}
	else
	{
		txtarea.value  += text;
		txtarea.focus();
	}
}

function mozInsert(txtarea, openTag, closeTag)
{
	var scrollTop = ( typeof(txtarea.scrollTop) == 'number' ? txtarea.scrollTop : -1 );
	
	if (txtarea.selectionEnd > txtarea.value.length) { txtarea.selectionEnd = txtarea.value.length; }
	
	var startPos = txtarea.selectionStart; 
	var endPos = txtarea.selectionEnd+openTag.length; 
	
	txtarea.value=txtarea.value.slice(0,startPos)+openTag+txtarea.value.slice(startPos); 
	txtarea.value=txtarea.value.slice(0,endPos)+closeTag+txtarea.value.slice(endPos); 
	
	txtarea.selectionStart = startPos+openTag.length; 
	txtarea.selectionEnd = endPos; 
	txtarea.focus();
	
	if( scrollTop >= 0 ) { txtarea.scrollTop = scrollTop; }
}

// Insert at Claret position
function storeCaret(textEl)
{
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}
