var selectedMsgBody="";

function x () {
	return;
}

function DoSmilie(smileicon) {

	var addSmilie;
	var revisedMessage;
	var currentMessage = document.forms[0].msgBody.value;

	if (smileicon == "smile") { addSmilie =" :) "; }
	if (smileicon == "frown") { addSmilie =" :( "; }
	if (smileicon == "redface") { addSmilie =" :o "; }
	if (smileicon == "wink") { addSmilie =" ;) "; }
	if (smileicon == "biggrin") { addSmilie =" :D "; }
	if (smileicon == " :p ") { addSmilie =" :p "; }
	if (smileicon == " ;p ") { addSmilie =" ;p "; }
	if (smileicon == " :kiss: ") { addSmilie =" :kiss: "; }
	if (smileicon == " :cool: ") { addSmilie =" :cool: "; }
	if (smileicon == " :rolleyes: ") { addSmilie =" :rolleyes: "; }
	if (smileicon == " :approve: ") { addSmilie =" :approve: "; }
	if (smileicon == " :suspect: ") { addSmilie =" :suspect: "; }
	if (smileicon == " :evil: ") { addSmilie =" :evil: "; }
	if (smileicon == " :dead: ") { addSmilie =" :dead: "; }
	if (smileicon == " :mad: ") { addSmilie =" :mad: "; }
	if (smileicon == " :eek: ") { addSmilie =" :eek: "; }
	if (smileicon == " :confused: ") { addSmilie =" :confused: "; }
	if (smileicon == " :dead: ") { addSmilie =" :dead: "; }
	if (smileicon == " :monkey: ") { addSmilie =" :monkey: "; }
	if (smileicon == " :bounce: ") { addSmilie =" :bounce: "; }
	if (smileicon == " :hot: ") { addSmilie =" :hot: "; }
	if (smileicon == " :wave: ") { addSmilie =" :wave: "; }
	if (smileicon == " :knock: ") { addSmilie =" :knock: "; }
	if (smileicon == " :puke: ") { addSmilie =" :puke: "; }


//	revisedMessage = currentMessage+addSmilie;
//	document.forms[0].msgBody.value=revisedMessage;
//	document.forms[0].msgBody.focus();
//add to cursor pos instead of at the end
	AddText(selectedMsgBody + addSmilie);
	return;
}

function DoPrompt(action) {
	var revisedMessage;
	var currentMessage = document.forms[0].msgBody.value;
	
	if (action == "url") {
		var thisURL = prompt("Enter the complete URL for the link you wish to add.", "http://");
		var thisTitle = prompt("Now enter the title of the web page you wish to reference.  For instance, if you are linking to the URL for infopop, you might use the title Infopop Homepage", "web page");
		var urlUBBCode = "[URL="+thisURL+"]"+thisTitle+"[/URL]";
		revisedMessage = currentMessage+urlUBBCode;
		document.forms[0].msgBody.value=revisedMessage;
		document.forms[0].msgBody.focus();
		return;
	}

	if (action == "email") {
		var thisEmail = prompt("Enter the complete email address that you wish to add.", "");
		var emailUBBCode = "[EMAIL]"+thisEmail+"[/EMAIL]";
		revisedMessage = currentMessage+emailUBBCode;
		document.forms[0].msgBody.value=revisedMessage;
		document.forms[0].msgBody.focus();
		return;
	}

	if (action == "bold") {
		var boldText ="[B]" +  selectedMsgBody + "[/B]";
		AddText(boldText);
		return;
	}

	if (action == "italics") {
		var italicText ="[I]" +  selectedMsgBody + "[/I]";
		AddText(italicText);
		return;
	}

	if (action == "image") {
		var thisImage = prompt("Enter the complete URL for the image you wish to display.", "http://");
		var imageUBBCode = "[IMG]"+thisImage+"[/IMG]";
		revisedMessage = currentMessage+imageUBBCode;
		document.forms[0].msgBody.value=revisedMessage;
		document.forms[0].msgBody.focus();
		return;
	}

	if (action == "quote") {
		var quoteUBBCode = "[QUOTE]  [/QUOTE]";
		revisedMessage = currentMessage+quoteUBBCode;
		document.forms[0].msgBody.value=revisedMessage;
		document.forms[0].msgBody.focus();
		return;
	}

	if (action == "code") {
		var codeUBBCode = "[CODE]  [/CODE]";
		revisedMessage = currentMessage+codeUBBCode;
		document.forms[0].msgBody.value=revisedMessage;
		document.forms[0].msgBody.focus();
		return;
	}

	if (action == "liststart") {
		var liststartUBBCode = "[LIST]";
		revisedMessage = currentMessage+liststartUBBCode;
		document.forms[0].msgBody.value=revisedMessage;
		document.forms[0].msgBody.focus();
		return;
	}

	if (action == "listend") {
		var listendUBBCode = "[/LIST]";
		revisedMessage = currentMessage+listendUBBCode;
		document.forms[0].msgBody.value=revisedMessage;
		document.forms[0].msgBody.focus();
		return;
	}
	if (action == "listitem") {
		var thisItem = prompt("Enter the new list item.  Note that each list group must be preceeded by a List Start and the entire list group must end with a List End (in order to display properly).", "");
		var itemUBBCode = "[*]"+thisItem;
		revisedMessage = currentMessage+itemUBBCode;
		document.forms[0].msgBody.value=revisedMessage;
		document.forms[0].msgBody.focus();
		return;
	}
	if (action == "list"){
		var AddTxt;
		var ordered = false;
		
		var txt=prompt("Type of list\nEnter 'A' for alphabetical, '1' for numbered, Leave blank for bulleted.","");               
		while ((txt!="") && (txt!="A") && (txt!="a") && (txt!="1") && (txt!=null)) {
			txt=prompt("ERROR!\nThe only possible values for type of list are blank 'A' and '1'.","");               
		}
		if (txt!=null) {
			if (txt=="") {
				AddTxt="\r[list]\r\n";
			} else {
				AddTxt="\r[list="+txt+"]\r";
				if((txt=="A") ||(txt=="a") || (txt=="1"))
					ordered = true;
			} 
			txt="1";
			while ((txt!="") && (txt!=null)) {
				txt=prompt("List item\nLeave blank to end list",""); 
				if (txt!="") {             
					AddTxt+="[*]"+txt+"\r"; 
				}                   
			} 
			if (ordered)
				AddTxt+="[/olist]\r";
			else
				AddTxt+="[/list]\r";
			
			AddTxt = currentMessage + AddTxt;
			document.forms[0].msgBody.value=AddTxt;
			document.forms[0].msgBody.focus();
			return;
		}
	}
}


function bobo(t)
{
	getActiveText(t);
	alert(selectedMsgBody);
}

function getActiveText(selectedtext) { 
	selectedMsgBody = (document.all) ? document.selection.createRange().text : document.getSelection();
	if (selectedtext.createTextRange) {
		selectedtext.caretPos = document.selection.createRange().duplicate();
	}
	return true;
}



function AddText(NewCode) {
	if (document.REPLIER.msgBody.createTextRange && document.REPLIER.msgBody.caretPos) {
		var caretPos = document.REPLIER.msgBody.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
	} else {
		document.REPLIER.msgBody.value+=NewCode
	}
	setfocus();
}

function setfocus() {
	document.REPLIER.msgBody.focus();
}


