$(document).ready(function() {
	
	// Änderung der Kategorie
	$("#tx_questions_pi1-category").bind("change", function(){		
	
		$("#tx_questions_pi1-reccategory_wrap").hide("slow");
		$("#tx_questions_pi1-reccategory").attr("disabled", true);
	
		var catUid = $("#tx_questions_pi1-category").val();
		$.getJSON("index.php?eID=getSubcategories&parent=" + catUid + "", function( json ){
			var options = '';
			$.each( json, function(i, item) {				
				options += '<option value="' + item.uid + '">' + item.name + '</option>';
			});
			if ($("#tx_questions_pi1-subcategory").attr("disabled") == true) {
				$("#tx_questions_pi1-subcategory").attr("disabled", false);
			}
			$("#tx_questions_pi1-subcategory").animate({opacity: 0.5}).animate({opacity: 1}).css("background-color","#DFECF5").html(options);
		});		
	});
	
	// Subkategorie "sonstiges"
	$("#tx_questions_pi1-subcategory").bind("change", function(){
		var selected = $("#tx_questions_pi1-subcategory option:selected").text();
		if (selected == 'sonstiges') {
			$("#tx_questions_pi1-reccategory_wrap").show("slow");
			$("#tx_questions_pi1-reccategory").attr("disabled", false);
			$("#tx_questions_pi1-reccategory").attr("value", "");
		} else {
			$("#tx_questions_pi1-reccategory_wrap").hide("slow");
			$("#tx_questions_pi1-reccategory").attr("disabled", true);
		}
	});
	
});

