
var print_clicked = false;

$(document).ready(function() {
	
	$('#esbpartner-form').submit(function (event) {
		
		if (!print_clicked) {
			event.preventDefault();
			
			$('.esbpartner-liste').html('<div class="ajaxloader"><img src="/fileadmin/templates/esb-online.com/gfx/ajax-loader.gif" /></div>');
			
			var data = $(this).serializeArray()
			
			data.push({name: 'type', value: '101'});
			
			$.post($(this).attr('action'), data, function(data) {
				$('.esbpartner-liste').html(data);
			});
		}
			
	});

	$('#esbpartner-form input[name="tx_esbpartner_pi1[print]"]').click(function (event) {
		print_clicked = true;
		$(this.form).attr('target', '_blank');
	});
	
	$('#esbpartner-selection1,#esbpartner-selection2,#esbpartner-order,#esbpartner-country,#esbpartner-branch').change(function (event) {
		$(this.form).submit();
	});
	
	$('div.csc-frame-foldable').each(function (){
		var $this = $(this);
		$('div.contentText',$this).hide();
		$('div.csc-textpic-imagewrap',$this).hide();
		
		$('h1',$this).css('cursor','pointer').click(function (){
			$('div.contentText',$(this).parent()).slideToggle();
			$('div.csc-textpic-imagewrap',$(this).parent()).slideToggle();
			$(this).toggleClass('opened');
		});
		
		var teasertext;
		if (teasertext = $('div.contentText .Subheadline',$this).html()) {
			$('h1',$this).after('<div style="margin: 2px 0 0 15px;">'+teasertext+'</div>');
			$('div.contentText p.Subheadline',$this).remove();
		}
	});
	
	$('select[name="tx_esbevents_pi1[month]"],select[name="tx_esbevents_pi1[city]"]').change(function () {
		var $this = $(this);
		
		/*if ($this.val() == '') {
			return;
		}*/
		
		$this.closest('form').submit();
	});
});
