// Validate fields on the My Preference 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 f = document.pref_form;
   var msg = "";
 
   if (f.contact_name.value == "") {
      badCount = badCount + 1;
	  msg = "Your Name";
   }
   if (f.company.value == "") {
      badCount = badCount + 1;
	  if (msg =="") {
	     msg = "Company (or Self)";
	  } else {
	      msg = msg + "\nCompany (or Self)";
	  }
   }
   if (f.email.value != "") {
  	 // check format of e-mail
	   tmp = f.email.value;
   
	   var fldEmail=f.email;
	   var strEmail=tmp
	   if (window.RegExp) { //For browsers that support RegExp
	   		var strReg1 = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
	     	var strReg2 = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
	    	var reg1 = new RegExp(strReg1);
	        var reg2 = new RegExp(strReg2);

			if (reg1.test(fldEmail.value) || !reg2.test(fldEmail.value)) {
				badCount = badCount + 1;
		  		if (msg =="") {
					badCount = badCount + 1;
		     		msg = "Improper e-mail format";
			  	} else {
					badCount = badCount + 1;
				    msg = msg + "\nImproper e-mail format";
		  	  	}
			}

	    } else { //For browsers that don't support RegExp
			if ( !(fldEmail.value.indexOf("@")>=0) ) {
				badCount = badCount + 1;
		  		if (msg =="") {
					badCount = badCount + 1;
		    		msg = "Improper e-mail format";
				} else {
					badCount = badCount + 1;
			    	msg = msg + "\nImproper e-mail format";
		  		}
			}
	    }
	} else {
		badCount = badCount + 1;
		msg = msg + "\nYour email address";
	}
   // check that one of the preferences has been selected
   var i = getSelectedButton(f.contact_preference)
   if (i == 99) {
      badCount = badCount + 1;
	  if (msg =="") {
	     msg = "Your Preference";
   	  } else {
	    msg = msg + "\nYour Preference";
	  }
   }
   
// Daisies
	if (f.daisies.value == "") {
		badCount = badCount + 1;
		msg = msg + "\nSolve the Human Check before proceeding";
	}
   
   if (badCount == 0) {
      return true;
    } else {
      alert ("Must enter all required fields: \n" + msg);
      return false;
     }
   
  }
