function waild(form) {
  var blad = false;
  var blad2 = false;
  var bledy = " ";
  
  var val = -1;

for( i = 0; i < document.myform.zal.length; i++ )
{
if( document.myform.zal[i].checked == true )
val = document.myform.zal[i].value;
}

  if( val == -1 )
  {
	var currTabElem = document.getElementById('zalTd');
    currTabElem.setAttribute("class", "inputError");
    currTabElem.setAttribute("className", "inputError");
	
	blad = true;
  }
  else
  {
	var currTabElem = document.getElementById('zalTd');
    currTabElem.setAttribute("class", "formInput");
    currTabElem.setAttribute("className", "formInput");
  }
  
  if( val == 1 )
  {
	  blad2 = true;
  }

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

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

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

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

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

  if(blad2)
  {
    alert ("Przykro nam, ale nie mamy oferty dla Ciebie.\nTwoje dane nie zostaly zapisane w naszej bazie.")
    return false
  }
  else if (blad)
  {
    alert ("Wypelnij (lub popraw) zaznaczone pola.")
    return false
  }
  
  if (form.agree1.checked)
  {
    form.agree1.value = 1;
  }
  else
  {
    form.agree1.value = 0;
  }
  
  if (form.agree2.checked)
  {
    form.agree2.value = 1;
  }
  else
  {
    form.agree2.value = 0;
  }
  
  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_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"
}

