﻿var Nazwisko = 0;
var Email = 0;
var Wiadomosc = 0;
var Code = 0;

function check()
{
	if(Nazwisko == 1 && Email == 1 && Wiadomosc == 1 && Code == 0)
		return true;
	else
	{
		checkNazwisko();
		checkWiadomosc();
		checkEmail();
		checkCode();
		return false;
	}
}

function checkWiadomosc()
{
	
	var wiadomosc, pole;
	wiadomosc = document.formularz.wiadomosc.value;
	pole = document.getElementById("wiadomoscinfo");
	if(wiadomosc.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Wiadomosc = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Wiadomosc = 1;
	}		
}

function checkNazwisko()
{
	var nazwisko, pole;
	nazwisko = document.formularz.nazwisko.value;
	pole = document.getElementById("nazwiskoinfo");
	if(nazwisko.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Nazwisko = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Nazwisko = 1;
	}	
}

function checkEmail()
{
	var mail, pole;
	var wyr = new RegExp("^[a-zA-z0-9\._-]+@[a-zA-z0-9\._-]+\.[a-zA-Z]{2,}$");
	mail = document.formularz.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 = "Należy podać prawidłowy adres e-mail";
		Email = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Email = 1;
	}	
}
function checkCode()
{
	
	var code, pole;
	code = document.formularz.code.value;
	pole = document.getElementById("codeinfo");
	if(code.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Wiadomosc = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Wiadomosc = 1;
	}		
}
