// Validates all fields in the specified form
function validate(form) {
var elements = form.getElementsByTagName('*');
var input = null;
var ok = true;
// Search for invalid inputs
for (var i = 0; i < elements.length; i++) {
input = elements[i];
var minlength=elements[i].getAttribute('minlength')
var confirm=elements[i].getAttribute('confirm')

minLength = (minlength) ? minlength : 0;


var konieczny=elements[i].getAttribute('required')

if (konieczny=='true') {
if (input.tagName.toLowerCase() == 'select') {
if (input.options.length == 0 ||
!input[input.selectedIndex].value) {
ok = false;
}
} 

else if (input.type.toLowerCase() == 'radio') {
var pole = eval("document.forms."+form.name+"."+input.name);
myOption = -1;
	for (j=pole.length-1; j > -1; j--) {
		if (pole[j].checked) {
		myOption = j; j = -1;
		}
	}
	if (myOption == -1) {
	ok = false;
	}

}

else if (input.type.toLowerCase() == 'checkbox' && !input.checked) {
ok = false;

}
else if (!input.value) {
ok = false;
}

if (!ok) {
window.alert('Wypelnij pole  "' + input.title + '"');
try {
input.focus();
} catch (e) {
}
return false;
}
}
// Minlength test		
	 if (minLength > 0) {
			if (input.value.length < minLength) {
				window.alert('Pole ' + input.title + ' musi zawierac minimum ' + minLength + ' znakow.');
				try {
				input.focus();
				} catch (e) {
				}
				return false;
		}
			}

if (confirm && confirm != '') {

if (input.value != document.getElementById(confirm).value) {
window.alert('Pola ' + document.getElementById(confirm).title 
+ ' i ' + input.title + ' nie zgadzają sie.');
return false;
}
}
}
return true;
}

// Validates all fields in the specified form
function validate_pelna(form,href) {
var elements = form.getElementsByTagName('*');
var input = null;
var ok = true;
// Search for invalid inputs
for (var i = 0; i < elements.length; i++) {
input = elements[i];
minLength = (input.minlength) ? input.minlength : 0;

var konieczny=elements[i].getAttribute('required_pelna')


if (konieczny) {
if (input.tagName.toLowerCase() == 'select') {
if (input.options.length == 0 ||
!input[input.selectedIndex].value) {
ok = false;
}
} else if (!input.value || input.value.length < minLength) {
ok = false;
}
if (!ok) {
window.alert('Wypelnij pole  "' + input.title + '"');
try {
input.focus();
} catch (e) {
}
return false;
}
}
if (input.confirm && input.confirm != '') {
if (input.value != document.getElementById(input.confirm).value) {
window.alert(document.getElementById(input.confirm).title 
+ ' and ' + input.title + ' nie zgadzają sie.');
return false;
}
}
}
window.location.href = href;
}


// Focuses on the first <input> or <select> field in the specified form
function focusForm(formId) {
var elements = (formId) 
? document.getElementById(formId).getElementsByTagName('*') 
: document.getElementsByTagName('*');
for (var i = 0; i < elements.length; i++) {
input = elements[i];
if (input.tagName.toLowerCase() == 'input' || 
input.tagName.toLowerCase() == 'select') {
input.focus();
break;
}
}
return true;
}
