function trackPageLink(e)
{
	if (typeof _gaq === 'undefined') return;

	var conf = $.extend({
		'type':     'event',
		'category': ''
	}, e.data || {});

	if (conf.type === 'event')
	{
		_gaq.push(['_trackEvent', conf.category, String(window.location).replace(/^https?:\/\/[^\/]*(.*)$/, '$1'), $(e.currentTarget).attr('href')]);
	}
	else if (conf.type === 'page')
	{
		if ($(e.currentTarget).attr('href') !== 'undefined')
		{
			var href = $(e.currentTarget).attr('href');
			_gaq.push(['_trackPageview', (/^(https?:)/.test(href) ? '' : conf.category) + href]);
		}
	}
};

$(document).ready(function() {
	$('#content table.border, #content table.alternating, #content-wide table.border, #content-wide table.alternating').colorize({
		bgColor:     '#f9f9f9',
		altColor:    '#ececec',
		hoverColor:  'none',
		hiliteColor: 'none'
	});

	if ($('div.gallery a.zoom').fancybox)
	{
		$('div.gallery a.zoom').add('div.pic-tl a.zoom').fancybox({
			'speedIn':            600,
			'speedOut':           200,
			'titlePosition' :     'inside',
			'hideOnContentClick': true
		});
	}

	$('#category-select > select').change(function(e) {
		$(this).closest('form').submit();
	})

	if (window.opera)
	{
		if ($('a.jqbookmark').attr('rel') != '')
		{
			// don't overwrite the rel attrib if already set
			$('a.jqbookmark').attr('rel', 'sidebar');
		}
	}

	$("a.bookmark").click(function(event) {
		event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		var url = document.URL;
		var title = document.title;

		if (window.sidebar)
		{ // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		}
		else if (window.external)
		{ // IE Favorite
			window.external.AddFavorite( url, title);
		}
		else if (window.opera)
		{ // Opera 7+
			return false; // do nothing - the rel="sidebar" should do the trick
		}
		else
		{ // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			 alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
		}
	});

	// tracking location lap
	$('#locations-map').submit(function(e) {
		if (typeof _gaq === 'undefined') return;

		var filters = {};
		$(e.target).find('fieldset')
			.filter(function() { return ($(this).find('input[type="checkbox"]:checked').size() > 0); })
			.each(function() {
				var element = $(this).find('select').get(0);
				var elementName = $(element).attr('name').replace(/^tx_twtinterseroh_pi\[filter\]\[(\w+)\](\[(\d+)\])?$/, '$1$3');
				filters[elementName] = element.options[element.selectedIndex].text;
			});

		for (key in filters)
			_gaq.push(['_trackEvent', 'location_map', key, filters[key]]);
	});

	// tracking external links
	$('#content, #context').find('a[href^="http"]')
		.filter(function() { return !/^https?:\/\/(www\.)?interseroh.com/.test($(this).attr('href')); })
		.click({'type': 'event', 'category': 'external_link'}, trackPageLink);

	// tracking downloads
	$('#content, #context').find('a[href^="fileadmin/"]')
		.filter(function() { return /\.\w+$/.test($(this).attr('href')); })
		.click({'type': 'page', 'category': '/downloads/'}, trackPageLink);
});

// Code von externem Newsletteranbieter
function checkForm()
{
	if (document.form1.feld_vorname.value == "")
	{
		alert("Das Feld  'Vorname' muss ausgef\u00FCllt werden!");
		document.form1.feld_vorname.focus();
		return false;
	}
	if (document.form1.feld_nachname.value == "")
	{
		alert("Das Feld  'Nachname' muss ausgef\u00FCllt werden!");
		document.form1.feld_nachname.focus();
		return false;
	}
	if (document.form1.feld_email.value == "")
	{
		alert("Das Feld  'E-Mail' muss ausgef\u00FCllt werden!");
		document.form1.feld_email.focus();
		return false;
	}
	if (!isValidEmail(document.form1.feld_email.value) )
	{
		alert("Bitte kontrollieren Sie Ihre Email-Adresse!");
		document.form1.feld_email.focus();
		return false;
	}

	return true;
};

function isValidEmail(str)
{
	var oRegExp = /^[\+_a-z0-9-](\.{0,1}[\+_a-z0-9-])*@([&auml;&uuml;&ouml;a-z0-9-]{1,}\.){0,}[&auml;&uuml;&ouml;a-z0-9-]{1,}(\.[a-zA-Z]{2,}){1,2}$/i
	return oRegExp.test(str);
};

