/**
 * @author sja
 */
$(document).ready(function()
{

	$("select#wg").change(function()
	{
		var wg=$("select#wg").val();
		var l=$("input#l").val();
		$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});
		
		$.ajax
				(
					{
						url:'/typo3conf/ext/cc_branchenbuch/pi1/js/php/get_sub_warengruppen.php',
						data:"type=1&wg="+wg+"&l="+l,
						dataType: 'json',
						success: function (data, status)
						{
							$('select#sub_wg1').html(data.content);
						},
						error: function (data, status, e)
						{
							alert(e);
						}
					}
				)
		}
	);
	
	$("select#sub_wg1").change(function()
	{
		var wg=$("select#sub_wg1").val();
		var l=$("input#l").val();
		
		$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});
		
		$.ajax
				(
					{
						url:'/typo3conf/ext/cc_branchenbuch/pi1/js/php/get_sub_warengruppen.php',
						data:"type=2&wg="+wg+"&l="+l,
						dataType: 'json',
						success: function (data, status)
						{
							$('select#sub_wg2').html(data.content);
						},
						error: function (data, status, e)
						{
							
						}
					}
				)
		}
	);
	
	
	$("#suche_starten").click(function () 
	{ 
		var values = $('#suchform').formSerialize(); 
		var l=$("input#l").val();
		
		
		/*$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});*/
		
		$().ajaxComplete($.unblockUI); 
	
	
		if (l==1)
		{
			$.blockUI({ message: '<img src="fileadmin/images/ajax-loader.gif" /> <h1 style="font-size:15px; color:#27316C;font-family:Verdana;">Just wait a moment...</h1>' });
		}
		else
		{
			$.blockUI({ message: '<img src="fileadmin/images/ajax-loader.gif" /> <h1 style="font-size:15px; color:#27316C;font-family:Verdana;">Bitte warten Sie einen Moment...</h1>' });
		}
		
		
		
		$.ajax
		(
			{
				url:'/typo3conf/ext/cc_branchenbuch/pi1/js/php/get_suchergebnis.php',
				data:values+"&l="+l,
				dataType: 'html',
				async:false,
				success: function (data, status)
				{
					
					$("#suchformular").hide();
					$("#suchergebnis").empty();
					$("#suchergebnis").html(data);
					$("#suchergebnis").show();
					//alert("test");
					
				},
				error: function (data, status, e)
				{
					
					
				}
			}
		)
    });
});

function zurueck_zur_suche(type)
{
	var type=type;
	
	if (type=="verzeichnis")
	{
		
		$("#warenverzeichnis_detail").empty();
		$("#warenverzeichnis_detail").hide();
		$("#warenverzeichnis_liste").show();
	}
	else if(type=="alpha")
	{
		$("#warenverzeichnis_alpha_detail").empty();
		$("#warenverzeichnis_alpha_detail").hide();
		$("#warenverzeichnis_liste_alpha").show();
	}
	else
	{
		$("#suchformular").show();
		$("#suchergebnis").empty();
		$("#suchergebnis").hide();
	}
	
	
}


function get_warenverzeichnis_detail(value,field,type)
{
	var field=field;
	var value=value;
	var type=type;
	var l=$("input#l").val();
	
	$().ajaxComplete($.unblockUI); 
	
	
	if (l==1)
	{
		$.blockUI({ message: '<img src="fileadmin/images/ajax-loader.gif" /> <h1 style="font-size:15px; color:#27316C;font-family:Verdana;">Just wait a moment...</h1>' });
	}
	else
	{
		$.blockUI({ message: '<img src="fileadmin/images/ajax-loader.gif" /> <h1 style="font-size:15px; color:#27316C;font-family:Verdana;">Bitte warten Sie einen Moment...</h1>' });
	}
	
	
	$.ajax
	(
		{
			url:'/typo3conf/ext/cc_branchenbuch/pi1/js/php/get_suchergebnis.php',
			data:"&"+field+"="+value+"&type="+type+"&l="+l,
			dataType: 'html',
			async:false,
			success: function (data, status)
			{
				if (type=="alpha")
				{
					$("#warenverzeichnis_liste_alpha").hide();
					$("#warenverzeichnis_alpha_detail").show();
					$("#warenverzeichnis_alpha_detail").empty();
					$("#warenverzeichnis_alpha_detail").html(data);
				}
				else
				{
					$("#warenverzeichnis_liste").hide();
					$("#warenverzeichnis_detail").show();
					$("#warenverzeichnis_detail").empty();
					$("#warenverzeichnis_detail").html(data);
				}
				
				
				
				
			},
			error: function (data, status, e)
			{
				
				
			}
		}
	)
}

function get_mitglied_detail(mitglied_id)
{
	var mitglied_id=mitglied_id;
	var l=$("input#l").val();

	$().ajaxComplete($.unblockUI); 
	
	
	if (l==1)
	{
		$.blockUI({ message: '<img src="fileadmin/images/ajax-loader.gif" /> <h1 style="font-size:15px; color:#27316C;font-family:Verdana;">Just wait a moment...</h1>' });
	}
	else
	{
		$.blockUI({ message: '<img src="fileadmin/images/ajax-loader.gif" /> <h1 style="font-size:15px; color:#27316C;font-family:Verdana;">Bitte warten Sie einen Moment...</h1>' });
	}

	$.ajax
	(
		{
		
		/*upa 09.10.2009, Aenderung auf get_mitglieder_detail.php, Reduktion des selectes*/
			url:'/typo3conf/ext/cc_branchenbuch/pi1/js/php/get_mitglieder_detail.php',
			data:"mitglied_id="+mitglied_id+"&l="+l,
			dataType: 'html',
			async:false,
			success: function (data, status)
			{
				tb_show('Mitglieder Detailansicht','#TB_inline?height=500&width=530&inlineId=mitglieder_detail','');
				$("#TB_ajaxContent").html(data);
				
			},
			error: function (data, status, e)
			{
				
				
			}
		}
	)
	
	
}
