var whitespace = " \t\n\r";
function isEmpty(s){return ((s == null) || (s.length == 0))}
function isWhitespace (s)
{
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}
function allValid(checkStr, add) {
  var checkOK = "AÁÄBCČDĎEÉĚFGHIÍJKLĹĽMNŇOÔÓÖPQRŔŘSŠTŤUÚŮÜVWXYÝZŽaáäbcčdďeéěfghiíjklĺľmnňoôóöpqrsštťuúůüwvxyýzž0123456789"+add;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++) { if (ch == checkOK.charAt(j)) break;}
    if (j == checkOK.length) return false;
  }
return true;
}

function validPhone(checkStr, add) {
  var checkOK = " 0123456789/\-+";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++) { if (ch == checkOK.charAt(j)) break;}
    if (j == checkOK.length) return false;
  }
return true;
}

function validZIP(checkStr, add) {
  var checkOK = " 0123456789";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++) { if (ch == checkOK.charAt(j)) break;}
    if (j == checkOK.length) return false;
  }
return true;
}

function validTitul(checkStr, add) {
  var checkOK = " AÁÄBCČDĎEÉĚFGHIÍJKLĹĽMNŇOÔÓÖPQRŔŘSŠTŤUÚŮÜVWXYÝZŽaáäbcčdďeéěfghiíjklĺľmnňoôóöpqrsštťuúůüvwxyýzž.";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++) { if (ch == checkOK.charAt(j)) break;}
    if (j == checkOK.length) return false;
  }
return true;
}

function validCity(checkStr, add) {
  var checkOK = " AÁÄBCČDĎEÉĚFGHIÍJKLĹĽMNŇOÔÓÖPQRŔŘSŠTŤUÚŮÜVWXYÝZŽaáäbcčdďeéěfghiíjklĺľmnňoôóöpqrsštťuúůüvwxyýzž.\/-_";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++) { if (ch == checkOK.charAt(j)) break;}
    if (j == checkOK.length) return false;
  }
return true;
}

 function isEmail (s)
{
 	if(!allValid(s,"@.-_")) return false;
	if (isEmpty(s)) return false;
	if (isWhitespace(s)) return false;
	var i = 2;
	var sLength = s.length;
	while ((i < sLength) && (s.charAt(i) != "@"))
	{ i++
	}
	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 3;
	while ((i < sLength) && (s.charAt(i) != "."))
	{ i++
	}
	if ((i >= sLength - 2) || (s.charAt(i) != ".")) return false;
	else return true;
}

function Validator(zamestnanecsignup)
{

  
    	if ((!isWhitespace(zamestnanecsignup.titlebeforename.value))&&(!validTitul(zamestnanecsignup.titlebeforename.value)))
  {
    alert("Prosíme, zadajte korektne Váš titul pred menom!");
    zamestnanecsignup.titlebeforename.focus();
    zamestnanecsignup.titlebeforename.select();
    return (false);
  }
  
  	if (isWhitespace(zamestnanecsignup.secondname.value))
  {
    alert("Prosíme, zadajte Vaše priezvisko!");
    zamestnanecsignup.secondname.focus();
    zamestnanecsignup.secondname.select();
    return (false);
  }
	if (isWhitespace(zamestnanecsignup.firstname.value))
  {
    alert("Prosíme, zadajte Vaše meno!");
    zamestnanecsignup.firstname.focus();
    zamestnanecsignup.firstname.select();
    return (false);
  }
  	if ((!isWhitespace(zamestnanecsignup.titleaftername.value))&&(!validTitul(zamestnanecsignup.titleaftername.value)))
  {
    alert("Prosíme, zadajte korektne Váš titul za menom!");
    zamestnanecsignup.titleaftername.focus();
    zamestnanecsignup.titleaftername.select();
    return (false);
  }
	if (isWhitespace(zamestnanecsignup.address.value))
  {
    alert("Prosíme, zadajte Vašu adresu!");
    zamestnanecsignup.address.focus();
    zamestnanecsignup.address.select();
    return (false);
  }
	if ((isWhitespace(zamestnanecsignup.city.value))||(!validCity(zamestnanecsignup.city.value)))
  {
    alert("Prosíme, korektne zadajte mesto!");
    zamestnanecsignup.city.focus();
    zamestnanecsignup.city.select();
    return (false);
  }
	if ((isWhitespace(zamestnanecsignup.zip.value))||(!validZIP(zamestnanecsignup.zip.value)))
  {
    alert("Prosíme, zadajte korektné PSČ!");
    zamestnanecsignup.zip.focus();
    zamestnanecsignup.zip.select();
    return (false);
  }
  	if ((!isWhitespace(zamestnanecsignup.phone.value))&&(!validPhone(zamestnanecsignup.phone.value)))
  {
    alert("Prosíme, zadajte korektné telefónne číslo!");
    zamestnanecsignup.phone.focus();
    zamestnanecsignup.phone.select();
    return (false);
  }
  	if ((!isWhitespace(zamestnanecsignup.mobil.value))&&(!validPhone(zamestnanecsignup.mobil.value)))
  {
    alert("Prosíme, zadajte korektné číslo mobilu!");
    zamestnanecsignup.mobil.focus();
    zamestnanecsignup.mobil.select();
    return (false);
  }
	if ((isWhitespace(zamestnanecsignup.email_address.value))||(!isEmail(zamestnanecsignup.email_address.value)))
  {
    alert("Prosíme, vložte korektne Vašu emailovú adresu!");
    zamestnanecsignup.email_address.focus();
    zamestnanecsignup.email_address.select();
    return (false);
  	}


  return (true);
}

