/* BobCatSearch Class
   structure_attribute: StructureAttribute Object
   use_attributes: Array of UseAttribute Objects
*/
function BobCatSearch () {
  this.structure_attribute;
  this.use_attributes;
  this.operator;
  this.database = "ADVANCE";
}

BobCatSearch.prototype.setStructureAttribute = function (structure_attribute) {
  this.structure_attribute = structure_attribute;
}

BobCatSearch.prototype.getStructureAttribute = function () {
  return this.structure_attribute;
}

BobCatSearch.prototype.setUseAttributes = function (use_attributes) {
  this.use_attributes = use_attributes;
}

BobCatSearch.prototype.getUseAttributes = function () {
  return this.use_attributes;
}

BobCatSearch.prototype.getUseTerm = function (use_attribute_value) {
  var term;
  if (this.getUseAttributes()) {
    var use_attributes = this.getUseAttributes();
    if (use_attributes) {
      var length = use_attributes.length;
      if (length) {
        for (var i=0; i <= length; i++) {
          var use_attribute = use_attributes[i];
          if (use_attribute) {
            var value = use_attribute.getValue();
            if (value == use_attribute_value) {
              term = use_attribute.getTerm();
            }
          }
        }
      }
    }
  }
  return term;
}

BobCatSearch.prototype.setOperator = function (operator) {
  this.operator = operator;
}

BobCatSearch.prototype.getOperator = function () {
  return this.operator;
}

BobCatSearch.prototype.setDatabase = function (database) {
  this.database = database;
}

BobCatSearch.prototype.getDatabase = function () {
  return this.database;
}

BobCatSearch.prototype.EZBobCatQueryString = function () {
  var qs = "&";
  if (this.getUseAttributes()) {
    var use_attributes = this.getUseAttributes();
    if (use_attributes) {
      var length = use_attributes.length;
      if (length) {
        for (var i=0; i < length; i++) {
          var use_attribute = use_attributes[i];
          if (use_attribute) {
            if (use_attribute.getValue()) {
              //qs += "index" + i + "=" + escape(use_attribute.getValue()) + "&";
              if (use_attribute.getTerm()) {
                qs += "freeText" + i + "=" + escape(use_attribute.getTerm()) + "&";
              }
            }
          }
        }
      }
    }
  }
  return qs;
}

/*Bib-1 Attribute Class*/
function Bib1Attribute () {
  this.key;
  this.value;
}

Bib1Attribute.prototype.setKey = function (key) {
  this.key = key;
}

Bib1Attribute.prototype.getKey = function () {
  return this.key;
}

Bib1Attribute.prototype.setValue = function (value) {
  this.value = value;
}

Bib1Attribute.prototype.getValue = function () {
  return this.value;
}

/*Use Attribute Class: extends Bib-1*/
UseAttribute.prototype = new Bib1Attribute();
UseAttribute.prototype.constructor=UseAttribute;
function UseAttribute(){
  this.setKey("1");
  this.term;
}

UseAttribute.prototype.setTerm = function (term) {
  this.term = term;
}

UseAttribute.prototype.getTerm = function () {
  return this.term;
}

/*Structure Attribute Class: extends Bib-1*/
StructureAttribute.prototype = new Bib1Attribute();
StructureAttribute.prototype.constructor=StructureAttribute;
function StructureAttribute(){
  this.setKey("4");
}

