/******************************************* 
 * A library of JavaScript bits and pieces.
 *  
 * @author  Natasha Moorfield
 *
 * @version 2(2011-12-26)(31)
 *  
 *******************************************/

/*
 *  Short script to switch on the required database
 *  search form (sb) and switch off those that are not required.
 *  Not necessarilly efficient but it does the job. Passing a value
 *  in sb not in the array myForm results in all search forms being
 *  hidden.
 */
function displaySearchBox(sb) {
  var myForm = new Array('s1', 's2');
  var i;
  for (i in myForm) {
    if (myForm[i] == sb) {
      document.getElementById(sb).style.display = "block";
    } else {
      document.getElementById(myForm[i]).style.display = "none";
    }
  }
}

/*
 *  email link functions
 */
function xf1() {
  a = new Array(110,98,106,109,117,112,59,111,98,117,98,116,105,98,110,112,112,115,103,106,102,109,101,65,98,112,109,47,100,112,110);
  sx = "";
  for (i in a) {
    sx += String.fromCharCode(a[i]-1)
  }
  return (sx);
}

function xf3(linkText, mSubject) {
  var outString = '<a href=' + xf1();
  if (mSubject) {
    outString += '?subject=';
    ptn = /\s+/g;
    outString += mSubject.replace(ptn, '%20');
  }
  if (!linkText) {
    linkText = 'eMail Natasha';
  }
  outString += '>'+linkText+'</a>';
  return (outString);
}

function xf3i(linkText, mSubject, icon) {
  if (!icon) {
    icon = 'mail.gif';
  }
  imgTag = '<img title="eMail Natasha" alt="Mailbox" src="webImg/icons/';
  imgTag += icon;
  imgTag += '" align="bottom" style="width: 24px; height: 24px; border: none; padding: 0px 10px;">';
  return (xf3(imgTag, mSubject) + "\n" + xf3(linkText, mSubject)) ;
}

function xf2(mSubject, linkText) {
  /*
   * The original xf2 function is now deprecated.
   * Any calls to xf2 are now merely translated into equivalent calls to xf3.
   */
  outString = "<span style='color: red;'>***</span>";
  outString += xf3(linkText, mSubject);
  return (outString);
}

/**
 * Display Brewery Item
 *
 * Displays the brewery information specified by the parameter 'bd' and
 * ensures that all others are not displayed.
 * @version 2(2011-12-26)(31)
 */
function displayBreweryItem(bd) {
  var breweryItem = new Array('factsheet', 'beerList', 'photos');
  var i;
  for (i in breweryItem) {
    if (breweryItem[i] == bd) {
      document.getElementById('bd_' + bd).style.display = 'block';
    } else {
      document.getElementById('bd_' + breweryItem[i]).style.display = 'none';
    }
  } 
}

