function validateForm(form) {
  var error = false;
  
  $(form.elements).filter('.required').each(function() {
    if (this.value.length == 0) {
			error = true;
			$(this).css('background-color', 'red');
		}
  });
	
	if (error) {
		 $(form).before('<p class="error">Please fill in all required fields before submitting.</p>');
		 setTimeout('removeErrorMessage()', 7000);
		 setTimeout('inputsToWhite()', 7000);
	}
  return (error) ? false : true;
}

function removeErrorMessage() {
	$("p.error").slideUp();
}

function inputsToWhite() {
	var form = document.emailNotifications;
	
	$(form.elements).filter('.required').animate({
		backgroundColor: 'white'
	}, 2000);
}

$(document).ready(function() {
  $(document.emailNotifications).submit(function() {
    return validateForm(this);
  });
});
