// Contact Form Validation
         
         // validates if the input is empty and displays the error message
         function validateNotEmpty( input, id )
         {
            var errorDisplay =  document.getElementById( id );
            var notEmpty;
            if ( input == "" ) // check if input is empty
            {
               errorDisplay.innerHTML = "* This is a required field";
               notEmpty = false; // update return value
            } // end if
            else
            {
               errorDisplay.innerHTML = ""; // clear the error area
               notEmpty = true; // update return value
            } // end else

            return notEmpty; // return whether the input is empty

         }// end function validateNotEmpty


         // validate that  the email has corect format and is allowed 
         function validateEmail( input )
         {
            if( validateNotEmpty( input, 'emailEmptyError' ) )
            {
               if ( validateEmailFormat( input ) ) // if correct format
               {
                  // send the request for a list of emails that are not
                  // allowed ot post
                  try
                  {
                     asyncRequest = new XMLHttpRequest();

                     // register event handler
                     asyncRequest.onreadystatechange = function()
                     {
                        checkIfAllowed( input ); 
                     }; 
                     asyncRequest.open( 'GET', 'emails.xml', true ); 
                     asyncRequest.send( null ); 
                  } // end try
                  catch ( exception )
                  {
                     alert( 'Request Failed' );
                  } // end catch

               } // end if

            } // end if

         } // end function validateEmail


         // validate that the email has correct format
         function validateEmailFormat( input )
         {
            var valid = false; // tracks validity of the e-mail address
            var section = 'user'; // tracks the section of the address
            for( var i = 0; i < input.length && !valid; i++ )
            {
               // if we reach an "@" the user section is over
               
               if( section == "user" && input.charAt( i )  == '@' )
               {
                  section = "domain"; // update section variable
               } //  end if

               // if we reach a "." the domain section is over 
               else if ( section == "domain" && input.charAt( i ) == '.' )
               {
                  // if there is something after the "." the email has 
                  // valid format
                  if ( i != input.length - 1 )
                  {
                     valid = true; // update validity
                  } //  end if

               } // end else if

            } // end for

            var errorDisplay = 
               document.getElementById( 'emailFormatError' );
            
            // display error if email does not have valid format
            if ( !valid )
            {
               errorDisplay.innerHTML = "* E-mail address is not in the correct format";
            } // end if
            else
            {
               errorDisplay.innerHTML = "";  // clear error area
            } // end else

            return valid; // return validity t
		 }

