/**
 *  label object
 */

/**
 *  set function that is used by InternetExplorer
 *
 *  " in the value must be coded as §!!§
 *  ' in the value must be coded as §!§
 */
function THLabel_set_ie(value)
{
  value = value.replace(/(§!!§)/g, '\"');
  value = value.replace(/(§!§)/g, '\'');

  this.label.innerHTML = (this.value = value) || "\xA0";
}

/**
 *  default dom2 function to set the caption
 */
function THLabel_set_dom2(value)
{
  value = value.replace(/§!!§/g, '\"');
  value = value.replace(/§!§/g, '\'');

  with (this.label)
  {
    //  does not work ...
		//replaceChild(this.document.createTextNode((this.value = value) || "\xA0"), firstChild);
		
		//  the code for the IE is also working in Netscape 7.0
		this.label.innerHTML = (this.value = value) || "\xA0";
  }
}

/**
 *  set caption function used by Netscape 4
 */
function THLabel_set_ns4(value)
{
  value = value.replace(/§!!§/g, '\"');
  value = value.replace(/§!§/g, '\'');

  this.value = value || "";
  with (this)
  {
    document.open();
    document.write('<div class="qlabel">' + (clickable ? '<a href="#" title="' + tooltip + '" onClick="return ' +
                    name + '.doEvent()" onMouseOut="window.top.status=\'\'" onMouseOver="window.top.status=' +
                    name + '.tooltip;return true">' + value + '</a>' : value) + '</div>');
    document.close();
  }
}

/**
 *  event handler
 */
function THLabel_doEvent()
{
  this.onClick(this.value, this.tag);
  return false;
}

/**
 *  label constructor
 */
function THLabel(parent, name, value, clickable, tooltip)
{
  value = value.replace(/(§!!§)/g, '\"');
  value = value.replace(/(§!§)/g, '\'');

  this.init(parent, name);
  this.value = value || "";
  this.clickable = clickable || false;
  this.tooltip = tooltip || "";
  this.doEvent = THLabel_doEvent;
  this.onClick = THControl.event;

  with (this)
  {
    if (document.getElementById || document.all)
    {
      document.write(clickable ? '<div class="qlabel" unselectable="on"><a id="' + id + '" href="#" title="' +
                     tooltip + '" onClick="return ' + name + '.doEvent()" onMouseOver="window.top.status=' +
                     name + '.tooltip;return true" onMouseOut="window.top.status=\'\'" hidefocus="true" '+
                     'unselectable="on">' + (value || '&nbsp;') + '</a></div>' : '<div id="' + id +
                     '" class="qlabel" unselectable="on">' + (value || '&nbsp;') + '</div>');
      this.label = document.getElementById ? document.getElementById(id) :
                   (document.all.item ? document.all.item(id) : document.all[id]);
      this.set = (label && (label.innerText ? THLabel_set_ie :
                 (label.replaceChild && THLabel_set_dom2))) || THControl.nop;
    }
    else if (document.layers)
    {
      var suffix = "";
      for (var j=value.length; j<THLabel.TEXTQUOTA; j++)
      {
        suffix += " &nbsp;";
      }
      
      document.write('<div><ilayer id="i' + id + '"><layer id="' + id + '"><div class="qlabel">' +
                     (clickable ? '<a href="#" title="' + tooltip + '" onClick="return ' + name +
                     '.doEvent()" onMouseOver="window.top.status=' + name +
                     '.tooltip;return true" onMouseOut="window.top.status=\'\'">' + value + suffix + '</a>' :
                     value + suffix) + '</div></layer></ilayer></div>');
      this.label = (this.label = document.layers["i" + id]) && label.document.layers[id];
      this.document = label && label.document;
      this.set = (label && document) ? THLabel_set_ns4 : QControl.nop;
    }
    else
    {
      document.write("Label object is not supported");
    }
  }
}

THLabel.prototype = new THControl();
THLabel.TEXTQUOTA = 50;
