/* installed file=/include/externalLinks.js
 *
 *	Copyright © 2010-2011 by FKE Internet.  All rights reserved.
 *
 *	$Id: /include/externalLinks.js,v $
 */
/**
*	Function to change links on the page to external sites so they
*		open in a new browser window
*
*	Derived from an article found at
*		http://articles.sitepoint.com/article/standards-compliant-world
*
*	Author:			Fred Koschara
*	Creation Date:	February seventeenth, 2010
*	Last Modified:	June 10, 2011 @ 12:34 am
*
*	Revision History:
*	   Date		  by		Description
*	2011/06/10	wfredk	support "rel=name:target" constructs
*	2011/06/10	wfredk	support FORM elements in addition to HREF
*	2010/08/18	wfredk	replace missing close-paren on href test
*	2010/07/27	wfredk	support rel="_top" and rel="_self" attributes
*	2010/02/17	wfredk	original development
*/

/**
* changes links to external sites on the page to open in a new
*	browser window, replacing the deprecated HTML TARGET attribute.
*	Links to external sites must have a 'rel="external"' attribute
*	where the TARGET attribute was formerly placed.
*
*/
function externalLinks()
{	if (!document.getElementsByTagName) return;

	var anchor;
	var anchors=document.getElementsByTagName("a");
	var attrib;

	for (var i=0; i<anchors.length; i++)
	{	var anchor=anchors[i];
		if (anchor.getAttribute("href")		// a href tags
		||	anchor.getAttribute("form"))	// form tags
		{	attrib=anchor.getAttribute("rel");
			if (attrib==null)				// marked tags only
				continue;
			if (attrib=="external")
				anchor.target="_blank";	// set the DOM target attribute
			else if (attrib=="_self")
				anchor.target="_self";	// set the DOM target attribute
			else if (attrib=="_top")
				anchor.target="_top";	// set the DOM target attribute
			else if (attrib.substring(0,5)=="name:")
				anchor.target=attrib.substring(5);
		}
	}
}

addLoadEvent(externalLinks);
//
// EOF: externalLinks.js

