////////////////////////////////////////////////////////////////////////////////
//
// AutoNewWindow
// Copyright (C) 2004 Homeboyz Interactive, Inc.
// License: BSD
// $Id: autoNewWindow.js,v 1.2 2004/04/01 17:48:20 tduffey Exp $
//
////////////////////////////////////////////////////////////////////////////////
//
// Automatically turn links with class "autoNewWindow" into
// links that use Javascript to open in a new window.
// e.g. if you have:
//
//	<a href="http://foobar.com" class="autoNewWindow" />
//
// then then this link will open in a new window in Javascript-enabled browsers
//
////////////////////////////////////////////////////////////////////////////////

function autoNewWindowPopup(href)
{
	window.open(href, "autoNewWindow");
}

function autoNewWindow()
{
	if (document.getElementById)
	{
		var searchRegex = /autoNewWindow/i;
		var anchors = document.getElementsByTagName("a");

		for (var i = 0; i < anchors.length; i++)
		{
			// If anchor has class "autoNewWindow"
			if (-1 != anchors[i].className.search(searchRegex))
			{
				anchors[i].onclick = function()
				{
					autoNewWindowPopup(this.href);
					return false;
				}
			}
		}
	}
}

if (typeof window.addEventListener != "undefined")
	window.addEventListener("load", autoNewWindow, false);
else if (typeof document.addEventListener != "undefined")
	document.addEventListener("load", autoNewWindow, false);
else if (typeof window.attachEvent != "undefined")
	window.attachEvent("onload", autoNewWindow);
else
{
	if (typeof window.onload == "function")
	{
		window.currentOnload = window.onload;

		window.onload = function()
		{
			window.currentOnload();
			autoNewWindow();
		}
	}
	else
		window.onload = autoNewWindow;
}
