function insertcode_msg(objname,code) {
    if (isopera)
        with (eval("document."+objname)) value += code;
    else instext_msg(eval("document."+objname),code);
    refocus_msg();
}

function refocus_msg() {
    document.hozzaszolas_form.hozzaszolas.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.hozzaszolas_form.hozzaszolas);
}

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);
var obj1 = document.hozzaszolas_form;
if ( obj1 != null ) {
  var obj = obj1.hozzaszolas;
  obj.onselect = savecaret_msg_;
  obj.onclick  = savecaret_msg_;
  obj.onkeyup  = savecaret_msg_;
}
