$(document).ready(function () {

	$('#wejdz_now').click(function() {
		var login	= $( '#iduzytkownika' ).val();
		var haslo	= $( '#haslo').val();
		
		$.ajax({
			url: "ajax/doLogin.php",
			type: "POST",
			dataType: "json",
			data: {login:login,haslo:haslo},
			success: function(dane) {
				if( dane.status == "OK" )
					$( '#login_form' ).submit();
				if( dane.status == "NO" )
					alert( "Niewłaściwa nazwa użytkownika lub hasło");
			},
			error : function(xhr, textStatus, errorThrown) {	
				alert( textStatus );
			    alert( xhr.status );
				alert( errorThrown );
			}
		});	
	});	
	
	$( '#logo' ).click( function() {
		window.location.href = "/00/glowna";
	});

});

function loginA()
{
	var login	= $( '#iduzytkownika1' ).val();
	var aukcja	= $( '#idaukcji').val();
	
	$.ajax({
		url: "ajax/doLoginA.php",
		type: "POST",
		dataType: "json",
		data: {login:login,aukcja:aukcja},
		success: function(dane) {
			if( dane.status == "OK" )
				window.location.href = dane.redirect;
			if( dane.status == "NO" )
				alert( "Niewłaściwa nazwa użytkownika lub niewłaściwy numer aukcji");
		},
		error : function(xhr, textStatus, errorThrown) {	
			alert( textStatus );
		    alert( xhr.status );
			alert( errorThrown );
		}
	});	
}

function login()
{
	var login	= $( '#iduzytkownika' ).val();
	var haslo	= $( '#haslo').val();
	
	$.ajax({
		url: "ajax/doLogin.php",
		type: "POST",
		dataType: "json",
		data: {login:login,haslo:haslo},
		success: function(dane) {
			if( dane.status == "OK" )
				window.location.href = "/88/szonline";
			if( dane.status == "NO" )
				alert( "Niewłaściwa nazwa użytkownika lub hasło");
		},
		error : function(xhr, textStatus, errorThrown) {	
			alert( textStatus );
		    alert( xhr.status );
			alert( errorThrown );
		}
	});		
}

function logOut()
{
		$.ajax({
			url: "ajax/doLogOut.php",
			type: "POST",
			success: function(dane) {
				window.location="/00/glowna";
			},
			error : function(xhr, textStatus, errorThrown) {	
				alert( textStatus );
			    alert( xhr.status );
				alert( errorThrown );
			}
		});	
}

