//in the az list show categories for the letter
function generalAjaxRequest(url, targetDivId, formIdToSerialize)
{
	$.ajax({
		type: "POST",
		url: url,
		data: $("#" + formIdToSerialize).serialize(),
		dataType: "html",
		success: ajaxLoading("#" + targetDivId),
		complete: function(requestObject, successType){
			$("#" + targetDivId).html(requestObject.responseText);
		}
	});
}

//-----------------------------------------------------------------------------------

//what to show while loading the new data
function ajaxLoading(divName)
{
	$(divName).html(js_text_ajax_loading);
}

//-----------------------------------------------------------------------------------

//show new thread layer
function newItemLayer(url, targetDivId, e, closeText, openText)
{
	var targetContent = $("#" + targetDivId);
	var time = new Date().valueOf();
	$(e).toggleClass('open');
	$(e).toggleClass('close');

	if (targetContent.css('display') == 'none')
	{
		targetContent.show();
		$("#" + e.id).html(closeText);

		generalAjaxRequest(url + '?t=' + time, targetDivId);
	}
	else
	{
		targetContent.slideUp(300);
		$("#" + e.id).html(openText);
	}
}

//-----------------------------------------------------------------------------------

//collapse (open/close) one div
function collapse(e, url)
{
	var targetContent = $('#' + e.id + '_div')[0]['id'];
	targetContent = $("#" + targetContent);

	var changeHeadline = false;
	if ($('#' + e.id + '_headline')[0]) changeHeadline = true;

	if (changeHeadline)
	{
		var headline = $('#' + e.id + '_headline')[0]['id'];
		headline = $("#" + headline);
	}

	if (targetContent.css('display') == 'none')
	{
		targetContent.slideDown(300);
		//$("#" + e.id).html('[-]');
		if (changeHeadline) headline.addClass("expanded");

		//if the content of opened div has to be loaded via ajax
		if (url) ajaxLoadContent(url, targetContent);
	}
	else
	{
		targetContent.slideUp(300);
		//$("#" + e.id).html('[+]');
		if (changeHeadline) headline.removeClass("expanded");
	}
}

//-----------------------------------------------------------------------------------

//after the div is slided down, load content via ajax
function ajaxLoadContent(url, targetContent)
{
	if (!targetContent.html())
	{
		$.ajax({
			type: "POST",
			url: url,
			dataType: "html",
			success: ajaxLoading(targetContent),
			complete: function(requestObject, successType){
				$(targetContent).html(requestObject.responseText);
			}
		});
	}
}

function ajaxReloadContent(url, targetContent) 
{
	$.ajax({
		type: "POST",
		url: url,
		dataType: "html",
		success: ajaxLoading(targetContent),
		complete: function(requestObject, successType){
			//not sure why - but the standard jquery ajax setting below does NOT work!
			//$(targetContent).html(requestObject.responseText);
			document.getElementById(targetContent).innerHTML = requestObject.responseText; 
		}
	});
}

//-----------------------------------------------------------------------------------

var global_is_collapsed = true;

//collapse (open/close) more divs
function collapse_all(e)
{

	$(e).toggleClass('open');
	$(e).toggleClass('close');

	if (global_is_collapsed)
	{
		$(".categories").each(function(i, n){
		  if (n.id) {
			  $("#" + n.id).addClass("expanded");
			}
		});

		$(".subcategories").each(function(i, n){
		  if (n.id) {
			  $("#" + n.id).slideDown(300);
			}
		});

		global_is_collapsed = false;
	}
	else
	{
		$(".categories").each(function(i, n){
		  if (n.id) {
			  $("#" + n.id).removeClass("expanded");
			}
		});

		$(".subcategories").each(function(i, n){
		  if (n.id) {
			  $("#" + n.id).slideUp(300);
			}
		});

		global_is_collapsed = true;
	}
}

//-----------------------------------------------------------------------------------

//change the size of the textarea
function enlargeTextarea(textareaId, toHide)
{
	$("#" + toHide).css({display: 'none'});
	$("#" + textareaId).css({height: '200px'});
}






