// Validate fields on the registration form 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

function getSelectedButton(buttonGroup){
	for (var i = 0; i < buttonGroup.length; i++) {
	 
		if (buttonGroup[i].checked) {
			return i
		}
	}
	return 99
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

function CheckFrm() {
   var badCount = 0;
   var timesCount = 0;
   var f = document.reg_form;
   var msg = "";
 
   if (f.f_firstName.value == "") {
      badCount = badCount + 1;
	  msg = "\tFirst Name";
   }
   if (f.f_lastName.value == "") {
      badCount = badCount + 1;
	  if (msg =="") {
	     msg = "\tLast Name";
	  } else {
	    msg = msg + "\n\tLast Name";
	  }
   }
     if (f.f_street.value == "") {
      badCount = badCount + 1;
	  if (msg =="") {
	     msg = "\tStreet";
	  } else {
	    msg = msg + "\n\tStreet";
	  }
   }
   if (f.f_city.value == "") {
      badCount = badCount + 1;
	  if (msg =="") {
	     msg = "\tCity";
	  } else {
	    msg = msg + "\n\tCity";
	  }
   }
   if (f.f_state.value == "None Selected") {
      badCount = badCount + 1;
	  if (msg =="") {
	     msg = "\tState";
	  } else {
	    msg = msg + "\n\tState";
	  }   
   }
   if (f.f_zip.value == "") {
      badCount = badCount + 1;
	  if (msg =="") {
	     msg = "\tZip Code";
	  } else {
	    msg = msg + "\n\tZip Code";
	  }
   }
 // either home or work phone must be filled in 
   if (f.f_homePhone.value == "") {
      if (f.f_workPhone.value == ""){
         badCount = badCount + 1;
	     if (msg =="") {
	        msg = "\tHome Phone or Work Phone";
	     } else {
	       msg = msg + "\n\tHome Phone or Work Phone";
	     }
	  } 
   }
 
   if (f.f_email.value == "") {
      badCount = badCount + 1;
	  if (msg =="") {
	     msg = "\tE-mail";
	  } else {
	    msg = msg + "\n\tE-mail";
	  }
   }
   // check that one of the genders has been selected
   var i = getSelectedButton(f.f_gender)
   if (i == 99) {
      badCount = badCount + 1;
	  if (msg =="") {
	     msg = "\tGender";
   	  } else {
	    msg = msg + "\n\tGender";
	  }
   }
   //check that one of the training options has been selected
   var i = getSelectedButton(f.f_training)
   if (i == 99) {
      badCount = badCount + 1;
      if (msg =="") {
	     msg = "\tTraining Option";
	  } else {
	     msg = msg + "\n\tTraining Option";
	  }
   } 
		 
      // Check to make sure that all time preferences are selected 
      if (f.f_bestTime.value == "None Selected"){
         timesCount = timesCount +1;
	     }
      if (f.f_secondBestTime.value == "None Selected") {
         timesCount = timesCount +1;
	     }
      if (f.f_thirdBestTime.value == "None Selected") {
         timesCount = timesCount +1;
	     } 
      if (f.f_bestTime.value == f.f_secondBestTime.value || f.f_bestTime.value == f.f_thirdBestTime.value) {
         timesCount = timesCount +1;
	     }
      if (f.f_secondBestTime.value == f.f_thirdBestTime.value) {  
         timesCount = timesCount +1;
         }

   if (timesCount >0) {
      badCount = badCount +1;
	  if (msg =="") {
	      msg = "\tThree Different Contact Times\n";
	  } else {
	      msg = msg + "\n\tThree Different Contact Times\n";
	  }
   }
    
// Comments
	tmp = f.f_comments.value;
	if (tmp.length > 0 ) {
		if (tmp.length < 256 ) {
			karen = 0;
			karen = tmp.search(/http/i);
			
			karen = karen + tmp.search(/www/i);
			
			karen = karen + tmp.search(/href/i);
			
			karen = karen + tmp.search(/url/i);
			
			karen = karen + tmp.search(/\.com/i);
			
			karen = karen + tmp.search(/\.net/i);
			
			karen = karen + tmp.search(/\.org/i);
			
			karen = karen + tmp.search(/\.mil/i);
			
			if (karen != -8) {
				badCount = badCount +1;
				msg = msg + "\nComments contain illegal characters. Please use standard punctuation.\n";
			}
		} else {
			msg = msg + "\nComments too long. Please be more concise.\n";
		}
	}

	
	tmpString = f.f_homePhone.value;
	if (tmpString.length > 0) {
		var stripped = tmpString.replace(/[\(\)\.\-\ ]/g, '');

		//strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) {
		  badCount = badCount + 1;	  
		  msg = msg + "\nThe Home Phone number contains illegal characters.";
		}
		if (stripped.length < 10) {
		  badCount = badCount + 1;
		  msg = msg + "\n The Home Phone number is the wrong length. Make sure you included an area code.\n";
	 	}
	}
  
	tmpString = f.f_workPhone.value;
	if (tmpString.length > 0) {
		var stripped = tmpString.replace(/[\(\)\.\-\ ]/g, '');

		//strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) {
		  badCount = badCount + 1;	  
		  msg = msg + "\nThe Work Phone number contains illegal characters.";
		}
		if (stripped.length < 10) {
		  badCount = badCount + 1;
		  msg = msg + "\nThe Work Phone number is the wrong length. Make sure you included an area code.\n";
		}
	}
	
	tmpString = f.f_fax.value;
	if (tmpString.length > 0) {
		var stripped = tmpString.replace(/[\(\)\.\-\ ]/g, '');

		//strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) {
		  badCount = badCount + 1;	  
		  msg = msg + "\nThe Fax number contains illegal characters.";
		}
		if (stripped.length < 10) {
		  badCount = badCount + 1;
		  msg = msg + "\nThe Fax number is the wrong length. Make sure you included an area code.\n";
		}
	}
 
   if (badCount == 0) {
      return true;
    } else {
      alert ("Must enter all required fields: \n" + msg);
      return false;
     }
   
  }