function $(id)
{
 	return document.getElementById(id);
}

function testuj_logowanie(){
	var f = document.forms['logowanie'];
	if(f.nick.value.length < 1 || f.haslo.value.length < 1) {
		alert('Wpisz Nick oraz Hasło!');
		return false;
	}
	return true;	
}

function testuj_rejestracja(){
	var f = document.forms['rejestracja_form'];
	if(f.nick.value.length < 1 || f.haslo1.value.length < 1 || f.haslo2.value.length < 1 || f.mail.value.length < 1 || f.regulamin.checked == false){
		alert('Pola z gwiazdką są obowiązkowe!');
		return false;
	}
	
	if(f.mail.value.length < 5){	
		alert('Nieprawidłowy adres e-mail!');
		return false;
	}
	if(f.haslo1.value != f.haslo2.value){	
		alert('Niezgodność haseł! Hasła muszą być identyczne.');
		return false;
	}
	
	return true;
}

function testuj_wiersz(){
	var f = document.forms['wiersz_form'];
	if(f.tytul.value.length < 1){
		alert('Wiersz musi posiadać tytuł!');
		return false;		
	}
	if(f.typID.value == 'brak'){
		alert('Musisz wybrać typ wiersza!');		
		return false;		
	}
	if(f.tresc_wiersza.value.length < 1){
		alert('Wiersz musi posiadać treść!');
		return false;
	}
	
	return true;
}

function testuj_komentarz(){
	var f = document.forms['komentarz_form'];
	if(f.tresc_komentarza.value.length < 1){
		alert('Musisz wpisać jakiś komentarz!');
		return false;
	}
	return true;
}

function testuj_szukaj(){
	var f = document.forms['szukaj_form'];
	if(f.wyrazenie.value.length < 1){
		alert('Musisz wpisać poszukiwane wyrażenie!');
		return false;	
	}	
	return true;
}

function testuj_opinie(){
	var f = document.forms['opinia_form'];
	if(f.wiadomosc.value.length < 1){
		alert('Musisz wpisać opinie!');
		return false;
	}
	return true;
}

function testuj_zdanie(){
	var f = document.forms['zdanie_form'];
	if(f.zdanie.value.length < 1){
		alert('Musisz wpisać jakiś tekst!');
		return false;
	}
	return true;
}

function testuj_edycja_autor(){
	var f = document.forms['edycja_autor_form'];
	
	if(f.haslo1.value.length < 1 || f.haslo2.value.length < 1) {
		alert('Pola z gwiazdką są obowiązkowe!');
		return false;
	}
	
	if(f.haslo1.value != f.haslo2.value){
		alert('Niezgodność haseł!');
		return false;
	}
	
	return true;
	
}

function testuj_usun_konto(){
	var f = document.forms['usun_konto_form'];
	if(f.haslo.value.length < 1){
		alert('Musisz wpisać hasło!');
		return false;
	}
	return true;
}

function testuj_mail(){
	var f = document.forms['mail_form'];
	if(f.wiadomosc.value.length < 1){
		alert('Musisz wpisać wiadomość!');
		return false;
	}
	return true;
}

function testuj_przypomnij(){
	var f = document.forms['przypomnij_form'];
	if(f.nick.value.length < 1){
		alert('Musisz wpisać swój Nick!');
		return false;
	}
	if(f.mail.value.length < 5){
		alert('Nieprawidłowy adres E-mail!');
		return false;
	}
	return true;
}


function testuj_polec(){
	var f = document.forms['polec_form'];
	if(f.mail.value.length < 5){
		alert('Musisz wpisać prawidłowy E-mail znajomego!');
		return false;
	}
	return true;
}

function testuj_temat(){
	var f = document.forms['temat_form'];
	if(f.temat.value.length < 1){
		alert('Musisz wpisać temat!');
		return false;
	}	
	
	if(f.tresc_tematu.value.length < 1){
		alert('Musisz wpisać treść tematu!');
		return false;
	}	
	return true;
}

function testuj_post(){
	var f = document.forms['post_form'];
	if(f.post.value.length < 1){
		alert('Musisz wpisać swoją wypowiedź!');
		return false;
	}
	return true;
}


function usun_wiersz(wierszID){
	if(confirm('Czy na pewno chcesz usunąć ten wiersz ?')) {
		document.location.href="usun_wiersz.php5?wierszID="+wierszID;
	}
}

function usun_wiersz_admin(wierszID,autorID){ 
	if(confirm('Czy na pewno chcesz usunąć ten wiersz ?')) {
		document.location.href="usun_wiersz_admin.php5?wierszID="+wierszID+"&autorID="+autorID;
	}
}


function usun_komentarz(komentarzID,wierszID){
	if(confirm('Czy na pewno chcesz usunąć ten komentarz ?')){
		document.location.href="usun_komentarz.php5?komentarzID="+komentarzID+"&wierszID="+wierszID;
	}
}

function usun_opinie(opiniaID){
	if(confirm('Czy na pewno chcesz usunąć tą opinie ?')){
		document.location.href="usun_opinie.php5?opiniaID="+opiniaID;
	}
}

function usun_zdanie(zdanieID){
	if(confirm('Czy na pewno chcesz usunąć to zdanie ?')){
		document.location.href="usun_zdanie.php5?zdanieID="+zdanieID;
	}
}


function usun_zdjecie(autorID){
	if(confirm('Czy na pewno chcesz usunąć zdjęcie ?')){
		document.location.href="usun_zdjecie.php5?autorID="+autorID;
	}
}

function usun_autora(autorID){
	if(confirm('Czy na pewno chcesz usunąć tego autora ?')){
		document.location.href="usun_autora.php5?autorID="+autorID;
	}
}

function usun_temat(tematID){
	if(confirm('Wszystkie posty pod tym tematem zostaną usunięte.\nCzy na pewno chcesz usunąć ten temat ?')){
		document.location.href="usun_temat.php5?tematID="+tematID;
	}
}

function usun_post(tematID,postID){
	if(confirm('Czy na pewno chcesz usunąć ten post?')){
		document.location.href="usun_post.php5?tematID="+tematID+"&postID="+postID;
	}
}


function aktualizuj_poziomy(){
	if(confirm('Czy na pewno chcesz aktualizować poziomy wszystkich autorów ? ')){
		document.location.href="aktualizuj_poziomy.php5";
	}
}



function testuj_wiadomosc()
{
 	var message = $('id_message');
 	if(message.value == '')
 	{
 	 	alert('Musisz wprowadzić jakąś treść wiadomości!');
 	 	return false;
 	}
	else
	{
	 	return true;
	}
}

function selectAllMessages()
{
	var messages = document.getElementsByTagName('input');
	var select = $('id_select');

	for(var i = 0; i < messages.length; i++)
	{
		if(messages[i].type == 'checkbox')
		{
			messages[i].checked = 'checked';
		}
	}
	select.innerHTML = 'Odznacz wszystkie';
	select.setAttribute('href','javascript: deselectAllMessages();');
}

function deselectAllMessages()
{
	var messages = document.getElementsByTagName('input');
	var select = $('id_select');
	
	for(var i = 0; i < messages.length; i++)
	{
		if(messages[i].type == 'checkbox')
		{
			messages[i].checked = '';
		}
	}
	select.innerHTML = 'Zaznacz wszystkie';
	select.setAttribute('href','javascript: selectAllMessages();');
}

function deleteMessages(type)
{
 	if(confirm("Czy na pewno chesz usunąć zaznaczone wiadomości?"))
 	{
 	 	$('id_type').setAttribute('value', type);
 	 	$('myForm').submit();	 	
 	}
}

