/*
  Website MKK
  Copyright (C) 2007-2009 by Systemantics, Bureau for Informatics

  Lutz Issler
  Mauerstr. 10-12
  52064 Aachen
  GERMANY

  Web:    www.systemantics.net
  Email:  mail@systemantics.net

  Permission granted to use the files associated with this
  website only on your webserver.
*/



$(function() {
	var f;

	if ($("#deliverysame").length>0) {
		$("#deliverysame")
			.click(function() {
				var fs = $(this).parents("fieldset");
				fs.find("input[type=text], input[type=radio], select")
					.attr("disabled", this.checked);
				if (this.checked) {
					fs.find("input[type=text]").val("");
				}
			})
			.parents("fieldset").find("input[type=text], input[type=radio], select")
				.attr("disabled", $("#deliverysame")[0].checked);
	}

	f = function() {
		$("#customamount-text").attr("disabled", !$("#customamount-radio").attr("checked"));
		if ($("#customamount-radio").attr("checked")) {
			$("#customamount-text").focus();
		}
	}
	$("input[name=amount]")
		.change(f)
		.click(f);
	$("input[name=amount]").change();

	f = function() {
		$("#donate-period").css(
			"display",
			$("#donate-mode input[value=once]").attr("checked")
				? "none"
				: "block"
			);
	};
	$("#donate-mode input[type=radio]")
		.change(f)
		.click(f);
	$("#donate-mode input[type=radio]").change();

	$.datepicker.setDefaults($.extend({
		changeMonth: true,
		changeYear: true,
		dateFormat: "dd.mm.yy",
		minDate: "0",
		showAnim: false
	}, $.datepicker.regional[$("meta[name='dc.language']").attr("content")]));
	$("#donate-period input[type=text]").datepicker();

	$.datepicker.setDefaults($.extend({
		changeMonth: true,
		changeYear: true,
		dateFormat: "dd.mm.yy",
		minDate: null,
		showAnim: false,
		yearRange: "1900:"+((new Date()).getYear()+1900)
	}, $.datepicker.regional[$("meta[name='dc.language']").attr("content")]));
	$("#dob, #partner_dob").datepicker();

	f = function() {
		$("#beuys-invitation-details").css(
			"display",
			$("#beuys").attr("checked")
				? "block"
				: "none"
			);
	};
	$("input[name=purpose]")
		.change(f)
		.click(f);
	$("input[name=purpose]").change();

	if ($("#beuys-invitation").length>0) {
		$("#beuys-invitation")
			.click(function() {
				var fs = $("#personal-data");
				fs.find("input[type=text], input[type=radio], select")
					.attr("disabled", !this.checked);
			});
		$("#personal-data").find("input[type=text], input[type=radio], select")
			.attr("disabled", !$("#beuys-invitation")[0].checked);
	}

	if ($("#donate-receipt").length>0) {
		$("#donate-receipt")
			.click(function() {
				var fs = $("#personal-data");
				fs.find("input[type=text], input[type=radio], select")
					.attr("disabled", !this.checked);
				if (!this.checked) {
					fs.find("input[type=text]").val("");
				}
			});
		$("#personal-data").find("input[type=text], input[type=radio], select")
			.attr("disabled", !$("#donate-receipt")[0].checked);
	}

	f = function() {
		$("#donate-payment-info-account").css(
			"display",
			$("#donate-payment-method input[value=DebitDE]").attr("checked")
				|| $("#donate-payment-method input[value=DebitNL]").attr("checked")
				? "block"
				: "none"
		);
		$("#donate-payment-info-sik").css(
			"display",
			$("#donate-payment-info-account").css("display")=="block"
				? "none"
				: "block"
		);
		$("#donate-payment-rtn").css(
			"display",
			$("#donate-payment-method input[value=DebitDE]").attr("checked")
				? "block"
				: "none"
			);
	};
	$("#donate-payment-method input[type=radio]")
		.change(f)
		.click(f);
	$("#donate-payment-method input[type=radio]").change();

	$("a.external, a.external[href^=http://]").click(function() {
		this.blur();
		window.open(this.href);
		return false;
	});

	$(".row").each(function() {
		var h = 0;
		$("img", this).each(function() {
			h = Math.max(h, $(this).height());
		});
		$("img", this).each(function() {
			$(this).parent().parent().css("padding-top", h-$(this).height());
		});
	});

	$(".sponsors tr").each(function() {
		var h = 0;
		$(".image", this)
			.each(function() {
				h = Math.max(h, $(this).height());
			})
			.height(h);
	});
});
