function addUser()
{
	var username=$("username");
	var email=$("email");
	var password=$("password");
	var repassword=$("repassword");	
	var akceptujeregulamin=$("akceptujeregulamin");
	var errorText='';
	var error=0;

	if (isEmpty(username))
	{
		error=1;
		errorText+='Musisz podać login<br />';
		username.className='errorInput';		
	}
	else
		username.className='';


	if (isEmpty(email))
	{
		error=1;
		errorText+='Musisz podać adres e-mail<br />';
		email.className='errorInput';		
	}
	else if (!isEmail(email.value))
	{
		error=1;
		errorText+='Wprowadź poprawny adres e-mail<br />';
		email.className='errorInput';		
	}
	else
		email.className='';
		
    if (password.value!=repassword.value)
	{
		error=1;
		errorText+='Hasła muszą być takie same<br />';
		password.className='errorInput';
	}	
	else
		password.className='';

  if (isEmpty(password))
	{
		error=1;
		errorText+='Musisz podać hasło<br />';
		password.className='errorInput';		
	}
	else
		password.className='';			

  if (isEmpty(repassword))
	{
		error=1;
		errorText+='Musisz podać drugi raz hasło<br />';
		repassword.className='errorInput';		
	}
	else
		repassword.className='';	

	if (!akceptujeregulamin.checked)
	{
		error=1;
		errorText+='Musisz zaakceptować regulamin';
		akceptujeregulamin.className='errorInput';		
	}
	else
		akceptujeregulamin.className='';		
		
	if(error==1){
		info('e','infoDiv',errorText);
	}else
	{
		advAJAX.submit(document.getElementById("addUser"), {
			onLoading : function(obj) { info('l','loadingDiv','Proszć czekać...'); },  
			onSuccess : function(obj) 
			{
				divOnOff('loadingDiv',0);
				if(obj.responseText=='inBase')
				{
					info('e','infoDiv','Użytkownik o takim loginie jest już zarejestrowany. Wybierz inny login.');					
				}
				else if (obj.responseText=='antyflood')
				{
					info('w','infoDiv','Nie można dodac kolejnego użytkownika z tego samego komputera tak szybko po poprzednim');
				}
				else if (obj.responseText=='added')
				{	
					info('o','infoDiv','Użytkownik zostań dodany');
					redirect('./site,rejestracjaok.html');
				}
					
			},
			onError : function(obj) { alert("Error: " + obj.status); }
		});
	}
}

function addFirmaUserForm()
{
	var nazwafirmy=$("nazwafirmy");
	//var catID=$("catID");
	//var wojID=$("wojID");
	//var descText=$("text");
	var errorText='';
	var error=0;


	if (isEmpty(nazwafirmy))
	{ 
		error=1;
 		errorText+='Musisz wpisać nazwę firmy<br />';
 		nazwafirmy.className='errorInput';
	}
	else
		nazwafirmy.className='';
/*
	if (catID.value=='w') 
	{ 
		error=1;
 		errorText+='Musisz wybrać kategorię<br />';
 		catID.className='errorInput';
	}
	else
		catID.className='';


	if (isEmpty(descText))
	{
		error=1;
		errorText+='Musisz wprowadzić opis';
		descText.className='errorInput';		
	}
	else
		descText.className='';
*/
	if(error==1)
		info('e','infoDiv',errorText);
	else
	{
		advAJAX.submit(document.getElementById("addFirmaUserForm"), {
			onLoading : function(obj) { info('l','loadingDiv','Proszę czekać...'); },  
			onSuccess : function(obj) 
			{
				divOnOff('loadingDiv',0);
				if(obj.responseText=='inBase')
					info('e','infoDiv','Ten opis jest już w bazie danych');
				else if (obj.responseText=='antyflood')
					info('w','infoDiv','Nie można dodac opisu tak szybko po poprzednim');
				else if (obj.responseText=='added')
					info('o','infoDiv','Opis został dodany');
			},
			onError : function(obj) { alert("Error: " + obj.status); }
		});
	}
}

function addDesc()
{
	var catID=$("catID");
	var descText=$("text");
	var errorText='';
	var error=0;

	if (catID.value=='w') 
	{ 
		error=1;
 		errorText+='Musisz wybrać kategorię<br />';
 		catID.className='errorInput';
	}
	else
		catID.className='';


	if (isEmpty(descText))
	{
		error=1;
		errorText+='Musisz wprowadzić opis';
		descText.className='errorInput';		
	}
	else
		descText.className='';

	if(error==1)
		info('e','infoDiv',errorText);
	else
	{
		advAJAX.submit(document.getElementById("addDesc"), {
			onLoading : function(obj) { info('l','loadingDiv','Proszę czekać...'); },  
			onSuccess : function(obj) 
			{
				divOnOff('loadingDiv',0);
				if(obj.responseText=='inBase')
					info('e','infoDiv','Ten opis jest już w bazie danych');
				else if (obj.responseText=='antyflood')
					info('w','infoDiv','Nie można dodac opisu tak szybko po poprzednim');
				else if (obj.responseText=='added')
					info('o','infoDiv','Opis został dodany');
			},
			onError : function(obj) { alert("Error: " + obj.status); }
		});
	}
}

function addSpecialDesc()
{
	var descText=$("text");
	var descType=$("type");
	var errorText='';
	var error=0;
	var txt='';
	var page='';

	if (isEmpty(descText))
	{
		error=1;
		if(descType.value=='C') txt='łańcuszek'; else txt='opis';
		errorText+='Musisz wprowadzić '+txt;
		descText.className='errorInput';		
		info('e','infoDiv',errorText);
	}
	else
		descText.className='';

	if(error==0)
	{
		advAJAX.submit(document.getElementById("addSpecialDesc"), {
			onLoading : function(obj) { info('l','loadingDiv','Proszę czekać...'); },  
			onSuccess : function(obj) 
			{
				divOnOff('loadingDiv',0);
				if (obj.responseText=='antyflood')
				{
					if(descType.value=='C') txt='łańcuszka'; else txt='opisu';
					info('w','infoDiv','Nie można dodać '+txt+' tak szybko po poprzednim');

				}
				else if (obj.responseText=='added')
				{
					if(descType.value=='C') txt='Łańcuszek'; else txt='Opis';
					info('o','infoDiv',txt+' został dodany');
					if(descType.value=='C') page='chains'; else page='verticals';
					redirect('./informator,'+page+'.html');
				}
			},
			onError : function(obj) { alert("Error: " + obj.status); }
		});
	}
}

function descChanger()
{
	var desc=$("phrase");
	var resultDiv=$("resultDivText");	

	if(isEmpty(desc))
	{
		info('e','infoDiv','Musisz wprowadzić frazę');
		desc.className='errorInput';
	}
	else
	{
		advAJAX.submit(document.getElementById("descChanger"), {
			onLoading : function(obj) { info('l','loadingDiv','Proszę czekać...'); },  
			onSuccess : function(obj) {
		
				divOnOff('loadingDiv',0);
				divOnOff('resultDiv', 1);
				resultDiv.innerHTML=obj.responseText;
			},
			onError : function(obj) { alert("Error: " + obj.status); }
		});
	}
}

function descVote()
{
	advAJAX.submit(document.getElementById("descVote"), {
		onLoading : function(obj) { info('l','loadingDiv','Proszę czekać...'); },  
		onSuccess : function(obj) 
		{
			divOnOff('loadingDiv',0);
			if (obj.responseText=='isVote')
				info('e','infoDiv','Nie można głosować dwa razy');
			if  (obj.responseText=='ok')
				info('o','infoDiv','Twój głos został dodany');
		},
		onError : function(obj) { alert("Error: " + obj.status); }
	});
}

function subscribe()
{
	var email=$("email");
	var error=0;
	var errorText='';

	if (isEmpty(email))
	{
		error=1;
		errorText+='Musisz podać adres e-mail';
		email.className='errorInput';		
	}
	else if (!isEmail(email.value))
	{
		error=1;
		errorText+='Wprowadź poprawny adres e-mail';
		email.className='errorInput';		
	}
	else
		email.className='';

	if (error==1)
		info('e','infoDiv',errorText);
	else
	{
		advAJAX.submit(document.getElementById("subscribeForm"), {
			onLoading : function(obj) { info('l','loadingDiv','Proszę czekać...'); },  
			onSuccess : function(obj) 
			{
				divOnOff('loadingDiv',0);
				if (obj.responseText=='notInBase')
					info('e','infoDiv','Tego adresu nie ma w bazie');
				else if (obj.responseText=='inBase')
					info('e','infoDiv','Twój adres e-mail jest już w bazie');
				else if (obj.responseText=='emailInserted')
					info('o','infoDiv','Twój adres e-mail został dodany do listy wysyłkowej');
				else if (obj.responseText=='emailDeleted')
					info('o','infoDiv','Twój adres e-mail został usunięty z listy wysyłkowej');

			},
			onError : function(obj) { alert("Error: " + obj.status); }
		});
	}
}

function recommendForm()
{
	var email1=$("email1");
	var email2=$("email2");
	var error=0;
	var errorText='';

	if (isEmpty(email1))
	{
		error=1;
		errorText+='Musisz podać adres e-mail znajomego<br />';
		email1.className='errorInput';		
	}
	else if (!isEmail(email1.value))
	{
		error=1;
		errorText+='Wprowadź poprawny własny adres e-mail<br />';
		email1.className='errorInput';		
	}
	else
		email1.className='';

	if (isEmpty(email2))
	{
		error=1;
		errorText+='Musisz podać swój adres e-mail<br />';
		email2.className='errorInput';		
	}
	else if (!isEmail(email2.value))
	{
		error=1;
		errorText+='Wprowadź poprawny adres e-mail znajomego<br />';
		email2.className='errorInput';		
	}
	else
		email2.className='';

	if (error==1)
		info('e','infoDiv',errorText);
	else
	{
		advAJAX.submit(document.getElementById("recommendForm"), {
			onLoading : function(obj) { info('l','loadingDiv','Proszę czekać...'); },  
			onSuccess : function(obj) 
			{
				divOnOff('loadingDiv',0);
				if (obj.responseText=='antyflood')
					info('w','infoDiv','Musisz poczekać trochę, aby ponownie użyć formularza');
				else
					info('o','infoDiv','List polecający został wysłany na adres '+email1.value);
			},
			onError : function(obj) { alert("Error: " + obj.status); }
		});
	}
}

function contactForm()
{
	var email=$("email");
	var mailText=$("mailText");
	var error=0;
	var errorText='';

	if (isEmpty(email))
	{
		error=1;
		errorText+='Musisz podać adres e-mail<br />';
		email.className='errorInput';		
	}
	else if (!isEmail(email.value))
	{
		error=1;
		errorText+='Wprowadź poprawny adres e-mail<br />';
		email.className='errorInput';		
	}
	else
		email.className='';

	if (isEmpty(mailText))
	{
		error=1;
		errorText+='Musisz treść listu';
		mailText.className='errorInput';		
	}
	else
		mailText.className='';


	if (error==1)
		info('e','infoDiv',errorText);
	else
	{
		advAJAX.submit(document.getElementById("contactForm"), {
			onLoading : function(obj) { info('l','loadingDiv','Proszę czekać...'); },  
			onSuccess : function(obj) 
			{
				divOnOff('loadingDiv',0);
				if (obj.responseText=='antyflood')
					info('w','infoDiv','Musisz poczekać trochę, aby ponownie użyć formularza');
				else
					info('o','infoDiv','List został wysłany');
			},
			onError : function(obj) { alert("Error: " + obj.status); }
		});
	}
}