 
var id_obrazka = -1;
function obrazek()
{
	id_obrazka++;
	id_obrazka %= 4;
	$('#obrazek').attr('src', 'themes/theme/grafika/domki_lewo'+(id_obrazka+1)+'.png');
	setTimeout(obrazek, 10000);
}


	
function zmiana_dostepu(modul)
{
	$.ajax
	(
		{
			url: '?path=admin,system,admins,zmienDostep&user='+user_id+'&modul='+modul,
			success: function(zwrot)
			{
				for(n = 0; n<3; n++)
				{
					$('#dostepusera_'+modul).fadeOut();
					$('#dostepusera_'+modul).html(zwrot);
					$('#dostepusera_'+modul).fadeIn();
				}
			}
		}
	)

}


function przeladuj_komunikaty()
{
	$('#komunikaty').fadeOut();
		$.ajax
		(
			{
				url: '?path=admin,nowosci,przeladuj',
				success: function(zwrot)
				{
					$('#komunikaty').html(zwrot);
					$('#komunikaty').fadeIn();
				}
			}
		);


}

function kasuj_komunikat($id)
{
	$.ajax
	(
		{
			url: '?path=admin,nowosci,kasuj&id='+$id
		}
	);
	przeladuj_komunikaty();
}




function przeladuj_arty(section)
{
	$('#komunikaty').fadeOut();
		$.ajax
		(
			{
				url: '?path=admin,content,przeladuj&s='+section,
				success: function(zwrot)
				{
					$('#komunikaty').html(zwrot);
					$('#komunikaty').fadeIn();
				}
			}
		);


}

function przeladuj_usterki(id)
{
	$('#usterki').fadeOut();
				$.ajax
				(
					{
						url: '?path=admin,usterki,zmien&id='+id,
						success: function(zwrot)
						{
							$('#usterki').html(zwrot);
							$('#usterki').fadeIn();
						}
					}
				
				);
				

}

function przeladuj_przetargi()
{
	$('#przetargi_lista').fadeOut();
		$.ajax
		(
			{
			
				url: '?path=admin,przetargi,lista,pobierz',
				success: function(zwrot)
				{
					$('#przetargi_lista').html(zwrot);
					$('#przetargi_lista').fadeIn();
				
				}
			}
		);
}

function kasuj_przetarg(id)
{
	$.ajax
	(
		{
			url: '?path=admin,przetargi,lista,kasuj&id='+id
		}
	);
	przeladuj_przetargi();
}



$(document).ready(function()
	{
	
		obrazek();
		przeladuj_przetargi();
		przeladuj_komunikaty();
		$('#logowanie').click(function()
			{
				$('#shadow').fadeIn();
			
			}
		);
		
				
				$('#zakonczone_usterki').click(function()
					{
						przeladuj_usterki(3);
					
					}
				);
				
				$('#realizowane_usterki').click(function()
					{
						przeladuj_usterki(2);
					}
				);
				
				$('#nowe_usterki').click(function()
					{
						przeladuj_usterki(1);
					}
				);
			
			
			
		$(function() 
		{
			

			$( "#birds" ).autocomplete(
			{
				source: "?path=admin,customers,podpowiedz",
				minLength: 2,
					select: function( event, ui ) 
					{
						window.location.href="?path=admin,customers,user,"+ui.item.id;
					}
			}
			);

			$("#nr_klienta" ).autocomplete(
			{
				source: "?path=admin,customers,nr_klienta",
				minLength: 2,
					select: function( event, ui ) 
					{
						window.location.href="?path=admin,customers,user,"+ui.item.id;
					}
			}
			);
			
			$("#ulica" ).autocomplete(
			{
				source: "?path=admin,customers,ulica",
				minLength: 2,
					
			}
			);
			
		});
		
		
	
	
		$('#login').submit(function()
			{
				$.ajax
				(
					{
						url: '?path=users,logowanie&'+$(this).serialize(),
						success: function(zwrot)
						{
							if(zwrot == 'ok')
							{
								location.reload(true);
							}
							else
							{
								$('#shadow .error').html('Logowanie nie powiodło się');
								for(n = 0; n<4; n++)
								{
								 $('#shadow .error').fadeOut();
								 $('#shadow .error').fadeIn();
								}
							}
						}
					
					}
				);
				
						return false;
			}
		);

			
		
		$('#alert_close').click(function()
			{
				$('#shadow').fadeOut();
			
			}
		);
	}
	
);

