
	function formTesting(oldnick){
		if(document.getElementById('registeremail')) {	
			document.getElementById('EmailCheckIframe').src='/libs/_rejestracja/sprawdz_email.asp?login='+document.getElementById('registeremail').value+'&amp;randomval='+Math.random()*1000000;
		}
		if(document.getElementById('NickCheckIframe')){
			document.getElementById('NickCheckIframe').src='/libs/_rejestracja/sprawdz_nick.asp?nick='+document.getElementById('nick').value+'&randomval='+Math.random()*1000000+'&oldnick='+oldnick;
		}
	}
	
	function passwordGIODOtest(pws) {
		// coby GIODO nie wracało...

		var male = false
		var duze = false
		var liczba = false
		var znak;
	
		for(var j=0; j<pws.value.length; j++) {
			znak = pws.value.substr(j,1).charCodeAt(0);
			if (znak >=65 && znak <= 90) duze = true;
			if (znak >=97 && znak <= 122) male = true;
			if (znak >=48 && znak <= 57) liczba = true;
		}

		if (!duze || !male || !liczba) {
			return false;
		}
	
		return true;

	}	

	function ByIdTest(p, minimal, maximal) {
		if (document.getElementById(p)) {
			if (document.getElementById(p).type != "hidden" && document.getElementById(p).value != "no_update") {
				if (document.getElementById(p).value.length >= minimal && document.getElementById(p).value.length <=maximal) {
					return true;
				} else {
					return false;
				}
			} else {
				return true;
			}
		} else {
			return true;
		}
	}

	function checkCheckbox(f,p,ile) {
		var x = 0;
		for(var a=0;a < f.length;a++) {
			if(f[a].name.indexOf(p) >=0) {
				if (f[a].checked) x++;
			}
		}
		if (x >= ile) {
			return true;
		} else {
			return false;
		}
	}

	function checkSelect(f) {
		var select_test = false;
		if (document.getElementById(f)) {
			if (document.getElementById(f).type != "hidden" && document.getElementById(f).value != "no_update") {
				for (var j=1; j<document.getElementById(f).length;j++){
					if (document.getElementById(f)[j].selected) {
						select_test = true;
						break;
					}
				}
			} else {
				select_test = true;
			}
		} else {
			select_test = true;
		}
		return select_test;
	}

	function test_form_rejestracja(f) {

		if (!document.getElementById("zgoda_na_zapis_w_bazie").checked) {
			return true;
		}
	
		var info = '';
		if (document.getElementById("registeremail")) {
		
			if (document.getElementById("freeEmailField").value !=1) {
				info += '\n - Adres email zawiera błędny, albo jest już w bazie.';
			}
			
		}
	
		if (document.getElementById("nick")) {
			if (document.getElementById("nick").value != "") {
				if (document.getElementById("freeNickField").value !=1) {
					info += '\n - Nick jest błędny, albo jest już w bazie.';
				}
			}
		}

		if (document.getElementById("registerhaslo") && document.getElementById("registerhaslo2")) {
			if (document.getElementById("registerhaslo").value != document.getElementById("registerhaslo2").value) {
				info += '\n - Pole hasło i potwierdź hasło zawiera różne ciągi znaków.';
			}
		}

		if (document.getElementById("registerhaslo")) {
			if (document.getElementById("registerhaslo").value.length > 0) {
				if (!passwordGIODOtest(document.getElementById("registerhaslo"))) {
					info += '\n - Twoje hasło powinno zawierać przynajmniej jedną dużą literę, jedną małą i cyfrę.';
				}
				reg_test = new RegExp('[^a-z0-9\-_ęóšłżćń]+', 'gi');						
				if(document.getElementById("registerhaslo").value.match(reg_test) != null) {
					info += '\n - Pole hasło zawiera niedozwolone znaki.';
				}	
			}
		}

		if (!ByIdTest("imie",3,20)) info += '\n - Pole imię powinno zawierać pomiędzy od 3 do 20 znaków.';
		if (!ByIdTest("nazwisko",3,20)) info += '\n - Pole nazwisko powinno zawierać pomiędzy od 3 do 20 znaków.';

		if (document.getElementById("zawod")) {
			if (document.getElementById("zawod").value != 4) {
				if (!ByIdTest("nazwa_stanowiska",3,100)) info += '\n - Pole stanowisko powinno zawierać pomiędzy od 3 do 100 znaków.';
				if (!ByIdTest("firma",3,150)) info += '\n - Pole firma powinno zawierać pomiędzy od 3 do 150 znaków.';
				if (!checkSelect("branza")) info += '\n - Wskaż branżę.';
				if (!checkSelect("wielkosc")) info += '\n - Wskaż wielkość zatrudnienia.';
				if (!ByIdTest("firma_ulica",3,100)) info += '\n - Pole ulica powinno zawierać pomiędzy od 3 do 100 znaków.';
				if (!ByIdTest("firma_kod_pocztowy",1,6)) info += '\n - Pole kod pocztowy powinno zawierać pomiędzy od 1 do 6 znaków.';
				if (!ByIdTest("firma_miejscowosc",1,100)) info += '\n - Pole miejscowość powinno zawierać pomiędzy od 1 do 100 znaków.';
				if (!ByIdTest("firma_telefon",1,50)) info += '\n - Pole telefon powinno zawierać pomiędzy od 1 do 50 znaków.';
				if (!ByIdTest("firma_kraj",1,50)) info += '\n - Pole kraj powinno zawierać pomiędzy od 1 do 50 znaków.';
			} else {
				if (!ByIdTest("osoba_ulica",3,100)) info += '\n - Pole ulica powinno zawierać pomiędzy od 3 do 100 znaków.';
				if (!ByIdTest("osoba_kod_pocztowy",1,6)) info += '\n - Pole kod pocztowy powinno zawierać pomiędzy od 1 do 6 znaków.';
				if (!ByIdTest("osoba_miejscowosc",1,100)) info += '\n - Pole miejscowość powinno zawierać pomiędzy od 1 do 100 znaków.';
				if (!ByIdTest("osoba_telefon",1,50)) info += '\n - Pole telefon powinno zawierać pomiędzy od 1 do 50 znaków.';
				if (!ByIdTest("osoba_kraj",1,50)) info += '\n - Pole kraj powinno zawierać pomiędzy od 1 do 50 znaków.';
			}
		}

		var zainteresowania_test
		zainteresowania_test = true
		if (document.getElementById("zainteresowania")) {
			if (document.getElementById("zainteresowania").value == "no_update") zainteresowania_test = false;
		}

		if (zainteresowania_test == true) {
			if (!checkCheckbox(f,'zainteresowania_',1)) info += '\n - Wskaż choć jedno zainteresowanie.';
		}
		
		if (document.getElementById("div_branza_glebiej")) {
			if (document.getElementById("div_branza_glebiej").style.display == "block") {
				if (!checkCheckbox(f,'branza_glebiej_',1)) info += '\n - Wskaż choć jedną branżę (checkbox).';
			}	
		}
		
		if (!checkSelect("zawod")) info += '\n - Wskaż sytuację zawodową';
		
		if (document.getElementById("div_zawod2")) {
			if (document.getElementById("div_zawod2").style.display == "block") {
				if (!checkSelect("zawod2")) info += '\n - Wskaż sytuację zawodową (2 poziom).';
			}
		}

		if (document.getElementById("div_zawod3")) {
			if (document.getElementById("div_zawod3").style.display == "block") {
				if (!checkSelect("zawod3")) info += '\n - Wskaż sytuację zawodową (3 poziom).';
			}
		}
		
		if (info.length > 0) {
			window.alert(info);
			return false;
		} else {
			return true;
		}
	}

	function info_kasowanie(x) {
		if (!x.checked)	{
			alert('Uwaga! Usuwasz zgodę na przechowywanie danych przez IDG. Po zatwierdzeniu przyciskiem "Zapisz" Twoje konto zostanie usunięte.')
		}
	}
		
	function zakladanie_konta(x) {
		if (!x.checked)	{
			alert('Aby utworzyć konto musisz wyrazić zgodę na umieszczenie swoich danych teleadresowych w bazie IDG.');
		}
	}

	function info_zgoda_marketingowa(x) {
		if (!x.checked)	{
			alert('Wyrażenie zgody na wykorzystanie adresu email do celów marketingowych jest konieczne do poprawnego korzystania z większości usług oferowanych w serwisie.');
		}
	}
	
	function zawodPokazListe2(f,x) {
		if (document.getElementById("zawod2")) {
			if (document.getElementById("zawod2").type != "hidden" && document.getElementById("zawod2").value != "no_update") {
				wizualizacja_grup(f);
				var s = document.getElementById("zawod2");
				s.length = 0;
				document.getElementById("zawod3").length = 0;
				if (sprawdzCzyJest(f)) {
					s.options[s.options.length] = new Option("-- wybierz --","",0,0);
				}
				for (var a=0;a < cru_tab_cfg.length; a++) {
					if (cru_tab_cfg[a][2] == f) {
						s.options[s.options.length] = new Option(cru_tab_cfg[a][1],cru_tab_cfg[a][0]);
					}
				}
				// dla Chrome/Ie
				for (var a=0;a < s.length; a++) {
					if (s[a].value == x) {
						s[a].selected = true;
					}
				}
				
				if (s.length > 0) {
					if (document.getElementById("div_zawod2")) {
						$("#div_zawod2").show("slow");
					}
					if (document.getElementById("div_zawod3")) {
						$("#div_zawod3").hide("slow");
					}
				} else {
					if (document.getElementById("div_zawod2")) {
						$("#div_zawod2").hide("slow");
					}
					if (document.getElementById("div_zawod3")) {
						$("#div_zawod3").hide("slow");
					}
				}
			}
		}
	}

	function zawodPokazListe3(f,x) {
		if (document.getElementById("zawod3")) {
			if (document.getElementById("zawod3").type != "hidden" && document.getElementById("zawod3").value != "no_update") {
				var s = document.getElementById("zawod3");
				s.length = 0;
				if (sprawdzCzyJest(f)) {
					s.options[s.options.length] = new Option("-- wybierz --","",0,0);
				}
				for (var a=0;a < cru_tab_cfg.length; a++) {
					if (cru_tab_cfg[a][2] == f) {
						s.options[s.options.length] = new Option(cru_tab_cfg[a][1],cru_tab_cfg[a][0]);
					}
				}
				// dla Chrome/Ie
				for (var a=0;a < s.length; a++) {
					if (s[a].value == x) {
						s[a].selected = true;
					}
				}
				if (s.length > 0) {
					if (document.getElementById("div_zawod3")) {
						$("#div_zawod3").show("slow");
					}
				} else {
					if (document.getElementById("div_zawod3")) {
						$("#div_zawod3").hide("slow");
					}
				}
			}
		}
	}

	function sprawdzCzyJest(f) {
		var out = false;
		for (var a=0;a < cru_tab_cfg.length; a++) {
			if (cru_tab_cfg[a][2] == f) {
				out = true;
				break;
			}
		}
		return out;
	}
	
	function zwrocOjca(f) {
		var out = 0;
		for (var a=0;a < cru_tab_cfg.length; a++) {
			if (cru_tab_cfg[a][0] == f) {
				out = cru_tab_cfg[a][2];
				break;
			}
		}
		return out;
	}

	function ustawStanowisko(id){
		if (document.getElementById("zawod")) {
			var s = document.getElementById("zawod");
			for (var i=0; i< s.length; i++){
				if (s[i].value == id){
					s[i].selected = true;
				}
			}
		}
	}

	function wizualizacja_grup(f) {
		// w zależnoci czy pracuje, czy nie
		if (f == 4 || f == 31 || f == 30 || f == 29) {
			if (document.getElementById("modul_firma")) {
				$("#modul_firma").hide("slow");
			}
			if (document.getElementById("modul_stanowisko")) {		
				$("#modul_stanowisko").hide("slow");
			}
			if (document.getElementById("info_firmowe")) {		
				$("#info_firmowe").hide("slow");
			}
			if (document.getElementById("info_osobowe")) {		
				$("#info_osobowe").show("slow");
			}
			if (document.getElementById("profil_typ")) {		
				document.getElementById("profil_typ").value = "b2c";
			}
		} else {
			try {
				if (document.getElementById("modul_firma")) {
					$("#modul_firma").show("slow");
				}
				if (document.getElementById("modul_stanowisko")) {
					$("#modul_stanowisko").show("slow");
				}
				if (document.getElementById("info_firmowe")) {
					$("#info_firmowe").show("slow");
				}
				if (document.getElementById("info_osobowe")) {
					$("#info_osobowe").hide("slow");
				}
				if (document.getElementById("profil_typ")) {
					document.getElementById("profil_typ").value = "b2b";
				}
			} catch(err) {}
		}
	}

	function sprawdzBranze(f) {
		if (f == 204) {
			if (document.getElementById("div_branza_glebiej")) {
				$("#div_branza_glebiej").show("slow");
			}
		} else {
			try {
				if (document.getElementById("div_branza_glebiej")){
					$("#div_branza_glebiej").hide("slow");
				}
			} catch(err) {}
		}
	}
