// Copyright Daniel Hillis 2006
// University of Wisconsin-Eau Claire
// McIntyre Library

var uwecProxyString = "http://ezproxy.uwc.edu/login?url=";
var uwecFormAction = "http://library.uwc.edu/metalib/redirect.asp";

function emptyFunction() { return; }

///////////////////////////////////////////////////////////////
//           show/hideObject()                               //
///////////////////////////////////////////////////////////////

function showObject(object) {
  if (!object.style) 
    object.visibility = 'visible';
  else 
    object.style.visibility = 'visible';
  }

function hideObject(object) {
  if (!object.style) 
    object.visibility = 'hidden';
  else 
    object.style.visibility = 'hidden';
  }

function expandObject(object) {
  if (!object.style) 
    object.display = 'block';
  else 
    object.style.display = 'block';
  }

function contractObject(object) {
  if (!object.style) 
    object.display = 'none';
  else 
    object.style.display = 'none';
  }
///////////////////////////////////////////////////////////////
//           InputGroup                                      //
///////////////////////////////////////////////////////////////

function InputGroup(name, visibilityDivId) {
  this.name = name || "";
  this.visibilityDivId = visibilityDivId || "";
  this.visibilityDiv = visibilityDivId ? document.getElementById(visibilityDivId) : null; 
  }

InputGroup.prototype.show = function() {
  if (!this.visibilityDiv)
    return false;
  expandObject(this.visibilityDiv);
  return true;
  }

InputGroup.prototype.hide = function() {
  if (!this.visibilityDiv)
    return false;
  contractObject(this.visibilityDiv);
  return true;
  }

///////////////////////////////////////////////////////////////
//           SingleIdInputGroup                              //
///////////////////////////////////////////////////////////////

function SingleIdInputGroup(name, visibilityDivId, inputId) {
  // inherit from InputGroup
  InputGroup.call(this, name, visibilityDivId);

  this.input = $E(inputId);
  }
SingleIdInputGroup.prototype = new InputGroup;

SingleIdInputGroup.prototype.getValue = function() {
  return this.input.getValue();
  }

SingleIdInputGroup.prototype.addEventListener = function(event, func, phase, newThis) {
  return this.input.addEventListener(event, func, phase, newThis);
  }

///////////////////////////////////////////////////////////////
//           AdvancedSelectionInputGroup                     //
///////////////////////////////////////////////////////////////

function AdvancedSelectionInputGroup(name, visibilityDivId, fromId, toId, addButtonId, removeButtonId) {
  // inherit from InputGroup
  InputGroup.call(this, name, visibilityDivId);

  this.fromInput = $E(fromId);
  this.toInput = $E(toId);
  this.addButton = $E(addButtonId);
  this.removeButton = $E(removeButtonId);
  this.addButton.addEventListener("click", this.addButtonHandler, false, this);
  this.removeButton.addEventListener("click", this.removeButtonHandler, false, this);
  }
AdvancedSelectionInputGroup.prototype = new InputGroup;

AdvancedSelectionInputGroup.prototype.addButtonHandler = function() {
  var oFromBox = this.fromInput.element;
  var oToBox = this.toInput.element;
  var selectedIndex = oFromBox.selectedIndex;

  if (selectedIndex == -1) {
    alert("Please select a resource first");
    return;
    }

  if (oFromBox.options[selectedIndex].disabled) 
    return;

  var oSelectedOption = oFromBox.options[selectedIndex];
  oToBox.options[oToBox.options.length] = new Option(oSelectedOption.text, oSelectedOption.value);
  oSelectedOption.disabled=true;
  oSelectedOption.className="disabledOption";

  }

AdvancedSelectionInputGroup.prototype.removeButtonHandler = function() {
  var oFromBox = this.fromInput.element;
  var oToBox = this.toInput.element;

  var selectedIndex = oToBox.selectedIndex;

  if (selectedIndex == -1) {
    alert("Please select a resource first");
    return;
    }

  var sText = oToBox.options[selectedIndex].text;
  var sValue = oToBox.options[selectedIndex].value;
  oToBox.options[selectedIndex]=null;

  for (i=0; i<oFromBox.options.length; i++) {
    if (oFromBox.options[i].value==sValue) {
      oFromBox.options[i].disabled=false;
      oFromBox.options[i].className="enabledOption";
      break;
      }
    }

  }

AdvancedSelectionInputGroup.prototype.getValue = function() {
  var returnArray = new Array();
  for (i=0; i<this.toInput.element.options.length; i++)
    returnArray.push(this.toInput.element.options[i].value);
  return returnArray;
  }

AdvancedSelectionInputGroup.prototype.addEventListener = function(event, func, phase, newThis) {
  this.fromInput.addEventListener(event, func, phase, newThis);
  this.toInput.addEventListener(event, func, phase, newThis);
  this.addButton.addEventListener(event, func, phase, newThis);
  this.removeButton.addEventListener(event, func, phase, newThis);
  return;
  }


///////////////////////////////////////////////////////////////
//           MultipleInputGroup                              //
///////////////////////////////////////////////////////////////

function MultipleInputGroup(name, visibilityDivId) {
  // inherit from InputGroup
  InputGroup.call(this, name, visibilityDivId);

  this.aInput = new Array();
  for (i=2; i<arguments.length; i++)
    this.aInput[this.aInput.length] = $E(arguments[i]);
  }
MultipleInputGroup.prototype = new InputGroup;

MultipleInputGroup.prototype.addEventListener = function(event, func, phase, newThis) {
  for (i=0; i<this.aInput.length; i++)
    this.aInput[i].addEventListener(event, func, phase, newThis);
  }

MultipleInputGroup.prototype.getValue = function() {
  var returnArray = new Array();
  for (i=0; i<this.aInput.length; i++)
    returnArray[returnArray.length] = this.aInput[i].getValue();
  return returnArray;
  }














//////////////////////////////////////////////////////////////////////////////
//                              LinkInterface                               //
//////////////////////////////////////////////////////////////////////////////

function LinkInterface(selectValue) {
  this.linkManager = null;
  this.selectValue = selectValue || null;
  }

LinkInterface.prototype.setLinkManager = function(lm) {
  this.linkManager = lm;
  }

LinkInterface.prototype.setOptionArray = function(optionArray) {
  this.optionArray = optionArray;
  }

LinkInterface.prototype.getOptionValue = function(optionName) {
  if (!this.optionArray[optionName]) {
    alert("option with\nname:" + optionName + "\nis not defined");
    return;
    }
  return this.optionArray[optionName].getValue();
  }

LinkInterface.prototype.getSelectValue = function() {
  return this.selectValue;
  }

//////////////////////////////////////////////////////////////////////////////
//                               GenericLink                                //
//////////////////////////////////////////////////////////////////////////////

function GenericLink(selectValue) {
  // Inherit from LinkInterface
  LinkInterface.call(this, selectValue);
  this.linkUrl = uwecProxyString + "http://metalib.wisconsin.edu/V/";
  this.openInNewWindow = "";
  this.linkText = "";
  }
GenericLink.prototype = new LinkInterface();

GenericLink.prototype.setLinkUrl = function(linkUrl) {
  this.linkUrl = linkUrl;
  }

GenericLink.prototype.onOptionChange = function() {
  this.linkManager.updateResults();
  }

GenericLink.prototype.onLinkChange = function() {
  this.linkManager.hideOptions();
  this.optionArray["openInNewWindow"].show();
  this.optionArray["linkText"].show();
  
  this.onOptionChange();
  }

GenericLink.prototype.getUrlResults = function() {
  return this.linkUrl;
  }

GenericLink.prototype.getHtmlResults = function() {
  return "<a href='"+this.linkUrl+"'"+this.getOptionValue("openInNewWindow")+">"+this.getOptionValue("linkText")+"</a>";
  }

GenericLink.prototype.getTestHtmlResults = function() {
  var target = " target='_blank'";
  return "<a href='"+this.linkUrl+"' target='_blank'>"+this.getOptionValue("linkText")+"</a>";
  }


//////////////////////////////////////////////////////////////////////////////
//                          BasicQuickSearchLink                            //
//////////////////////////////////////////////////////////////////////////////

function BasicQuickSearchLink(selectValue) {
  // Inherit from LinkInterface
  GenericLink.call(this, selectValue);
  this.setLinkUrl(uwecProxyString + "http://metalib.wisconsin.edu/V/?func=quick-1");
  }
BasicQuickSearchLink.prototype = new GenericLink();


//////////////////////////////////////////////////////////////////////////////
//                         BasicAllResourcesLink                            //
//////////////////////////////////////////////////////////////////////////////

function BasicAllResourcesLink(selectValue) {
  // Inherit from LinkInterface
  GenericLink.call(this, selectValue);
  this.setLinkUrl(uwecProxyString + "http://metalib.wisconsin.edu/V/?func=find-db-1-title");
  }
BasicAllResourcesLink.prototype = new GenericLink();

BasicAllResourcesLink.prototype.onOptionChange = function() {
  this.setLinkUrl(uwecProxyString + "http://metalib.wisconsin.edu/V/?func=find-db-1-title" + this.getOptionValue("tableBrief"));
  this.linkManager.updateResults();
  }

BasicAllResourcesLink.prototype.onLinkChange = function() {
  this.linkManager.hideOptions();
  this.optionArray["openInNewWindow"].show();
  this.optionArray["linkText"].show();
  this.optionArray["tableBrief"].show();
  
  this.onOptionChange();
  }
//////////////////////////////////////////////////////////////////////////////
//                            BasicCustomSearchLink                         //
//////////////////////////////////////////////////////////////////////////////

function BasicCustomSearchLink(selectValue) {
  // Inherit from LinkInterface
  GenericLink.call(this, selectValue);
  this.setLinkUrl(uwecProxyString + "http://metalib.wisconsin.edu/V/?func=meta-1");
  }
BasicCustomSearchLink.prototype = new GenericLink();

//////////////////////////////////////////////////////////////////////////////
//                            BasicFindResourcesLink                        //
//////////////////////////////////////////////////////////////////////////////

function BasicFindResourcesLink(selectValue) {
  // Inherit from LinkInterface
  GenericLink.call(this, selectValue);
  this.setLinkUrl(uwecProxyString + "http://metalib.wisconsin.edu/V/?func=find-db-1");
  }
BasicFindResourcesLink.prototype = new GenericLink();

BasicFindResourcesLink.prototype.onOptionChange = function() {
  this.setLinkUrl(uwecProxyString + "http://metalib.wisconsin.edu/V/?func=find-db-1" + this.getOptionValue("titlesLocateCategory"));
  this.linkManager.updateResults();
  }

BasicFindResourcesLink.prototype.onLinkChange = function() {
  this.linkManager.hideOptions();
  this.optionArray["openInNewWindow"].show();
  this.optionArray["linkText"].show();
  this.optionArray["titlesLocateCategory"].show();
  
  this.onOptionChange();
  }
//////////////////////////////////////////////////////////////////////////////
//                           advancedSearchBox code                         //
//////////////////////////////////////////////////////////////////////////////

var advancedSearchBox = "";
advancedSearchBox += "  <table cellpadding='0' cellspacing='0' border='0'> \n";
advancedSearchBox += "    <tr> \n";
advancedSearchBox += "      <td>Search in fields:&nbsp;&nbsp;</td> \n";
advancedSearchBox += "      <td> \n";
advancedSearchBox += "        <select name='find_code_2'> \n";
advancedSearchBox += "          <option value='WRD' selected>All Fields</option> \n";
advancedSearchBox += "          <option value='WSU' >Subject</option> \n";
advancedSearchBox += "          <option value='WTI' >Title</option> \n";
advancedSearchBox += "          <option value='WAU' >Author</option> \n";
advancedSearchBox += "          <option value='ISSN'>ISSN</option> \n";
advancedSearchBox += "          <option value='ISBN'>ISBN</option> \n";
advancedSearchBox += "          <option value='WYR' >Year</option> \n";
advancedSearchBox += "        </select> \n";
advancedSearchBox += "        <input name='find_request_2' type='text' class='form' maxlength='100' value='' size='24'> \n";
advancedSearchBox += "      </td> \n";
advancedSearchBox += "      <td> \n";
advancedSearchBox += "        &nbsp; \n";
advancedSearchBox += "        <select name='find_op_1'> \n";
advancedSearchBox += "          <option value='AND'>And</option> \n";
advancedSearchBox += "          <option value='OR' >Or</option> \n";
advancedSearchBox += "          <option value='NOT'>Without</option> \n";
advancedSearchBox += "        </select> \n";
advancedSearchBox += "      </td> \n";
advancedSearchBox += "      <td rowspan='2'> \n";
advancedSearchBox += "        &nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' value='Go'> \n";
advancedSearchBox += "      </td> \n";
advancedSearchBox += "    </tr> \n";
advancedSearchBox += "    <tr> \n";
advancedSearchBox += "     <td>&nbsp;</td> \n";
advancedSearchBox += "      <td> \n";
advancedSearchBox += "        <select name='find_code_3'> \n";
advancedSearchBox += "          <option value='WRD' > All Fields</option> \n";
advancedSearchBox += "          <option value='WSU' >Subject</option> \n";
advancedSearchBox += "          <option value='WTI' >Title</option> \n";
advancedSearchBox += "          <option value='WAU' >Author</option> \n";
advancedSearchBox += "          <option value='ISSN'>ISSN</option> \n";
advancedSearchBox += "          <option value='ISBN'>ISBN</option> \n";
advancedSearchBox += "          <option value='WYR' >YEAR</option> \n";
advancedSearchBox += "        </select> \n";
advancedSearchBox += "        <input name='find_request_3' type='text' size='24' maxsize='100' value=''> \n";
advancedSearchBox += "      </td> \n";
advancedSearchBox += "    </tr> \n";
advancedSearchBox += "  </table> \n";

//////////////////////////////////////////////////////////////////////////////
//                           SearchCustomSetLink                            //
//////////////////////////////////////////////////////////////////////////////

function SearchCustomSetLink(selectValue) {
  // Inherit from LinkInterface
  LinkInterface.call(this, selectValue);
  }
SearchCustomSetLink.prototype = new LinkInterface();

SearchCustomSetLink.prototype.onOptionChange = function() {
  this.linkManager.updateResults();
  }

SearchCustomSetLink.prototype.onLinkChange = function() {
  this.linkManager.hideOptions();
  this.optionArray["openInNewWindow"].show();
  this.optionArray["simpleAdvanced"].show();
  this.optionArray["resourceSet"].show();
  //this.optionArray["simpleQuery"].show();
  //this.optionArray["advancedQuery"].show();

  this.onOptionChange();
  }

SearchCustomSetLink.prototype.getUrlResults = function() {
  return false;
  }

SearchCustomSetLink.prototype.getHtmlResults = function(forceOpenInNewWindow) {
  var openInNewWindow = this.getOptionValue("openInNewWindow");
  if (forceOpenInNewWindow)
    openInNewWindow = " target='_blank'";

  var resources = this.getOptionValue("resourceSet");
  var resourcesHtml = "";
  for (i=0; i<resources.length; i++)
    resourcesHtml += "  <input type='hidden' name='ckbox' value='"+resources[i]+"'>\n";

  if (this.getOptionValue("simpleAdvanced") == "simple") {
    var searchBox = "";
    searchBox += "  Enter search term(s): &nbsp;&nbsp;\n";
    searchBox += "  <input type='text' size='30' name='find_request_1'>\n";
    searchBox += "  &nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' value='Go'>\n";
    }
  else {
    var searchBox = advancedSearchBox; // see above for advancedSearchBox code
    }

  var form= "<form action='" + uwecFormAction + "' method='post'"+openInNewWindow+">\n";
  form += "  <input type='hidden' name='func' value='meta-1-check'> \n";
  form += "  <input type='hidden' name='INIT_TYPE' value='CategoryList'> \n";
  form += "  <input type='hidden' name='mode' value='"+this.getOptionValue("simpleAdvanced")+"'> \n";
  form += "  <input type='hidden' name='url' value='http://metalib.wisconsin.edu/V/'> \n";
  form += "  <input type='hidden' name='type' value='proxyform'> \n";
  form += resourcesHtml;
  form += searchBox;
  form += "</form>"; 
 
  
  return form;
  }

SearchCustomSetLink.prototype.getTestHtmlResults = function() {
  return this.getHtmlResults(true);
  }


//////////////////////////////////////////////////////////////////////////////
//                          SearchForResourceLink                           //
//////////////////////////////////////////////////////////////////////////////

function SearchForResourceLink(selectValue) {
  // Inherit from LinkInterface
  LinkInterface.call(this, selectValue);
  }
SearchForResourceLink.prototype = new LinkInterface();

SearchForResourceLink.prototype.onOptionChange = function() {
  this.linkManager.updateResults();
  }

SearchForResourceLink.prototype.onLinkChange = function() {
  this.linkManager.hideOptions();
  this.optionArray["openInNewWindow"].show();
  this.optionArray["startsWithContainsExact"].show();
  
  this.onOptionChange();
  }

SearchForResourceLink.prototype.getUrlResults = function() {
  return null;
  }

SearchForResourceLink.prototype.getHtmlResults = function(forceOpenInNewWindow) {
  var openInNewWindow = this.getOptionValue("openInNewWindow");
  if (forceOpenInNewWindow)
    openInNewWindow = " target='_blank'";

  var form= "<form action='" + uwecFormAction + "' method='post'"+openInNewWindow+">\n";
  form += "  <input type='hidden' name='func' value='find-db-1-title'> \n";
  form += "  <input type='hidden' name='mode' value='titles'> \n";
  form += "  <input type='hidden' name='search_type' value='"+this.getOptionValue("startsWithContainsExact")+"'> \n";
  form += "  <input type='hidden' name='url' value='http://metalib.wisconsin.edu/V/'> \n";
  form += "  <input type='hidden' name='type' value='proxyform'> \n";
  form += "  <input type='text' name='scan_start' size='30'> \n";
  form += "  &nbsp;&nbsp;<input type='submit' value='Go'> \n";
  form += "</form>"; 
 
  
  return form;
  }

SearchForResourceLink.prototype.getTestHtmlResults = function() {
  return this.getHtmlResults(true);
  }

//////////////////////////////////////////////////////////////////////////////
//                           SearchQuicksetLink                             //
//////////////////////////////////////////////////////////////////////////////

function SearchQuicksetLink(selectValue) {
  // Inherit from LinkInterface
  LinkInterface.call(this, selectValue);
  }
SearchQuicksetLink.prototype = new LinkInterface();

SearchQuicksetLink.prototype.onOptionChange = function() {
  this.linkManager.updateResults();
  }

SearchQuicksetLink.prototype.onLinkChange = function() {
  this.linkManager.hideOptions();
  this.optionArray["openInNewWindow"].show();
  this.optionArray["simpleAdvanced"].show();
  this.optionArray["quicksetID"].show();
  
  this.onOptionChange();
  }

SearchQuicksetLink.prototype.getUrlResults = function() {
  return null;
  }

SearchQuicksetLink.prototype.getHtmlResults = function(forceOpenInNewWindow) {
  var openInNewWindow = this.getOptionValue("openInNewWindow");
  if (forceOpenInNewWindow)
    openInNewWindow = " target='_blank'";

  if (this.getOptionValue("simpleAdvanced") == "simple") {
    var searchBox = "";
    searchBox += "  Enter search term(s): &nbsp;&nbsp;\n";
    searchBox += "  <input type='text' size='30' name='find_request_1'>\n";
    searchBox += "  &nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' value='Go'>\n";
    }
  else {
    var searchBox = advancedSearchBox; // see above for advancedSearchBox code
    }

  var form= "<form action='" + uwecFormAction + "' method='post'"+openInNewWindow+">\n";
  form += "  <input type='hidden' name='func' value='quick-1-check1'> \n";
  form += "  <input type='hidden' name='mode' value='"+this.getOptionValue("simpleAdvanced")+"'> \n";
  form += "  <input type='hidden' name='group_number' value='"+this.getOptionValue("quicksetID")+"'> \n";
  form += "  <input type='hidden' name='url' value='http://metalib.wisconsin.edu/V/'> \n";
  form += "  <input type='hidden' name='type' value='proxyform'> \n";
  form += searchBox;
  form += "</form>"; 
 
  
  return form;
  }

SearchQuicksetLink.prototype.getTestHtmlResults = function() {
  return this.getHtmlResults(true);
  }

//////////////////////////////////////////////////////////////////////////////
//                      SearchCustomSetPredefinedLink                       //
//////////////////////////////////////////////////////////////////////////////

function SearchCustomSetPredefinedLink(selectValue) {
  // Inherit from LinkInterface
  GenericLink.call(this, selectValue);
  }
SearchCustomSetPredefinedLink.prototype = new GenericLink();

SearchCustomSetPredefinedLink.prototype.onOptionChange = function() {
  var baseUrl = uwecProxyString + "http://metalib.wisconsin.edu/V/?func=meta-1-check&INIT_TYPE=CategoryList";
  var queryUrl = "";

  var modeUrl = "";
  if (this.getOptionValue("simpleAdvanced") == "simple") {
    this.optionArray["simpleQuery"].show();
    this.optionArray["advancedQuery"].hide();
    modeUrl = "&mode=simple";
    queryUrl = "&find_request_1=" + escape(this.getOptionValue("simpleQuery"));
    }
  else {
    this.optionArray["simpleQuery"].hide();
    this.optionArray["advancedQuery"].show();
    modeUrl = "&mode=advanced";
    queryUrl = "&find_code_2="+this.getOptionValue("advancedQuery")[0];
    queryUrl +="&find_request_2="+escape(this.getOptionValue("advancedQuery")[1]);
    queryUrl +="&find_op_1="+this.getOptionValue("advancedQuery")[2];
    queryUrl +="&find_code_3="+this.getOptionValue("advancedQuery")[3];
    queryUrl +="&find_request_3="+escape(this.getOptionValue("advancedQuery")[4]);
    }

  var resources = this.getOptionValue("resourceSet");
  var resourcesUrl = "";
  for (i=0; i<resources.length; i++)
    resourcesUrl += "&ckbox="+resources[i];

  this.setLinkUrl(baseUrl + modeUrl + resourcesUrl + queryUrl);
  this.linkManager.updateResults();
  }

SearchCustomSetPredefinedLink.prototype.onLinkChange = function() {
  this.linkManager.hideOptions();
  this.optionArray["openInNewWindow"].show();
  this.optionArray["linkText"].show();
  this.optionArray["simpleAdvanced"].show();
  this.optionArray["resourceSet"].show();
  this.optionArray["simpleQuery"].show();
  this.optionArray["advancedQuery"].show();

  this.onOptionChange();
  }

//////////////////////////////////////////////////////////////////////////////
//                     SearchForResourcePredefinedLink                      //
//////////////////////////////////////////////////////////////////////////////

function SearchForResourcePredefinedLink(selectValue) {
  // Inherit from LinkInterface
  GenericLink.call(this, selectValue);
  }
SearchForResourcePredefinedLink.prototype = new GenericLink();

SearchForResourcePredefinedLink.prototype.onOptionChange = function() {
  var baseUrl = uwecProxyString + "http://metalib.wisconsin.edu/V/?func=find-db-1-title&mode=titles";
  var queryUrl = "&scan_start=" + escape(this.getOptionValue("resourceQuery"));
  var searchTypeUrl = "&search_type=" + this.getOptionValue("startsWithContainsExact");

  this.setLinkUrl(baseUrl + queryUrl + searchTypeUrl);
  this.linkManager.updateResults();
  }

SearchForResourcePredefinedLink.prototype.onLinkChange = function() {
  this.linkManager.hideOptions();
  this.optionArray["openInNewWindow"].show();
  this.optionArray["linkText"].show();
  this.optionArray["startsWithContainsExact"].show();
  this.optionArray["resourceQuery"].show();

  this.onOptionChange();
  }

//////////////////////////////////////////////////////////////////////////////
//                      SearchQuicksetPredefinedLink                        //
//////////////////////////////////////////////////////////////////////////////

function SearchQuicksetPredefinedLink(selectValue) {
  // Inherit from LinkInterface
  GenericLink.call(this, selectValue);
  }
SearchQuicksetPredefinedLink.prototype = new GenericLink();

SearchQuicksetPredefinedLink.prototype.onOptionChange = function() {
  var baseUrl = uwecProxyString + "http://metalib.wisconsin.edu/V/?func=quick-1-check1";
  var queryUrl = "";

  var modeUrl = "";
  if (this.getOptionValue("simpleAdvanced") == "simple") {
    this.optionArray["simpleQuery"].show();
    this.optionArray["advancedQuery"].hide();
    modeUrl = "&mode=simple";
    queryUrl = "&find_request_1=" + escape(this.getOptionValue("simpleQuery"));
    }
  else {
    this.optionArray["simpleQuery"].hide();
    this.optionArray["advancedQuery"].show();
    modeUrl = "&mode=advanced";
    queryUrl = "&find_code_2="+this.getOptionValue("advancedQuery")[0];
    queryUrl +="&find_request_2="+escape(this.getOptionValue("advancedQuery")[1]);
    queryUrl +="&find_op_1="+this.getOptionValue("advancedQuery")[2];
    queryUrl +="&find_code_3="+this.getOptionValue("advancedQuery")[3];
    queryUrl +="&find_request_3="+escape(this.getOptionValue("advancedQuery")[4]);
    }

  var quicksetUrl = "&group_number=" + this.getOptionValue("quicksetID");

  this.setLinkUrl(baseUrl + modeUrl + quicksetUrl + queryUrl);
  this.linkManager.updateResults();
  }

SearchQuicksetPredefinedLink.prototype.onLinkChange = function() {
  this.linkManager.hideOptions();
  this.optionArray["openInNewWindow"].show();
  this.optionArray["linkText"].show();
  this.optionArray["simpleAdvanced"].show();
  this.optionArray["quicksetID"].show();
  this.optionArray["simpleQuery"].show();
  this.optionArray["advancedQuery"].show();

  this.onOptionChange();
  }

//////////////////////////////////////////////////////////////////////////////
//                      ResourceInNativeInterfaceLink                       //
//////////////////////////////////////////////////////////////////////////////

function ResourceInNativeInterfaceLink(selectValue) {
  // Inherit from LinkInterface
  GenericLink.call(this, selectValue);
  this.setLinkUrl(uwecProxyString + "http://metalib.wisconsin.edu/V/?func=native-link");
  }
ResourceInNativeInterfaceLink.prototype = new GenericLink();

ResourceInNativeInterfaceLink.prototype.onOptionChange = function() {
  this.setLinkUrl(uwecProxyString + "http://metalib.wisconsin.edu/V/?func=native-link&resource=" + this.getOptionValue("resourceID"));
  this.linkManager.updateResults();
  }

ResourceInNativeInterfaceLink.prototype.onLinkChange = function() {
  this.linkManager.hideOptions();
  this.optionArray["openInNewWindow"].show();
  this.optionArray["linkText"].show();
  this.optionArray["resourceID"].show();
  
  this.onOptionChange();
  }

//////////////////////////////////////////////////////////////////////////////
//                        ResourceInSearchSpotLink                          //
//////////////////////////////////////////////////////////////////////////////

function ResourceInSearchSpotLink(selectValue) {
  // Inherit from LinkInterface
  GenericLink.call(this, selectValue);
  this.setLinkUrl(uwecProxyString + "http://metalib.wisconsin.edu/V/?func=find-db-4");
  }
ResourceInSearchSpotLink.prototype = new GenericLink();

ResourceInSearchSpotLink.prototype.onOptionChange = function() {
  this.setLinkUrl(uwecProxyString + "http://metalib.wisconsin.edu/V/?func=find-db-4&resource=" + this.getOptionValue("resourceID"));
  this.linkManager.updateResults();
  }

ResourceInSearchSpotLink.prototype.onLinkChange = function() {
  this.linkManager.hideOptions();
  this.optionArray["openInNewWindow"].show();
  this.optionArray["linkText"].show();
  this.optionArray["resourceID"].show();
  
  this.onOptionChange();
  }


//////////////////////////////////////////////////////////////////////////////
//                              LinkManager                                 //
//////////////////////////////////////////////////////////////////////////////

function LinkManager(aLink, aOption, linkSelect, sUrlId, sTestUrlId, sHtmlId, sTestHtmlId, sUrlMainId, sNoUrlMainId) {
  this.aOption = aOption;
  this.aLink = new Array();
  this.linkSelect = linkSelect;
  this.oUrlResult = $(sUrlId);
  this.oTestUrlResult = $(sTestUrlId);
  this.oHtmlResult = $(sHtmlId);
  this.oTestHtmlResult = $(sTestHtmlId);
  this.oUrlMain = $(sUrlMainId);
  this.oNoUrlMain = $(sNoUrlMainId);
  this.currentLink = this.aLink[0];

  this.linkSelect.addEventListener("valuechange", this.linkChangeHandler, false, this);

  for (i=0; i<aLink.length; i++) {
    this.aLink[aLink[i].getSelectValue()] = aLink[i];
    aLink[i].setOptionArray(this.aOption);
    aLink[i].setLinkManager(this);
    }

  for (var i in this.aOption) {
    aOption[i].addEventListener("valuechange", this.optionChangeHandler, false, this);
    }

  this.linkChangeHandler();
  }

LinkManager.prototype.hideOptions = function() {
  for (i in optionArray)
    optionArray[i].hide();
  }

LinkManager.prototype.updateResults = function() {
  if (!this.currentLink.getUrlResults()) {
    expandObject(this.oNoUrlMain);
	contractObject(this.oUrlMain);
    }
  else {
    contractObject(this.oNoUrlMain);
	expandObject(this.oUrlMain);
    this.oUrlResult.value = this.currentLink.getUrlResults();
    this.oTestUrlResult.href = this.currentLink.getUrlResults();
    }
  this.oHtmlResult.value = this.currentLink.getHtmlResults();
  this.oTestHtmlResult.innerHTML = this.currentLink.getTestHtmlResults();
  }

LinkManager.prototype.linkChangeHandler = function() {
  this.currentLink = this.aLink[this.linkSelect.getValue()];
  this.currentLink.onLinkChange();
  }

LinkManager.prototype.optionChangeHandler = function() {
  this.currentLink.onOptionChange();
  }



