﻿ie4 = (document.all) ? true:false;
nn4 = (document.layers) ? true:false;
nn6 = (document.getElementById) ? true:false;

function aktywne(nazwa) {
	if (ie4) {
		document.all[nazwa].style.background = "#FFFFFF";
	}
	if (nn4) {
		document.layers[nazwa].style.background = "#FFFFFF";
	}
	if (nn6)	 {
		document.getElementById(nazwa).style.background = "#FFFFFF";
	}
}

function nieaktywne(nazwa) {
	if (ie4) {
		document.all[nazwa].style.background = "#DDDDDD";
	}
	if (nn4) {
		document.layers[nazwa].style.background = "#DDDDDD";
	}
	if (nn6)	 {
		document.getElementById(nazwa).style.background = "#DDDDDD";
	}
}

function sprawdz_szukaj() {
	wzor = new RegExp(".{3,}");
	if (!wzor.test(document.szukaj.fraza.value)) {
		alert("Musisz wpisać minimum 3 znaki!");
		document.szukaj.fraza.focus();
		document.szukaj.fraza.select();
		return false;
	}
}
	

function sprawdz_mail() {	
	wzor = new RegExp("^.+@.+[\.].{2,}$");
	if (!wzor.test(document.subskrypcja.mail.value)) {
		alert("To nie jest poprawny adres e-mail!");
		document.subskrypcja.mail.focus();
		document.subskrypcja.mail.select();
		return false;
	}
}


function sprawdz_ksiega() {	
	if (document.ksiega.txtAutor.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.ksiega.txtAutor.focus();
		document.ksiega.txtAutor.select();
		return false;
	}
	if (document.ksiega.txtTresc.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.ksiega.txtTresc.focus();
		document.ksiega.txtTresc.select();
		return false;
	}
}

function sprawdz_kondolencje() {	
	if (document.kondolencje.txtAutor.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.kondolencje.txtAutor.focus();
		document.kondolencje.txtAutor.select();
		return false;
	}
	if (document.kondolencje.txtTresc.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.kondolencje.txtTresc.focus();
		document.kondolencje.txtTresc.select();
		return false;
	}
}

function sprawdz_pytanie() {	
	if (document.pytanie.txtAutor.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.pytanie.txtAutor.focus();
		document.pytanie.txtAutor.select();
		return false;
	}
	wzor = new RegExp("^.+@.+[\.].{2,}$");
	if (!wzor.test(document.pytanie.txtMail.value)) {
		alert("To nie jest poprawny adres e-mail!");
		document.pytanie.txtMail.focus();
		document.pytanie.txtMail.select();
		return false;
	}
	if (document.pytanie.txtTresc.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.pytanie.txtTresc.focus();
		document.pytanie.txtTresc.select();
		return false;
	}
}


function sprawdz_firmy() {	
	if (document.firmy.txtNazwa.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.firmy.txtNazwa.focus();
		document.firmy.txtNazwa.select();
		return false;
	}
	if (document.firmy.txtUlica.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.firmy.txtUlica.focus();
		document.firmy.txtUlica.select();
		return false;
	}
	wzor = new RegExp("^[0-9]{2}-[0-9]{3}$");
	if (!wzor.test(document.firmy.txtKod.value)) {
		alert("To nie jest poprawny format kodu!");
		document.firmy.txtKod.focus();
		document.firmy.txtKod.select();
		return false;
	}
	if (document.firmy.txtMiasto.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.firmy.txtMiasto.focus();
		document.firmy.txtMiasto.select();
		return false;
	}
	if (document.firmy.txtTelefon.value == "") {
		alert("Nie firmy wszystkich obowiązkowych pól!");
		document.firmy.txtTelefon.focus();
		document.firmy.txtTelefon.select();
		return false;
	}
}


function sprawdz_ekartki() {	
	wzor = new RegExp("^.+@.+[\.].{2,}$");
	/*
	if (document.ekartki.txtNadawca.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.ekartki.txtNadawca.focus();
		document.ekartki.txtNadawca.select();
		return false;
	}
	*/
	if (!wzor.test(document.ekartki.txtNadawcaMail.value)) {
		alert("To nie jest poprawny adres e-mail!");
		document.ekartki.txtNadawcaMail.focus();
		document.ekartki.txtNadawcaMail.select();
		return false;
	}
	/*
	if (document.ekartki.txtOdbiorca.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.ekartki.txtOdbiorca.focus();
		document.ekartki.txtOdbiorca.select();
		return false;
	}
	*/
	if (!wzor.test(document.ekartki.txtOdbiorcaMail.value)) {
		alert("To nie jest poprawny adres e-mail!");
		document.ekartki.txtOdbiorcaMail.focus();
		document.ekartki.txtOdbiorcaMail.select();
		return false;
	}
	if (document.ekartki.txtTytul.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.ekartki.txtTytul.focus();
		document.ekartki.txtTytul.select();
		return false;
	}
	if (document.ekartki.txtPodpis.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.ekartki.txtPodpis.focus();
		document.ekartki.txtPodpis.select();
		return false;
	}
}

function sprawdz_goscie() {
	wzor = new RegExp("^.+@.+[\.].{2,}$");
	if (document.goscie.txtImie.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.goscie.txtImie.focus();
		document.goscie.txtImie.select();
		return false;
	}
	if (document.goscie.txtNazwisko.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.goscie.txtNazwisko.focus();
		document.goscie.txtNazwisko.select();
		return false;
	}
	/*
	wzor = new RegExp("^[0-9]{1,2}$");
	if (!wzor.test(document.goscie.txtWiek.value)) {
		alert("To nie jest liczba!");
		document.goscie.txtWiek.focus();
		document.goscie.txtWiek.select();
		return false;
	}
	*/
	wzor = new RegExp("^.+@.+[\.].{2,}$");
	if (!wzor.test(document.goscie.txtMail.value)) {
		alert("To nie jest poprawny adres e-mail!");
		document.goscie.txtMail.focus();
		document.goscie.txtMail.select();
		return false;
	}
	if (document.goscie.txtLogin.value.length < 3) {
		alert("Login musi mieć minimum 3 znaki!");
		document.goscie.txtLogin.focus();
		document.goscie.txtLogin.select();
		return false;
	}
	if ((document.goscie.txtHaslo.value.length < 6) || (document.goscie.verHaslo.value.length < 6)) {
		alert("Hasło musi mieć minimum 6 znaków!");
		document.goscie.txtHaslo.value="";
		document.goscie.verHaslo.value="";
		document.goscie.txtHaslo.focus();
		document.goscie.txtHaslo.select();
		return false;
	}
	if (document.goscie.txtHaslo.value != document.goscie.verHaslo.value) {
		alert("Niezgodne hasła!");
		document.goscie.txtHaslo.value="";
		document.goscie.verHaslo.value="";
		document.goscie.txtHaslo.focus();
		document.goscie.txtHaslo.select();
		return false;
	}
}

function sprawdz_kalendarz_impreza() {
	licznik = 0;
	if (document.kalendarz_impreza.txtTytul.value == "") {
		licznik = 1;
		alert("Należy wypełnić pole Tytuł!");
		document.kalendarz_impreza.txtTytul.focus();
		document.kalendarz_impreza.txtTytul.select();
		return false;
	}
	if (document.kalendarz_impreza.txtPodpis.value == "") {
		licznik = 1;
		alert("Należy wypełnić pole Podpis");
		document.kalendarz_impreza.txtPodpis.focus();
		document.kalendarz_impreza.txtPodpis.select();
		return false;
	}
	wzor = new RegExp("^.+@.+[\.].{2,}$");
	if (!wzor.test(document.kalendarz_impreza.txtMail.value)) {
		licznik = 1;
		alert("To nie jest poprawny adres e-mail!");
		document.kalendarz_impreza.txtMail.focus();
		document.kalendarz_impreza.txtMail.select();
		return false;
	}
	if (document.kalendarz_impreza.notTresc.value == "") {
		licznik = 1;
		alert("Należy wypełnić treść wydarzenia!");
		document.kalendarz_impreza.notTresc.focus();
		document.kalendarz_impreza.notTresc.select();
		return false;
	}
	if (licznik==0){
		 document.kalendarz_impreza.b.value='zapisz'; 
		 document.kalendarz_impreza.submit();
	}
}

function sprawdz_dane() {	
	if (document.dane.txtImieNazwisko.value == "") {
		alert("Nie wypełniłeś obowiązkowego pola imię i nazwisko!");
		document.dane.txtImieNazwisko.focus();
		document.dane.txtImieNazwisko.select();
		return false;
	}
	if (document.dane.txtAdres.value == "") {
		alert("Nie wypełniłeś obowiązkowego pola adres!");
		document.dane.txtAdres.focus();
		document.dane.txtAdres.select();
		return false;
	}
	wzor = new RegExp("^[0-9]{2}-[0-9]{3}$");
	if (!wzor.test(document.dane.txtKod.value)) {
		alert("To nie jest poprawny format kodu!\nWymagane xx-yyy.");
		document.dane.txtKod.focus();
		document.dane.txtKod.select();
		return false;
	}
	if (document.dane.txtMiasto.value == "") {
		alert("Nie wypełniłeś obowiązkowego pola miejscowość!");
		document.dane.txtMiasto.focus();
		document.dane.txtMiasto.select();
		return false;
	}
}

function sprawdz_cv() {	
	if (document.cv.txtImieNazwisko.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.cv.txtImieNazwisko.focus();
		document.cv.txtImieNazwisko.select();
		return false;
	}
	if (document.cv.txtAdres.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.cv.txtAdres.focus();
		document.cv.txtAdres.select();
		return false;
	}
	if (document.cv.txtTelefon.value == "") {
		alert("Nie wypełniłeś wszystkich obowiązkowych pól!");
		document.cv.txtTelefon.focus();
		document.cv.txtTelefon.select();
		return false;
	}
	wzor = new RegExp("^.+@.+[\.].{2,}$");
	if (document.cv.txtMail.value != "" && !wzor.test(document.cv.txtMail.value)) {
		alert("To nie jest poprawny adres e-mail!");
		document.cv.txtMail.focus();
		document.cv.txtMail.select();
		return false;
	}
}

function sprawdz_nieruchomosci() {
	wzor = new RegExp("^[0-9]{4}-[0-9]{2}-[0-9]{2}$");
	if (!wzor.test(document.nieruchomosci.txtStart.value)) {
		alert("To nie jest poprawny format daty!\nWymagane RRRR-MM-DD.");
		document.nieruchomosci.txtStart.focus();
		document.nieruchomosci.txtStart.select();
		return false;
	}
	wzor = new RegExp("^[0-9]{4}-[0-9]{2}-[0-9]{2}$");
	if (!wzor.test(document.nieruchomosci.txtStop.value)) {
		alert("To nie jest poprawny format daty!\nWymagane RRRR-MM-DD.");
		document.nieruchomosci.txtStop.focus();
		document.nieruchomosci.txtStop.select();
		return false;
	}
	wzor1 = new RegExp("^[0-9]{1,},[0-9]{2}$");
	wzor2 = new RegExp("^[0-9]{1,}$");
	if (!wzor1.test(document.nieruchomosci.intPowierzchnia.value) && !wzor2.test(document.nieruchomosci.intPowierzchnia.value)) {
		alert("To nie jest poprawna liczba!");
		document.nieruchomosci.intPowierzchnia.focus();
		document.nieruchomosci.intPowierzchnia.select();
		return false;
	}
	wzor1 = new RegExp("^[0-9]{1,},[0-9]{2}$");
	wzor2 = new RegExp("^[0-9]{1,}$");
	if (!wzor1.test(document.nieruchomosci.intCena.value) && !wzor2.test(document.nieruchomosci.intCena.value)) {
		alert("To nie jest poprawna liczba!");
		document.nieruchomosci.intCena.focus();
		document.nieruchomosci.intCena.select();
		return false;
	}
}

function sprawdz_smsnumer() {
	wzor = new RegExp("^[\+]{1}[0-9]{11}$");
	if (!wzor.test(document.sms.numer.value)) {
		alert("To nie jest poprawny numer telefonu!\nPoprawny numer to +xxyyyyyyyyy.");
		document.sms.numer.focus();
		document.sms.numer.select();
		return false;
	}
}
