$(document).ready(function(){

	/* Newsletter */

	$("#newsletterform").hide();

	$(".newsletterbutton").click(function () {
		if ($("#newsletterform").is(":hidden")) {
			$("#newsletterform").slideDown("slow");
			$(".newsletterbutton").removeClass("newsletterclosed");
			$(".newsletterbutton").addClass("newsletteropen");

		} else {
			$("#newsletterform").slideUp();
			$(".newsletterbutton").removeClass("newsletteropen");
			$(".newsletterbutton").addClass("newsletterclosed");
		}
	});
	
	/* Tabbed contents */	
	
	var tabContainers = $('div.tabs > div');
	tabContainers.hide().filter(':first').show();
			
	$('div.tabs ul.tabNavigation a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div.tabs ul.tabNavigation a').removeClass('selectedtab');
		$(this).addClass('selectedtab');
		return false;
	}).filter(':first').click();
	
	/* Expandable Tables */	
	
	$("#seminare tr:odd").addClass("odd");
	$("#seminare tr:not(.odd)").hide();
	$("#seminare tr:first-child").show();

	$("#seminare tr.odd").click(function() {
		var tr = $(this).next("tr");

		if(tr.css("display") == "none")
		tr.css("display", "table-row");
		else
		tr.css("display", "none");

		$(this).toggleClass("seminarzeileoffen-intro");
		$(this).next("tr").toggleClass("seminarzeileoffen-additional");
	});
        
        /* Attach the Print-Button-Link with functionality to the footer, but only only when JS is enabled */	
        
	$('div#footer').prepend('<a id="drucken" href="#Drucken" title="Drucken"></a>');
	$('a#drucken').click(function() {
		window.print();
		return false;
	});
	
	/* Offer some basic eMail-address protection by simple obfuscation */
        
	jQuery.fn.protectmail = function() {
	    var at = / at /;
	    var punkt = / punkt /g;
	    this.each( function() {
		var addr = jQuery(this).text().replace(at,"@").replace(punkt,".");
		var title = jQuery(this).attr('title')
		$(this)
		    .after('<a href="mailto:'+addr+'" class="linkexternal" title="'+title+'">'+ addr +'</a>')
		    .remove();
	    });
	};
	$('span.protectmail').protectmail();
	
	/* Second mail-obfuscation function specially for registration at seminars  */
	
	jQuery.fn.protectseminarmail = function() {
	    var at = / at /;
	    var punkt = / punkt /g;
	    this.each( function() {
		var addr = jQuery(this).text().replace(at,"@").replace(punkt,".");
		var title = jQuery(this).attr('title').replace(/Ä/g,"&Auml;").replace(/ä/g,"&auml;").replace(/Ö/g,"&Ouml;").replace(/ö/g,"&ouml;").replace(/Ü/g,"&Uuml;").replace(/ü/g,"&uuml;").replace(/!/g,"&#33;").replace(/"?"/g,"&#63;").replace(/"$"/g,"&#36;").replace(/"%"/g,"&#37;").replace(/"&"/g,"&#38;").replace(/"+"/g,"&#43;").replace(/"ß"/g,"&szlig;");
		$(this)
		    .after('<a href="mailto:'+addr+'?subject='+title+'" class="seminaranmeldebutton" title="Zu diesem Seminar anmelden">"Anmelden"</a>')
		    .remove();
	    });
	};
	$('span.protectseminarmail').protectseminarmail();	

	/* Open links with rel="newtab" in ... you've guessed it ... a new tab */

   $('a[rel*=newtab]').click( function() {
		window.open(this.href);
		return false;
	});
	
	/* Disable the Submit button unless something has been typed into the form-fields */
	
	$('input[type="submit"]').attr('disabled','disabled');
	$('input[type="text"]').keyup(function(){
		 if($('input[type="text"]').val() == ""){
		     $('input[type="submit"]').attr('disabled','disabled');
		 }
		 else{
		     $('input[type="submit"]').removeAttr('disabled');
		 }
	});
	

	
});

