/**
* xtarget.js - A JavaScript class for links on XHTML pages in new windows
*
* XHTML strict mode doesn't support the target attribute on links.
* This piece of Javascript hooks into links with class "external",
* and adds an onclick handler to open the link in a new window.
* Mix-in CSS classes are supported - i.e. if you need to specify a
* class for the link to change its appearance, you can still do that
* and have it open in a new window: class="yourclass external"
*
* This version only allows for opening in a new window, as you would
* get with target="_blank"
*
* @version 1.02.01 2008-10-25
* @package validation
* @author Ross McKay <rmckay@webaware.com.au>
* @link http://www.webaware.com.au/free/xtarget/
* @copyright copyright © 2007-2008 WebAware Pty Ltd
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*
* Full license: {@link http://www.webaware.com.au/free/license.htm}
*/

/**
* Hook the onload event of the window, ready to process all anchor tags
*
* @constructor
*/
function XTarget() {
	// hook into the page load event, so we can hook all static links when page has been loaded
	// add a hook to the document's onload event, so that our object is initialised after page load completes
	if (window.addEventListener) window.addEventListener("load", XTarget.hookOnLoad, false);
	else if (window.attachEvent) window.attachEvent("onload", XTarget.hookOnLoad);
}

/**
* onload hook - hook all static links on the page where anchor has a class 'external'
*/
XTarget.hookOnLoad = function() {
	var lks = document.getElementsByTagName('a');

	for(var i in lks) {
		var lk = lks[i];
		// find links with an href and CSS class "external" (NB: className can contain more than one CSS class!)
		if (lk.href && lk.className && /\bexternal\b/.test(lk.className)) {
			lk.onclick = XTarget.linkOnClick;
		}
	}
}

/**
* link onclick function - open the link in a new window
*
* @return {boolean} returns false to ensure that page doesn't navigate to href
*/
XTarget.linkOnClick = function() {
	window.open(this.href, "_blank");
	return false;
}

/**
* kick it into action
*/
var xtarget = new XTarget();
