function normalmode(theform) {
        return true;
        }

function setfocus(theform) {
        theform.focus();
        }

var selectedText = "";
AddTxt = "";

function getActiveText(msg) {
        selectedText = (document.all) ? document.selection.createRange().text : document.getSelection();if (msg.createTextRange) msg.caretPos = document.selection.createRange().duplicate();return true;
        }

function AddText(NewCode,theform) {
        if (theform.createTextRange && theform.caretPos) {
                var caretPos = theform.caretPos;caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
                } else theform.value+=NewCode

AddTxt = "";setfocus(theform);
}

function cmscode(theform,cmscode,prompttext) {
        setfocus(theform);
                if ((normalmode(theform)) || (cmscode=="IMG")) {
                if (selectedText) var dtext=selectedText;
                else var dtext=prompttext;
                {
                if (dtext) {} else {
                dtext = "";
                }
                AddTxt = "["+cmscode+"]"+dtext+"[/"+cmscode+"]";AddText(AddTxt,theform);
                }

                }
                setfocus(theform);
        }



function smile(theform,cmscode,prompttext) {

	        setfocus(theform);
                if ((normalmode(theform)) || (cmscode=="IMG")) {
                	if (selectedText) var dtext=selectedText;
	                else var dtext=prompttext;
                	{
        	        if (dtext) {} else {
                			dtext = "";
			                }
	                AddTxt =dtext+"\ "+cmscode+"\ ";AddText(AddTxt,theform);
        	        }
	        } else {
                        donotinsert = false;for (i = 0; i < tags.length; i++) {if (tags[i] == cmscode) donotinsert = true;}if (!donotinsert) {theform.value += "["+cmscode+"";arraypush(tags,cmscode);
                        }
                }
                setfocus(theform);
        }

function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart && myField.selectionStart != '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
} 

