function getElementsByClassName(oElm, strTagName, strClassName) {
  var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
  var arrReturnElements = new Array();
  strClassName = strClassName.replace(/\-/g, "\\-");
  var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
  var oElement;

  for(var i = 0; i < arrElements.length; i++) {
    oElement = arrElements[i];      
     if(oRegExp.test(oElement.className)) {
       arrReturnElements.push(oElement);
    }
  }
  return (arrReturnElements);
}
function applyPopUps() {
  var i;
  var elm;

  var arrElements = getElementsByClassName(document, "*", "showpop");
  var count = arrElements.length;
  for (i = 0; i < count; i++) {
    elm = arrElements[i];

    elm.onclick = function() {
      showPopUp(this);
      return false; // prevents link being followed, and stops jumping
    }
    elm.onkeypress = function() {
      showPopUp(this);
      return false;
    }
  }

  arrElements = getElementsByClassName(document, "*", "hidepop");
  count = arrElements.length;
  for (i = 0; i < count; i++) {
    elm = arrElements[i];

    elm.onclick = function() {
      hidePopUp(this);
      return false; // prevents link being followed, and stops jumping
    }
    elm.onkeypress = function() {
      hidePopUp(this);
      return false;
    }
  }
}
function hidePopUp(elm) {
  var elmId;
  var popDiv;
  var shim_id;
  var shimIfr;

  elmId = elm.getAttribute("id");

  // check that elmId isn't already the pop_id (it should be, if function call is coming
  // from frontent 'auto' popup
  if (elmId.substring(0,3) != "pop") {
  // find the number at the end of the id (slice off the leading 'show', replace with 'pop')
  elmId = elmId.slice(4);
  elmId = "pop" + elmId;
  }

  // get the popup div and hide it
  popDiv = document.getElementById(elmId);
  popDiv.style.visibility = "hidden";

  // find the number at the end of the id (slice off the leading 'pop')
  // get the iframe with the matching shim_id and hide it
  shim_id = elmId.slice(3);
  shimIfr = document.getElementById("shim" + shim_id);
  shimIfr.style.display = "none";
}
function showPopUp(elm) {
  var elmId;
  var popDiv;
  var shim_id;
  var shimIfr;

  elmId = elm.getAttribute("id");

  // check that elmId isn't already the pop_id (it should be, if function call is coming
  // from frontent 'auto' popup
  if (elmId.substring(0,3) != "pop") {
  // find the number at the end of the id (slice off the leading 'show', replace with 'pop')
  elmId = elmId.slice(4);
  elmId = "pop" + elmId;
  }

  // get the popup div and show it
  popDiv = document.getElementById(elmId);
  popDiv.style.visibility = "visible";

  // find the number at the end of the id (slice off the leading 'pop')
  // get the iframe with the matching shim_id
  // match the dimensions and position of the popup div, but one layer below
  shim_id = elmId.slice(3);
  shimIfr = document.getElementById("shim" + shim_id);
  shimIfr.style.width = popDiv.offsetWidth;
  shimIfr.style.height = popDiv.offsetHeight;
  shimIfr.style.top = popDiv.offsetTop;
  shimIfr.style.left = popDiv.offsetLeft;
  shimIfr.style.display = "block";
}