validateFields Function

Added function to validate fields. Restructured variables (global to
upper of document, those with function calls to lower of document).