if (!ATagHandler)
{
// ------------------------------------------------------------------------------------------------
// open new window

function newWindow(url,width,height,language,flags)
{
	var LangParam = '';
	var Matches;
	var WndNum = Math.round(Math.random() * 10000);
	
	if (flags==null)
		var flags = 4;
	height = parseInt(height) + 23;
	if (language!=null && language!='')
		LangParam = "lang=" + language + "&";
	else
	{
		Matches = /\/doc\/(\w+)\//.exec(window.location.href);
		if (Matches.length>1)
			LangParam = "lang=" + Matches[1] + "&";
	}
	var window_flags = "";
	window_flags += (flags & 1)!=0 ? "location=yes," : "location=no,";
	window_flags += (flags & 2)!=0 ? "menubar=yes," : "menubar=no,";
	window_flags += (flags & 4)!=0 ? "resizable=yes," : "resizable=no,";
	window_flags += (flags & 8)!=0 ? "scrollbars=yes," : "scrollbars=no,";
	window_flags += (flags & 16)!=0 ? "status=yes," : "status=no,";
	window_flags += (flags & 32)!=0 ? "toolbar=yes," : "toolbar=no,";
	window_flags += "width=" + width +",height=" + height; 
	window.open('/runtime/cms.run/doc/Deutsch/37/proxy/glossary/mediathek/defaultScripts/PHP/popup.php?width=' + width + "&height=" + height + "&" + LangParam + "url=" + encodeURIComponent(url),'PopUp_' + WndNum,window_flags);
}

// ------------------------------------------------------------------------------------------------
// open a simple popup window

function simplePopUp(url,width,height)
{
	var WndNum = Math.round(Math.random() * 10000);
    window.open(url,'simplePopUp_' + WndNum,'resizable=yes,scrollbars=yes,status=no,width=' + width +',height=' + height);
}

// ------------------------------------------------------------------------------------------------
// track link click information

function trackLink(linkid, type, request) {
	var xmlhttp = null;
	var failed = false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e1) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
			xmlhttp = null;
		}
	}
	if (!this.xmlhttp) {
		if (typeof XMLHttpRequest != "undefined") {
			xmlhttp = new XMLHttpRequest();
		} else {
			failed = true;
		}
	}
	if (!failed) {
		xmlhttp.open("GET","/runtime/cms.run/doc/Deutsch/37/proxy/glossary/mediathek/defaultScripts/PHP/trackLink.php?linkid="+linkid+"&type="+type+"&request="+request+"&referer="+window.location.href,false);
		xmlhttp.send(null);
	}
}

// ------------------------------------------------------------------------------------------------
// remove focus from a tags and initialize hotkeys

var ATagHandler =
{
	OldOnLoad: null,
	hotkeylist: [],
	focus_element: null,
	ctrl_pressed: false,
	alt_pressed: false,

	init: function(e)
	{
		var self = ATagHandler;
		
		if (self.OldOnLoad!=null)
			self.OldOnLoad(e);
		var aTags = document.getElementsByTagName("a");
		var i = 0;

		for (i=0; i<aTags.length; i++)
		{
			aTags[i].onfocus = aTags[i].blur;
			if (aTags[i].accessKey!="")
			{
				self.hotkeylist.push({ hotkey: aTags[i].accessKey.charCodeAt(0), atag: aTags[i] });
				if (!aTags[i].click)
					aTags[i].click = self.simulateclick;
			}
		}	
		self.hotkeylist.sort(self.compare);
		document.onkeypress = self.hotkey;
		document.onkeydown = self.keydown;
		document.onkeyup = self.keyup;

		var inputTags = document.getElementsByTagName("input");
		for (i=0; i<inputTags.length; i++)
		{
			if (inputTags[i].type=="text" || inputTags[i].type=="password" || inputTags[i].type=="file")
			{
				inputTags[i].onfocus = self.set_focus; 
				inputTags[i].onblur = self.remove_focus;
			}
		}
		var textareaTags = document.getElementsByTagName("textarea");
		for (i=0; i<textareaTags.length; i++)
		{
			textareaTags[i].onfocus = self.set_focus; 
			textareaTags[i].onblur = self.remove_focus;
		}
	},
	
	compare: function(a,b)
	{
		return (a.hotkey<b.hotkey ? -1 : (a.hotkey>b.hotkey ? 1 : 0))
	},

	hotkey: function(e)
	{
		var self = ATagHandler;
		var key;
		var i;

		if (self.focus_element==null && !self.alt_pressed && !self.ctrl_pressed)
		{
			if (!e)
				var e = window.event;
			key = (e.charCode || e.keyCode);
			for (i=0; i<self.hotkeylist.length; i++)
			{
				if (self.hotkeylist[i].hotkey==key)
				{
					self.hotkeylist[i].atag.click();
					e.cancelBubble = true;
					if (e.stopPropagation)
						e.stopPropagation();				
					return false;
				}
			}
		}	
		return true;
	},
	
	keyup: function(e)
	{
		var self = ATagHandler;
		var key;

		if (!e)
			var e = window.event;
		key = e.keyCode;
		if (key==18)
			self.alt_pressed = false;
		else if (key==17)
			self.ctrl_pressed = false;
		return true;
	},

	keydown: function(e)
	{
		var self = ATagHandler;
		var key;

		if (!e)
			var e = window.event;
		key = e.keyCode;
		if (key==18)
			self.alt_pressed = true;
		else if (key==17)
			self.ctrl_pressed = true;
		return true;
	},
	
	set_focus: function(e)
	{
		var self  = ATagHandler;
		self.focus_element = this;
	},
	
	remove_focus: function(e)
	{
		var self  = ATagHandler;
		self.focus_element = null;
	},
	
	simulateclick: function()
	{
		window.location.href = this.href;
		/*if (this.fireEvent)
			this.fireEvent("onclick");
		else
		{
			var e = document.createEvent("MouseEvents");
  			e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
			this.dispatchEvent(e);
		}*/
	}
};

ATagHandler.OldOnLoad = window.onload;
window.onload = ATagHandler.init;
}
