$(document).ready(function() {

	// Validate signup form on keyup and submit
	$('#contactUs').validate({
		rules: {
			name: {
				required: true,
				notEqual: '* Name'
			},
			phone: {
				required: true,
				phoneUS: true
			},
			email: {
				required: true,
				email: true
			}
		},
		messages: {
			name: 'Please enter your name.',
			phone: 'Please enter a valid phone number.',
			email: 'Please enter a valid email.'
		},
		submitHandler: function() {
			
			// Hide form fields, show/hide loading image
			$('#contactUs')
				.hide();
			$('#form-loading')
				.show();
			$('#post-results')
				.delay(2500)
				.html('Your request has been sent. Thank you!')
				.fadeIn();
			$('#form-loading')
				.hide();
			form.submit();
//			$.ajax({
//				// Posting the form data
//				type: 'POST',
//				data: $('#contactUs').serialize(),
//				url: 'http://formprocessor.levelfivesolutions.com/mailer/formSubmit',
//				success: function(msg) {
//					$('#post-results').ajaxComplete(function(event, request, settings) {
//						// Form data processed --- Show the 'Thank You' message and hide loading image
//						if (msg.search(/fail/i) == -1) 
//						{
//							result = 'Your request has been sent. Thank you!';
//						}
//						else
//						{
//							result = 'There was an error with your request. Sorry!';
//						}
//						$('#form-loading')
//							.hide();
//						$('#post-results')
//							.html(result)
//							.fadeIn('fast');
//					});
//				}
//				
//			}); // CLOSING .ajax
			
		} // CLOSING submitHandler
		
	}); // CLOSING .validate

	// Show position dropdown if user is inquiring about job
	$('#inquiry').change(function() {
		if($(this).val() == 'Applying for job')
		{
			$('#position').fadeIn();
		}
		else
		{
			$('#position').hide();
		}
	});
	// If page refresh defaults to have that selected already
	if($('#inquiry').val() == 'Applying for job')
	{
		$('#position').show();
	}

	// Show form once everything has loaded
	$('#form-loading').hide();
	$('#contactUs').show();

});

jQuery.validator.addMethod("notEqual", function(value, element, param) {
	return this.optional(element) || value !== param;
}, "Please choose a value!");

