function waild(form) {
  var blad = false 
  var bledy = " ";

  if (!waliduj_text (form.temat.value))
  {
    var currTabElem = document.getElementById('temat');
    currTabElem.setAttribute("class", "select_error");
    currTabElem.setAttribute("className", "select_error");
    
    blad = true
  }
  else
  {
    var currTabElem = document.getElementById('temat');
    currTabElem.setAttribute("class", "kont_select");
    currTabElem.setAttribute("className", "kont_select");
  }

  if (!waliduj_imie (form.imie.value))
  {
    var currTabElem = document.getElementById('imie');
    currTabElem.setAttribute("class", "input_error");
    currTabElem.setAttribute("className", "input_error");
    
    blad = true
  }
  else
  {
    var currTabElem = document.getElementById('imie');
    currTabElem.setAttribute("class", "input_text");
    currTabElem.setAttribute("className", "input_text");
  }

  if (!waliduj_imie (form.nazwisko.value))
  {
    var currTabElem = document.getElementById('nazwisko');
    currTabElem.setAttribute("class", "input_error");
    currTabElem.setAttribute("className", "input_error");
    
    blad = true
  }
  else
  {
    var currTabElem = document.getElementById('nazwisko');
    currTabElem.setAttribute("class", "input_text");
    currTabElem.setAttribute("className", "input_text");
  }


  if (!waliduj_tel (form.kwota.value))
  {
    var currTabElem = document.getElementById('kwota');
    currTabElem.setAttribute("class", "input_error");
    currTabElem.setAttribute("className", "input_error");
    
    blad = true
  }
  else
  {
    var currTabElem = document.getElementById('kwota');
    currTabElem.setAttribute("class", "input_text");
    currTabElem.setAttribute("className", "input_text");
  }


  if (!waliduj_text (form.miasto.value))
  {
    var currTabElem = document.getElementById('miasto');
    currTabElem.setAttribute("class", "input_error");
    currTabElem.setAttribute("className", "input_error");
    
    blad = true
  }
  else
  {
    var currTabElem = document.getElementById('miasto');
    currTabElem.setAttribute("class", "input_text");
    currTabElem.setAttribute("className", "input_text");
  }

  if (!waliduj_kod (form.kod_1.value, form.kod_2.value))
  {
    var currTabElem = document.getElementById('k1');
    currTabElem.setAttribute("class", "input_error_k1");
    currTabElem.setAttribute("className", "input_error_k1");
    
    var currTabElem = document.getElementById('k2');
    currTabElem.setAttribute("class", "input_error_k2");
    currTabElem.setAttribute("className", "input_error_k2");
     
    blad = true
  }
  else
  {   
    var currTabElem = document.getElementById('k1');
    currTabElem.setAttribute("class", "input_text_k1");
    currTabElem.setAttribute("className", "input_text_k1");
    
    var currTabElem = document.getElementById('k2');
    currTabElem.setAttribute("class", "input_text_k2");
    currTabElem.setAttribute("className", "input_text_k2");
  }

  if (!waliduj_tel (form.tel_kom.value))
  {
    var currTabElem = document.getElementById('tel_kom');
    currTabElem.setAttribute("class", "input_error");
    currTabElem.setAttribute("className", "input_error");
    
    blad = true
  }
  else
  {
    var currTabElem = document.getElementById('tel_kom');
    currTabElem.setAttribute("class", "input_text");
    currTabElem.setAttribute("className", "input_text");
  }

  if (!waliduj_email (form.email.value))
  {
    var currTabElem = document.getElementById('email');
    currTabElem.setAttribute("class", "input_error");
    currTabElem.setAttribute("className", "input_error");
    
    blad = true
  }
  else
  {
    var currTabElem = document.getElementById('email');
    currTabElem.setAttribute("class", "input_text");
    currTabElem.setAttribute("className", "input_text");
  }

  if (!checkbox(form.cb1))
  {
    var currTabElem = document.getElementById('cb1');
    currTabElem.setAttribute("class", "cb_error");
    currTabElem.setAttribute("className", "cb_error");
    
    blad = true
  }
  else
  {
    var currTabElem = document.getElementById('cb1');
    currTabElem.setAttribute("class", "cb_ok");
    currTabElem.setAttribute("className", "cb_ok");
  }

  if (blad)
  {
    alert ("Wypelnij (lub popraw) zaznaczone pola.")
    return false
  }
  sendMail()
  return true
}



function waliduj_email (email) 
{
         zabronione = "<>?"/" /:,;\|!#$%^&*()"
         if (email == "")
            return false
         for (i=0; i< zabronione.length; i++) 
         {
            zly = zabronione.charAt(i)
            if (email.indexOf(zly,0) != -1) 
              return false
         }
         malpa = email.indexOf("@", 0)
         if (malpa == -1 || malpa == 0)
            return false
         if (email.indexOf("@", malpa+1) != -1)
            return false
         kropka = email.indexOf(".",malpa)
         if((kropka==-1) || (kropka==malpa+1))
            return false
         if(kropka+3 > email.length)
            return false
         return true
}

function waliduj_imie (imie) 
{
         var zabronione = "~`!@#$%^&*()_+=-|}{\":?><\][';/.,1234567890"
         if (imie == "")
            return false
         for (i=0; i< zabronione.length; i++) 
         {
            zly = zabronione.charAt(i)
            if (imie.indexOf(zly,0) != -1) 
              return false
         }
         return true
}

function waliduj_tel (tel)
{
    if (tel == "")
        return false
    for (i=0; i< tel.length; i++) 
    {
      if (isNaN( tel.charAt(i) ) ) 
        return false
    }
    return true
}

function waliduj_kod (kod, kod2) 
{
    var zm = true
    if (kod.length != 2 || kod2.length != 3)
      zm = false
    for (i = 0; i < 2; i++)
    {
      if (isNaN (kod.charAt(i)))
        zm = false
    }
    for (i = 0; i < 3; i++)
    {
      if (isNaN (kod2.charAt(i)))
        zm = false
    }
    return zm
}

function waliduj_text (text)
{
  if ( text != "" )
    return true
  return false
}

function checkbox (cb)
{
  if (cb.checked)
    return true
  return false
}

function keyPress(evt)
{
  if(window.event){
    kod = window.event.keyCode;
  }
  else{
    kod = evt.which;
  }
  if(window.event){
    if(kod > 64){
      window.event.returnValue = false;
    }
    else{
      window.event.returnValue = true;
    }
  }
  else{
    if(kod > 64){
      evt.returnValue = false;
      evt.preventDefault();
    }
    else{
      evt.returnValue = true;
    }
  }
}

function sendMail()
{
    document.formularz.method="post"
}

