//   DESCRIPTION:  Cross-browser Button Handler
function buttonSwap() {
  document.images[this.name].src=this.current
}
function buttonUp() {
  if ( this.disabled==false ) {
    if (this.toggle==true && this.active==true) {
      this.current = this.activeState
    } else {
      this.current = this.upState
    }
    this.swap()
  }  
  window.status=""
  return true
}
function buttonDo() {
  eval( this.action )
  return true
}
function buttonClick() {
  if ( this.disabled==false ) {
    if ( this.toggle==true ) {
      if ( this.active==true ) {
        this.current = this.upState
        this.active=false
        this.doAction()
      } else {
        this.current = this.activeState
        this.active=true
        this.doAction()
      }
    } else {
      this.current = this.overState
      this.doAction()
    }
    this.swap()
  }  
  window.status=""
  return true
}
function buttonOver() {
  if ( this.disabled==false ) {
    if (this.toggle==true && this.active==true) {
      this.current = this.downState
    } else {
      this.current = this.overState
    }
    this.swap()
  }
}
function buttonDown() {
  if ( this.disabled==false ) {
    if (this.toggle==true && this.active==true) {
      this.current = this.overState
    } else {
      this.current = this.downState
    }
    this.swap()
  }
}
function buttonOff() {
  this.disabled = true
  this.current = this.offState
  this.swap()
}

function buttonOn() {
  this.disabled = false
  if (this.toggle==true && this.active==true) {
    this.current = this.activeState
  } else {
    this.current = this.upState
  }
  this.swap()
}

// What is this function for?? .. Alex
function generateHTML() {
  if ( this.disabled==true ) {
    this.current = this.offState
  } else if ( (this.toggle==true) && (this.active==true) ) {
    this.current = this.downState
  }

  document.write('<div title="'+this.statustext+'" onmouseover="'+this.name+'.over();window.status=\''+this.statustext+'\';return true;" onmousedown="'+this.name+'.down();" onmouseout="'+this.name+'.up();" onmouseup="'+this.name+'.clicked();"><img name="'+this.name+'" src="'+this.current+'" border="0" width="'+this.width+'" height="'+this.height+'" /></div>')
  return true
}

function nButton_setEnabled( en ) {
    if (en ) {
        this.enable();
    } else {
        this.disable();
    }
}

function CIgenerateHTML() {
  if ( this.disabled==true ) {
    this.current = this.offState
  } else if ( (this.toggle==true) && (this.active==true) ) {
    this.current = this.activeState
  }
	var statustext = this.statustext.replace(/'/g, "\\'");
  document.write('<div id="'+this.id+'" title="'+this.statustext+'" onmouseover="'+this.name+'.over();window.status=\''+statustext+'\';return true;" onmousedown="'+this.name+'.down();" onmouseout="'+this.name+'.up();" onmouseup="'+this.name+'.clicked();return true;"><img name="'+this.name+'" src="'+this.current+'" border="0" width="'+this.width+'" height="'+this.height+'" /></div>')
  return true
}

/*
Contructor.
Parameters:
imgExt - Image file extension, e.g. "gif", "png", "jpg". Defaults to "gif"
*/
function nButton ( id, nm, path, act, width, height, disb, stxt, toggle, active, imgExt ) {
  if (!imgExt) {
    imgExt = "gif";
  }
  this.upState = path+"."+imgExt
  this.overState = path+"-over."+imgExt
  this.downState = path+"-down."+imgExt
  this.offState = path+"-disabled."+imgExt
  this.activeState = path+"-active."+imgExt

  this.upImg = new Image()
  this.ovImg = new Image()
  this.dnImg = new Image()
  this.ofImg = new Image()
  this.acImg = new Image()
  this.upImg.src = this.upState
  this.ovImg.src = this.overState
  this.dnImg.src = this.downState
  this.ofImg.src = this.offState
  this.acImg.src = this.activeState

  this.toggle = toggle
  this.active = active
  this.action = act
  this.width = width;
  this.height = height;
  this.id = id
  this.name = nm
  this.statustext = stxt
  this.generateHTML = generateHTML
  this.CIgenerateHTML = CIgenerateHTML
  this.swap = buttonSwap
  this.up = buttonUp
  this.over = buttonOver
  this.down = buttonDown
  this.clicked = buttonClick
  this.doAction = buttonDo
  this.disable = buttonOff
  this.enable = buttonOn
  this.disabled = disb
  this.current = this.upState
  this.setEnabled = nButton_setEnabled
}

