$(function() {
	var requiredFields = new Array(
		'name', 'ssn', 'dob', 'present-street', 'present-city', 'present-state', 'present-zip', 'permanent-street', 'permanent-city', 'permanent-state', 'permanent-zip', 'phone',
		'start-date', 'salary',
		'employer_1-name', 'employer_1-street', 'employer_1-city', 'employer_1-state', 'employer_1-zip', 'employer_1-start_date', 'employer_1-end_date', 'employer_1-title', 'employer_1-starting_salary', 'employer_1-final_salary', 'employer_1-supervisor', 'employer_1-supervisor-title', 'employer_1-supervisor-phone', 'employer_1-description', 'employer_1-reason_for_leaving',
		'employer_2-name', 'employer_2-street', 'employer_2-city', 'employer_2-state', 'employer_2-zip', 'employer_2-start_date', 'employer_2-end_date', 'employer_2-title', 'employer_2-starting_salary', 'employer_2-final_salary', 'employer_2-supervisor', 'employer_2-supervisor-title', 'employer_2-supervisor-phone', 'employer_2-description', 'employer_2-reason_for_leaving',
		'employer_3-name', 'employer_3-street', 'employer_3-city', 'employer_3-state', 'employer_3-zip', 'employer_3-start_date', 'employer_3-end_date', 'employer_3-title', 'employer_3-starting_salary', 'employer_3-final_salary', 'employer_3-supervisor', 'employer_3-supervisor-title', 'employer_3-supervisor-phone', 'employer_3-description', 'employer_3-reason_for_leaving',
		'reference_1-name', 'reference_1-phone', 'reference_1-business', 'reference_1-years',
		'reference_2-name', 'reference_2-phone', 'reference_2-business', 'reference_2-years',
		'reference_3-name', 'reference_3-phone', 'reference_3-business', 'reference_3-years',
		'primary_county',

		'bid_name'
	);
	var radios = new Array(
		'position', 'employed', 'worked_for_lifenet',
		'felony', 'limitations', 'resided_outside_of_wi',
		'employer_1-contact', 'employer_2-contact', 'employer_3-contact',
		'traffic_citations',

		'bid_A1', 'bid_A2', 'bid_A3', 'bid_A4', 'bid_A5', 'bid_A6', 'bid_A7',
		'bid_B1', 'bid_B2', 'bid_B3', 'bid_B4', 'bid_B5', 'bid_B6'
	);

	$('#application').submit(function(e) {
		var x;
		var blank;
		var error = false;

		// Parse requiredFields
		$.each(requiredFields, function(index, id) {
			if (!$('#'+id).val()) {
				$('#'+id).addClass('invalid');
				error = true;
			}
			else {
				$('#'+id).removeClass('invalid');
			}
		});

		// Parse radios
		$.each(radios, function(index, name) {
			var blank = true;
			var parent = false;
			$('input[name='+name+']').each(function(i, el) {
				parent = $(el).parent('td');
				if (el.checked) {
					blank = false;
				}
			});

			if (blank) {
				error = true;
				parent.addClass('invalid');
			}
		});

		if (error) {
			alert("Please complete all required fields before proceeding.");
			e.preventDefault();
		}
	});
});

