function check_email(email)
{
  if (email == "")
  {
    alert("E-mail nesmí být prázdný.");
    return (false);
  }
  var checkO = "0123456789ABCDEFGHIJKLMNOPQRSTUVWYZXabcdefghijklmnopqrstuvxywz._-@#+";
  var allVali = true;
  for (i = 0;  i < email.length;  i++)
  {
    ch = email.charAt(i);
    for (j = 0;  j < checkO.length;  j++)
      if (ch == checkO.charAt(j))
        break;
    if (j == checkO.length)
    {
      allVali = false;
      break;
    }
  }
  if (!allVali)
  {
    alert("E-mail obsahuje nepovolené znaky.");
    return (false);
  }
// position of the @
    var position_of_at = email.indexOf("@");

// at least 1 @ in e-mail?
    if (position_of_at < 0)
      {
      alert("E-mail neobsahuje @!");
      return false;
      }
// getting the part before and after the @
    var part_before_at = email.substring(0,position_of_at);
    var part_after_at = email.substring(position_of_at+1,email.length);
// is there more than 1 @ in email?
    if (part_after_at.indexOf("@") >= 0)
       {
       alert("E-mail obsahuje více, než jeden @!");
       return false;
       }
// 0 length of the part before the @
    if (part_before_at.length <= 0)
        {
        alert("E-mail není úplný (@ nemůže být prvním znakem)!");
        return false;
        }
// 0 length of the part after the @
    if (part_after_at.length <= 0)
        {
        alert("E-mail není úplný (@ nemůže být posledním znakem)!");
        return false;
        }
// position of the last dot in the part after the @
    var position_of_last_dot = part_after_at.lastIndexOf(".");
// at least 1 dot after the @
    if (position_of_last_dot == -1)
       {
       alert("E-mail musí obsahovat alespoň jednu tečku za @!");
       return false;
       }

// number of characters after the last dot
    var num_of_chars_after_last_dot = part_after_at.length - position_of_last_dot - 1;
// less then 2 chars  and not more then 4 chars after the last dot
    if (num_of_chars_after_last_dot < 2  ||  num_of_chars_after_last_dot > 4)
        {
        alert("E-mail musí obsahovat 2-4 znaky za poslední tečkou!");
        return false;
        }
// 2 dots together
    var position_of_2_dots = email.indexOf("..");
    if (position_of_2_dots >= 0)
        {
        alert("E-mail nesmí obsahovat dvě tečky vedle sebe!");
        return false;
        }
// dot in the beginning of email and directly before @
    if (part_before_at.charAt(0) == ".")
        {
        alert("E-mail nesmí začínat tečkou!");
        return false;
        }
// dot in the end of email and directly after @
    if (part_after_at.charAt(0) == "."  ||  part_after_at.charAt(part_after_at.length-1) == ".")
        {
        alert("E-mail nesmí končit tečkou nebo obsahovat tečku těsně za @!");
        return false;
        }
// at least 2 chars before last dot
dot=0;
offset=0;
for (i = position_of_last_dot-1; i >= 0; i--)
  {
  if ((part_after_at.charAt(i) == ".") && (dot==0))
    {
    dot=i;
  }
  if ((i==0) && (dot==0))
    {
    dot=-1;
  }
}  
offset=position_of_last_dot-1-dot;
if (offset<1)
  {
  alert("E-mail musí mít alespoň 1 znak před poslední tečkou!");
  return false;
}

// if we are here everything is O.K.
return (true);
}

