/*
 * Add bbcode to a message.
 */
function addCode(target, code)
{
	// A few arrays for checking tags.
	var openingTags    = new Array("[b]", "[i]", "[u]", "[url]", "[img]", "[quote]", "[code]");
	var closingTags    = new Array("[/b]", "[/i]", "[/u]", "[/url]", "[/img]", "[/quote]", "[/code]");
	var openTagTitles  = new Array("B", "I", "U", "URL", "IMG", "Quote", "Code");
	var closeTagTitles = new Array("B*", "I*", "U*", "URL*", "IMG*", "Quote*", "Code*");

	// Add the code to the end of the message.
	document.getElementById(target).value += code;

	// Figure out what was clicked so we can change the
	// value (text) of the button and the onclick event.
	for (var i = 0; i < openingTags.length; i++)
	{
		if (code == openingTags[i] || code == closingTags[i])
		{
			var tag = document.getElementById("bbcode_" + openTagTitles[i]);
			tag.value = tag.value == openTagTitles[i] ? closeTagTitles[i] : openTagTitles[i];
			if (tag.value == openTagTitles[i])
			{
				tag.onclick = function()
				{
					addCode("msg_area", openingTags[i]);
				}
			}
			else
			{
				tag.onclick = function()
				{
					addCode("msg_area", closingTags[i]);
				}
			}

			return;
		}
	}
}

/*
 *
 */
function addBuddy(source, target)
{
	document.getElementById(target).value = source;
}
function addEmoticon(source, target)
{
	document.getElementById(target).value += source;
	document.getElementById(target).focus();
}

function jsRefresh(str) 
{
	window.location = str;
}
