//Environment Variables
var bobcat_host = "library.nyu.edu";
var bobcat_port = "";
var bobcat_version = "";

/**
  * Possible Skins:
  *    NYU - New York University
  *    NS - New School University
  *    CU - Cooper Union
  *    NYSID - New York School of Interior Design
  *    NYHS - New-York Historical Society
  *    BHS - Brooklyn Historical Society
  *
  **/

function EZBobcatBasicSearchScreenURLGenerator (skin) {
  var path = "/bobcat/searchscreen";
  return bobcatURLGenerator (skin, path, "");
}

function EZBobcatExpertSearchScreenURLGenerator (skin) {
  var path = "/bobcat/searchscreen";
  var query_string = "&mode=Advanced";
  return bobcatURLGenerator (skin, path, query_string);
}

function EZBobcatReserveSearchScreenURLGenerator (skin) {
  var path = "/bobcat/searchscreen";
  var query_string = "&tab=reserves";
  return bobcatURLGenerator (skin, path, query_string);
}

function EZBobcatPatronLoginScreenURLGenerator (skin) {
  var path = "/patron";
  return bobcatURLGenerator (skin, path, "");
}

/** Function: string EZBobcatKeywordSearchURLGenerator
  *  Returns a URL string which will execute a basic keyword search in BobCat based on a term and it's attribute.
  *  Result are presented with the given skin. If no skin is specified, the default skin will be applied.
  * 
  * Parameters:
  *  string skin:
  *    see possible skins above
  *
  *  string term1:
  *    term to be searched
  * 
  *  string attr1 (NOT IN USE):
  *    attribute corresponding to term1
  *    kw: - All
  *    au: - Author
  *    ti: - Title
  *    su: - Subject
  */
function EZBobcatKeywordSearchURLGenerator (skin, term, attr) {
  var bobCatSearch = getBobCatSearch(attr, term);
  return searchBobcatByKeywordURLGenerator (skin, bobCatSearch);
}

/** Function: string EZBobcatAllKeywordSearchURLGenerator
  *  Returns a URL string which will execute a basic keyword search in BobCat in All Keywords based on a single term.
  *  Result are presented with the given skin. If no skin is specified, the default skin will be applied.
  * 
  * Parameters:
  *  string skin:
  *    see possible skins above
  *
  *  string term1:
  *    term to be searched
  * 
  */
function EZBobcatAllKeywordSearchURLGenerator (skin, term) {
  return searchBobcatByAllKeywordURLGenerator (skin, term);
}

/** Function: string EZBobcatTitleKeywordSearchURLGenerator
  *  Returns a URL string which will execute a basic keyword search in BobCat in Title Keywords based on a single term.
  *  Result are presented with the given skin. If no skin is specified, the default skin will be applied.
  * 
  * Parameters:
  *  string skin:
  *    see possible skins above
  *
  *  string term1:
  *    term to be searched
  * 
  */
function EZBobcatTitleKeywordSearchURLGenerator (skin, term) {
  return searchBobcatByTitleKeywordURLGenerator (skin, term);
}

/** Function: string EZBobcatAuthorKeywordSearchURLGenerator
  *  Returns a URL string which will execute a basic keyword search in BobCat in Author Keywords based on a single term.
  *  Result are presented with the given skin. If no skin is specified, the default skin will be applied.
  * 
  * Parameters:
  *  string skin:
  *    see possible skins above
  *
  *  string term1:
  *    term to be searched
  * 
  */
function EZBobcatAuthorKeywordSearchURLGenerator (skin, term) {
  return searchBobcatByAuthorKeywordURLGenerator (skin, term);
}

/** Function: string EZBobcatAllKeywordSearchForMediaURLGenerator
  *  Returns a URL string which will execute a basic keyword search in BobCat in All Keywords
  *  limited to media based on a single term.
  *  Result are presented with the given skin. If no skin is specified, the default skin will be applied.
  * 
  * Parameters:
  *  string skin:
  *    see possible skins above
  *
  *  string term1:
  *    term to be searched
  * 
  */
function EZBobcatAllKeywordSearchForMediaURLGenerator (skin, term) {
  return searchBobcatByAllKeywordForMediaURLGenerator (skin, term);
}

/** Function: string EZBobcatAllKeywordSearchForVideosURLGenerator
  *  Returns a URL string which will execute a basic keyword search in BobCat in All Keywords
  *  limited to videos based on a single term.
  *  Result are presented with the given skin. If no skin is specified, the default skin will be applied.
  * 
  * Parameters:
  *  string skin:
  *    see possible skins above
  *
  *  string term1:
  *    term to be searched
  * 
  */
function EZBobcatAllKeywordSearchForVideosURLGenerator (skin, term) {
  return searchBobcatByAllKeywordForVideosURLGenerator (skin, term);
}

/** Function: string EZBobcatAllKeywordSearchForSoundsURLGenerator
  *  Returns a URL string which will execute a basic keyword search in BobCat in All Keywords
  *  limited to sound recordings based on a single term.
  *  Result are presented with the given skin. If no skin is specified, the default skin will be applied.
  * 
  * Parameters:
  *  string skin:
  *    see possible skins above
  *
  *  string term1:
  *    term to be searched
  * 
  */
function EZBobcatAllKeywordSearchForSoundsURLGenerator (skin, term) {
  return searchBobcatByAllKeywordForSoundsURLGenerator (skin, term);
}

/** Function: string EZBobcatAllKeywordSearchForScoresURLGenerator
  *  Returns a URL string which will execute a basic keyword search in BobCat in All Keywords
  *  limited to scores based on a single term.
  *  Result are presented with the given skin. If no skin is specified, the default skin will be applied.
  * 
  * Parameters:
  *  string skin:
  *    see possible skins above
  *
  *  string term1:
  *    term to be searched
  * 
  */
function EZBobcatAllKeywordSearchForScoresURLGenerator (skin, term) {
  return searchBobcatByAllKeywordForScoresURLGenerator (skin, term);
}

/** Function: string EZBobcatAllKeywordSearchForBooksURLGenerator
  *  Returns a URL string which will execute a basic keyword search in BobCat in All Keywords
  *  limited to books based on a single term.
  *  Result are presented with the given skin. If no skin is specified, the default skin will be applied.
  * 
  * Parameters:
  *  string skin:
  *    see possible skins above
  *
  *  string term1:
  *    term to be searched
  * 
  */
function EZBobcatAllKeywordSearchForBooksURLGenerator (skin, term) {
  return searchBobcatByAllKeywordForBooksURLGenerator (skin, term);
}

/** Function: string EZBobcatReserveAllKeywordSearchURLGenerator
  *  Returns a URL string which will execute a basic reserve keyword search in BobCat in Title Keywords
  *  limited to journals based on a single term.
  *  Result are presented with the given skin. If no skin is specified, the default skin will be applied.
  * 
  * Parameters:
  *  string skin:
  *    see possible skins above
  *
  *  string term1:
  *    term to be searched
  * 
  */
function EZBobcatReserveAllKeywordSearchURLGenerator (skin, term) {
  return searchBobcatReservesByAllKeywordURLGenerator (skin, term);
}


/**
  *The following methods are not for public consumption
  *
  */

function searchBobcatByAllKeywordForMediaURLGenerator (skin, term1, term2, term3) {
  var facet_name = "facet_rtype";
  var facet_value = "media";
  return searchBobcatByAllKeywordURLGenerator (skin, term1, term2, term3, facet_name, facet_value);
}

function searchBobcatByAllKeywordForVideosURLGenerator (skin, term1, term2, term3) {
  var facet_name = "facet_rtype";
  var facet_value = "video";
  return searchBobcatByAllKeywordURLGenerator (skin, term1, term2, term3, facet_name, facet_value);
}

function searchBobcatByAllKeywordForScoresURLGenerator (skin, term1, term2, term3) {
  var facet_name = "facet_rtype";
  var facet_value = "scores";
  return searchBobcatByAllKeywordURLGenerator (skin, term1, term2, term3, facet_name, facet_value);
}

function searchBobcatByAllKeywordForSoundsURLGenerator (skin, term1, term2, term3) {
  var facet_name = "facet_rtype";
  var facet_value = "audio";
  return searchBobcatByAllKeywordURLGenerator (skin, term1, term2, term3, facet_name, facet_value);
}

function searchBobcatByAllKeywordForBooksURLGenerator (skin, term1, term2, term3) {
  var facet_name = "facet_rtype";
  var facet_value = "books";
  return searchBobcatByAllKeywordURLGenerator (skin, term1, term2, term3, facet_name, facet_value);
}

function searchBobcatByAllKeywordURLGenerator (skin, term1, term2, term3, facet_name, facet_value) {
  var attr = "kw:";
  var tab = "all";
  return searchBobcatByKeywordURLGenerator(skin, tab, attr, term1, attr, term2, attr, term3, facet_name, facet_value);
}

function searchBobcatByTitleKeywordURLGenerator (skin, term1, term2, term3, facet_name, facet_value) {
  var attr = "ti:";
  var tab = "all";
  return searchBobcatByKeywordURLGenerator(skin, tab, attr, term1, attr, term2, attr, term3, facet_name, facet_value);
}

function searchBobcatByAuthorKeywordURLGenerator (skin, term1, term2, term3, facet_name, facet_value) {
  var attr = "au:";
  var tab = "all";
  return searchBobcatByKeywordURLGenerator(skin, tab, attr, term1, attr, term2, attr, term3, facet_name, facet_value);
}

function searchBobcatReservesByAllKeywordURLGenerator (skin, term1, term2, term3, facet_name, facet_value) {
  var attr = "kw:";
  var tab = "reserves";
  return searchBobcatByKeywordURLGenerator(skin, tab, attr, term1, attr, term2, attr, term3, facet_name, facet_value);
}

/** Function: string searchBobcatByKeywordURLGenerator
  *  Returns a URL string which will execute a keyword search in BobCat.
  *  Result are presented with the given skin. If no skin is specified, the default skin will be applied.
  * 
  * Parameters:
  *  string skin:
  *    see possible skins above
  *
  *  string tab:
  *    see possible tab above
  *
  *  string term1:
  *    term to be searched
  * 
  *  string attr1:
  *    attribute corresponding to term1
  *      kw: - All
  *      ti: - Title
  *      jl: - Journal Title
  *      au: - Author
  *      su: - Subject
  *
  *  string term2 (optional):
  *    second term to be searched
  *    optional
  * 
  *  string attr2 (optional):
  *    attribute corresponding to term2
  *    required if term2 contains text
  *    see attr1 for valid values
  *
  *  string term3 (optional):
  *    second term to be searched
  *    optional
  * 
  *  string attr3 (optional):
  *    attribute corresponding to term2
  *    required if term2 contains text
  *    see attr1 for valid values
  *
  *  array facet_name (optional):
  *    select 1 or more of the following: 
  *       facet_rtype - resource type
  *       facet_topic - subject
  *       facet_library - library
  */
function searchBobcatByKeywordURLGenerator (skin, tab, attr1, term1, attr2, term2, attr3, term3, facet_name, facet_value) {
  var path = "/bobcat/search"
  var query_string = "&tab="+tab+"&freeText0="+term1;
  if (facet_name && facet_value) {
    query_string += "&facetName0="+facet_name+"&facetValue0="+facet_value+"";
  }
  return bobcatURLGenerator (skin, path, query_string);
}

/**
  */
function bobcatURLGenerator (skin, path, query_string) {
  var queryStringSkin="NYU";
  if (skin) {
    queryStringSkin = skin;
  }

  var bobcat_url = "http://" + bobcat_host + bobcat_port + path + "?vid=" + queryStringSkin;
  if (query_string) {
    bobcat_url += query_string;
  }
  return bobcat_url;
}

