var xHttp;

  function DejNick(dataSource) 
  { 
     xHttp = VytvorXMLHttp();
     xHttp.open("GET", dataSource); 
     xHttp.onreadystatechange = function()
     { 
       if (xHttp.readyState == 4 && xHttp.status == 200) 
       { 
          if(xHttp.responseText == "Obsazeny")
          {
             var oznam = document.getElementById("oznam");
             oznam.innerHTML = "<font color='red'>Nelze použit.</font>";
          }else{
             var oznam = document.getElementById("oznam");
             oznam.innerHTML = "Lze použit.";
          }
       }
     } 
     xHttp.send(null); 
   }

   function KontrolaNicku(udalost) 
   {
        udalost = (udalost) ? udalost: window.event;
        txt = (udalost.target) ? udalost.target : udalost.srcElement;

        if (udalost.type == "keyup") 
        {
          var oznam = document.getElementById("oznam");
          oznam.innerHTML = "<span>zkoumá se</span>";
          if (txt.value!="") {
          DejNick("validace.php?pristupovyklic=" + txt.value);
          }else{
          oznam.innerHTML = "<span>Prázdný znak nelze</span>";
          }
        }
    }

  function VytvorXMLHttp() 
  {
      var xmlHttp= false;
  
      if (window.ActiveXObject) 
          {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
       else if (window.XMLHttpRequest) 
          {xmlHttp = new XMLHttpRequest();}
    return xmlHttp;
  }


function KonrolaFormulare(Form) {
    for( var i=0; i<Form.length; i++ ) {
     with(Form.elements[i]) { 
      if( type=="text" || type=="password") {
        if( name.indexOf("num")==0 ) {
            if( (value.length==0) || isNaN(parseInt(value)) ) {
                alert('V poli má být číselná hodnota"' + name.slice(3) + '".');
                focus();
                return false;        
            }
        } else {
            if( value.length==0) {
                alert('Pole nesmí být prázdné"' + name + '".');
                focus();
                return false;        
            }
        }
      }
     }
    }
    return true;
}

function zkontroluj_email(adresa)
{
    re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;
    return adresa.search(re) == 0;
}

function zkontroluj_formular(id)
{
  if (!zkontroluj_email(window.document.getElementById(id).value))
  {
    alert("Odesílatel nemá správně vyplněnou adresu!");
    window.document.getElementById(id).focus();
    return false;
  }
  return true;  
}

