/*
Sammlung von Funktionen die ueberall Sinn machen
DropNet AG 2009

function setTarget();		setzt fŸr alle externen und PDF-Verweise das Attribut target="_blank"
					bereits gesetzte 'target'-Attribute werden nicht ueberschrieben

function resizeText(1);	1 / -1
					setzt die Schriftgroesse und speichert den Wert in einem Cookie
	
function changeFavicon('/favicon.ico');
					€ndert favicon.ico dynamisch
					muss mit rel="shortcut icon" type="image/x-icon" definiert sein

function writeCookie(name, value, expires);
					Schreibt ein Cookie mit name=value; expires in Tagen oder leer

function readCookie(name);
					Gibt den Wert des Cookies 'name' zurŸck

*/

function setTarget()
	{
	var arrHREF = document.getElementsByTagName('a');
	var rg = new RegExp('http://' + window.location.hostname, 'i');
	for(var i=0; i<arrHREF.length; i++)
		{
		if (arrHREF[i].target) { continue; }
		var blank = 0;
		if (arrHREF[i].href.indexOf('http://') != -1 && arrHREF[i].href.search(rg) == -1) blank = 1;
		else if (arrHREF[i].href.match(/\.pdf$/)) blank = 1;
		else if (arrHREF[i].href.match(/\.doc$/)) blank = 1;
		else if (arrHREF[i].href.match(/\.xls$/)) blank = 1;
		if (blank == 1)
			{
			arrHREF[i].setAttribute('target', '_blank');
			if (arrHREF[i].parentNode.getAttribute('onclick'))
				{
				if (arrHREF[i].parentNode.getAttribute('onclick').search(rg) == -1)
					{
					arrHREF[i].parentNode.setAttribute('onclick', 'window.open(\'' + arrHREF[i].href + '\',\'_blank\');return false;');
					}
				}
			}
		}
	}

function resizeText(multiplier)
	{
	var size = readCookie('site_font_size');
	var fontsize = '100%';
	if (size) fontsize = size;
	fontsize = Math.round((parseFloat(fontsize) + parseFloat(multiplier * 10)) * 100) / 100 + '%';
//	alert(fontsize);
//	document.body.style.zoom = fontsize;
//	var arr = document.getElementsByTagName('body');
//	for(var i=0; i< arr.length; i++)
//		{
//		arr[i].style.fontSize = fontsize;
//		}
//	writeCookie('site_font_size', fontsize, 365);
	}

function changeFavicon(iconURL)
	{
	if (iconURL == '') return true;
	var links = document.getElementsByTagName('head')[0].getElementsByTagName('link');
	for (var i=0; i<links.length; i++)
		{
		var link = links[i];
		if (link.type == 'image/x-icon' && link.rel == 'shortcut icon')
			{
			document.getElementsByTagName('head')[0].removeChild(link);
			break;
			}
		}
	var link = document.createElement('link');
	link.type = 'image/x-icon';
	link.rel = 'shortcut icon';
	link.href = iconURL;
	document.getElementsByTagName('head')[0].appendChild(link);
	return true;
	}

function writeCookie(name, value, expire)
	{
	var cookie = name + '=' + escape(value);
	cookie += '; path=/';
	if (expire)
		{
		var date = new Date();
		date.setTime(date.getTime() + expire * 24 * 60 * 60 * 1000);
		cookie += '; expires=' + date.toGMTString();
		}
	document.cookie=cookie;
	}

function readCookie(name)
	{
	var value = document.cookie.match('(?:^|;)\\s*' + name + '=([^;]*)');
	return (value) ? decodeURIComponent(value[1]) : null;
	}

function addLoadListener(fn)
	{
	if (typeof window.addEventListener != 'undefined') window.addEventListener('load', fn, false);
	else if (typeof document.addEventListener != 'undefined') document.addEventListener('load', fn, false);
	else if (typeof window.attachEvent != 'undefined') window.attachEvent('onload', fn);
	else
		{
		var oldfn = window.onload;
		if (typeof window.onload != 'function') window.onload = fn;
		else window.onload = function() { oldfn(); fn(); }
		}
	}

addLoadListener(setTarget);
//	addLoadListener(resizeText(0));


