function LinkFinder() {
  this.Kategorie = '';
  this.obj = false;
  this.iFrame = false;

  this.show = function(p, s_Kategorie) {
    this.obj = document.getElementById('LinkFinder.div');
    this.iFrame = document.getElementById('LinkFinder.iFrame');
    this.input = document.getElementById('LinkFinder.input');
    this.target = document.getElementById('LinkFinder.target.' + s_Kategorie);
    var redraw = s_Kategorie != this.Kategorie;
    this.p = p;
    if (this.obj && this.p) {
      if (this.target) {
        this.target.appendChild(this.obj);
        redraw && this.Kategorie != '' ? document.getElementById('LinkFinder.target.' + this.Kategorie).style.display='none' : 0;
        this.target.style.display = '';
      } else {
        redraw ? this.p.parentNode.insertBefore(this.obj, this.p.nextSibling.nextSibling) : 0;
      }
      this.obj.style.display = '';
      this.Kategorie = s_Kategorie;
      var p = document.LinkFinderSearch.hdr;
      p ? p.value = this.Kategorie : 0;
      this.input.value = '';
      this.input.focus();
      this.iFrame.style.display = 'none';
      this.iFrame.src = 'about:blank';
    }
  }
  
  this.hide = function() {
    this.obj ? this.obj.style.display = 'none' : 0;
    if (this.iFrame) {
      this.iFrame.src = 'about:blank';
      this.iFrame.style.display = 'none';
    }
  }
  
  this.add_item = function(s_Kategorie, s_Text) {
    var p = document.getElementById('LinkFinder.' + s_Kategorie);
    if (p) {
      var arr_items = p.value.split(';');
      var b_add = true;
      for (var i in arr_items) {
        var s_item = trim(arr_items[i]);
        if (s_item == s_Text) {
          b_add = false;
          break;
        }
      }
      s_add = p.value != '' ? '; ' + s_Text : s_Text;
      b_add ? p.value = p.value + s_add : 0;
    } 
  }
  
  this.submit = function() {
    document.LinkFinderSearch.submit();
    this.iFrame ? this.iFrame.style.display = '' : 0;
  }

  function trim(s) {
    while (s.substring(0,1) == ' ')
      s = s.substring(1,s.length);
    while (s.substring(s.length-1,s.length) == ' ')
      s = s.substring(0,s.length-1);
    return s;
  }
}

var myLinkFinder = new LinkFinder();

