function ValidForm(theForm){
  if (trim_string(theForm.jmeno.value) == "")
  {
    alert("Vyplňte prosím \"Jméno\".");
    theForm.jmeno.focus();
    return (false);
  }	

  if (trim_string(theForm.prijmeni.value) == "")
  {
    alert("Vyplňte prosím \"Příjmení\".");
    theForm.prijmeni.focus();
    return (false);
  }	

  if (trim_string(theForm.ulice.value) == "")
  {
    alert("Vyplňte prosím \"Ulice\".");
    theForm.ulice.focus();
    return (false);
  }	

  if (trim_string(theForm.mesto.value) == "")
  {
    alert("Vyplňte prosím \"Město\".");
    theForm.mesto.focus();
    return (false);
  }	

  if (trim_string(theForm.psc.value) == "")
  {
    alert("Vyplňte prosím \"PSČ\".");
    theForm.psc.focus();
    return (false);
  }	

  if (trim_string(theForm.telefon.value) == "")
  {
    alert("Vyplňte prosím \"Telefon\".");
    theForm.telefon.focus();
    return (false);
  }	

  if (trim_string(theForm.mail.value) == "")
  {
    alert("Vyplňte prosím \"e-mail\".");
    theForm.mail.focus();
    return (false);
  }	

  if (!(theForm.mail.value == ""))
  {
    if (!isEmail(theForm.mail.value))
    {
      alert("Pole \"E-mail\" nemá platný formát pro e-mailovou adresu.");
      theForm.mail.focus();
      return (false);
    }
}
  return (true);
}

	function isNumeric(checkStr){
	  var checkOK = "0123456789";
	  var allValid = true;
	  var decPoints = 0;
	  var allNum = "";
	  
	  if (checkStr == '') return(false)
	  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)
		{
		  allValid = false;
		  break;
		}
		allNum += ch;
	  }
	  if (!allValid)
	  {
		return (false);
	  }
	  return (true)
	}
		
	function isPlusMinusNumeric(checkStr){
	  var checkOK = "0123456789";
	  var allValid = true;
	  var decPoints = 0;
	  var allNum = "";
	  var startnum = 0;
	  
	  if (checkStr == '') return(false)

	  if (!( (isNumeric(checkStr.charAt(0)) || (checkStr.charAt(0) == "-")) )) return(false)

	  if (checkStr.charAt(0) == "-") startnum = 1;
	  if ((startnum == 1) && (checkStr.length == 1)) return(false)

	  for (i = startnum;  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)
		{
		  allValid = false;
		  break;
		}
		allNum += ch;
	  }
	  if (!allValid)
	  {
		return (false);
	  }
	  return (true)
	}
	function isAlphaNumeric(checkStr){
	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	  var allValid = true;
	  var decPoints = 0;
	  var allNum = "";
	  
	  if (checkStr == '') return(false)
	  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)
		{
		  allValid = false;
		  break;
		}
		allNum += ch;
	  }
	  if (!allValid)
	  {
		return (false);
	  }
	  return (true)
	}

	function isPhone(checkStr){
	  var checkOK = "0123456789()+ \t\r\n\f";
	  var allValid = true;
	  var decPoints = 0;
	  var allNum = "";
	  
	  if (checkStr == '') return(false)
	  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)
		{
		  allValid = false;
		  break;
		}
		allNum += ch;
	  }
	  if (!allValid)
	  {
		return (false);
	  }
	  return (true)
	}


	function isEmail(email) {
		email = "" + email;
		var ch;
	
	    if (email.indexOf('@', 0) < 1 || email.indexOf('.', 0) == -1 || email.length < 6 || email.indexOf('@') != email.lastIndexOf('@') || ((email.length) - (email.lastIndexOf('.') + 1)) < 2 || email.indexOf('.') == 0 || (email.charAt((email.indexOf('@')) - 1)) == "." || (email.charAt((email.indexOf('@')) + 1)) == "." || email.indexOf('..') > -1) {
	      return false;
	    }
	    for (i = 0; i < email.length; i++) {
	      ch = email.charAt(i); 
	      if (ch > "~" || ch < " ") {
	        return false;
	      }
	    }
	    return true;
	  }

	function isDate(a){
	//	window.onerror=null // for all other strange errors
		var err=0
					
		if (a.length > 10) return(false)
		
		pos1 = a.indexOf(".")
		pos2 = a.lastIndexOf(".")
		if ((pos1 == pos2) || (pos1 == -1) || (pos2 == -1)) return(false)

		d = a.substring(0, pos1)
		m = a.substring(pos1+1,pos2)
		y = a.substring(pos2+1,a.length)

		if (!isNumeric(d)) return(false)
		if (!isNumeric(m)) return(false)
		if (!isNumeric(y)) return(false)


		//basic error checking
		if (d<1 || d>31) return(false)
		if (m<1 || m>12) return(false)
		if (y<1900 || y>2100) return(false)
		
		
		//advanced error checking

		// months with 30 days
		if (m==4 || m==6 || m==9 || m==11){
			if (d==31) return(false)
		}

		// february, leap year
		if (m==2){
			// feb
			var g=parseInt(y/4)
			if (isNaN(g)) {
				return(false)
			}

			if (d>29) return(false)
			if (d==29 && ((y/4)!=parseInt(y/4))) return(false)
		}

		return(true)
	}

	function isSpacedNumeric(checkStr){
	  var checkOK = "0123456789 \t\r\n\f";
	  var allValid = true;
	  var decPoints = 0;
	  var allNum = "";
	  
	  if (checkStr == '') return(false)
	  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)
		{
		  allValid = false;
		  break;
		}
		allNum += ch;
	  }
	  if (!allValid)
	  {
		return (false);
	  }
	  return (true)
	}

	function isPostCode(checkStr){

	  if (!(checkStr.length == 6)) return(false)
	  if (!isSpacedNumeric(checkStr)) return(false)
	  if (!isNumeric(checkStr.charAt(0))) return(false)
	  if (!isNumeric(checkStr.charAt(1))) return(false)
	  if (!isNumeric(checkStr.charAt(2))) return(false)
	  if (!isNumeric(checkStr.charAt(4))) return(false)
	  if (!isNumeric(checkStr.charAt(5))) return(false)
	
	  return(true)
	}


	function isLen(checkStr, len){

	  if (checkStr.length != len) return(false)
	  return(true)
	}

	function isMinLen(checkStr, minlen){

	  if (checkStr.length < minlen) return(false)
	  return(true)
	}
	

	function isMaxLen(checkStr, maxlen){

	  if (checkStr.length > maxlen) return(false)
	  return(true)
	}
	

	function isIdentity(ch1, ch2){

	  if (ch1 != ch2) return (false);
	  return (true);
	}


	function isInInterval(checkVal, minVal, maxVal)
	{
	  	if (!((parseInt(checkVal) >= minVal) && (parseInt(checkVal) <= maxVal)))  
		{
			return(false)
		}
		return(true)
	}


	function trim_string(checkStr){

	  var ichar, icount
	  var strValue = checkStr

	  ichar = strValue.length - 1;
	  icount = -1;
	  while (strValue.charAt(ichar)==' ' && ichar > icount)
		--ichar;
	  if (ichar!=(strValue.length-1))
		strValue = strValue.slice(0,ichar+1);
	  ichar = 0;
	  icount = strValue.length - 1;
	  while (strValue.charAt(ichar)==' ' && ichar < icount)
		++ichar;
	  if (ichar!=0)
		strValue = strValue.slice(ichar,strValue.length);
	  return strValue	
	}



