// See page 15 of "The Javascript Anthology"
// a Sitepoint book by James Edwards and Cameron Adams
// for a discussion of addLoadListener().
function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}

/*
addEvent function by Scott Andrew.  See pages 165-166
in "Beginning Javascript With Dom Scripting and Ajax" 
by Christian Heilmann, Apress, isbn 1-59059-680-3.
*/
function addEvent(elm, evType, fn, useCapture)
{
  if (elm.addEventListener)
  {
    elm.addEventListener(evType, fn, useCapture)
    return true;
  }
  else if (elm.attachEvent)
  {
    var r = elm.attachEvent('on' + evType, fn); // IE onevent syntax
    return r;
  }
  else
  {
    elm['on' + evType] = fn;  // non-dom support
  }
}

dom_utilities = {
  get_CSS_class:function(elm)
  // Returns the CSS class of the element (elm) passed in as an argument. 
  {
    var elm_CSS_class = "";
    elm_CSS_class = elm.getAttribute('className'); // IE
    if (elm_CSS_class == null)
    {
      elm_CSS_class = elm.getAttribute('class'); // DOM compliant browsers
    }
    return elm_CSS_class;
  },
  set_CSS_class:function(elm,new_class)
  /*
     Re-sets the CSS class of elm to new_class. 
     Does not accomodate multiple classes.
  */
  {
    var elm_CSS_class = "";
    elm_CSS_class = elm.getAttribute('className'); // IE
    if (elm_CSS_class !== null)
    {
      elm.setAttribute('className',new_class);      
    }
    if (elm_CSS_class == null)
    {    
      elm_CSS_class = elm.getAttribute('class'); // DOM compliant browsers
      if (elm_CSS_class !== null)
      {
        elm.setAttribute('class',new_class);      
      }
    }
  },
  get_nextSibling:function(entry_node)
  // Gets the next sibling node to entry_node.
  {
    var next_sibling_node = entry_node.nextSibling;
    while (next_sibling_node.nodeType == "3")
    {
      next_sibling_node = next_sibling_node.nextSibling;
    }
    return next_sibling_node;
  },
  get_previousSibling:function(entry_node)
  // Gets the previous sibling node to entry_node.
  {
    var previous_sibling_node = entry_node.previousSibling;
    while (previous_sibling_node.nodeType == "3")
    {
      previous_sibling_node = previous_sibling_node.previousSibling;
    }
    return previous_sibling_node;
  },  
  get_firstChild:function(entry_node)
  // Gets the first child node to entry_node.
  {
    var first_child_node = entry_node.firstChild;
    while (first_child_node.nodeType == "3")
    {
      first_child_node = first_child_node.nextSibling;
    }
    return first_child_node;
  },
  get_ParentNode:function(entry_node)
  // Gets the parent node to entry_node.
  {
    var parent_Node = entry_node.parentNode;
    while (parent_Node.nodeType == "3")
    {
      parent_Node = parent_Node.parentNode;
    }
    return parent_Node;
  },
  get_Target:function(e)
  {
    // IE uses window.event.srcElement; DOM compliant browsers use e.target.  
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target){return false;}
    /*
    Fix for Safari bug that returns the text node inside of the link instead of link element (a). 
    See pages 167-168 in "Beginning Javascript With Dom Scripting and Ajax" 
    by Christian Heilmann, Apress, isbn 1-59059-680-3.
    */		
    while(target.nodeType!=1 && target.nodeName.toLowerCase()!='a')
    {
      target=target.parentNode;
    }
    return target;
  },
  stop_Default:function(e)
  {
    if(window.event && window.event.returnValue)
    {
      window.event.returnValue = false;
    } 
    if (e && e.preventDefault)
    {
      e.preventDefault();
    }
  },
  cancel_Click:function(e)
  {
    if (window.event)
    {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.stopPropagation && e.preventDefault)
    {
      e.stopPropagation();
      e.preventDefault();
    }
  },
  get_Browser:function() 
// See pages 194-197 of "The Javascript Anthology"
// a Sitepoint book by James Edwards and Cameron Adams
// for a discussion of the get_Browser() function.  
  {
    var agent = navigator.userAgent.toLowerCase();
    if (typeof navigator.vendor != "undefined" && navigator.vendor == "KDE" &&
        typeof window.sidebar != "undefined")
    {
      return "kde";
    }
    else if (typeof window.opera != "undefined")
    {
      var version = parseFloat(agent.replace(/.*opera[\/ ]([^ $]+).*/, "$1"));
  
      if (version >= 7)
      {
        return "opera7";
      }
      else if (version >= 5)
      {
        return "opera5";
      }
  
      return false;
    }
    else if (typeof document.all != "undefined")
    {
      if (typeof document.getElementById != "undefined")
      {
        var browser = agent.replace(/.*ms(ie[\/ ][^ $]+).*/, "$1").replace(/ /, "");
  
        if (typeof document.uniqueID != "undefined")
        {
          if (browser.indexOf("5.5") != -1)
          {
            return browser.replace(/(.*5\.5).*/, "$1");
          }
          else
          {
            return browser.replace(/(.*)\..*/, "$1");
          }
        }
        else
        {
          return "ie5mac";
        }
      }
  
      return false;
    }
    else if (typeof document.getElementById != "undefined")
    {
      if (navigator.vendor.indexOf("Apple Computer, Inc.") != -1)
      {
        if (typeof window.XMLHttpRequest != "undefined")
        {
          return "safari1.2";
        }
  
        return "safari1";
      }
      else if (agent.indexOf("gecko") != -1)
      {
        return "mozilla";
      }
    }
    return false;
  }  
}

poppers = {
  little_pop:function(e) {
    var URL = '';
    var newWindow = '';
    if (window.event) {
      URL = window.event.srcElement.getAttribute('href');
    }
    else {
      URL = e.target.getAttribute('href');
    }
    newWindow = window.open(URL,'pop_window','width=600,height=620'+',scrollbars=yes,resizeable=no,fullscreen=no,status=yes');
    if (window.focus) {
      newWindow.focus()
    }
    return false;
  },
  getLinks:function() {
    var x = document.getElementsByTagName('a');
    var xClass = "";
    for (var i=0;i<x.length;i++) {
      xClass = dom_utilities.get_CSS_class(x[i]);
      if (xClass == 'pop_msg') {
        addEvent(x[i],'click',dom_utilities.cancel_Click,false);      
        addEvent(x[i],'click',poppers.little_pop,false);
        // x[i].title += ' (Popup)';
      }
    }
  }
}

fix_Height={
/*
If div#sidebar is higher than div#content set the height
of div#content equal to div#sidebar. This evens up the heights
of the divs and the border dividing them.
*/

  init:function()
  {
  alert("Running fix_height.init.");
    if(!document.getElementById || !document.createTextNode){return;}
    var content_height;
    var sidebar_height;
    var content_div = document.getElementById('content');
    var sidebar_div = document.getElementById('sidebar');  
    if(!(content_div && sidebar_div)){return;}    
    content_height = content_div.offsetHeight;
    sidebar_height = sidebar_div.offsetHeight;
    if (sidebar_height >= content_height)
    {
      content_div.style.height = parseInt(sidebar_height - 1) + "px";
    }
    content_height = content_div.offsetHeight;
    // sidebar_height = sidebar_div.offsetHeight;    
    // alert ("After fixing." + "\n" + "content_height: " + content_height + "\n" + "sidebar_height: " + sidebar_height);
  }
}

// addLoadListener(fix_Height.init);
addEvent(window,'load',poppers.getLinks,false);