$(document).ready(function() {

	var _failed = false;
	
	$('a.appNav').click(function() {
    	
    	if ($(this).hasClass('back')) {
    		return true;
    	}
    	    	
		$('input.required').each(function() {
			if ($(this).val().length == 0) {
				$(this).addClass("error-form");
				_failed = true;
			}
		});
			
		$('textarea.required').each(function() {
			if ($(this).val().length == 0) {
				$(this).addClass("error-form");
				_failed = true;
			}
		});
		
		if ($('form.page_4').length) {
			if (_failed) {
				alert('Required information below has not been entered, pelase answer all questions.');
			} else {
				if ($('input#signature1_verify').attr('checked') == false) {
					_failed = true
					$('#signature1_verify_question').addClass('error-form');
					alert('You must check the box to verity that all information provided is true and correct to the best of your knowledge');
				}
			}
		}
		
		if ($('form.page_3').length) {
			
			if (_failed) {
				alert('Required information below has not been entered, please answer all questions.');
			}
		}
			
		if ($('form.page_1').length) {
		
			if (_failed) {
				alert('Required information below has not been entered, please fill in all required boxes');
			} else {
				
				var _radio = false;
				$('input.radiorequired').each(function() {
					if (_radio == false) {
						if ($(this).attr('checked') == true) {
							_radio = true;
						}
					}
				});
				
				if (_radio == false) {
					_failed = true;
					$('#classInfoQuestion').addClass('error-form');
					alert('Please check off your class information towards the bottom of the page');
				}
			}
		}
		
		if ($('form.page_2').length) {
		
			if (_failed) {
				alert('Required information below has not been entered, please fill in all required boxes');
			} else {
				
				var _radio = false;
				$('input.radiomarital').each(function() {
					if (_radio == false) {
						if ($(this).attr('checked') == true) {
							_radio = true;
						}
					}
				});
				if (_radio == false) {
					_failed = true;
					$('#parents_marital_status_question').addClass("error-form");
					alert('Please check off your marital status');
				}
				
				
				var _radio = false;
				$('input.radiolang').each(function() {
					if (_radio == false) {
						if ($(this).attr('checked') == true) {
							_radio = true;
						}
					}
				});
				if (_failed == false && _radio == false) {
					_failed = true;
					$('#language_question').addClass("error-form");
					alert('Please check off wether your child\'s first language is english');
				}
				
				if (_failed == false && $('input.radiolang:checked').val() == 'no' && $('input#what_language').val() == '') {
					_failed = true;
					$('input#what_language').addClass("error-form");
					alert('Please indicate what language your child speaks');
				}
				
				var _radio = false;
				$('input.radiounder').each(function() {
					if (_radio == false) {
						if ($(this).attr('checked') == true) {
							_radio = true;
						}
					}
				});
				if (_failed == false && _radio == false) {
					_failed = true;
					$('#understand_english_question').addClass("error-form");
					alert('Please check off wether or not your child understands english');
				}
				
				var _radio = false;
				$('input.radioanother').each(function() {
					if (_radio == false) {
						if ($(this).attr('checked') == true) {
							_radio = true;
						}
					}
				});
				if (_failed == false && _radio == false) {
					_failed = true;
					$('#attended_another_school_question').addClass("error-form");
					alert('Please check off wether or not your child has attended another school');
				}
				
				if (_failed == false && $('input.radioanother:checked').val() == 'yes' && $('input#what_school').val() == '') {
					_failed = true;
					$('input#what_school').addClass("error-form");
					alert('Please indicate what school your child has attended and for how long');
				}
				
				
				var _radio = false;
				$('input.radiograde').each(function() {
					if (_radio == false) {
						if ($(this).attr('checked') == true) {
							_radio = true;
						}
					}
				});
				if (_failed == false && _radio == false) {
					_failed = true;
					$('#grade_complete_question').addClass("error-form");
					alert('Please indicate the grade level you intend your child to complete at Daycroft');
				}
							
			}
			
		}
		
		if (_failed) {
			_failed = false;
			return false;
		} else {
			$('form.online_app').submit();
    	}
    	
    	return false;
	});
    
});