﻿var Nazwisko = 0;
var Email = 0;
var Wiadomosc = 0;

function check()
{
		checkNazwisko();
		checkWiadomosc();
		checkEmail();
	if(Nazwisko == 1 && Email == 1 && Wiadomosc == 1)
		return true;
	else
		return false;
}
function check1()
{
		checkNazwisko1();
		checkWiadomosc1();
		checkEmail1();
	if(Nazwisko == 1 && Email == 1 && Wiadomosc == 1)
		return true;
	else
		return false;
}
function check2()
{
		checkNazwisko2();
		checkWiadomosc2();
		checkEmail2();
	if(Nazwisko == 1 && Email == 1 && Wiadomosc == 1)
		return true;
	else
		return false;
}
function checkNazwisko()
{
	var nazwisko, pole;
	nazwisko = document.getElementById("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 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.firstChild.nodeValue = " ";
		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.firstChild.nodeValue = " ";
		Email = 1;
	}	
}



function checkNazwisko1()
{
	var nazwisko, pole;
	nazwisko = document.getElementById("nazwisko").value;
	pole = document.getElementById("nazwiskoinfo");
	if(nazwisko.length == 0)
	{		
		pole.firstChild.nodeValue = "A field cannot be empty";
		Nazwisko = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Nazwisko = 1;
	}	
}

function checkWiadomosc1()
{
	var wiad, pole;
	wiad = document.getElementById("wiadomosc").value;
	pole = document.getElementById("wiadomoscinfo");
	if(wiad.length == 0)
	{		
		pole.firstChild.nodeValue = "A field cannot be empty";
		Wiadomosc = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Wiadomosc = 1;
	}	
}
function checkEmail1()
{
	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 = "A field cannot be empty";
		Email = 0;
	}
	else if(wyr.exec(mail)==null)
	{
		pole.firstChild.nodeValue = "Incorrect email address";
		Email = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Email = 1;
	}	
}



function checkNazwisko2()
{
	var nazwisko, pole;
	nazwisko = document.getElementById("nazwisko").value;
	pole = document.getElementById("nazwiskoinfo");
	if(nazwisko.length == 0)
	{		
		pole.firstChild.nodeValue = "Dieses Feld darf nicht leer sein";
		Nazwisko = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Nazwisko = 1;
	}	
}

function checkWiadomosc2()
{
	var wiad, pole;
	wiad = document.getElementById("wiadomosc").value;
	pole = document.getElementById("wiadomoscinfo");
	if(wiad.length == 0)
	{		
		pole.firstChild.nodeValue = "Dieses Feld darf nicht leer sein";
		Wiadomosc = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Wiadomosc = 1;
	}	
}
function checkEmail2()
{
	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 = "Dieses Feld darf nicht leer sein";
		Email = 0;
	}
	else if(wyr.exec(mail)==null)
	{
		pole.firstChild.nodeValue = "Fehlerhafte e-mail Adresse";
		Email = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Email = 1;
	}	
}
