
   // determine if the user input a valid e-mail address. 
   function validate_email (email_address) {

      // set local variable. 
      var validationResultsFlag = "failed"; 

      // the regular expression used to analyze the e-mail 
      // address originated from the Fresh Mango Web site:  
      // http://www.freshmango.com/articles/display/?articleID=10
      var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

      // determine if the e-mail address is valid. 
      if (email_address.match(emailRegEx)) { 
         // update a flag, acknowledging 
         // that the e-mail address is valid. 
         validationResultsFlag = "passed"; 
      } // end-if statement 

      // return the validation results to 
      // the function that called for it. 
      return validationResultsFlag; 

   } // end-function validate_email


   // determine if the user input a valid phone number. 
   function validate_phone (phone_number) {

      // set local variable. 
      var validationResultsFlag = "failed"; 

      // the regular expression used to analyze the phone 
      // number originated from coldfusion mx's form validation.
      // the pattern matches any united states telephone number. 
      // matches: 617.219.2000; (617) 283-3599 x234; 
      //          1 (222) 333-4444; 1 (617) 283-3599 ext. 234; 
      //          222-333-4444; 1-222-333-4444; 219-2000; 
      var phoneRegEx = /^(((1))?[ ,\-,\.]?([\\(]?([1-9][0-9]{2})[\\)]?))?[ ,\-,\.]?([^0-1]){1}([0-9]){2}[ ,\-,\.]?([0-9]){4}(( )((x|ex|ext)[\.]?[ ]?([0-9]){1,5}){0,1})?$/;

      // determine if the phone number is valid. 
      if (phone_number.match(phoneRegEx)) { 
         // update a flag, acknowledging 
         // that the phone number is valid. 
         validationResultsFlag = "passed"; 
      } // end-if statement 

      // return the validation results to 
      // the function that called for it. 
      return validationResultsFlag; 

   } // end-function validate_phone


   // check whether the submission should go through. if there 
   // are problems, let the user know and stop the submission. 
   function validate() {  

      // set a variable that will contain the error message. 
      var msg = ""; 
      // initialize global variables. 
      var showErrors = false; 
      var counter = 0; 

      // assume that all properties referenced 
      // below are prefaced with this object. 
      with (window.document.forms[0]) { 

         // if the first name field is blank, add to the error 
         // message and set a flag so the error alert box appears. 
         if (firstname.value == "") { 
            msg = msg + "*     " + "Please input your 'First Name'. " + "\n";  
            showErrors = true; 
            counter++; 
         } // end-if statement 

         // if the last name field is blank, add to the error 
         // message and set a flag so the error alert box appears. 
         if (lastname.value == "") { 
            msg = msg + "*     " + "Please input your 'Last Name'. " + "\n";  
            showErrors = true; 
            counter++; 
         } // end-if statement 

         // if both the phone number and e-mail address 
         // fields are blank, add to the error message 
         // and set a flag so the error alert box appears. 
         if ((phone_number.value  == "") && 
             (email_address.value == "")) { 
            msg = msg + "*     " + "Please input an 'E-mail Address' and/or a 'Phone Number'. " + "\n"; 
            showErrors = true; 
            counter++; 

         // otherwise, one or both fields have content in them. 
         } else { 

            // determine if the e-mail address field is not blank. 
            if (email_address.value != "") { 

               // test the e-mail address to see if it is valid. 
               var emailTestResults = validate_email(email_address.value); 

               // determine if the e-mail address failed the validation test. 
               if (emailTestResults == "failed") { 
                  msg = msg + "*     " + "Please input a valid 'E-mail Address'. " + "\n"; 
                  showErrors = true; 
                  counter++; 
               } // end-if statement 

            } // end-if statement 

            // determine if the phone number field is not blank. 
            if (phone_number.value != "") { 

               // test the phone number to see if it is valid. 
               var phoneTestResults = validate_phone(phone_number.value); 

               // determine if the phone number failed the validation test. 
               if (phoneTestResults == "failed") { 
                  msg = msg + "*     " + "Please input a valid 'Phone Number'. " + "\n"; 
                  showErrors = true; 
                  counter++; 
               } // end-if statement 

            } // end-if statement 

         } // end-if statement 

         // if the show date field is blank, add to the error 
         // message and set a flag so the error alert box appears. 
         if (show_date.value == "") { 
            msg = msg + "*     " + "Please input a show date into 'Day of Performance' field. " + "\n";  
            showErrors = true; 
            counter++; 
         } // end-if statement 

         // if the show time field is blank, add to the error 
         // message and set a flag so the error alert box appears. 
         if (show_time.value == "") { 
            msg = msg + "*     " + "Please input a show time into 'Time of Performance' field. " + "\n";  
            showErrors = true; 
            counter++; 
         } // end-if statement 

         // if no tickets have been reserved, add to the error 
         // message and set a flag so the error alert box appears. 
           if (tickets_totalcount.value < 1) { 
            msg = msg + "*     " + "Please reserve at least one ticket. " + "\n";  
            showErrors = true; 
            counter++; 
         } // end-if statement 

        // if the error message flag is true, pop up an alert box with a  
        // complete list of errors and prevent the submission from going through. 
        if (showErrors == true) { 

           // declare a local variable. 
           var introMessage; 

           // change the intructional message based 
           // on the number of errors on the page. 
           if (counter > 1) { 
              introMessage = "Please correct the following fields: " + "\n" + " \n"; 
           } else { 
              introMessage = "Please correct the following field: "  + "\n" + " \n"; 
           } // end-if statement 

           // add the introductory message to 
           // the beginning of the errors list. 
           msg = introMessage + msg; 

           // pop up the error message in an alert box. 
           alert(msg); 

           // don't allow the submission to go through. 
           return false; 
 
        } // end-if statement 

      } // end-with statement

   } // end-validate function 
