function storeCaret (textEl)
{
	if (textEl.createTextRange)
		textEl.caretPos = document.selection.createRange().duplicate();
} // end fn

function insertUBB(textEl, text)
{
	$(textEl).focus();
	
	if ($(textEl).createTextRange && $(textEl).caretPos) {
		var caretPos = $(textEl).caretPos;
		caretPos.text =
			caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
			text + ' ' : text;
	} else {
		$(textEl).value  = $(textEl).value + text; // for non MSIE browsers just append it
	}

	return true;
}// fn




function DoSmilie(el, addSmilie)
{
	var revisedMessage;
	var currentMessage = $(el).value;
	revisedMessage = currentMessage+addSmilie;
	$(el).value=revisedMessage;
	$(el).focus();
	return;
}

function DoColor(color)
{

	insertAtCaret(document.f3.messageUBB, ' ' + "[color:" +color + "]  [/color]" + ' ' );
	document.f3.messageUBB.focus();
	return;

}

function promptUBB(messageField,action)
{
	if(action == "url")
	{
		var thisURL = prompt("Enter the complete URL for the link you wish to add.", "http://");
		if (thisURL == null) return;

		var thisTitle = prompt("Now enter the title of the webpage you wish to reference. For instance, if you are linking to the URL for Infopop, you might use the title Infopop Homepage.", "Web Page Title");
		if (thisTitle == null) return;

		insertUBB(messageField, ' ' + "[url=" + thisURL + "]" + thisTitle + "[/url]" + ' ');
	}

	if (action == "color") 
	{
	  var thisColor = prompt("Enter the font color you want to use. May be a color code such as #ff1123 or something like blue","");
	  if (thisColor == null) return;
	  insertUBB(messageField, ' ' + "[color:" + thisColor + "] [/color] ");
	}

	if (action == "email")
	{
		var thisEmail = prompt("Enter the complete email address that you wish to add.", "");
		if (thisEmail == null){return;}

		insertUBB(messageField, ' ' + "[email=" + thisEmail + "]" + thisEmail + "[/email]" + ' ' );
	}

	if (action == "bold")
	{
		var thisBold = prompt("Enter the text that you wish to make bold.", "");
		if (thisBold == null){return;}

		insertUBB(messageField, ' ' + "[b]" + thisBold + "[/b]" + ' ' );
	}

	if (action == "underline")
	{
		var thisUnderline = prompt("Enter the text that you wish to underline.", "");
		if (thisUnderline == null){return;}

		insertUBB(messageField, ' ' + "[u]" + thisUnderline + "[/u]" + ' ' );
	}

	if (action == "italics")
	{
		var thisItal = prompt("Enter the text that you wish to italicize.", "");
		if (thisItal == null){return;}

		insertUBB(messageField, ' ' + "[i]" + thisItal + "[/i]" + ' ' );
	}

	if (action == "image")
	{
		var thisImage = prompt("Enter the complete URL for the image you wish to display.", "http://");
		if (thisImage == null){return;}

		insertUBB(messageField, ' ' + "[image]" + thisImage + "[/image]" + ' ' );
	}

	if (action == "quote")
		insertUBB(messageField, ' ' + "[quote]  [/quote]" + ' ' );

	if (action == "code")
		insertUBB(messageField, ' ' + "[code]  [/code]" + ' ' );

	if (action == "liststart")
		insertUBB(messageField, ' ' + "[list]" + ' ' );

	if (action == "listend")
		insertUBB(messageField, ' ' + "[/list]" + ' ' );

	if (action == "listitem")
	{
		var thisItem = prompt("Enter the new list item. Note that each list group must be preceded by a List Start and the entire list group must end with a List End (in order to display properly).", "");

		if (thisItem == null){return;}

		insertUBB(messageField, ' ' + "[*]" + thisItem + '[/*] ' );
	}
	
	$(messageField).focus();
	return;
}