/*

links.js
Author: Maurice Kühlborn
$LastChangedDate: 2006-12-11 13:42:27 +0100 (Mon, 11 Dec 2006) $
$Rev: 222 $

Excerpts inspired by
http://www.456bereastreet.com/archive/200605/opening_new_windows_with_javascript_version_11/
Thanks to Roger Johansson from 456 Berea Street

*/

Links = {
	
	touch_external_links:function(classname) {
		links = document.getElementsByTagName("a");
		for(i=0; i < links.length; i++) {
			link = links[i];
			if(link.className.indexOf(classname) != -1) {
				Links.attach_onclick_event(link);
				Links.set_title(link);
			}
		}
	},
	
	touch_external_links_within:function(id) {
		if(document.getElementById(id)) {
			links = document.getElementById(id).getElementsByTagName("a");
			for(i=0; i < links.length; i++) {
				link = links[i];
				Links.attach_onclick_event(link);
				Links.set_title(link);
			}
		}
	},
	
	attach_onclick_event:function(tag) {
		tag.onclick = function(e) {
			if (!e) var e = window.event;
			if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
				return true;
			}
			var new_window = window.open(this.href, "_blank");
			if (new_window) {
				if (new_window.focus) {
					new_window.focus();
					return false;
				}
			}
			return true;
		}
	},
	
	set_title:function(tag) {
		tag.setAttribute("title", "Link in neuem Fenster öffnen");
	}

}