   // this MUST be here!
   var str;

   ////////////////////////////////////////////////
   ////////////////////////////////////////////////
   function only_numbers(evt) {
      evt = (evt) ? evt : event;
      var char_code = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
      if(char_code > 31 && (char_code < 48 || char_code > 57)) {
         alert("Only numbers allowed.");
	 return false;
      }
      return true;
   }

   ////////////////////////////////////////////////
   ////////////////////////////////////////////////
   function only_digits(field) {
      var i;
      for(i = 0; i < field.value.length; i++) {
         if(field.value.charAt(i) < "0") {
            alert("please use only numbers");
            field.value = '';
            field.focus();
            return false;
         }

         if(field.value.charAt(i) > "9") {
            alert("please use only numbers");
            field.value = '';
            field.focus();
            return false;
         }
      }
      return true
   }

   ////////////////////////////////////////////////
   ////////////////////////////////////////////////
   function no_dupe3(popup, val) {
      var this_popup, rank_val, i;
      var names = new Array(7);
      names[0] = 'four_year';
      names[1] = 'two_year';
      names[2] = 'technical';
      names[3] = 'apprentice';
      names[4] = 'military';
      names[5] = 'workforce';
      names[6] = 'other_goal';

      rank_val = popup.options[popup.selectedIndex].text;

      for(i = 0; i <= 6; i++) {
         if(i != val) {
            this_popup = eval("document.training." + names[i]);
            if(this_popup.options[rank_val].selected == true) {
               this_popup.options[rank_val].selected = false
               this_popup.options[0].selected = true
            }
         }
      }

      return true;
   }

   ////////////////////////////////////////////////
   ////////////////////////////////////////////////
   function no_dupe5(popup, val) {
      var this_popup, rank_val, i;
      names = new Array(9);
      names[0] = 'career_asses';
      names[1] = 'career_res';
      names[2] = 'major_exp';
      names[3] = 'tech_search';
      names[4] = 'app_info';
      names[5] = 'finaid';
      names[6] = 'local_search';
      names[7] = 'school_search';
      names[8] = 'other_prim_obj';

      rank_val = popup.options[popup.selectedIndex].text;

      for(i = 0; i <= 8; i++) {
         if(i != val) {
            this_popup = eval("document.training." + names[i]);
            if(this_popup.options[rank_val].selected == true) {
               this_popup.options[rank_val].selected = false
               this_popup.options[0].selected = true
            }
         }
      }

      return true;
   }

   ////////////////////////////////////////////////
   ////////////////////////////////////////////////
   function count3() {
      var this_popup, rank_val, i;
      var names = new Array(7);
      names[0] = 'four_year';
      names[1] = 'two_year';
      names[2] = 'technical';
      names[3] = 'apprentice';
      names[4] = 'military';
      names[5] = 'workforce';
      names[6] = 'other_goal';

      var count = 0;
      for(i = 0; i <= 6; i++) {
         this_popup = eval("document.training." + names[i]);
         if(this_popup.selectedIndex != 0) count++;
      }

      if(count < 3)
         { str += "You did not rank 3 post-secondary goals.\n" }
   }

   ////////////////////////////////////////////////
   ////////////////////////////////////////////////
   function count5() {
      var this_popup, rank_val, i;
      var names = new Array(9);
      names[0] = 'career_asses';
      names[1] = 'career_res';
      names[2] = 'major_exp';
      names[3] = 'tech_search';
      names[4] = 'app_info';
      names[5] = 'finaid';
      names[6] = 'local_search';
      names[7] = 'school_search';
      names[8] = 'other_prim_obj';

      var count = 0;
      for(i = 0; i <= 8; i++) {
         this_popup = eval("document.training." + names[i]);
         if(this_popup.selectedIndex != 0) count++;
      }

      if(count < 5)
         { str += "You did not rank 5 primary objective for this program.\n" }
   }

   ////////////////////////////////////////////////
   ////////////////////////////////////////////////
   function amenity(num_stations) {
      var this_popup, i;
      var count = 0;
      for(i = 1; i <= 9; i++) {
         this_popup = eval("document.training.amenity" + i);
         if(this_popup.checked) count++;
      }

      if(!count)
         { str += "You did not check the technological amenities at your site.\n" }

      if(count) {
         if(document.training.amenity8.checked && !num_stations) {
            str += "You did not specify how many attendee worksations you have.\n"
         }
      }
   }

   /////////////////////////////////////////////////
   /////////////////////////////////////////////////
   function check_form(form) {
      // error message string
      str = ''; 

      var reg = /^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

      // form fields to check
      var name = form.name.value;
      var req_time = form.req_time.value;
      var area = form.area.value;
      var pre = form.pre.value;
      var pos = form.pos.value;
      var email = form.email.value;
      var school_group = form.school_group.value;
      var site = form.site.value;
      var city = form.city.value;
      var room = form.room.value;
      var build_park_info = form.build_park_info.value;
      var num_stations = form.num_stations.value;
      var num_parts = form.num_parts.value;
      var percentage = form.percentage.value;

      // remove spaces
      name = remove(name, ' ');
      req_time = remove(req_time, ' ');
      area = remove(area, ' ');
      pre = remove(pre, ' ');
      pos = remove(pos, ' ');
      school_group = remove(school_group, ' ');
      site = remove(site, ' ');
      city = remove(city, ' ');
      room = remove(room, ' ');
      build_park_info = remove(build_park_info, ' ');
      num_stations = remove(num_stations, ' ');
      num_parts = remove(num_parts, ' ');
      percentage = remove(percentage, ' ');

      //////////////////////////////////////////
      // radio buttons in the top half of form
      //////////////////////////////////////////

      var attend = false;
      for(i = 0; i < form.attend.length; i++) {
         if(form.attend[i].checked) { attend = true; }
      }

      var categorizes = false;
      for(i = 0; i < form.categorizes.length; i++) {
         if(form.categorizes[i].checked) { categorizes = true; }
      }

      var comfort = false;
      for(i = 0; i < form.comfort.length; i++) {
         if(form.comfort[i].checked) { 
            comfort = true; 
         }
      }

      if(!name) { str += "You did not enter a contact name.\n"; }

      var flag = false;
      if(!area  || !pre || !pos) { 
         str += "You did not enter a daytime phone number.\n"; 
         flag =true;
      }

      if(!flag) {
         if(area.lenght < 3 || pre.length < 3 || pos.length < 4)
	    { str += "You did not enter a correct phone number.\n"; }
      }

      /////////////////////////////////
      // check for valid email string
      /////////////////////////////////
      if(email) {
         if(!reg.test(email)) {
            str += '"' + email + '"' + " is not a valid email address.\n"; 
         }
      }

      if(!school_group) { 
         str += "You did not enter a School or Group name.\n"; 
      }

      if(form.month.value == 'mm' || form.day.value == 'dd' || form.year.value == 'yyyy') {
         str += "You did not select a training date.\n";
      }

      if(!req_time) { 
         str += "You did not enter a Requested Workshop Time.\n"; 
      }


      if(!site) { str += "You did not enter a Training Site Address.\n"; }

      if(!city) { str += "You did not enter a city.\n"; }

      if(!room) { str += "You did not enter a Training Site room #.\n"; }

      amenity(num_stations);

      if(!build_park_info) 
         { str += "You did not enter Building and Parking Information.\n"; }

      if(!attend) {
         str += "You did not answer whether you will be attending.\n";
      }

      if(!categorizes) {
         str +=
            "You did not select which best categorizes the participants.\n";
      }

      if(!num_parts) {
         str += "You did not enter the number of anticipated participants.\n";
      }

      if(form.categorizes[0].checked) {
         var grade_level = form.grade_level.value;
         grade_level = remove(grade_level, ' ');
         if(!grade_level)
            { str += 'In "categorize the participants" you did not fill in the grade level of students\n'; }
      }

      if(form.categorizes[5].checked) {
         var other_cat = form.other_cat.value;
         other_cat = remove(other_cat, ' ');
         if(!other_cat)
            { str += 'In "categorize the participants" you did not fill in the ""Please Specify" field.\n'; }
      }

      count3();

      if(!comfort) {
         str += 
            "You did not select the participants technology comfort level.\n";
      }

      if(!percentage) { 
         str += 
            "You did not enter the % of participants who have used COMPASS Guide/ECOS before.\n"; 
      }

      count5();

      if(form.other_prim_obj.selectedIndex != 0) {
         var other_prim_obj_txt = form.other_prim_obj_txt.value;
         other_prim_obj_txt = remove(other_prim_obj_txt, ' ');
         if(!other_prim_obj_txt)
            { str += 'In "rank 5 primary objectives" you did not fill in the ""Please Specify" field.\n'; }
      }


      if(str != '') { alert(str); return false; }

      return true;
   }
