function refocus_msg()

{
 document.kbmsg.msg.focus();
}

function refocus_msg2()

{
 document.szadat.bemutatkozas.focus();
}

function savecaret_msg(obj)
{
  if (!document.all) return;

  if (obj.isTextEdit)
    obj.caretPos = document.selection.createRange();
}

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_()
{
  savecaret_msg(document.kbmsg.msg);
}

function insertcode_msg(code)
{
 if (isopera)
   with (document.kbmsg.msg)
     value += code;
 else
   instext_msg(document.kbmsg.msg,code);
 return true;
}

function insertcode_msg2(code)
{
 if (isopera)
   with (document.szadat.bemutatkozas)
     value += code;
 else
   instext_msg(document.szadat.bemutatkozas,code);
 return true;
}

function insertcode_msgopener(code)
{
 if (isopera)
   with (window.opener.document.kbmsg.msg)
     value += code;
 else
   instext_msg(opener.document.kbmsg.msg,code);
 return true;
}


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.kbmsg.msg;
 //obj.onselect = savecaret_msg_;
 //obj.onclick  = savecaret_msg_;
 //obj.onkeyup  = savecaret_msg_;
}
