function check_pocet(elem) {
  if( Number(elem) > 0 ) return true;
  else alert("Zadajte prosím správny počet kusov.");
  return false;
}
function trim(str) {
  return str.replace(/^\s+|\s+$/g, '');
}
function do_trim(elem) {
  elem.value = trim(elem.value);
}
function focusElem(elem) {
  var e = document.getElementById(elem);
  if(e != null) e.focus();
}
function ValidMenoPriezvisko() {
  var men = document.getElementById('meno');
  var prie = document.getElementById('priezvisko');
  var meno = trim(men.value);
  var priezvisko = trim(prie.value);
  var result = (priezvisko.length > 0 && meno.length > 0);
  if (meno.length > 0) focusElem('priezvisko');
  else focusElem('meno');
  return result;
}
function ValidEmail() {
  var mail = document.getElementById('email');
  var email = trim(mail.value);
  
	if ( email.length < 7 ) return false;
	if ( email.indexOf ('@') == -1) return false;
	if ( email.indexOf (' ') != -1) return false;
	if ( email.indexOf ('.', email.indexOf ('@')) == -1) return false;
  if ( email.indexOf ('@') != email.lastIndexOf ('@')) return false;
	if ( email.indexOf ('@.') != -1) return false;

	index = email.indexOf('@');
	if (index==0) return false;
	else start = email.substring(0, index);
	if (start.length < 1) return false;
	stred = email.substring(email.indexOf('@'), email.lastIndexOf('.'));
	if (stred.length < 2) return false;
	konec = email.substring(email.lastIndexOf('.'), email.length);
	if (konec.length < 3) return false;

	return true;
}
function ValidStat() {
  var st = document.getElementById('stat');
  var stat = trim(st.value);
  if ( stat.length > 1 ) return true;
  else return false;
}
function ValidPsc() {
  var ps = document.getElementById('psc');
  var psc = trim(ps.value);
  if ( psc.length > 4 ) return true;
  else return false;
}
function ValidMesto() {
  var mes = document.getElementById('mesto');
  var mesto = trim(mes.value);
  if ( mesto.length > 3 ) return true;
  else return false;
}
function ValidAdresa() {
  var adr = document.getElementById('adresa');
  var adresa = trim(adr.value);
  if ( adresa.length > 4 ) return true;
  else return false;
}
function ValidMobil() {
  var cislo = document.getElementById('tcislo');
  var tcislo = trim(cislo.value);
  if ( tcislo.length > 1 ) return true;
  else return false;
}
function ValidRegForm() {
  if ( !ValidMenoPriezvisko() )  { alert('Zadajte prosím Vaše meno a priezvisko.'); return false; }
  //if ( !ValidMobil() ) { alert('Prosím zadajte mobil alebo telefónne číslo.'); focusElem('tcislo'); return false; }
  if ( !ValidEmail() ) { alert('Prosím zadajte správny formát e-mailovej adresy.'); focusElem('email'); return false; }
  if ( !ValidAdresa() ) { alert('Zadajte prosím Vašu adresu.'); focusElem('adresa'); return false; }
  if ( !ValidMesto() ) { alert('Zadajte prosím mesto.'); focusElem('mesto'); return false; }
  if ( !ValidPsc() ) { alert('Zadajte prosím psč.'); focusElem('psc'); return false; }
  if ( !ValidStat() ) { alert('Zadajte prosím krajinu.'); focusElem('stat'); return false; } 
  
  return true;
}