function onRegistrationRequestComplete(responseText)
{
	// check response text
	switch (responseText)
	{
		case 'login_empty':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Rejestracja', 'Wprowadź swój login.', 'OK', 'registration_login');
			break;
			
		case 'login_invalid':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Rejestracja', 'Twój login zawiera niedozwolone znaki.<br /><br />Dozwolone znaki to: &quot;a-z 0-9 . - _&quot;.', 'OK', 'registration_login');
			break;			
			
		case 'login_too_long':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Rejestracja', 'Twój login jest zbyt długi.<br /><br />Maksymalna długość loginu to 255 znaków.', 'OK', 'registration_login');
			break;
			
		case 'user_exists':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Rejestracja', 'Użytkownik o podanym loginie już istnieje.', 'OK', 'registration_login');
			break;
			
		case 'email_empty':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Rejestracja', 'Wprowadź swój adres e-mail.', 'OK', 'registration_email');
			break;
			
		case 'email_invalid':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Rejestracja', 'Nieprawidłowy adres e-mail.', 'OK', 'registration_email');
			break;			
			
		case 'email_too_long':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Rejestracja', 'Twój adres e-mail jest zbyt długi.<br /><br />Maksymalna długość adresu e-mail to 255 znaków.', 'OK', 'registration_email');
			break;
			
		case 'email_exists':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Rejestracja', 'Podany adres e-mail jest przypisany do innego konta.', 'OK', 'registration_email');		
			break;
			
		case 'email_not_send':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Rejestracja', 'Błąd podczas wysyłania wiadomości na Twój adres email.', 'OK', 'registration_email');
			break;

		case 'temporary_not_possible':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Rejestracja', 'Rejestracja jest tymczasowo niemożliwa.', 'OK', 'registration_login');
			break;						
			
		case 'ok':
			var contentElement = document.getElementById('content_left');
			contentElement.innerHTML = '<h1>Rejestracja zakończona pomyślnie</h1>';
			contentElement.innerHTML += '<br />';
			contentElement.innerHTML += '<br />';
			contentElement.innerHTML += '<h2>Dziękujemy za zarejestrowanie się w naszym serwisie</h2>';
			contentElement.innerHTML += '<br />';
			contentElement.innerHTML += 'Wiadomość z danymi niezbędnymi do zalogowania się została przesłana na Twój adres e-mail.';
			StyledPopup.hidePopup();			
			break;
			
		case 'reload':
			window.location.reload();
			break;
			
		default:
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Rejestracja', 'Wystąpił nieoczekiwany błąd systemu.', 'OK');
			break;
	}
}

function onRegisterClick()
{
	// show "please wait" popup
	StyledPopup.showWaitPopup();
	
	// prepare parameters which will be sent to the server
	var parameters = new Array();
	parameters['login'] = document.getElementById('registration_login').value;
	parameters['email'] = document.getElementById('registration_email').value;
	parameters['action'] = 'register';
	
	// send request to the server
	Ajax.sendRequest('registration', parameters, onRegistrationRequestComplete);
}

//------------------------------------------------------------------------------

function onRecoveryRequestComplete(responseText)
{
	// check response text
	switch (responseText)
	{
		case 'login_empty':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Odzyskiwanie hasła', 'Wprowadź swój login.', 'OK', 'recovery_login');
			break;
			
		case 'login_invalid':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Odzyskiwanie hasła', 'Twój login zawiera niedozwolone znaki.<br /><br />Dozwolone znaki to: &quot;a-z 0-9 . - _&quot;.', 'OK', 'recovery_login');
			break;			
			
		case 'login_too_long':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Odzyskiwanie hasła', 'Twój login jest zbyt długi.<br /><br />Maksymalna długość loginu to 255 znaków.', 'OK', 'recovery_login');
			break;
			
		case 'email_empty':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Odzyskiwanie hasła', 'Wprowadź swój adres e-mail.', 'OK', 'recovery_email');
			break;
			
		case 'email_invalid':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Odzyskiwanie hasła', 'Nieprawidłowy adres e-mail.', 'OK', 'recovery_email');
			break;			
			
		case 'email_too_long':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Odzyskiwanie hasła', 'Twój adres e-mail jest zbyt długi.<br /><br />Maksymalna długość adresu e-mail to 255 znaków.', 'OK', 'recovery_email');
			break;
			
		case 'email_not_send':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Odzyskiwanie hasła', 'Błąd podczas wysyłania wiadomości na Twój adres email.', 'OK', 'recovery_email');
			break;			
			
		case 'invalid_login_or_email':
			document.getElementById('recovery_login').value = '';
			document.getElementById('recovery_email').value = '';		
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Odzyskiwanie hasła', 'Nieprawidłowy login lub adres e-mail.', 'OK', 'recovery_login');
			break;
			
		case 'temporary_not_possible':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Odzyskiwanie hasła', 'Odzyskanie hasła jest tymczasowo niemożliwe.', 'OK', 'recovery_login');
			break;									
			
		case 'ok':
			var contentElement = document.getElementById('content_left');
			contentElement.innerHTML = '<h1>Odzyskiwanie hasła zakończone</h1>';
			contentElement.innerHTML += '<br />';
			contentElement.innerHTML += '<br />';
			contentElement.innerHTML += '<h2>Procedura odzyskiwania hasła do Twojego konta konta została pomyślnie zakończona.</h2>';
			contentElement.innerHTML += '<br />';
			contentElement.innerHTML += 'Nowe hasło do Twojego konta zostało przesłane na Twój adres e-mail.';
			StyledPopup.hidePopup();			
			break;
			
		case 'reload':
			window.location.reload();
			break;
			
		default:
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Odzyskiwanie hasła', 'Wystąpił nieoczekiwany błąd systemu.', 'OK');
			break;
	}
}

function onRecoverPasswordClick()
{
	// show "please wait" popup
	StyledPopup.showWaitPopup();
	
	// prepare parameters which will be sent to the server
	var parameters = new Array();
	parameters['login'] = document.getElementById('recovery_login').value;
	parameters['email'] = document.getElementById('recovery_email').value;
	parameters['action'] = 'recover_password';
	
	// send request to the server
	Ajax.sendRequest('recovery', parameters, onRecoveryRequestComplete);
}

//------------------------------------------------------------------------------

function onLogInRequestComplete(responseText)
{
	// check response text
	switch (responseText)
	{
		case 'invalid_login_or_password':
			document.getElementById('login').value = '';
			document.getElementById('password').value = '';
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Logowanie', 'Nieprawidłowa nazwa użytkownika lub hasło.', 'OK', 'login');
			break;
			
		case 'ok':
			window.location.reload();
			break;
			
		case 'reload':
			window.location.reload();
			break;
			
		default:
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Logowanie', 'Wystąpił nieoczekiwany błąd systemu.', 'OK');
			break;
	}
}

function onLogInClick()
{
	// show "please wait" popup
	StyledPopup.showWaitPopup();
	
	// prepare parameters which will be sent to the server
	var parameters = new Array();
	parameters['login'] = document.getElementById('login').value;
	parameters['password'] = document.getElementById('password').value;
	parameters['action'] = 'log_in';
	
	// send request to the server
	Ajax.sendRequest('login', parameters, onLogInRequestComplete);
}

//------------------------------------------------------------------------------

function onLogOutRequestComplete(responseText)
{
	// check response text
	switch (responseText)
	{
		case 'ok':
			window.location.href = "";
			break;
			
		case 'reload':
			window.location.reload();
			break;			
			
		default:
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Moje konto', 'Wystąpił nieoczekiwany błąd systemu.', 'OK');
			break;
	}
}

function onLogOutClick()
{
	// show "please wait" popup
	StyledPopup.showWaitPopup();
	
	// prepare parameters which will be sent to the server
	var parameters = new Array();
	parameters['action'] = 'log_out';
	
	// send request to the server
	Ajax.sendRequest('account', parameters, onLogOutRequestComplete);
}

//------------------------------------------------------------------------------

function onChangePasswordRequestComplete(responseText)
{
	// check response text
	switch (responseText)
	{
		case 'password_empty':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana hasła', 'Podaj nowe hasło.', 'OK', 'password');
			break;
			
		case 'password_too_short':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana hasła', 'Nowe hasło jest zbyt krótkie.<br /><br />Minimalna długość hasła to 6 znaków.', 'OK', 'password');
			break;			
			
		case 'invalid_password_confirmation':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana hasła', 'Nieprawidłowe potwierdzenie hasła.', 'OK', 'password_confirmation');
			break;			
			
		case 'temporary_not_possible':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana hasła', 'Zmiana hasła jest tymczasowo niemożliwa.', 'OK', 'password');
			break;						
			
		case 'ok':
			document.getElementById('password').value = '';
			document.getElementById('password_confirmation').value = '';
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana hasła', 'Twoje hasło zostało zmienione.', 'OK');
			break;
			
		case 'reload':
			window.location.reload();
			break;			
			
		default:
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana hasła', 'Wystąpił nieoczekiwany błąd systemu.', 'OK');
			break;
	}
}

function onChangePasswordClick()
{
	// show "please wait" popup
	StyledPopup.showWaitPopup();
	
	// prepare parameters which will be sent to the server
	var parameters = new Array();
	parameters['password'] = document.getElementById('password').value;
	parameters['password_confirmation'] = document.getElementById('password_confirmation').value;
	parameters['action'] = 'change_password';
	
	// send request to the server
	Ajax.sendRequest('account', parameters, onChangePasswordRequestComplete);
}

//------------------------------------------------------------------------------

function onChangeEmailRequestComplete(responseText)
{
	// check response text
	switch (responseText)
	{
		case 'email_empty':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana adresu e-mail', 'Wprowadź swój adres e-mail.', 'OK', 'email');
			break;
			
		case 'email_invalid':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana adresu e-mail', 'Nieprawidłowy adres e-mail.', 'OK', 'email');
			break;			
			
		case 'email_too_long':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana adresu e-mail', 'Twój adres e-mail jest zbyt długi.<br /><br />Maksymalna długość adresu e-mail to 255 znaków.', 'OK', 'email');
			break;
			
		case 'email_exists':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana adresu e-mail', 'Podany adres e-mail jest przypisany do innego konta.', 'OK', 'email');		
			break;
			
		case 'temporary_not_possible':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana adresu e-mail', 'Zmiana adresu e-mail jest tymczasowo niemożliwa.', 'OK', 'email');
			break;								
			
		case 'ok':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana adresu e-mail', 'Twój adres e-mail został zmieniony.', 'OK');
			break;
			
		case 'reload':
			window.location.reload();
			break;			
			
		default:
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Zmiana adresu e-mail', 'Wystąpił nieoczekiwany błąd systemu.', 'OK');
			break;
	}
}

function onChangeEmailClick()
{
	// show "please wait" popup
	StyledPopup.showWaitPopup();
	
	// prepare parameters which will be sent to the server
	var parameters = new Array();
	parameters['email'] = document.getElementById('email').value;
	parameters['action'] = 'change_email';
	
	// send request to the server
	Ajax.sendRequest('account', parameters, onChangeEmailRequestComplete);
}

//------------------------------------------------------------------------------

function onDeregisterRequestComplete(responseText)
{
	// check response text
	switch (responseText)
	{
		case 'administrator_account_cannot_be_deleted':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Usuwanie konta', 'Nie można usunąć wbudowanego konta administratora systemu.', 'OK');
			break;
	
		case 'ok':
			window.location.href = "";
			break;
			
		case 'reload':
			window.location.reload();
			break;					
			
		default:
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Usuwanie konta', 'Wystąpił nieoczekiwany błąd systemu.', 'OK');
			break;
	}
}

function onDeregisterClick()
{
	var action = 'StyledPopup.showWaitPopup();';
	action += 'var parameters = new Array();';
	action += 'parameters[\"action\"] = \"deregister\";';
	action += 'Ajax.sendRequest(\"account\", parameters, onDeregisterRequestComplete);';
	StyledPopup.showPromptPopup ('templates/bbp_szare/images/icon.gif', 'Usuwanie konta', 'Na pewno chcesz usunąć swoje konto z naszego systemu?', 'Tak', 'Nie', action);
}


//------------------------------------------------------------------------------

function onPollSubmitRequestComplete(responseText)
{
	// check response text
	switch (responseText)
	{
		case 'poll_item_empty':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Wysyłanie ankiety', 'Zaznacz jedną z dostępnych odpowiedzi.', 'OK');
			break;				
	
		case 'poll_item_invalid':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Wysyłanie ankiety', 'Nieprawidłowa odpowiedź.', 'OK');
			break;			
			
		case 'temporary_not_possible':
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Wysyłanie ankiety', 'Wysłanie ankiety jest tymczasowo niemożliwe.', 'OK');
			break;								
			
		case 'ok':
			window.location.reload();
			break;
			
		case 'reload':
			window.location.reload();
			break;			
			
		default:
			alert(responseText);
			StyledPopup.showInformationPopup('templates/bbp_szare/images/icon.gif', 'Wysyłanie ankiety', 'Wystąpił nieoczekiwany błąd systemu.', 'OK');
			break;
	}
}

function onPollSubmitClick()
{
	// show "please wait" popup
	StyledPopup.showWaitPopup();
	
	// get selected poll item
	var selectedPollItem = '';
	var pollItems = document.getElementsByName('poll_item');
	for (var i = 0; i < pollItems.length; i++)
	{
		if (pollItems[i].checked)
		{
			selectedPollItem = pollItems[i].value;
			break;
		}
	}
	
	// prepare parameters which will be sent to the server
	var parameters = new Array();
	parameters['name'] =  document.getElementById('name').value;
	parameters['poll_item'] = selectedPollItem;
	parameters['action'] = 'submit';
	
	// send request to the server
	Ajax.sendRequest('poll', parameters, onPollSubmitRequestComplete);
}

//------------------------------------------------------------------------------

function onSearch(query)
{
	// show "please wait" popup
	StyledPopup.showWaitPopup();
	
	// redirect to search uri
	window.location.href = 'search/' + encodeURIComponent(query);
}