editor = "none";

function toggle_info(id)
{
  block = "block_" + id;
  exp = "exp_" + id;
  val = document.getElementById(block).style.display;
  if (val == "none")
  {
    document.getElementById(block).style.display = "block";
    document.getElementById(exp).innerHTML = "-";
  }
  else
  {
    document.getElementById(block).style.display = "none";
    document.getElementById(exp).innerHTML = "+";
  }  
}

function toggle_obj(obj_ex, obj_id)
{
  var exp_str = obj_ex.innerHTML.substring(0, 1);
  var got_exp = (exp_str == '+' || exp_str == '-');
  var obj_info = document.getElementById(obj_id);
  if (obj_info.style.display == "block")
  {
    obj_info.style.display = "none";
    if (got_exp)
      obj_ex.innerHTML = '+' + obj_ex.innerHTML.substring(1);
  }
  else
  {
    obj_info.style.display = "block";
    if (got_exp)
      obj_ex.innerHTML = '-' + obj_ex.innerHTML.substring(1);
  }
}

function editor_append_flag(flag)
{
  if (editor == "none") return;
  edit = document.getElementById(editor);
  if (edit == null) return;
  edit.focus();
  pos = document.selection.createRange();
  //str = edit.innerText;
  pos.text = "[" + flag + "]";
}

function editor_append(str)
{
  if (editor == "none") return;
  edit = document.getElementById(editor);
  if (edit == null) return;
  //str0 = edit.innerText;
  edit.innerText += str;
}

function editor_apply(edit)
{
  editor = edit;
}

function editor_paste(str)
{
  if (editor == "none") return;
  edit = document.getElementById(editor);
  if (edit == null) return;
  edit.focus();
  pos = document.selection.createRange();
  pos.text = str;
}

var lastMenu = null;
var lastTicker = null;

function show_menu(prnt, base, mname)
{
  if ((mn = document.getElementById(mname)) == null)
    return;
  if (prnt != null)
    prnt.style.backgroundImage = "url(appi3/h" + base + "_h.jpg)";
  mn.style.display = 'block';
  if (lastMenu != null)
  {
    if (lastTicker != null)
    {
      clearTimeout(lastTicker);
      lastTicker = null;
    }
    if (lastMenu != mn)
      lastMenu.style.display = 'none';
    lastMenu = null;
  }
  apply_position(mn, prnt);
}

function refresh_menu()
{
  if (lastMenu != null)
  {
    if (lastTicker != null)
    {
      clearTimeout(lastTicker);
      lastTicker = null;
    }
    lastMenu = null;
  }
}

function hide_menu(prnt, base, mname)
{
  if ((mn = document.getElementById(mname)) == null)
    return;
  if (prnt != null)
    prnt.style.backgroundImage = "url(appi3/h" + base + ".jpg)";
  lastMenu = mn;
  lastTicker = setTimeout(hide_menu_timeout, 300);
}

function hide_menu_timeout(e)
{
  if (lastMenu != null)
    lastMenu.style.display = 'none';
  lastTicker = null;
}

function highlight_menu(menu, do_light)
{
  if (menu == null)
    return;
  if (do_light)
    menu.style.backgroundImage = "url(appi3/hmenu_subitem_h.jpg)";
  else
    menu.style.backgroundImage = "url(appi3/hmenu_subitem.jpg)";
}

function apply_position(menu, obj)
{
  if (menu == null || obj == null)
    return;
  leftpos = obj.offsetLeft;
  toppos = obj.offsetTop + obj.offsetHeight + 1;// + obj.offsetHeight + 4;
  parentObj = obj;
  while ((parentObj = parentObj.offsetParent) != null)
  {
    toppos  += parentObj.offsetTop;
    leftpos += parentObj.offsetLeft;
  }
  menu.style.left = leftpos;
  menu.style.top  = toppos;
  menu.style.width = obj.offsetWidth;
}
