function sprawdzPole(pole,komunikat){
  pole=document.getElementById(pole).value;
  if(!pole || pole=='' || pole==undefined)
    return komunikat;
  else
    return '';
}

function sprawdz(){
var email = document.getElementById('email').value ;
var emailPat=/^(.+)@(.+)\.(.+)$/ ;
var matchArray=email.match(emailPat);
var komunikat='';

komunikat+=sprawdzPole('tresc',"- Wpisz komentarz\n");
komunikat+=sprawdzPole('nazwa',"- Podaj Imię/Nazwisko lub Nick\n");
  if (email=='')
komunikat+="- Podaj Adres e-mail\n";

 if (email!='' && matchArray==null)
  komunikat+="* podany adres e-mail jest niewłaściwy\n";

  if(komunikat!=''){
    alert("Wypełnij wymagane pola:\n\n"+komunikat);
    return false;
  }

  else{
    return true;
  }
}

function dodaj(){
var email = document.getElementById('email').value ;
var emailPat=/^(.+)@(.+)\.(.+)$/ ;
var matchArray=email.match(emailPat);
var komunikat='';

komunikat+=sprawdzPole('tytul1',"- Wpisz Tytuł\n");
komunikat+=sprawdzPole('pytanie',"- Wpisz pytanie\n");
komunikat+=sprawdzPole('nazwa',"- Podaj Imię/Nazwisko lub Nick\n");
  if (email=='')
komunikat+="- Podaj Adres e-mail\n";

 if (email!='' && matchArray==null)
  komunikat+="* podany adres e-mail jest niewłaściwy\n";

  if(komunikat!=''){
    alert("Wypełnij wymagane pola:\n\n"+komunikat);
    return false;
  }

  else{
    return true;
  }
}


function dodaj_wiad(theForm)
{

  if (theForm.tytul1.value == "")
  {
    alert("Podaj tytuł widomości");
    theForm.tytul1.focus();
    return (false);
  }

  if (theForm.tytul1.value.length > 100)
  {
    alert("W polu tytuł może być najwięcej 100 znaków");
    theForm.tytul1.focus();
    return (false);
  }

  if (theForm.pytanie.value == "")
  {
    alert("Podaj twoje pytanie");
    theForm.pytanie.focus();
    return (false);
  }

  if (theForm.pytanie.value.length > 1000)
  {
    alert("W Pytaniu może być najwięcej 1000 znaków");
    theForm.pytanie.focus();
    return (false);
  }

  if (theForm.nazwa.value == "")
  {
    alert("Podaj Imię/Nazwisko lub Nick");
    theForm.nazwa.focus();
    return (false);
  }

  if (theForm.nazwa.value.length > 50)
  {
    alert("W polu Imię/Nazwisko lub Nick może być najwięcej 50 znaków");
    theForm.nazwa.focus();
    return (false);
  }

  if (theForm.publish.checked)
  {

     if (theForm.email.value == "")
      {
       alert("Podaj adres email");
       theForm.email.focus();
       return (false);
      }

      if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value)){
      return (true)
      }
      alert("Podany adres e-mail jest nieprawidłowy")
      return (false)

  return (true);
  }

  return (true);
}

function dodaj_kom(theForm)
{

 
  if (theForm.tresc.value == "")
  {
    alert("Wpisz twój komentarz");
    theForm.tresc.focus();
    return (false);
  }

  if (theForm.tresc.value.length > 1000)
  {
    alert("W Komentarzu może być najwięcej 1000 znaków");
    theForm.tresc.focus();
    return (false);
  }

  if (theForm.nazwa.value == "")
  {
    alert("Podaj Imię/Nazwisko lub Nick");
    theForm.nazwa.focus();
    return (false);
  }

  if (theForm.nazwa.value.length > 50)
  {
    alert("W polu Imię/Nazwisko lub Nick może być najwięcej 50 znaków");
    theForm.nazwa.focus();
    return (false);
  }

  if (theForm.publish.checked)
  {

     if (theForm.email.value == "")
      {
       alert("Podaj adres email");
       theForm.email.focus();
       return (false);
      }

      if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value)){
      return (true)
      }
      alert("Podany adres e-mail jest nieprawidłowy")
      return (false)

  return (true);
  }

  return (true);
}

function change_address_field(){
		var state=!document.getElementById("bbb").checked;
		if (!state) color="#FFFFFF";
		else color="#f8f8f8";

		x=document.getElementById("aaa");
		if (x) {x.disabled=state;x.style.backgroundColor=color;}
			x=document.getElementById("fm_ac_code");
		
}
