﻿var Warsztat = 0;
var Imie = 0;
var Nazwisko = 0;
var Adres = 0;
var Zawod = 0;
var Data = 0;
var Kontakt = 0;
var Termin = 0;
var Email = 0;

function check()
{
	if(Warsztat == 1 && Imie == 1 && Nazwisko == 1 && Adres == 1 && Zawod == 1 && Data == 1 && Kontakt == 1 && Termin == 1 && Email == 1)
		return true;
	else
	{
		checkWarsztat();
		checkImie();
		checkNazwisko();
		checkAdres();
		checkZawod();
		checkData();
		checkKontakt();
		checkTermin();
		checkEmail();
		return false;
	}
}

function checkWarsztat()
{
	var warsztat, pole;
	warsztat = document.formularz.warsztat.value;
	pole = document.getElementById("warsztatinfo");
	if(warsztat.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Warsztat = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Warsztat = 1;
	}	
}

function checkTermin()
{
	var termin, pole;
	termin = document.formularz.termin.value;
	pole = document.getElementById("termininfo");
	if(termin.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Termin = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Termin = 1;
	}	
}

function checkImie()
{
	var imie, pole;
	imie = document.formularz.imie.value;
	pole = document.getElementById("imieinfo");
	if(imie.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Imie = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Imie = 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 checkAdres()
{
	var adres, pole;
	adres = document.formularz.adres.value;
	pole = document.getElementById("adresinfo");
	if(adres.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Adres = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Adres = 1;
	}	
}
function checkZawod()
{
	var zawod, pole;
	zawod = document.formularz.zawod.value;
	pole = document.getElementById("zawodinfo");
	if(zawod.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Zawod = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Zawod = 1;
	}	
}
function checkData()
{
	var data, pole;
	var wyr = new RegExp("^[0-9]{2}.[0-9]{2}.[0-9]{4}$");
	data = document.formularz.data.value;
	pole = document.getElementById("datainfo");
	if(data.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Data = 0;
	}
	else if(wyr.exec(data)==null)
	{
		pole.firstChild.nodeValue = "Podaj datę w formacie DD.MM.RRRR";
		Data = 0;
	}
	else
	{
		pole.firstChild.nodeValue = " ";
		Data = 1;
	}	
}
function checkKontakt()
{
	var kontakt, pole;
	kontakt = document.formularz.kontakt.value;
	pole = document.getElementById("kontaktinfo");
	if(kontakt.length == 0)
	{		
		pole.firstChild.nodeValue = "Pole nie może być puste";
		Kontakt = 0;
	}	
	else
	{
		pole.firstChild.nodeValue = " ";
		Kontakt = 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;
	}	
}