// $Id: contextlinks.js,v 1.2.2.1 2006/05/10 16:12:47 jhriggs Exp $

/**
 * The contextlinks.js file provides a JavaScript function for opening
 * links in a new browser window.  Links with the rel attribute set to
 * "CONTEXTLINKS_NEW_WINDOW" will be opened in a new browser.  This is
 * used instead of the target attribute to allow strict HTML4 and
 * XHTML pages to validate.
 *
 * @version $Id: contextlinks.js,v 1.2.2.1 2006/05/10 16:12:47 jhriggs Exp $
 * @copyright Copyright (c) 2004-2006 Jim Riggs.  All rights reserved.
 * @author Jim Riggs <drupal at jim and lissa dot com>
 */

// add the onload event
if (isJsEnabled()) {
  addLoadEvent(contextlinks_new_window_links);
}

/**
 * Sets all document anchors with a rel attribute of
 * "CONTEXTLINKS_NEW_WINDOW" to open in a new window.
 */
function contextlinks_new_window_links() {
  if (!document.getElementsByTagName) {
    return;
  }

  var theLinks = document.getElementsByTagName("a");

  for (var i = 0; i < theLinks.length; i++) {
    if (theLinks[i].getAttribute("href") && (theLinks[i].getAttribute("rel") == "CONTEXTLINKS_NEW_WINDOW")) {
      theLinks[i].target = "_blank";
    }
  }
}
