function setFocus(aField) {
document.forms[0][aField].focus();
}

function isAnEmailAddress(aTextField) {
// 1+@3+ [or x@x.x] is as close as we will test

if (document.forms[0][aTextField].value.length<5) {
return false;
}
else if (document.forms[0][aTextField].value.indexOf("@") < 1) {
return false;
}
else if (document.forms[0][aTextField].value.length -
 document.forms[0][aTextField].value.indexOf("@") < 4) {
return false;
}
else { return true; }
}

function isEmpty(aTextField) {
if ((document.forms[0][aTextField].value.length==0) ||
 (document.forms[0][aTextField].value==null)) {
return true;
}
else { return false; }
}

function validate1() {

if (isEmpty("nazwa_firmy")) {
	alert("Proszę wypełnić pole 'Nazwa firmy'");
	setFocus("nazwa_firmy");
	return false;
}if (isEmpty("ulica1")) {
	alert("Proszę wypełnić pole 'Ulica'");
	setFocus("ulica1");
	return false;
}if (isEmpty("nr_domu1")) {
	alert("Proszę wypełnić pole 'Nr domu'");
	setFocus("nr_domu1");
	return false;
}if (isEmpty("kod_pocztowy1")) {
	alert("Proszę wypełnić pole 'Kod pocztowy'");
	setFocus("kod_pocztowy1");
	return false;
}if (isEmpty("miasto1")) {
	alert("Proszę wypełnić pole 'Miasto'");
	setFocus("miasto1");
	return false;
}if (isEmpty("nip")) {
	alert("Proszę wypełnić pole 'NIP'");
	setFocus("nip");
	return false;
}if (isEmpty("regon")) {
	alert("Proszę wypełnić pole 'REGON'");
	setFocus("regon");
	return false;
}
OpenDetail('reszta');
return;
}

function validate2() {


if (isEmpty("imie_nazwisko")) {
	alert("Proszę wypełnić pole 'Imię i nazwisko'");
	setFocus("imie_nazwisko");
	return false;
}if (isEmpty("ulica2")) {
	alert("Proszę wypełnić pole 'Ulica'");
	setFocus("ulica2");
	return false;
}if (isEmpty("nr_domu2")) {
	alert("Proszę wypełnić pole 'Nr domu'");
	setFocus("nr_domu2");
	return false;
}if (isEmpty("kod_pocztowy2")) {
	alert("Proszę wypełnić pole 'Kod pocztowy'");
	setFocus("kod_pocztowy2");
	return false;
}if (isEmpty("miasto2")) {
	alert("Proszę wypełnić pole 'Miasto'");
	setFocus("miasto2");
	return false;
}if (isEmpty("pesel")) {
	alert("Proszę wypełnić pole 'PESEL'");
	setFocus("pesel");
	return false;
}if (isEmpty("dok_tozsamosci")) {
	alert("Proszę wypełnić pole 'Numer i seria dokumentu tozsamosci'");
	setFocus("dok_tozsamosci");
	return false;
}
OpenDetail('reszta');
return;
}

function validate3(){

if (isEmpty("inst_miejscowosc")) {
	alert("Proszę wypełnić pole 'Miejscowosc'");
	setFocus("inst_miejscowosc");
	return false;
}if (isEmpty("inst_ulica")) {
	alert("Proszę wypełnić pole 'Ulica'");
	setFocus("inst_ulica");
	return false;
}if (isEmpty("inst_nr_domu")) {
	alert("Proszę wypełnić pole 'Nr domu'");
	setFocus("inst_nr_domu");
	return false;
}

if (isEmpty("dane_nazwa")) {
	alert("Proszę wypełnić pole 'Imie i nazwisko / Nazwa firmy'");
	setFocus("dane_nazwa");
	return false;
}if (isEmpty("dane_ulica")) {
	alert("Proszę wypełnić pole 'Ulica'");
	setFocus("dane_ulica");
	return false;
}if (isEmpty("dane_nr_domu")) {
	alert("Proszę wypełnić pole 'Nr domu'");
	setFocus("dane_nr_domu");
	return false;
}if (isEmpty("dane_kod_pocztowy")) {
	alert("Proszę wypełnić pole 'Kod pocztowy'");
	setFocus("dane_kod_pocztowy");
	return false;
}if (isEmpty("dane_miejscowosc")) {
	alert("Proszę wypełnić pole 'Miejscowosc'");
	setFocus("dane_miejscowosc");
	return false;
}if (isEmpty("dane_telefon2")) {
	alert("Proszę wypełnić pole 'Telefon'");
	setFocus("dane_telefon1");
	return false;
}if (isEmpty("email")) {
	alert("Proszę wypełnić pole 'E-mail'");
	setFocus("email");
	return false;
}if (!isAnEmailAddress("email")) {
	alert("Wprowadzono nieprawidłowy adres e-mail");
	setFocus("email");
	return false;
}

return;

}
