var incompetent_browser = document.all && navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('Opera') == -1;
var atarget = null;
function initMessageBox(isqr)
{
	atarget = $$('message');
	if (atarget !== null)
	{
		if (isqr != '1') { atarget.focus(); }
		if (typeof atarget.createTextRange != 'undefined')
		{

			atarget.onkeyup = storeCursor;
			atarget.onclick = storeCursor;
			atarget.onselect = storeCursor;
			atarget.onselect();
		}
	}
}
function storeCursor()
{
	this.cursorPos = document.selection.createRange().duplicate();
}

function det_replace(type, text)
{
	var aval = '';
	switch (type)
	{
		case 'plain':
			break;

	}

	return text;
}

function AddSmile(text)
{
	putExt('plain', text);
}
function putExt(type, text)
{
	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 $$() {
	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;
}

