function smiley(code) {
if (isopera)
with (document.shform.message)
value += code;
else
instext_msg(document.shform.message,code);
return true;
}

function refocus_msg() {
document.shform.message.focus();
}

function instext_msg(obj, txt) {
if (isie) {
if (!obj.isTextEdit) return;
if ( obj.caretPos )
obj.caretPos.text = txt;
else
obj.value = obj.value + txt;
}
else {
otext = obj.value; ss = obj.selectionStart;
obj.value = otext.substring(0,ss) + txt + otext.substring(ss,obj.value.length);
obj.selectionStart = ss + txt.length;
obj.selectionEnd = obj.selectionStart;
}
}

function savecaret_msg(obj) {
if (!document.all) return;
if (obj.isTextEdit)
obj.caretPos = document.selection.createRange();
}

function savecaret_msg_() {
savecaret_msg(document.shform.message);
}

function replaceSubstring_msg(text,expression,value) {
var exp = new RegExp(expression,'g');
return text.replace(exp,value);
}

function myquery_msg(promptcaption, defvalue) {
return window.prompt(promptcaption,defvalue);
}

function insertcodequery_msg(code, promptcaption, defvalue) {
x = window.prompt(promptcaption,defvalue);
if(!x) return false;
if (x!="undefined") {
code = replaceSubstring_msg(code,'%input%',x);
return insertcode_msg(code);
}
}


var isie = (document.all);
var isopera = (navigator.userAgent.indexOf('Opera')!=-1);
obj = document.shform.message;
obj.onselect = savecaret_msg_;
obj.onclick  = savecaret_msg_;
obj.onkeyup  = savecaret_msg_;
