
$(document).ready(function() {
	// datepicker mojo
	$(".datepicker").datepick();

	// type enforcement mojo
	$("#zip").autotab({ format: 'numeric' });
	$("#cellNumber").autotab({ format: 'numeric' });
	$("#otherPhone").autotab({ format: 'numeric' });
	
	
	// Submit Validation
	$("#application").submit(function(e){  
		

		// begin generic validation
		
		// firstName
		var field = $("#firstName").val();
		if(field.length <= 0) {
			alert("You must enter a first name.");
			return false;
		}
		
		// lastName
		var field = $("#lastName").val();
		if(field.length <= 0) {
			alert("You must enter a last name.");
			return false;
		}
	
		// streetAddress
		var field = $("#streetAddress").val();
		if(field.length <= 0) {
			alert("You must enter an address.");
			return false;
		}
		
		// City
		var field = $("#city").val();
		if(field.length <= 0) {
			alert("You must enter a city.");
			return false;
		}
		
		// state
		var field = $("#state").val();
		if(field.length <= 0) {
			alert("You must enter a state.");
			return false;
		}
		
		// zip
		var field = $("#zip").val();
		if(field.length != 5) {
			alert("You must enter a valid zip code.");
			return false;
		}
	
		// end generic validation
		
		// begin parent child validation
		
		// previously_applied
		/*
		alert($("input[name='previously_applied']:checked").val());
		if($("input[name='previously_applied']:checked").val() == 1) {
			var field = $("#previously_applied_date").val();
			if(field.length <= 0) {
				alert("You must enter a previously applied date.");
				return false;
			}
		}
		*/
		
	}); 
	
	// hear about bling
	$("#hear_about").change(function(e){
		var hearAbout = $("#hear_about").val();
		
		$("#hear_about_mask input").val(""); // reset whats there
		$("#hear_about_mask div").hide();    // and hide them
		
		if(hearAbout != "") {
			$("#hear_about_mask").show();
	
			switch(hearAbout) {
				case "Word of mouth":
					$("#hear_about_word_mask").show();
					break;
				case "Referred by employee":
					$("#hear_about_employee_mask").show();
					break;
				case "Referred by an Agency":
					$("#hear_about_agency_mask").show();
					break;
				case "Newspaper":
					$("#hear_about_newspaper_mask").show();
					break;
				case "Internet":
					$("#hear_about_web_mask").show();
					break;
			}
		} else {
			$("hear_about_mask").hide();
		}
	});
	
	
	
	// yes/no options
	
	var yesMasks = new Array(
		"previously_applied",
		"previous_pocket_employee",
		"currently_employed",
		"criminal",
		"relative",
		"unavailable_shift"
	);
	
	$("input[type=radio]").change(function(e){
		
		var name = $(this).attr("name");
		var mask = "#"+name+"_mask";
		
		if(yesMasks.join().indexOf(name) != -1) {
			if($(this).val() == "1") {
				$(mask).show();
			} else {
				$(mask).hide();
				$(mask + " input").val("");
			}
		}
	});
	
});