// %W% %E% %Q% Copyright (c) 2000 by Xinet, Inc.  All Rights Reserved.
// WN_Include_Safe

var inc = 0;
var CONTEXT_BROWSE    = 1 << (++inc);
var CONTEXT_SEARCH    = 1 << (++inc);
var CONTEXT_IMAGEINFO = 1 << (++inc);
var CONTEXT_BASKET    = 1 << (++inc);
var CONTEXT_ALL       = 0xFFFFFFFF;
var CONTEXT_UNDEFINED = 0;

// Button Class

function WNButton(img, alt, context, orderPreference) {
  this.img = img;
  this.alt = alt;
  this.context = context;
  this.orderPreference = orderPreference;

  this.checkPermission = null;
  this.getAnchorProperties = null;
}

WNButton.prototype.visibleInContext = function(context) {
  return (this.context & context) > 0;
}

WNButton.prototype.writeHTML = function(framedoc, file, userInfo, args, context) {
  if( this.visibleInContext(context) ) {
    if( this.checkPermission ) {
      if( this.checkPermission(file, userInfo) ) {
        if( this.getAnchorProperties ) {
          framedoc.write( "<A " + this.getAnchorProperties(file, userInfo, args, context) + ">" );
        }
        if( this.img.charAt(0) == '/' ) {
          framedoc.write("<IMG ALT='" + this.alt + "' ALIGN=middle BORDER=0 WIDTH=" + wn_iconwidth + " HEIGHT=" + wn_iconheight + " SRC='" + this.img + "'>")
        } else {
          putwnicon(this.alt, this.img, framedoc);
        }
        if( this.getAnchorProperties ) {
          framedoc.write("</A>");
        }
      }
    }
  }
}

WNButton.prototype.getHouseMouseOverProperties = function(args, msg) {
  var result = "";
  var fref = args['fref'];
  var controlFrame = args['controlFrame'];

  if( fref ) {
    result += "onMouseOver='"
    if( controlFrame ) {
      result += controlFrame+"."
    }
    result += "showMessage("+fref.docPath+", \""+fref.spanID+"\", \"" + msg + " \");";
    result += " return true' ";
    result += "onMouseOut='"
    if( controlFrame ) {
      result += controlFrame+"."
    }
    result += "showMessage("+fref.docPath+", \""+fref.spanID+"\", \"\");";
    result += " return true' ";
  }

  return result;
}

WNButton.prototype.registerCheckPermission = function( cpf ) {
  this.checkPermission = cpf;
}

WNButton.prototype.registerGetAnchorProperties = function( gapf ) {
  this.getAnchorProperties = gapf;
}

// Manager Class

function WNButtonManager() {
  this.buttons = new Array(1024);
  this.buttonCount = 0;
}

WNButtonManager.prototype.addButton = function(button) {
  this.buttonCount++;

  for(var i = 0; i < this.buttonCount; ++i) {
    if( i == this.buttonCount-1 ) {
      this.buttons[i] = button;

    } else if( this.buttons[i].orderPreference < button.orderPreference ) {

      for( var j = i; j < this.buttonCount-1; ++j ) {
        this.buttons[j+1] = this.buttons[j];
      }
      this.buttons[i] = button;
      
      break;
    }
  } 
}

WNButtonManager.prototype.removeButtonAt = function(i) {
  var result = (i < this.buttonCount) ? this.buttons[i] : null;
  if( result ) {
    --this.buttonCount;
    for( var j = i; j < this.buttonCount; ++j ) {
      this.buttons[j] = this.buttons[j+1];
    }
  } 
  return result;
}

WNButtonManager.prototype.getButtonAt = function(i) {
  return (i < this.buttonCount) ? this.buttons[i] : null;
}

WNButtonManager.prototype.getButtonCount = function() {
  return this.buttonCount;
}

WNButtonManager.prototype.writeButtons = function(framedoc, file, userInfo, args, context) {
  for( var i = 0; i < this.buttonCount; ++i ) {
    this.buttons[i].writeHTML(framedoc, file, userInfo, args, context);
  }
}

// manager object

var wnButtonManager = new WNButtonManager();
var wnStyleContext  = CONTEXT_UNDEFINED;

