﻿var Nazwa = 0;
var Email = 0;
var Wiadomosc = 0;

function check()
{
		checkNazwa();
		checkWiadomosc();
		checkEmail();
	if(Nazwa == 1 && Email == 1 && Wiadomosc == 1)
		return true;
	else
		return false;
}

function checkNazwa()
{
	var nazwa, pole;
	nazwa = document.getElementById("nazwa").value;
	pole = document.getElementById("nazwainfo");
	if(nazwa.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Nazwa = 0;
	}
	else
	{
		pole.innerHTML = "&nbsp;";
		Nazwa = 1;
	}	
}

function checkWiadomosc()
{
	var wiad, pole;
	wiad = document.getElementById("wiadomosc").value;
	pole = document.getElementById("wiadomoscinfo");
	if(wiad.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Wiadomosc = 0;
	}
	else
	{
		pole.innerHTML = "&nbsp;";
		Wiadomosc = 1;
	}	
}
function checkEmail()
{
	var mail, pole;
	var wyr = new RegExp("^[a-zA-z0-9\._-]+@[a-zA-z0-9\._-]+\.[a-zA-Z]{2,}$");
	mail = document.getElementById("mail").value;
	pole = document.getElementById("mailinfo");
	
	if(mail.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Email = 0;
	}
	else if(wyr.exec(mail)==null)
	{
		pole.firstChild.nodeValue = "Niepoprawny adres e-mail";
		Email = 0;
	}
	else
	{
		pole.innerHTML = "&nbsp;";
		Email = 1;
	}	
}

