//-- Browsercheck



function setOpacity(el, opacity)
{
	if (el && (!el.opacity || el.opacity != opacity))
	{
		el.opacity = opacity;
		if (el.filters)
		{
			if (el.filters.alpha)
			{
				el.filters.alpha.opacity = opacity * 100;
			}
			else
			{
				el.style.filter = 'alpha(opacity=' + (opacity * 100) + ')';
			}
		}
		else
		{
			el.style.opacity = opacity;
		}
	}
}

//-- Message box editing functions
var target = null;
function initMessageBox()
{
	target = document.getElementById('message');
	if (target)
	{
		target.focus();
		if (typeof target.createTextRange != 'undefined')
		{
			//target.onkeydown = shortkey;
			target.onkeyup = storeCursor;
			target.onclick = storeCursor;
			target.onselect = storeCursor;
			target.onselect();
		}
		else
		{
			//target.onkeypress = shortkey;
		}
	}
}

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

function det_replace(type, text)
{
	var val = '';
	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 'marque':
			text = '[m]'+text+'[/m]';
			break;
	}

	return text;
}

function putStr(text)
{
	putExt('plain', text);
}

function putExt(type, text)
{
	if (target)
	{
		if (typeof target.cursorPos != 'undefined')
		{
			var cursorPos = target.cursorPos;
			if (type != 'plain') text = cursorPos.text;
			cursorPos.text = det_replace(type, text);
		}
		else if (typeof target.selectionStart != 'undefined')
		{
			// remember scrollposition
			var scrollTop = target.scrollTop;

			var sStart = target.selectionStart;
			var sEnd = target.selectionEnd;
			if (type != 'plain') text = target.value.substring(sStart, sEnd);
			text = det_replace(type, text);
			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);

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

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

