$(document).ready(function()
{
	var a=0;
	var b=0;
	var c=0;
	var d=0;
	var e=0;
	var f=0;
	
	$("#imie").blur(function()
	{
		var reg = /^[a-zA-ZążśźćęńółĄŻŚŹĆĘÓŁ]{2,}$/;
  		var correct_first=reg.test($(this).val());
		if (!correct_first) 
		{
			$(this).parent().parent().next().show();
			a=0;
		}
		else
		{
			$(this).parent().parent().next().hide();
			a=1;
		}
	});
	
	$("#nazwisko").blur(function()
	{
		var reg = /^[a-zA-ZążśźćęńółĄŻŚŹĆĘÓŁ]{2,}(-[a-zA-ZążśźćęńółĄŻŚŹĆĘÓŁ]{2,})?$/;
  		var correct_name=reg.test($(this).val());
		if (!correct_name) 
		{
			$(this).parent().parent().next().show();
			b=0;
		}
		else
		{			
			$(this).parent().parent().next().hide();
			b=1;
		}
	});
	
	$("#klasa").blur(function()
	{
		var reg = /^[a-zA-Z0-9]{1,}$/;
  		var correct_class=reg.test($(this).val());
		if (!correct_class) 
		{
			$(this).parent().parent().next().show();
			c=0;
		}
		else
		{
			$(this).parent().parent().next().hide();
			c=1;
		}
	});
	

	$("#email").blur(function()
	{
		var reg = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  		var correct_email=reg.test($(this).val());

		if (!correct_email) 
		{
			$(this).parent().parent().next().show();
			d=0;
		}
		else
		{
			$(this).parent().parent().next().hide();
			d=1;
		}
	});
	
	
	$("#rocznik").blur(function()
	{
		var reg = /^([1][9])[0-9]{2}$|([2][0][0][0-8])$/;
  		var correct_year=reg.test($(this).val());
		if (!correct_year) 
		{
			$(this).parent().parent().next().show();
			e=0;
		}
		else
		{
			$(this).parent().parent().next().hide();
			e=1;
		}
	});
	
	
	$("#zgoda").click(function()
	{
		if($(this).attr('checked')) 
		{
			$(this).parent().parent().next().hide();		
			f=1;	
		}
		else
		{
			f=0;
		}
	});
	
	
	$(".but").click(function()
	{
		
		if($(this).attr('type')=="reset") 
		{	
			$(".error").hide();	
			a=b=c=d=e=f=0;
		}
		
		if($(this).attr('type')=="submit") 
		{
			if (a == 0) {
				$(this).parent().parent().prev().prev().prev().prev().prev().prev().prev().prev().prev().show();
			}
			if (b == 0) {
				$(this).parent().parent().prev().prev().prev().prev().prev().prev().prev().show();
			}
			if (c == 0) {
				$(this).parent().parent().prev().prev().prev().prev().prev().show();
			}
			if (d == 0) {
				$(this).parent().parent().prev().prev().prev().show();
			}
			if (e == 0) {
				$(this).parent().parent().prev().show();
			}
			if (f == 0) {
				$(this).parent().parent().next().next().show();
			}
			
			if(a+b+c+d+e+f!=6)
			{
				$(".dane").bind("submit", function()
				{
					return false;
				});		
			}
			else
			{
				$(".dane").unbind();
			}
		}
	});
});
