/**   button .down fixer  **/

function ButtonWidget(debug,defer,allowFocus) {
  // debug (true/false): enables debugging mode
  // defer (true/false): defers init() call (will have to be called manually)
  // noNetscapeBlur (true/false): allows buttons to get and keep focus (annoying inner border shown - workaround for Netscape 7.0 when buttons in <fieldset> tags, ie. demo page)
  var self = this;
  this.debugEnabled = (debug?1:0);
  this.defer = (defer?1:0);
  this.noFocus = (allowFocus?0:1);
  this.b = document.getElementsByTagName("button");
  this.init = function() {
    // Main loop (assigns button event handlers etc.)
    for (var i=0; i<this.b.length; i++) {
	  this.b[i].htmlMouseDownHandler = (this.b[i].onmousedown?this.b[i].onmousedown:function(){});
	  this.b[i].htmlMouseUpHandler = (this.b[i].onmouseup?this.b[i].onmouseup:function(){});
	  this.b[i].htmlMouseOutHandler = (this.b[i].onmouseout?this.b[i].onmouseout:function(){});
	  this.b[i].onmousedown = function() {
	    this.id = this.id+'-down';
	    if (self.debugEnabled) this.debug();
	    this.htmlMouseDownHandler();
	  }
      this.b[i].onmouseup = function() {
  	    this.id = this.id.replace(/\-down/,'');
	    if (self.debugEnabled) this.debug();
	    this.htmlMouseUpHandler();
	  }
	  if (this.noFocus) {
	    this.b[i].onfocus = function() {
	      this.blur();
	    }
	  }
	  this.b[i].onmouseout = function() {
  	    this.id = this.id.replace(/\-down/,'');
		if (self.debugEnabled) this.debug();
		this.htmlMouseOutHandler();
	  }
	  if (self.debugEnabled) {
	    this.b[i].onmouseover = function() {
		  this.debug();
		}
	  }
      this.b[i].debug = function() {
	    window.status = 'ButtonWidget(): '+this.id;
	  }
    }
  }
  if (!this.defer) {
    this.init();
  }
}

var buttonWidget = null;
onloadHandlers[onloadHandlers.length] = 'buttonWidget = new ButtonWidget()';