// JavaScript Document

window.addEvent('domready', function() {
	// browser detection (task 49153,55871)
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	var is_firefox36 = navigator.userAgent.toLowerCase().indexOf('firefox/3.6') > -1;
	var is_firefox4 = navigator.userAgent.toLowerCase().indexOf('firefox/4.0') > -1;
	var is_firefox5 = navigator.userAgent.toLowerCase().indexOf('firefox/5.0') > -1;
	var is_firefox6 = navigator.userAgent.toLowerCase().indexOf('firefox/6.0') > -1;
	var is_firefox7 = navigator.userAgent.toLowerCase().indexOf('firefox/7.0') > -1;
	var is_firefox8 = navigator.userAgent.toLowerCase().indexOf('firefox/8.0') > -1;
	var is_firefox9 = navigator.userAgent.toLowerCase().indexOf('firefox/9.0') > -1;
	var is_firefox10 = navigator.userAgent.toLowerCase().indexOf('firefox/10.0') > -1;
	var is_firefox11 = navigator.userAgent.toLowerCase().indexOf('firefox/11.0') > -1;
	var is_firefox12 = navigator.userAgent.toLowerCase().indexOf('firefox/12.0') > -1;
	var is_ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6.0') > -1;
	var is_ie7 = navigator.userAgent.toLowerCase().indexOf('msie 7.0') > -1;
	var is_ie8 = navigator.userAgent.toLowerCase().indexOf('msie 8.0') > -1;
	var is_ie9 = navigator.userAgent.toLowerCase().indexOf('msie 9.0') > -1;

	//deactivate pop under in browser (task 49153,55871):
	if (is_firefox4 || is_firefox5 || is_firefox6 || is_firefox7 || is_firefox8 || is_firefox9 || is_firefox10 || is_firefox11 || is_firefox12) popIsDead = true;

	exit_link.initialize();
});

/* Date-Tool start */
// global_getDate() zum beziehen eines Datums inklusive Uhrzeit nach individuellen Format
// format (Bsp: "dd.mm.yyyy um hh:mm:ss" oder "am DD den dd. (hh:miampm)"):
//   dd = Tag des Monats mit f�hrender 0 falls einstellig
//   DD = Wochentag
//   mm = Monat mit f�hrender 0 falls einstellig
//   MM = Monat ausgeschrieben
//   yyyy = Jahr vierstellig
//   yy = Jahre zweistellig mit '
//   hh = Stunden mit f�hrender 0 falls einstellig
//   mi = Minuten mit f�hrender 0 falls einstellig
//   ss = Sekunden mit f�hrender 0f falls einstellig
//   ampm = Gibt eine zw�lfst�ndige Uhrzeit mit am / pm zur�ck
// days: Array mit den Wochentagen
// month: Array mit den Monaten
// Bsp:
//   $('dateTime').set('text',global_getDate('{dd}.{mm}.{yyyy} {hh}:{mi}:{ss}'));
//   var days = ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'];
//   var month = ['Januar','Februar','M�rz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'];
//   $('dateTime').set('text',global_getDate('{DD} der {dd}. {MM} {yy} um {hh}:{mi}:{ss}{ampm}',days,month));
global_getDate = function(format, days, month) {
	global_getDate.now = new Date();
	var ampm = false;
	if(format.search(/{ampm}/) > -1) {
		format = format.replace(/{ampm}/g, global_getDate.getAMPM());
		ampm = true;
	}
	if(format.search(/{dd}/) > -1) format = format.replace(/{dd}/g, global_getDate.getDay());
	if(format.search(/{DD}/) > -1) format = format.replace(/{DD}/g, global_getDate.getDay(days));
	if(format.search(/{mm}/) > -1) format = format.replace(/{mm}/g, global_getDate.getMonth());
	if(format.search(/{MM}/) > -1) format = format.replace(/{MM}/g, global_getDate.getMonth(month));
	if(format.search(/{yyyy}/) > -1) format = format.replace(/{yyyy}/g, global_getDate.getYear(true));
	if(format.search(/{yy}/) > -1) format = format.replace(/{yy}/g, global_getDate.getYear(false));
	if(format.search(/{hh}/) > -1) format = format.replace(/{hh}/g, global_getDate.getHours(ampm));
	if(format.search(/{mi}/) > -1) format = format.replace(/{mi}/g, global_getDate.getMinutes());
	if(format.search(/{ss}/) > -1) format = format.replace(/{ss}/g, global_getDate.getSeconds());
	return format;
}
global_getDate.getDay = function(days) {
	var result = '';
	if($type(days) == 'array') {
		result = days[global_getDate.now.getDay()];
	} else {
		result = global_getDate.now.getDate();
		if(result.length < 10) result = '0' + result;
	}
	return result;
}
global_getDate.getMonth = function(month) {
	var result = '';
	if($type(month) == 'array') {
		result = month[global_getDate.now.getMonth()];
	} else {
		result = global_getDate.now.getMonth() + 1;
		if(result < 10) result = '0' + result;
	}
	return result;
}
global_getDate.getYear = function(full) {
	var result = '';
	result = global_getDate.now.getFullYear();
	if(!full) result = '\'' + (result.toString()).substring(2,4);
	return result;
}
global_getDate.getHours = function(ampm) {
	var result = '';
	result = global_getDate.now.getHours();
	if(ampm && result > 12) result -= 12;
	if(result < 10) result = '0' + result;
	return result;
}
global_getDate.getMinutes = function() {
	var result = '';
	result = global_getDate.now.getMinutes();
	if(result < 10) result = '0' + result;
	return result;
}
global_getDate.getSeconds = function() {
	var result = '';
	result = global_getDate.now.getSeconds();
	if(result < 10) result = '0' + result;
	return result;
}
global_getDate.getAMPM = function() {
	var result = '';
	if(global_getDate.now.getHours() > 12) result = 'pm';
	else  result = 'am';
	return result;
}
/* Date-Tool end */

/* Exit-Link-Tool start */
var exit_link = new Object();
exit_link.is_clicked = false;
exit_link.initialize = function() {
	if(exit_link.check_requirements() == true) {
		$(exitlink_text_id).set('html', exitlink.exit.label);
		$(exitlink_target_id).setProperty('title', exitlink.exit.label);
		$(exitlink_target_id).addEvent('click', function() {
			if(exit_link.is_clicked == false) {
				exit_link.is_clicked = true;
				exit_link.fade_page(exitlink.exit.url);
			}
			return false;
		});
		$(exitlink_target_id).setStyle('display', 'block');
	}
}
exit_link.check_requirements = function() {
	var result = false;
	try {
		if(typeof(exitlink) == 'object' && $(exitlink_target_id) && $(exitlink_text_id)) {
			if(exitlink.exit.url && exitlink.exit.label) result = true;
		}
	} catch(error) {
	}
	return result;
}
exit_link.fade_page = function(target_url) {
	new Element('div', {
		id: 'exit_link_fader'
	}).inject($(document.body));
	$('exit_link_fader').setStyles({
		'opacity': 0,
		'z-index': 2100,
		'height': $(document.body).getSize().y
	});
	var exit_tool_fader_tween = new Fx.Tween('exit_link_fader', {
		duration: 500,
		property: 'opacity',
		onComplete: function() {
			window.location.href = target_url;
		}
	}).start(0, 1);
}
/* Exit-Link-Tool end */

/* Log-Tool start */
log = new Object();
log.settings = {
	'url': '/cgi-bin/global.pl',
	'params': {
		'ident': 'pi_42_reg_half',
		'todo': 'log_misc'
	}
} // dummy / default params - do not change, they'll be overwritten
log.send = function(settings) {
	if(typeof(settings) == 'object') {
		log.settings = settings;
		log.request();
	}
}
log.request = function() {
	var temp_params = "";
	Object.each(log.settings.params, function(value, key) {
		temp_params += key + '=' + value + '&';
	});
	temp_params = temp_params.replace(/&$/gi, '');
	var temp_request = new Request({
		url: log.settings.url
	}).send(temp_params);
}
/* Log-Tool end */

/* Image Preloader start */
image_preloader = new Object();
image_preloader.preloaded_images = new Array();
image_preloader.preload = function(images) {
	var result = false;
	if(typeof(images) == 'array') {
		images.each(function(image) {
			var temp_image = new Image();
			temp_image.src = images;
			image_preloader.preloaded_images.push(temp_image);
		});
		result = image_preloader.preloaded_images;
	}
	return result;
}
/* Image Preloader end */

/* $_GET - URL Parameter auslesen start */
get_parameter = function(parameter) {
	var temp_regex = new RegExp("[\?&]" + parameter + "=([^&]+)", "gi");
	if(window.location.search.search(temp_regex) > -1) {
		return window.location.search.replace(temp_regex, '{{$1}}').replace(/^.*{{(.+)}}.*$/i, '$1');
	} else {
		return "";
	}
}
/* $_GET - URL Parameter auslesen end */

/* Pop-under-Tool start */
var map_elements = function() {
	var clicktarget;
	if (typeof(POPUNDER) !="object") {
		return false;
	}
	if (typeof(MAPPER) == "object") {
		//Pop-under function; var POPUNDER is filled in html files (#44805)
		for (var mapped in MAPPER) {
			if ( MAPPER[mapped] && POPUNDER[mapped] != undefined ) {
				if (typeof(MAPPER[mapped]) == 'string') {
					clicktarget = $(MAPPER[mapped]);
				} else if (typeof(MAPPER[mapped]) == 'object') {
					//is array?
					if (MAPPER[mapped].length) {
						clicktarget = MAPPER[mapped][0]; 
					} else {
						clicktarget = MAPPER[mapped];
					}
				}
				if(mapped == 'extra' && MAPPER[mapped].get('id') == 'no_thanks') {
					$('no_thanks').addClass('show_no_thanks');
				}
				if (clicktarget) {
					clicktarget.mapkey = mapped;
					clicktarget.addEvent( 'click', function() {
						if(this.mapkey == 'extra' && MAPPER['extra'].get('id') == 'no_thanks') {
							showPu(POPUNDER[this.mapkey]['url'], false);
							return false;
						} else showPu(POPUNDER[this.mapkey]['url'], POPUNDER[this.mapkey]['size']); 
					});
				}
			}
		}
	} else {
		setTimeout(function(){map_elements();}, 1000);
	}
}
//switch off Popunder in the meantime:
preventPop = false;
//switch off popunder permanently:
popIsDead = false;
//call the popunder: showPu('url': give different url's for multiple popunder windows)
var showPu = function(url, size) {
	if(size == false) {
		if (!preventPop) {
			noThanks(url);
		}
	} else {
		if (size == 'fullscreen') {
			mywidth = screen.width;
			myhight = screen.height;
		} else if (size == 'parentsize') {
			var S = window.getSize();
			mywidth = S.x;
			myhight = S.y;
		} else if (size && size.match(/\d+x\d+/)) {
			mywidth = size.split('x')[0];
			myhight = size.split('x')[1];
		} else {
			mywidth = 600;
			myhight = 600;
		}
		var options = 'scrollbars=yes,width=' + mywidth + ',height=' + myhight + ',resizable=yes';
		if ((!popIsDead) && (!preventPop)) {
			popunder(url,'',options);
		}
	}
}

var coregPop = function(url, size) {
	var make_it_popunder = false;
	if (size == 'fullscreen' || size == '0x0') {
		mywidth = screen.width;
		myhight = screen.height;
		make_it_popunder = true;
	} else if (size == 'parentsize') {
		var S = window.getSize();
		mywidth = S.x;
		myhight = S.y;
	} else if (size && size.match(/\d+x\d+/)) {
		mywidth = size.split('x')[0];
		myhight = size.split('x')[1];
	}
	var options = 'scrollbars=yes,width=' + mywidth + ',height=' + myhight + ',resizable=yes';

	if (checkPopunder(url)) {
		if (make_it_popunder) {
			if (!popIsDead) {
				var win = window.open(url,'',options);
				win.blur();
				window.focus();
			}
		} else {
			var win = window.open(url,'',options);
		}
	}
}


// fade current page for pounder
function noThanks(theURL) {
	if (checkPopunder(theURL)) {
		new Element('div', {
			id: 'no_thanks_fader'
		}).inject($(document.body));
		$('no_thanks_fader').setStyles({
			'opacity': 0,
			'z-index': 2100,
			'height': $(document.body).getSize().y
		});
		var no_thanks_fader_tween = new Fx.Tween('no_thanks_fader', {
			duration: 500,
			property: 'opacity',
			onComplete: function() {
				window.location.href = theURL;
			}
		}).start(0, 1);
	}
}
// launch "popunder" windows once
function popunder(theURL,winName,features) {
	if (checkPopunder(theURL)) {
		var win = window.open(theURL,winName,features);
		win.blur();
		window.focus();
	}
}
function arrayContain(url) {
	return popunderCol.indexOf(url)!=-1;
}  
// check if already launched and add to collection
var popunderCol = new Array;
function checkPopunder(url) {
	var isinarray = arrayContain(url); 
	if (isinarray) {
		return false;
	} else {
		var newItem = popunderCol.push(url);
		return true;
	}
}
/* Pop-under-Tool end */

/* Globales Script das Selectboxen sichtbar und unsichtbar macht ************************************************************************************************* */
// Einblendung muss im Schliessen-Link des hinteren GWS-Layers eingebaut sein 
function hidetagsIE(tag_selector){
	if ( navigator.userAgent.indexOf("MSIE 6") != -1 ){
		$$(tag_selector).each(function(el) {
			el.setStyle('visibility', 'hidden');
		});
	}
}

function showtagsIE(tag_selector){
	if ( navigator.userAgent.indexOf("MSIE 6") != -1 ){
		$$(tag_selector).each(function(el) {
			el.setStyle('visibility', 'visible');
		});
	}
}

var isIE = function(version) {
	var regex = new RegExp('MSIE '+version+'\.0');
	if(navigator.userAgent.search(regex) > -1) return true;
	else return false;
}
