var incompetent_browser = document.all && navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('Opera') == -1;
var target = null;
function initMessageBox()
{
	target = document.getElementById('message');
	if (target !== null)
	{
		target.focus();
		if (typeof target.createTextRange != 'undefined')
		{
			//target.onkeydown = shortkey;
			target.onkeyup = storeCursor;
			target.onclick = storeCursor;
			target.onselect = storeCursor;
			target.onselect();
		}

	}
}
function storeCursor()
{
	this.cursorPos = document.selection.createRange().duplicate();
}

function AddSmile(text)
{
	if (target !== null)
	{
		if (typeof target.cursorPos != 'undefined')
		{
			var cursorPos = target.cursorPos;
			cursorPos.text = text;
		}
		else if (typeof target.selectionStart != 'undefined')
		{
			// remember scrollposition
			var scrollTop = target.scrollTop;

			var sStart = target.selectionStart;
			var sEnd = target.selectionEnd;

			target.value = target.value.substr(0, sStart) + text + target.value.substr(sEnd);
			var nStart = sStart == sEnd ? sStart + text.length : sStart;
			var nEnd = sStart + text.length;
			target.setSelectionRange(nStart, nEnd);

			target.scrollTop = scrollTop;
		}

		target.focus();
		if (typeof target.cursorPos != 'undefined') {target.onselect();}
	}
}

