function validate(f){
 
  var state_list_array = new Array();
  var fe = document[f];


  function emptyField(field){
        var a = document.client_form[field].value
        if((a == null) || (a == "") || (a.search(/^[\s]+$/) != -1))
                  var no_content = true;
                else
                        var no_content = false;
         return no_content;
  }
/*  
function emailTest(field){
	  var a = fe[field].value.search(/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i);
	  return a;
  }     
*/

function read_multi(elementName, count){
  for(var i = 0; i < count; i++) {
    var a_button = document.getElementById(elementName + '_' + i);
    if(a_button.checked){
    	var but_value = a_button.value;
    }
  }
  return but_value;
}

  function test_multi(elementName, count){
    var but_check = false;
    for(var i = 0; i < count; i++) {
      var a_button = document.getElementById(elementName + '_' + i);
      if(a_button.checked){
    	but_check = true;
      }
    }
  return but_check;
  }

  function changeClassRed(field){
        document.getElementById(field).className = 'query_red';
  }
  
  function changeClassBlue(field) {
        document.getElementById(field).className = 'query_optional';
  }  
  function resetClass(field){
        document.getElementById(field).className = 'query';
  }


  var msg = null;
  
// First name tests.


  if(emptyField('firstName') == true) {
        msg += "\nYou did not fill out the first name field.";
        changeClassRed('firstNameLabel');
        state_list_array[0] = 'false';
  }

  else if (f.firstName.value.search(/^[a-z'\-.\s]+$/i) == -1) {
        msg += "\nYou made an invalid entry in the first name field. Only letters, apostrophes, hyphens, periods, and spaces are allowed.";
        changeClassRed('firstNameLabel');
        state_list_array[0] = 'false';
  }


  else {
        resetClass('firstNameLabel');
        state_list_array[0] = 'true';
  }



// Last Name tests.


  if(emptyField('lastName') == true){
        msg += "\nYou did not fill out the last name field.";
        changeClassRed('lastNameLabel');
        state_list_array[1] = 'false';
  }
  
  else if(f.lastName.value.search(/^[a-z'\-.\s]+$/i) == -1){
        msg += "\nYou made an invalid entry in the last name field. Only letters, apostrophes, hyphens, periods, and spaces are allowed.";
        changeClassRed('lastNameLabel');
        state_list_array[1] = 'false';
  }


  else {
        resetClass('lastNameLabel');
        state_list_array[1] = 'true';
  }  
  
   
  if((emptyField('streetAddress') == false) && (f.streetAddress.value.search(/^[a-z0-9'\-.#\s]+$/i) == -1)) {
        msg += "\nYou did not enter a valid Street Address. It is not necessary to fill out this field, but if it contains data it must be correctly formatted. Only letters, numbers, hyphens, periods, #, and spaces are allowed. The street name must be preceded by a number.";
        changeClassRed('streetAddressLabel');
        state_list_array[2] = 'false';
  }
  
  else {
        changeClassBlue('streetAddressLabel');
        state_list_array[2] = 'true';
  }



// City tests.


  if(emptyField('city') == true) {
        msg += "\nYou did not enter a city name.";
        changeClassRed('cityLabel');
        state_list_array[3] = 'false';
  }
  
  else if((f.city.value.search(/^[a-z'\-.\s]+$/i) == -1)) {
        msg += "\nYou entered an invalid city name. Only letters, hyphens, and spaces are allowed.";
        changeClassRed('cityLabel');
        state_list_array[3] = 'false';
  }


  else {
        resetClass('cityLabel');
        state_list_array[3] = 'true';
  }



// State tests.


  if(emptyField('state') == true) {
        msg += "\nYou did not enter a state name.";
        changeClassRed('stateLabel');
        state_list_array[4] = 'false';
  }


  else if(f.state.value.search(/^[a-z'.\s]+$/i) == -1) {
        msg += "\nYou did not enter a valid state name. Only letters, periods, and spaces are permitted.";
        changeClassRed('stateLabel');
        state_list_array[4] = 'false';
  }


  else {
        resetClass('stateLabel');
        state_list_array[4] = 'true';
  }



// Zip Code tests.


  if((emptyField('zipCode') == false) && (f.zipCode.value.search(/^[0-9]{5}( |-[0-9]{4})?$/) == -1)) {
        msg += "\nYou entered an invalid zip code. This field is optional, but it can only accept 5 or 9 digit zip codes.";
        changeClassRed('zipCodeLabel');
        state_list_array[5] = 'false';
  }
  
  else {
        changeClassBlue('zipCodeLabel');
        state_list_array[5] = 'true';
  } 



// Email tests.

var email_reg_exp = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;

  if(emptyField('email_1')){
    msg += "\nYou did not fill out the first email  field.";
        changeClassRed('emailLabel');
    state_list_array['email_1'] = 'false';
    }
    
  else if(f.email_1.value.search(email_reg_exp) == -1){
    msg += "\nYou entered an invalid email address in the first email field.";
        changeClassRed('emailLabel');
    state_list_array[6] = 'false';
    }
    
  else {
    state_list_array[6] = 'true';
    }    


  if(emptyField('email_2')){
    msg += "\nYou did not fill out the second email field.";
        changeClassRed('emailLabel');
    state_list_array[7] = 'false';
    }
    
  else if(f.email_2.value.search(email_reg_exp) == -1){
    msg += "\nYou entered an invalid email address in the second email field.";
        changeClassRed('emailLabel');
    state_list_array[7] = 'false';
    }
  
  else {
    state_list_array[7] = 'true';
    }


  state_list_array[8] = 'false';
    
  if (('email_1' != 'email_2') && !((emptyField('email_1') && !emptyField('email_2')) || (!emptyField('email_1') && emptyField('email_2')))){
        msg += "\nYou entered unmatching email addresses. Please correct this.";
        changeClassRed('emailLabel');
        state_list_array[8] = 'false';
    }
  
  else if((state_list_array[6] == 'true') && (state_list_array[7] == 'true')) {
        resetClass('emailLabel');
        state_list_array[8] = 'true';
  }



// Phone Number tests.
  
  if((f.phone.value.search(/^(1|1-|1 )?([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/) == -1) && (!(!f.phone.value))){
    msg += "\nThe telephone number you entered is not a valid 10 digit US telephone number. Providing your telephone number is optional, but if provided it must be in a  conventional US format, including hyphens. Parentheses around the area code are optional.";
    changeClassRed('phoneLabel');
        state_list_array[9] = 'false';
  }


  else {
        changeClassBlue('phoneLabel');
        state_list_array[9] = 'true';
  }
 


// Own files tests.
  
  if(!test_multi('own_files', '2')) {
        msg += "\nYou did not indicate whether or not you would supply your own text and images.";
        changeClassRed('own_filesLabel');
        state_list_array[10] = 'false';
  }
  
  else {
        resetClass('own_filesLabel');
        state_list_array[10] = 'true';
  }
  


// Site size tests.
   
  if((f.site_size.value.search(/^[0-9]+(-| or | to )?[0-9]*$/i) == -1) && (f.site_size.value != "")) {
    msg += "\nYou entered invalid data for the number of pages you expect to need. Only numbers, hyphens, and the words “or” and “to” are permitted.";
    changeClassRed('site_sizeLabel');
        state_list_array[11] = 'false';
  }
  
  else if(emptyField('site_size') == true ) {
    msg += "\nYou did not fill out the number of pages field.";
    changeClassRed('site_sizeLabel');
        state_list_array[11] = 'false';
  }


  else {
        resetClass('site_sizeLabel');
        state_list_array[11] = 'true';
  }


// Need forms tests.
  
  if(!test_multi('need_forms', '2')){
        msg += "\nYou did not indicate whether or not you need forms for your web site.";
        changeClassRed('need_formsLabel');
        state_list_array[12] = 'false';
  }
  
  else {
        resetClass('need_formsLabel');
        state_list_array[12] = 'true';
  }


  
// Database tests.
   
  if(!test_multi('database', '2')){
        msg += "\nYou did not indicate whether or not you need a database.";
        changeClassRed('databaseLabel');
        state_list_array[13] = 'false';
  }

    
  else {
        resetClass('databaseLabel');
        state_list_array[13] = 'true';
  }
  
  var need_db_y = document.getElementById('database_0');
  
  if((need_db_y.checked) && (emptyField('field_count'))) {
        msg += "\nYou indicated that you need a database, but you did not provide an approximation how many fields your database will have.";
        changeClassRed('field_countLabel');
        state_list_array[14] = 'false';
  }
  
  
// Field count tests 
  
  if((emptyField('field_count') == false) && (f.field_count.value.search(/^[0-9](-| or | to )?[0-9]*/i) == -1)) {
    msg += "\nYou entered invalid data for the number of database fields you expect to need. Only numbers, and hyphens, and the words “or” and “to” are permitted.";
    changeClassRed('field_countLabel');
        state_list_array[14] = 'false';
  }
  
  else {
        resetClass('field_countLabel');
        state_list_array[14] = 'true';
  }


// Database reports tests.
  
  if((need_db_y.checked) && (test_multi('reports', '2') == false)){
        msg += "\nYou indicated that you need a database, but you did not indicate whether or not you want a program to generate reports from the database.";
        changeClassRed('reportsLabel');
        state_list_array[14] = 'false';         
  }
  
  else {
        resetClass('reportsLabel');
        state_list_array[14] = 'true';
  }


// Commerce tests.
  
  if(!test_multi('commerce', '2')) {
        msg += "\nYou did not indicate whether or not you plan on engaging in commerce through your web site.";
        changeClassRed('commerceLabel');
        state_list_array[15] = 'false';         
  }	
  
  else {
        resetClass('commerceLabel');
        state_list_array[15] = 'true';
  }


// Business category tests.

  if((document.getElementById('commerce_0').checked) && (document.client_form.category.value == 'SELECT ONE')) {
        msg += "\nYou indicated that you want to engage in e-commerce, but you did not select your business category. Selecting an option becomes required when you asking for a commercial web site.";
        changeClassRed('categoryLabel');
    state_list_array[16] = 'false';
  }
  
  else {
    state_list_array[16] = 'true';
        changeClassBlue('categoryLabel');
  } 
  
// Subject matter tests.
   
  if((emptyField('subject_matter') == true) || (f.subject_matter.value.search(/\w/) == -1)) {
        msg += "\nYou did not provide a statement regarding what your web site will be about.";
        changeClassRed('subject_matterLabel');
        state_list_array[16] = 'false';
  }
  
  else {
        resetClass('subject_matterLabel');
        state_list_array[16] = 'true';
  }


        


// Audience tests.
  
  if(emptyField('audience') == true) {
        msg += "\nYou did not provide a statement regarding who your intended audience is.";
        changeClassRed('audienceLabel');
    state_list_array[17] = 'false';
  }

   
  else {
        resetClass('audienceLabel');
    state_list_array[17] = 'false';
  }


// Valid url tests.
 
  var url_test = f.url.value.match(/((\w+):\/\/)?(www\.)?(\w\.)+[a-z0-9]{2,}(\/\S)*/ig);
  
  if(!url_test){
    msg += "\nYou did not provide valid web addresses for any web sites that you like.";
    changeClassRed('urlLabel');
        state_list_array[18] = 'false';
  }
  
  else if(url_test.length < 2){
    msg += "\nYou only provided a valid address for one web site that you like. Please supply a valid address for a second site that you like.";
    changeClassRed('urlLabel');
        state_list_array[18] = 'false';
  }


  else {
        resetClass('urlLabel');
        state_list_array[18] = 'true';
  }  
 
// Beginning of text/html appended to the page.
  
alert(' Parse message into an array.\n Line 441');
  var msg_array = msg.split("\n");  
  var msg_length = msg_array.length;
  
  var ol_elem = document.getElementById('broken');
  var kids = ol_elem.childNodes;
  var numkids = kids.length;  
// This for() loop removes previous submissions 
// error messages if any exist.
  for(var j = numkids-1; j >= 0; j--){
  	ol_elem.removeChild(kids[j]);
  }

// This for() loop iterates through the error msg_array
// and appends children.
  for(var k = 1; k < msg_length; k++){
    var li = document.createElement('li');
    li.appendChild(document.createTextNode(msg_array[k]));
    ol_elem.appendChild(li);
  }// End of error list for() loop.


   
  //var error_message_content;

  var state_list = state_list_array.join();
  
  if(state_list.indexOf('false') != -1)
    var state = false;
  else
        var state = true;

  window.scrollTo(0, 750);
  document.getElementById('error_list').setAttribute('style', '');
  return state;

}// End of validate()

function read_multi(elementName, count){
  for(var i = 0; i < count; i++) {
    var a_button = document.getElementById(elementName + '_' + i);
    if(a_button.checked){
      alert('The value of the chosen button is ' + a_button.value);
    }
  }
}
