function diCodes(obj_id)
{
  this.obj = {
    id: obj_id,
    e: _ge(obj_id)
  };

  this.reset_size_select = function()
  {
    _ge('dic_size_sel').selectedIndex = 0;
  }

  this.action = function(which, value)
  {
    var x1 = this.obj.e.selectionStart;
    var x2 = this.obj.e.selectionEnd;
    var len = x2 - x1;

    var s_prefix = this.obj.e.value.substr(0, x1);
    var s = this.obj.e.value.substr(x1, len);
    var s_suffix = this.obj.e.value.substr(x2);

    var code, code2, sel_diff;

    switch (which)
    {
      case 'b':
      case 'i':
      case 'u':
        code = which;
        break;

      case 'size':
      case 'align':
        code = which+'='+value.value;
        code2 = which;
        break;
    }

    if (!code2) code2 = code;

    if (
        (which == 'size' || which == 'align') &&
        s.substr(0, which.length + 1) == '['+which+'' &&
        s.substr(s.length - (which.length + 3), (which.length + 2)) == '[/'+which+''
       )
    {
      s = s.substr(which.length + 4, s.length - (which.length + 3) - (which.length + 4));
      s = '['+code+']'+s+'[/'+code2+']';
      sel_diff = 0;
    }
    else if (
        s.substr(0, code.length + 2) == '['+code+']' &&
        s.substr(s.length - (code2.length + 3)) == '[/'+code2+']'
       )
    {
      s = s.substr(code.length + 2, s.length - (code2.length + 3) - (code.length + 2));
      sel_diff = 0;
    }
    else
    {
      s = '['+code+']'+s+'[/'+code2+']';
      sel_diff = code.length + 2;;
    }

    this.obj.e.value = s_prefix + s + s_suffix;
    this.obj.e.selectionStart = x1 + sel_diff;
    this.obj.e.selectionEnd = this.obj.e.selectionStart;
    this.obj.e.focus();
  }

  this.cut = function()
  {
    var t = document.selection.createRange();
    t.execCommand("Cut");
  }

  this.copy = function()
  {
    var t = document.selection.createRange();
    t.execCommand("Copy");
  }

  this.paste = function()
  {
    this.obj.e.focus();

    var t = this.obj.e.createTextRange();
    t.execCommand("Paste");
  }
}
