function validateForm( )
{
   // local variables

   var index;
   var iLength;
   var regExp;
   var field;
   var strError = "";      // Error string that will be set to an
                           // appropriate message if error is detected.
                           // Otherwise it will remain null.
   var strValue;
   var regExpBlank = /^[\s]*$/;
  
   // Loop through all fields in the form

   for (index=0; index<document.STC_registration_form.length; index++) {

      field = document.STC_registration_form.elements[ index ];
      strValue = field.value;
      iLength = strValue.length;
	  strError = "";

      // For each field, verify that the user has entered a valid 
      // data string. If invalid, then set the error string to an
      // appropriate message. 

      switch( field.name ) {
               
         // Proper name field.
         // Only alphanumeric characters, ' and whitespace allowed 

         case( "name" ):

            regExp  = /^([a-zA-Z-'\.\s]{2,50})$/;            

           if ( !regExp.test( strValue ) || regExpBlank.test( strValue )  ) {
               strError = "Please enter a valid name for the Name field";
            }
            break;	
			
		 case( "N_no" ):
			
			if ( regExpBlank.test( strValue ) ) {
				strError = "Please enter a value in the Aircraft N number field";
			}
			break;
			
		 case( "serial_no" ):
			
			if ( regExpBlank.test( strValue ) ) {
				strError = "Please enter a value in the Aircraft serial number field";
			}
			break;
			
		 case( "address" ):
			
			if ( regExpBlank.test( strValue ) ) {
				strError = "Please enter a value in the Address field";
			}
			break;
			
		 case( "city" ):
		    regExp  = /^([a-zA-Z-'\.\,\s]{2,50})$/;
			
			if ( !regExp.test( strValue ) || regExpBlank.test( strValue )  ) {
               strError = "Please enter a valid name for the City field";
			}
			break;
			
		 case( "state" ):
		    regExp  = /^([a-zA-Z-'\.\s]{2,50})$/;            

           if ( !regExp.test( strValue ) || regExpBlank.test( strValue )  ) {
               strError = "Please enter a valid name for the State/Province field";
			}
			break;
			
		 case( "zip" ):
			regExp = /^[a-zA-Z\d]{5,6}$/;   
			
            if ( !regExp.test( strValue ) || regExpBlank.test( strValue ) ) {
               strError = "Please enter a valid zip or postal code (e.g., 12345)";
			}
			break;

		 case( "phone" ):
		 	regExp = /^1?\s*-?\s*(\d{3}|\(\s*\d{3}\s*\))\s*-?\s*\d{3}\s*-?\s*\d{4}$/
			if ( !regExp.test( strValue ) ) {
				strError = "Please enter a valid phone number with area code (e.g., 123-456-7890)";
			}
			break;

         // Email address field. Must be a valid email address between 5 and 64
         // characters, inclusive. Only alphanumeric characters, '-', '_', '@'
         // and '.' are allowed.

         case( "email" ):
            regExp = /^([\w\.\-])+\@(([\w\-])+\.)+([a-zA-Z0-9])+$/;

            if ( !regExp.test( strValue ) || iLength < 5 || iLength > 64 ) {
               strError = "Please enter a valid email address (e.g., joe@foo.com)";
            }
            break;

         default: 
            // Do nothing

      }  // end switch( )

      // If error string is anything other than null, then an error has
      // been detected. Display the error string, and return focus to the 
      // offending form field.

      if (strError) {
         alert( strError );
         field.focus( );
         field.select( );
         return false;
      }

   }  // end for( )

   // If we've reached this point, then no error has been detected. 
   // Form validates correctly.

   return true;

}  // end function validateForm( )  