function validate_form(formular) {
	var inputs = formular.elements;
    var error = -1; //-1 = OK, jinak index prvniho chybneho inputu
    var errorMsg = "";
    for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].nodeName.toLowerCase() == 'textarea') {
			tp = 'text';
		} else if (inputs[i].nodeName.toLowerCase() == 'select') {
			tp = 'select';
		} else {
			tp = inputs[i].type;
		}
		//nesmi se pouzit 2,n protoze zasrany zkurveny svine
		mailRegExp = new RegExp('^[^@]{2,}@[_a-zA-Z0-9\.\-]{2,}\.[a-zA-Z]{2,4}$');
    	switch (tp) {
			case 'checkbox':
				if (inputs[i].className.match('mandatory') && !inputs[i].checked) {
					if (error == -1) {error = i;}
					errorMsg += "Prosím vyplňte položku "+inputs[i].title+". \n";
				}
			case 'password':
			case 'file':
			case 'text':
				if (inputs[i].nodeName.toLowerCase() == 'textarea') {
				    val = inputs[i].innerHTML;
				} else {
				    val = inputs[i].value;
				}
				if (inputs[i].className.match('mandatory') && (inputs[i].value == '')) {
            		if (error == -1) {error = i;}
					errorMsg += "Prosím vyplňte položku "+inputs[i].title+". \n";
        		}
        		if (inputs[i].className.match('email') && (!inputs[i].value.match(mailRegExp))) {
					if (error == -1) {error = i;}
            		errorMsg += "Prosím vyplňte platný email "+"\n";
        		}
        		if (inputs[i].className.match('number') && (!inputs[i].value.match("^[0-9]+$"))) {
					if (error == -1) {error = i;}
            		errorMsg += "Prosím vyplňte platné číslo "+"\n";
        		}
			case 'select':
			    if (inputs[i].className.match('mandatory') && (inputs[i].selectedIndex == 0)) {
            		if (error == -1) {error = i;}
					errorMsg += "Prosím vyplňte položku "+inputs[i].title+". \n";
				}
        }
    }
    if (error != -1) {
    	alert(errorMsg);
        inputs[error].focus();
        return false;
    } else {return true;}
}
