  /**
   * --------------------------------------------------------------------------
   * function f_getWindowDimension
   * --------------------------------------------------------------------------
   */
  function f_getWindowDimension(){
    var w_docWidth = 0;
    var w_docHeight = 0;
    if(typeof(window.innerWidth) == 'number'){
      //Non-IE
      w_docWidth = window.innerWidth;
      w_docHeight = window.innerHeight;
    }
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
      //IE 6+ in 'standards compliant mode'
      w_docWidth  = document.documentElement.clientWidth;
      w_docHeight = document.documentElement.clientHeight;
    }
    else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
      //IE 4 compatible
      w_docWidth = document.body.clientWidth;
      w_docHeight = document.body.clientHeight;
    }
    return [w_docWidth, w_docHeight];
  }
  
  /**
   * --------------------------------------------------------------------------
   * function f_getScrollXY
   * --------------------------------------------------------------------------
   */
  function f_getScrollXY(){
    var scrOfX = 0;
    var scrOfY = 0;
    //Netscape compliant
    if(typeof(window.pageYOffset) == 'number'){
      scrOfX = window.pageXOffset;
      scrOfY = window.pageYOffset;
    }
    //DOM compliant
    else if(document.body && (document.body.scrollLeft || document.body.scrollTop)){
      scrOfX = document.body.scrollLeft;
      scrOfY = document.body.scrollTop;
    }
    //IE6 standards compliant mode
    else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
      scrOfX = document.documentElement.scrollLeft;
      scrOfY = document.documentElement.scrollTop;
    }
    return [scrOfX, scrOfY];
  }
  
  /**
   * --------------------------------------------------------------------------
   * function f_findPos
   * --------------------------------------------------------------------------
   */
  function f_findPos(obj){
    var curleft = curtop = 0;
    if(obj.offsetParent){
      curleft = obj.offsetLeft
      curtop = obj.offsetTop
      while(obj = obj.offsetParent){
        curleft += obj.offsetLeft
        curtop += obj.offsetTop
      }
    }
    return [curleft, curtop];
  }
  
  /**
   * --------------------------------------------------------------------------
   * function f_positionDiv
   * --------------------------------------------------------------------------
   */
  function f_positionDiv(p_oElement){
    var w_aPagDim   = f_getWindowDimension();
    var w_aSrollPos = f_getScrollXY();
    var t_sPattern  = /\D/gi;
    // width
    var w_iDiv_W    = f_regularExpression('replace', t_sPattern, f_getStyle(p_oElement, 'width'), '');
    
    // height
    
    //var w_iDiv_H    = f_regularExpression('replace', t_sPattern, f_getStyle(p_oElement, 'height'), '');
    var w_iDiv_H    = p_oElement.offsetHeight;
    //alert(w_iDiv_H + ', ' + t_iDiv_H);
    
    // padding-left
    var w_iDiv_PL = 0;
    var t_iDiv_PL;
    if(t_iDiv_PL = f_getStyle(p_oElement, 'paddingLeft')){
      w_iDiv_PL   = f_regularExpression('replace', t_sPattern, t_iDiv_PL, '');
    }
    else if(t_iDiv_PL = f_getStyle(p_oElement, 'padding-left')){
      w_iDiv_PL   = f_regularExpression('replace', t_sPattern, t_iDiv_PL, '');
    }
    
    // padding-top
    var w_iDiv_PT = 0;
    var t_iDiv_PT;
    if(t_iDiv_PT = f_getStyle(p_oElement, 'paddingTop')){
      var w_iDiv_PT   = f_regularExpression('replace', t_sPattern, t_iDiv_PT, '');
    }
    else if(t_iDiv_PT = f_getStyle(p_oElement, 'padding-top')){
      var w_iDiv_PT   = f_regularExpression('replace', t_sPattern, t_iDiv_PT, '');
    }
    
    var w_iTop  = (((w_aPagDim[1]*1 /2) -(w_iDiv_H*1 /2)) -(w_iDiv_PT*1 /2) +w_aSrollPos[1]*1);
    var w_iLeft = (((w_aPagDim[0]*1 /2) -(w_iDiv_W*1 /2)) -(w_iDiv_PL*1 /2) +w_aSrollPos[0]*1);
    
    if(w_iTop < w_aSrollPos[1]){
      w_iTop = w_aSrollPos[1]+10;
    }
    
    p_oElement.style.left = w_iLeft + 'px';
    p_oElement.style.top  = ((w_iTop < 0) ? 0 : w_iTop) + 'px';
  }
  
  /**
   * --------------------------------------------------------------------------
   * function f_getStyle
   * --------------------------------------------------------------------------
   * Description:
   *   finds a style for an element and returns the value.
   */
  function f_getStyle(p_oElement, p_sStyleName){
    var w_sStyleValue;
    if(p_oElement.currentStyle){
      if(w_sStyleValue = p_oElement.currentStyle[p_sStyleName]){
        return w_sStyleValue;
      }
    }
    else if(window.getComputedStyle){
      if(w_sStyleValue = document.defaultView.getComputedStyle(p_oElement, null).getPropertyValue(p_sStyleName)){
        return w_sStyleValue;
      }
    }
    return false;
  }
  
  /**
   * --------------------------------------------------------------------------
   * function f_regularExpression
   * --------------------------------------------------------------------------
   */
  function f_regularExpression(p_eType, p_sPattern, p_sString, p_sReplace){
    // p_eType -> match / exec / replace / test
    switch(p_eType){
      case 'match':{
        var w_oRegExp = new RegExp(p_sPattern);
        if(p_sString.match(w_oRegExp)){
          return true;
        }
        return false;
        break;
      }
      case 'exec':{
        var w_oRegExp = new RegExp(p_sPattern);
        var m = w_oRegExp.exec(p_sString);
        if (m == null) {
          return false;
        }
        else{
          var w_sString = "Match at position " + m.index + ":\n";
          for(i = 0; i < m.length; i++){
            w_sString = w_sString + m[i] + "\n";
          }
          return w_sString;
        }
        break;
      }
      case 'replace':{
        var w_oRegExp = new RegExp(p_sPattern);
        return p_sString.replace(w_oRegExp, p_sReplace);
        break;
      }
      case 'test':{
        var w_oRegExp = new RegExp(p_sPattern);
        if(w_oRegExp.test(p_sString)){
          return true;
        }
        return false;
        break;
      }
      default:{
        break;
      }
    }
  }
  
  /**
   * --------------------------------------------------------------------------
   * function f_setOpacity
   * --------------------------------------------------------------------------
   */
  function f_setOpacity(p_oObj, p_iOpacity){
    w_iOpacity = ((p_iOpacity == 100) ? 99.999 : p_iOpacity);
    p_oObj.style.filter       = "alpha(opacity:" + w_iOpacity + ")"; // IE/Win
    p_oObj.style.KHTMLOpacity = w_iOpacity/100;                      // Safari smThan 1.2, Konqueror
    p_oObj.style.MozOpacity   = w_iOpacity/100;                      // Older Mozilla and Firefox
    p_oObj.style.opacity      = w_iOpacity/100;                      // Safari 1.2, newer Firefox and Mozilla, CSS3
  }
  
  /* --------------------------------------------------------------------------
   * function f_adjustSiteForPopupDiv
   * --------------------------------------------------------------------------
   */
  var g_oPoppedUpDiv = null;
  var g_oBlackOver   = null;
  function f_adjustSiteForPopupDiv(p_bPopup, p_oPopupDiv){
    // create black layover
    if(g_oBlackOver == null){
      g_oBlackOver = document.createElement('div');
      g_oBlackOver.id                    = 'blackOver';
      g_oBlackOver.style.position        = 'absolute';
      g_oBlackOver.style.top             = '0px';
      g_oBlackOver.style.left            = '0px';
      g_oBlackOver.style.width           = '100%';
      g_oBlackOver.style.height          = '100%';
      g_oBlackOver.style.backgroundColor = 'black';
      g_oBlackOver.style.display         = 'none';
      g_oBlackOver.style.zIndex          = 9999;
      g_oBlackOver.style.overflow        = 'hidden';
      g_oBlackOver.onmousedown           = function(){f_adjustSiteForPopupDiv(false, p_oPopupDiv);};
      document.body.appendChild(g_oBlackOver);
      f_setOpacity(g_oBlackOver, 50);
    }
    
    // this function is called upon improperly
    if((p_oPopupDiv == g_oPoppedUpDiv) && !p_bPopup){
      g_oPoppedUpDiv.style.display = 'none';
      g_oPoppedUpDiv = null;
    }
    
    // if these div-elements aren't the same, make sure that the one that's not called upon is closed.
    if(p_oPopupDiv != g_oPoppedUpDiv){
      if(g_oPoppedUpDiv != null){
        g_oPoppedUpDiv.style.display = 'none';
      }
      // set a reference for the div-element that is called upon
      g_oPoppedUpDiv = p_oPopupDiv;
    }
    
    //f_setOpacity(p_oPopupDiv, 90);
    p_oPopupDiv.style.display  = ((p_bPopup) ? 'block' : 'none');
    g_oBlackOver.style.display = ((p_bPopup) ? 'block' : 'none');
    
    // make sure this layover is beneath the 'blackOver'
    document.body.appendChild(p_oPopupDiv);
    
    // position div
    f_positionDiv(p_oPopupDiv);
  }