function pokaz_ukryj(obiekt, co) { 
	document.getElementById(obiekt).style.display = co;
}

function licz(pole,max){
	if (pole.value.length > max){
	   pole.value = pole.value.substr(0,max);
	   alert('Proszę wprowadzić maksymalnie '+max+' znaków');
	}
} 

function Formularz(){
	var error = false;
	var error_txt = '';
	var kod=/^[0-9]{2}-[0-9]{3}$/;
	var rok=/^[0-9]{4}$/;
	var email = /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*@([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)*(\.[a-zA-Z]{2,4})$/;

	
	document.getElementById('nazwa1').style.backgroundColor="#FFFFFF";
    document.getElementById('kod_pocztowy').style.backgroundColor="#FFFFFF";
    document.getElementById('miasto').style.backgroundColor="#FFFFFF";
    document.getElementById('adres').style.backgroundColor="#FFFFFF";
    document.getElementById('woj').style.backgroundColor="#FFFFFF";
    document.getElementById('powiat').style.backgroundColor="#FFFFFF";
	document.getElementById('rzalozenia').style.backgroundColor="#FFFFFF";
    document.getElementById('tel').style.backgroundColor="#FFFFFF";
	document.getElementById('kat1').style.backgroundColor="#FFFFFF";
	document.getElementById('kat2').style.backgroundColor="#FFFFFF";
    document.getElementById('nip').style.backgroundColor="#FFFFFF";
    document.getElementById('fprawna').style.backgroundColor="#FFFFFF";
    document.getElementById('fwlasnosci').style.backgroundColor="#FFFFFF";
	document.getElementById('www').style.backgroundColor="#FFFFFF";
	document.getElementById('email').style.backgroundColor="#FFFFFF";
	document.getElementById('opis').style.backgroundColor="#FFFFFF";
	document.getElementById('tagi').style.backgroundColor="#FFFFFF";
	document.getElementById('chek').style.backgroundColor="#FFFFFF";
	

	if (!document.getElementById('nazwa1').value != '') {
		document.getElementById('nazwa1').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać nazwę firmy.\n';
		error = true;
	}
	
	if (!document.getElementById('kod_pocztowy').value.match(kod) || !document.getElementById('kod_pocztowy').value != '') {
		document.getElementById('kod_pocztowy').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny kod pocztowy.\n';
		error = true;
	}
	
	if (!document.getElementById('miasto').value != '') {
		document.getElementById('miasto').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać miasto.\n';
		error = true;
	}
	
	if (!document.getElementById('adres').value != '') {
		document.getElementById('adres').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać adres (ulica; nr domu, lokalu).\n';
		error = true;
	}
	
	if (document.getElementById('woj').value == 0){
		document.getElementById('woj').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę wybrać województwo.\n';
		error = true;
	}
	
	if (!document.getElementById('powiat').value != '') {
		document.getElementById('powiat').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać powiat.\n';
		error = true;
	}
	
	if (!document.getElementById('rzalozenia').value.match(rok) && document.getElementById('rzalozenia').value != '') {
		document.getElementById('rzalozenia').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny rok założenia.\n';
		error = true;
	}
	
	if (!document.getElementById('tel').value != '') {
		document.getElementById('tel').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać telefon.\n';
		error = true;
	}
	
	if (document.getElementById('kat1').value == 0){
		document.getElementById('kat1').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę wybrać przynajmniej jedną kategorię z nowego podziału.\n';
		error = true;
	}
	
	if (document.getElementById('kat1').value == 0 && document.getElementById('kat2').value != 0){
		document.getElementById('kat1').style.backgroundColor="#FFDDDD";
		document.getElementById('kat2').style.backgroundColor="#FFDDDD";
		error_txt += 'Aby wybrać 2 kategorię, należy wybrać także 1 kat..\n';
		error = true;
	}
	
	if (document.getElementById('kat1').value == document.getElementById('kat2').value){
		document.getElementById('kat1').style.backgroundColor="#FFDDDD";
		document.getElementById('kat2').style.backgroundColor="#FFDDDD";
		error_txt += 'Nie możesz wybrać dwóch taki samych kategorii.\n';
		error = true;
	}

	if (document.getElementById('nip').value == '') {
		document.getElementById('nip').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny NIP.\n';
		error = true;
	}
	
	if (document.getElementById('fprawna').value == 0){
		document.getElementById('fprawna').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę wybrać formę prawną.\n';
		error = true;
	}
	
	if (document.getElementById('fwlasnosci').value == 0){
		document.getElementById('fwlasnosci').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę wybrać formę własności.\n';
		error = true;
	}
	
	if (document.getElementById('www').value.substring(0,7) == "http://") {
		document.getElementById('www').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać adres www bez przedrostka http:// \n';
		error = true;
	}

	if (!document.getElementById('email').value.match(email) || document.getElementById('email').value == '') {
		document.getElementById('email').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny E-mail.\n';
		error = true;
	}
	
	if (document.getElementById('opis').value.length < 200 && document.getElementById('opis').value != '') {
		document.getElementById('opis').style.backgroundColor="#FFDDDD";
		error_txt += 'Opis musi zawierać od 200 do 5000 znaków.\n';
		error = true;
	}
	
	if (!document.getElementById('tagi').value != '') {
		document.getElementById('tagi').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać słowa kluczowe.\n';
		error = true;
	}
	
	if (!document.getElementById('chek').checked) {
		document.getElementById('chek').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę zaakceptować regulamin.\n';
		error = true;
	}
	
	if (error == true) {
		alert(error_txt);
	} else {
		document.getElementById('form').submit();	
	}
}

function Formularz_edytuj(){
	var error = false;
	var error_txt = '';
	var kod=/^[0-9]{2}-[0-9]{3}$/;
	var rok=/^[0-9]{4}$/;
	var email = /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*@([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)*(\.[a-zA-Z]{2,4})$/;

	
	document.getElementById('nazwa1').style.backgroundColor="#FFFFFF";
    document.getElementById('kod_pocztowy').style.backgroundColor="#FFFFFF";
    document.getElementById('miasto').style.backgroundColor="#FFFFFF";
    document.getElementById('adres').style.backgroundColor="#FFFFFF";
    document.getElementById('woj').style.backgroundColor="#FFFFFF";
    document.getElementById('powiat').style.backgroundColor="#FFFFFF";
	document.getElementById('rzalozenia').style.backgroundColor="#FFFFFF";
    document.getElementById('tel').style.backgroundColor="#FFFFFF";
	document.getElementById('kat1').style.backgroundColor="#FFFFFF";
	document.getElementById('kat2').style.backgroundColor="#FFFFFF";
    document.getElementById('nip').style.backgroundColor="#FFFFFF";
    document.getElementById('fprawna').style.backgroundColor="#FFFFFF";
    document.getElementById('fwlasnosci').style.backgroundColor="#FFFFFF";
	document.getElementById('www').style.backgroundColor="#FFFFFF";
	document.getElementById('email').style.backgroundColor="#FFFFFF";
	document.getElementById('opis').style.backgroundColor="#FFFFFF";
	document.getElementById('tagi').style.backgroundColor="#FFFFFF";
	document.getElementById('chek').style.backgroundColor="#FFFFFF";

	if (!document.getElementById('nazwa1').value != '') {
		document.getElementById('nazwa1').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać nazwę firmy.\n';
		error = true;
	}
	
	if (!document.getElementById('kod_pocztowy').value.match(kod) || !document.getElementById('kod_pocztowy').value != '') {
		document.getElementById('kod_pocztowy').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny kod pocztowy.\n';
		error = true;
	}
	
	if (!document.getElementById('miasto').value != '') {
		document.getElementById('miasto').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać miasto.\n';
		error = true;
	}
	
	if (!document.getElementById('adres').value != '') {
		document.getElementById('adres').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać adres (ulica; nr domu, lokalu).\n';
		error = true;
	}
	
	if (document.getElementById('woj').value == 0){
		document.getElementById('woj').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę wybrać województwo.\n';
		error = true;
	}
	
	if (!document.getElementById('powiat').value != '') {
		document.getElementById('powiat').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać powiat.\n';
		error = true;
	}
	
	if (!document.getElementById('rzalozenia').value.match(rok) && document.getElementById('rzalozenia').value != '') {
		document.getElementById('rzalozenia').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny rok założenia.\n';
		error = true;
	}
	
	if (!document.getElementById('tel').value != '') {
		document.getElementById('tel').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać telefon.\n';
		error = true;
	}
	
	if (document.getElementById('kat1').value == 0){
		document.getElementById('kat1').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę wybrać przynajmiej jedną kategorię z nowego podziału.\n';
		error = true;
	}
	
	if (document.getElementById('kat1').value == 0 && document.getElementById('kat2').value != 0){
		document.getElementById('kat1').style.backgroundColor="#FFDDDD";
		document.getElementById('kat2').style.backgroundColor="#FFDDDD";
		error_txt += 'Aby wybrać 2 kategorię, należy wybrać także 1 kat..\n';
		error = true;
	}
	
	if (document.getElementById('kat1').value == document.getElementById('kat2').value){
		document.getElementById('kat1').style.backgroundColor="#FFDDDD";
		document.getElementById('kat2').style.backgroundColor="#FFDDDD";
		error_txt += 'Nie możesz wybrać dwóch taki samych kategorii.\n';
		error = true;
	}

	if (document.getElementById('nip').value == '') {
		document.getElementById('nip').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny NIP.\n';
		error = true;
	}
	
	if (document.getElementById('fprawna').value == 0){
		document.getElementById('fprawna').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę wybrać formę prawnę.\n';
		error = true;
	}
	
	if (document.getElementById('fwlasnosci').value == 0){
		document.getElementById('fwlasnosci').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę wybrać formę własności.\n';
		error = true;
	}
	
	if (document.getElementById('www').value.substring(0,7) == "http://") {
		document.getElementById('www').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać adres www bez przedrostka http:// \n';
		error = true;
	}

	if (!document.getElementById('email').value.match(email) || document.getElementById('email').value == '') {
		document.getElementById('email').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny E-mail.\n';
		error = true;
	}
	
	if (document.getElementById('opis').value.length < 200 && document.getElementById('opis').value != '') {
		document.getElementById('opis').style.backgroundColor="#FFDDDD";
		error_txt += 'Opis musi zawierać od 200 do 5000 znaków.\n';
		error = true;
	}
	
	if (!document.getElementById('tagi').value != '') {
		document.getElementById('tagi').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać słowa kluczowe.\n';
		error = true;
	}
	
	if (!document.getElementById('chek').checked) {
		document.getElementById('chek').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę zaakceptować regulamin.\n';
		error = true;
	}
	
	if (error == true) {
		alert(error_txt);
	} else {
		document.getElementById('form').submit();	
	}
}

function Haslo(){
	var error = false;
	var error_txt = '';

	document.getElementById('haslo_old').style.backgroundColor="#FFFFFF";
	document.getElementById('haslo1').style.backgroundColor="#FFFFFF";
	document.getElementById('haslo2').style.backgroundColor="#FFFFFF";
	
	if (document.getElementById('haslo_old').value == '') {
		document.getElementById('haslo_old').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać stare hasło.\n';
		error = true;
	}
	
	if (document.getElementById('haslo1').value != document.getElementById('haslo2').value) {
		document.getElementById('haslo1').style.backgroundColor="#FFDDDD";
		document.getElementById('haslo2').style.backgroundColor="#FFDDDD";
		error_txt += 'Hasła nie są takie same.\n';
		error = true;
	}
	
	if (document.getElementById('haslo1').value.length < 6) {
		document.getElementById('haslo1').style.backgroundColor="#FFDDDD";
		document.getElementById('haslo2').style.backgroundColor="#FFDDDD";
		error_txt += 'Hasło jest za krótkie.\n';
		error = true;
	}
	
	if (error == true) {
		alert(error_txt);
	} else {
		document.getElementById('form').submit();	
	}
}

function Usun(){
	var error = false;
	var error_txt = '';

	document.getElementById('haslo').style.backgroundColor="#FFFFFF";
	
	if (document.getElementById('haslo').value == '') {
		document.getElementById('haslo').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać hasło.\n';
		error = true;
	}
	
	if (error == true) {
		alert(error_txt);
	} else {
		document.getElementById('form1').submit();	
	}
}

function Haslo_przyp(){
	var error = false;
	var error_txt = '';
	var id = /^[0-9]+(\.[0-9]+)*$/;
	var email = /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*@([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)*(\.[a-zA-Z]{2,4})$/;
	
	document.getElementById('id').style.backgroundColor="#FFFFFF";
	document.getElementById('email').style.backgroundColor="#FFFFFF";
	
	if (!document.getElementById('id').value.match(id) || document.getElementById('id').value == '') {
		document.getElementById('id').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny numer ID (numer składa sie tylko z liczb).\n';
		error = true;
	}
	
	if (!document.getElementById('email').value.match(email) || document.getElementById('email').value == '') {
		document.getElementById('email').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny E-mail.\n';
		error = true;
	}
	
	if (error == true) {
		alert(error_txt);
	} else {
		document.getElementById('form').submit();	
	}
}

function Email(){
	var error = false;
	var error_txt = '';
	var email = /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*@([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)*(\.[a-zA-Z]{2,4})$/;
	
	document.getElementById('imie').style.backgroundColor="#FFFFFF";
	document.getElementById('email').style.backgroundColor="#FFFFFF";
	document.getElementById('tresc').style.backgroundColor="#FFFFFF";
	
	if (document.getElementById('imie').value == ''){
		document.getElementById('imie').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać imię i nazwisko.\n';
		error = true;
	}
	
	if (!document.getElementById('email').value.match(email) || document.getElementById('email').value == '') {
		document.getElementById('email').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny E-mail.\n';
		error = true;
	}
	
	if (document.getElementById('tresc').value == ''){
		document.getElementById('tresc').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać wiadomość.\n';
		error = true;
	}
	
	if (error == true) {
		alert(error_txt);
	} else {
		document.getElementById('form').submit();	
	}
}

function Wyslijznaj(){
	var error = false;
	var error_txt = '';
	var email = /^[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*@([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)*(\.[a-zA-Z]{2,4})$/;
	
	document.getElementById('imie').style.backgroundColor="#FFFFFF";
	document.getElementById('email_znaj').style.backgroundColor="#FFFFFF";
	
	if (document.getElementById('imie').value == ''){
		document.getElementById('imie').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać imię.\n';
		error = true;
	}
	
	if (!document.getElementById('email_znaj').value.match(email) || document.getElementById('email_znaj').value == '') {
		document.getElementById('email_znaj').style.backgroundColor="#FFDDDD";
		error_txt += 'Proszę podać poprawny E-mail znajomego.\n';
		error = true;
	}
	
	if (error == true) {
		alert(error_txt);
	} else {
		document.getElementById('form').submit();	
	}
}