
function fw_link(id, anchor)
{
  if (anchor)
  {
    this.elem = anchor;
  }
  else if (id)
  {
    this.elem = document.getElementById(id);
    if (! this.elem)
    {
      alert("unable to find link instance " + id);
    }
  }
}

fw_link.prototype.get_id = function()
{
  return this.elem.getAttribute("id");
}

fw_link.prototype.get_add_properties_to_url = function()
{
  var result = this.elem.getAttribute("iw_addPropertiesToUrl");
  return (result ? eval(result) : true);
}

fw_link.prototype.get_url = function()
{
  return this.elem.href;
}

fw_link.prototype.set_url = function(url)
{
  this.elem.href = url;
}

fw_link.prototype.get_target = function()
{
  return this.elem.target;
}

fw_link.prototype.is_enabled = function()
{
  return eval(this.elem.getAttribute("iw_enabled"));
}

fw_link.prototype.set_enabled = function(enabled)
{
  if (enabled == this.is_enabled())
  {
    return;
  }

  this.elem.setAttribute("iw_enabled", enabled);
  var newCss = this.elem.getAttribute(enabled ? "iw_cssE" : "iw_cssD");
  if ( !newCss )
  {
    var baseCss = this.elem.getAttribute(fwIsIE ? "className" : "class");
    baseCss = baseCss.replace( /-disabled$/, "");
    newCss = enabled ? baseCss : (baseCss + "-disabled");
  }
  this.elem.setAttribute(fwIsIE ? "className" : "class", newCss);
  this.elem.setAttribute("style", this.elem.getAttribute(enabled ? "iw_styleE" : "iw_styleD"));

  if (!enabled)
  {
    if (!this.elem.iw_onClickWhenEnabled)
    {
      this.elem.iw_onClickWhenEnabled = this.elem.onclick;
    }
    this.elem.onclick = function() { return false; };
  }
  else
  {
    var onclick_backup = this.elem.iw_onClickWhenEnabled;
    if (! onclick_backup)
    {
      // for the first time on mozilla, it is necessary to use getAttribute
      // since it has not yet been loaded into the JS DOM tree
      onclick_backup = this.elem.getAttribute("iw_onClickWhenEnabled");
    }

    if (typeof onclick_backup == "string")
    {
      //need to convert it into a function object.
      onclick_backup = new Function("event", onclick_backup);
      this.elem.iw_onClickWhenEnabled = onclick_backup;
    }
    this.elem.onclick = (onclick_backup 
                         ? onclick_backup 
                         : function() {  return true; });
  }
}


fw_link.prototype.set_image = function(imageSrc)
{
    if (imageSrc.indexOf("/") == 0)
    {
        imageSrc = "/iw-cc" + imageSrc;
    }

    this.elem.getElementsByTagName("IMG")[0].src = imageSrc;
}

fw_link.prototype.set_tooltip_desc = function(title)
{
    this.elem.getElementsByTagName("IMG")[0].title = title;
}

fw_link.prototype.get_flags = function()
{
  return this.elem.getAttribute("iw_flags");
}

fw_link.prototype.set_flags = function(flags)
{
  return this.elem.setAttribute("iw_flags",flags);
}


function fw_button(id)
{
  this.base = fw_link;
  this.base(id);
}

fw_button.prototype = new fw_link();

fw_button.prototype.toString = function()
{
  return "button " + this.get_id() + " is " + (this.is_enabled() ? "enabled" : "disabled");
}

