window.onload = function()
{
  if(typeof(fixSchemetaPngs) == "function") fixSchemetaPngs();
  // window.getElementsByClassName = getElementsByClassName;
  hyperlinksInNewWindow("external", document, "externalWindow", "", false);
};

function getElementsByClassName(classList, baseElement, elementFilter)
{
  var _classes, _searchElements, _output = new Array(), _base;
  switch(typeof(classList))
  {
  case "object":
    _classes = classList;
    break;
  case "string":
    _classes = classList.split(" ");
    break;
  default:
    throw {
      name: "ArgumentException",
      message: "Parameter 'classList' was of an unexpected type",
      data:
      {
        ClassList: classList,
        Base: baseElement,
        Filter: elementFilter
      }
    };
  };
  switch(typeof(elementFilter))
  {
  case "array":
    _searchElements = elementFilter;
    break;
  case "string":
    _searchElements = elementFilter.split(" ");
    break;
  default:
    _searchElements = ["*"];
  };
  _base = ( typeof(baseElement) == "object" && 
            typeof(baseElement.getElementsByTagName) == "function")?
              baseElement : document;

  var _i, _j, _k, _elements, _current, _classString, _classList;
  for(_i = 0; _i < _searchElements.length; _i++)
  {
    _elements = _base.getElementsByTagName(_searchElements[_i]);
    for(_j = 0; _j < _elements.length; _j++)
    {
      _current = _elements[_j];
      _classString = (String.notEmpty(_current.getAttribute("class")))?
        _current.getAttribute("class") : _current.getAttribute("className");
      if(!String.notEmpty(_classString)) continue;
      else _classList = _classString.split(" ");
      for(_k = 0; _k < _classList.length; _k++)
        if(_classes.contains(_classList[_k])) _output.push(_current);
    };
  };
  return _output;
};

function hyperlinksInNewWindow(classes, base, winName, winSpec, rep)
{
  var _processed = 0, _hyperlinks = (typeof(classes) != "undefined")?
    window.getElementsByClassName(classes, base, "a") :
    ( typeof(base) == "object" &&
      typeof(base.getElementsByTagName) == "function")?
    base.getElementsByTagName("a") : document.getElementsByTagName("a");
  for(var _i = 0; _i < _hyperlinks.length; _i++)
  {
    openInNewWindow(_hyperlinks[_i], winName, winSpec, rep);
    _processed ++;
  };
  return _processed;
};

function openInNewWindow(objRef, winName, winSpec, rep)
{
  if( typeof(objRef) != "object" ||
      typeof(objRef.nodeName) != "string" ||
      objRef.nodeName != "A")
  {
    throw {
      name: "ArgumentException",
      message: "Parameter 'objRef' is not an HTML 'a' object.",
      data:
      {
        ObjectRef: objRef,
        Name: winName,
        Specs: winSpec,
        Replace: rep
      }
    };
  };
  var _winName = (typeof(winName) == "string")?
    winName : "externalWindow";
  var _winSpec = (typeof(winSpec) == "string")?
    winSpec : "";
  var _replace = (typeof(rep) == "boolean")? rep : false;
  objRef.onclick = function()
  {
    window.open(this.getAttribute("href"), _winName, _winSpec, _replace);
    return false;
  };
  objRef.onkeypress = function(e)
  {
    var _keypressed = (window.event)? e.keyCode : e.which;
    if(_keypressed == 13 || _keypressed == 32)
    {
      window.open(this.getAttribute("href"), _winName, _winSpec, _replace);
      return false;
    };
    return true;
  };
  return true;
};
String.notEmpty = function(str)
{
  if(typeof(str) == "string" && str.length > 0) return true;
  else return false;
};
Array.prototype.contains = function(ele)
{
  for(var _i = 0; _i < this.length; _i ++)
  {
    if(this[_i] === ele)
      return true;
  };
  return false;
};

