$(document).ready(function() {
	
	sprawdz();
	
	$("#test_id").click(function(){
		sprawdz();
		}).css('cursor','pointer');
	
	$("#details_employment_in_the_uk").change(function(){
		sprawdz();
		});
		
	
	$("#send").click(function(){
		if ($("#checkbox").attr('checked') == false) {
			alert("Please tick box to show you agree with the previous statement");
			return false;
			}
		
		if ($("#details_forename").val() == '') {
			alert("Please input details forename");
			return false;
			}
		
		
		if ($("#details_sername").val() == '') {
			alert("Please input details sername");
			return false;
			}

			
/*		
		niefunction ValidMail(input_data)
			{
			var valid = /^[0-9a-z]+([\.\-_][0-9a-z]+)*\@[0-9a-z]+([\.\-][0-9a-z]+)*\.(([a-z]{2,4})|(travel)|(museum))
			return input_data.test(valid);
			},
		
		strpos()
			
		[^@]+@[^@]+
	*/		
		
//		if (!("#details_email_address").val().indexOf('@')) {
		if ($("#details_email_address").val() == '') {
			alert("Please input details email address");
			return false;
			}

//		if (!("#details_telephone_number").val().indexOf('@')) {
                if ($("#details_telephone_number").val() == '') {
			alert("Please input details telephone");
			return false;
			}

	        if ($("#details_position_applied_for").val() == '') {
			alert("Please input details position applied for");
			return false;
			}

		if ($("#details_employment_in_the_uk").val() == '') {
			alert("Please input details employment in the uk");
			return false;
			}
			
		//alert("wysyłanie ..... => testowo ten komunikat")
		//return false;
		});
		
	});

	
function sprawdz() {

//alert('sprawdzam poprawnosc i blokuje');
//alert();
//$("#checkbox").attr('disabled',wartosc);

	/*
	jeśli któryś z tych pól jest póste
	$('span.required').parent().parent().parent(). -> (td.input) -> (input).val()
	to nakaz poprawy
	*/


/*details_forename
details_sername
details_email_address
details_telephone_number*/

	
	
	if ($("#details_employment_in_the_uk").val() != "Yes")
		blokuj(true);
	else
		blokuj(false);
	}
	
	
function blokuj(wartosc) {
	
	$("#send").attr('disabled',wartosc);					//blokowanie przycisku wysyania zgłoszenia
	
	$("#details_valid_work_permit").attr('disabled',wartosc);
	$("#details_date_of_expiry").attr('disabled',wartosc);
	$("#details_eu_passport").attr('disabled',wartosc);
	$("#details_other_kind_of_permit").attr('disabled',wartosc);
	$("#details_physical_disabilities").attr('disabled',wartosc);
	$("#details_physical_disabilities_describe").attr('disabled',wartosc);
	$("#details_position_applied_for").attr('disabled',wartosc);
	$("#employer1_employer").attr('disabled',wartosc);
	$("#employer1_type_of_business").attr('disabled',wartosc);
	$("#employer1_address").attr('disabled',wartosc);
	$("#employer1_type_of_work").attr('disabled',wartosc);
	$("#employer1_dates_from").attr('disabled',wartosc);
	$("#employer1_dates_to").attr('disabled',wartosc);
	$("#employer1_weekly_starting_pay").attr('disabled',wartosc);
	$("#employer1_present_pay_on_leaving").attr('disabled',wartosc);
	$("#employer1_reason_for_leaving").attr('disabled',wartosc);
	
	$("#employer2_employer").attr('disabled',wartosc);
	$("#employer2_type_of_business").attr('disabled',wartosc);
	$("#employer2_address").attr('disabled',wartosc);
	$("#employer2_type_of_work").attr('disabled',wartosc);
	$("#employer2_dates_from").attr('disabled',wartosc);
	$("#employer2_dates_to").attr('disabled',wartosc);
	$("#employer2_weekly_starting_pay").attr('disabled',wartosc);
	$("#employer2_present_pay_on_leaving").attr('disabled',wartosc);
	$("#employer2_reason_for_leaving").attr('disabled',wartosc);
	
	$("#employer_contact_of_employers").attr('disabled',wartosc);
	$("#employer_contact_of_employers_whit_not").attr('disabled',wartosc);
	$("#practical_skills_1").attr('disabled',wartosc);
	$("#practical_skills_2").attr('disabled',wartosc);
	
	$("#general_interests_hobbies").attr('disabled',wartosc);
	$("#general_part_time_jobs").attr('disabled',wartosc);
	$("#general_commitments").attr('disabled',wartosc);
	$("#general_future_training_plans").attr('disabled',wartosc);
	$("#general_dismissed").attr('disabled',wartosc);
	$("#general_criminal").attr('disabled',wartosc);
	$("#general_other_information_relevant").attr('disabled',wartosc);
	}