// Event registration Checks
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

function getSelectedButton(buttonGroup){
	for (var i = 0; i < buttonGroup.length; i++) {
	 
		if (buttonGroup[i].checked) {
			return i
		}
	}
	return 99
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
function checkreg() {
	var f = document.event_reg;
	var badCount = 0;
	var msg = "";

// validate the fields
	
	if (f.f_firstname.value == "") {
		msg = msg +  "\nEnter First Name";
		badCount = badCount + 1;
	}
	if (f.f_lastname.value == "") {
		msg = msg +  "\nEnter Last Name";
		badCount = badCount + 1;
	}
	if (f.f_company.value == "") {
		msg = msg +  "\nEnter Company Name";
		badCount = badCount + 1;
	}
	if (f.f_street.value == "") {
		msg = msg + "\nEnter Street";
		badCount = badCount + 1;
	}	
	if (f.f_city.value == "") {
		msg = msg + "\nEnter City";
		badCount = badCount + 1;
	}
	var curfld=("f.f_state")
	var this_event = eval(curfld +".options[" +curfld +".selectedIndex].value");
	if (this_event == "None Selected") {
		msg = msg + "\nSelect a State";
		badCount = badCount + 1;
	}
	
	if (f.f_zip.value == "") {
		msg = msg + "\nEnter Zip Code";
		badCount = badCount + 1;
	}	

	var curfld=f.f_phone.value
	if (curfld.length < 12) {
		badCount = badCount + 1;
		msg = msg + "\nEnter Phone Number";
	}
	
 /*    e-mail not required
 		if (f.f_email.value == "") {
  	    badCount = badCount + 1;
		  if (msg =="") {
			badCount = badCount + 1;
			msg = "Enter E-mail";
		  } else {
			badCount = badCount + 1;
		    msg = msg + "\nEnter E-mail";
		  }
   	  }
	 */
   
	if (f.f_email.value != "") {
  	 // check format of e-mail
	   tmp = f.f_email.value;
   
	   var fldEmail=f.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";
		  		}
			}
	    }
	}
	// check that someone has been registered
	if ((f.reg_name_1.value == "Full Name" || f.reg_name_1.value == "") && (f.reg_name_2.value == "Full Name" || f.reg_name_2.value == "") && (f.reg_name_3.value == "Full Name" || f.reg_name_3.value == "")) {
		badCount = badCount + 1;
	    msg = msg + "\nEnter the Full Names of the people you are registering.";
	  }
	
	var no_events = 0;
	var event1 = 0;
	var curfld=("f.event_1")
	var this_event = eval(curfld +".options[" +curfld +".selectedIndex].value");
	if (this_event == 0) {
		no_events = no_events + 1;	// no event has been selected
		event1 = event1 + 1;
	}
	var event2 = 0;
	var curfld=("f.event_2")
	var this_event = eval(curfld +".options[" +curfld +".selectedIndex].value");
	if (this_event == 0) {
		no_events = no_events + 1;
		event2 = event2 + 1;
	}
	var event3 = 0;
	var curfld=("f.event_3")
	var this_event = eval(curfld +".options[" +curfld +".selectedIndex].value");
	if (this_event == 0) {
		no_events = no_events + 1;
		event3 = event3 + 1;
	}	
	
	if (no_events == 3) {
		badCount = badCount + 1;
	    msg = msg + "\nSelect the Events for which you are registering.";
	}
	
	   //check that one of the Membership options has been selected
	var no_status = 0;
	var memstat1 = 0;
   var i = getSelectedButton(f.mem_status_1)
   if (i == 99) {
		no_status = no_status + 1; // no membership status checked
		memstat1 = memstat1 +1;
   }
   var memstat2 = 0;
   var i = getSelectedButton(f.mem_status_2)
   if (i == 99) {
		no_status = no_status + 1;
		memstat2 = memstat2 +1;
   } 
   	var memstat3 = 0;
   var i = getSelectedButton(f.mem_status_3)
   if (i == 99) {
		no_status = no_status + 1;
		memstat3 = memstat3 +1;
   } 
   if (no_status == 3) {
		badCount = badCount + 1;
	    msg = msg + "\nCheck the Membership Status of the people you are registering.";
	}
	
	if ((f.reg_name_1.value != "Full Name" && f.reg_name_1.value != "") && ((event1 > 0) || (memstat1 > 0))) {
		badCount = badCount + 1;
	    msg = msg + "\nInformation for first Regsistrant is incomplete"; 
	} else {
		if ((f.reg_name_1.value == "Full Name" || f.reg_name_1.value == "") && ((event1 == 0) || (memstat1 == 0))) {
			badCount = badCount + 1;
		    msg = msg + "\nInformation for first Regsistrant is incomplete"; 
		}
	}
	if ((f.reg_name_2.value != "Full Name" && f.reg_name_2.value != "") && ((event2 > 0) || (memstat2 > 0))) {
		badCount = badCount + 1;
	    msg = msg + "\nInformation for second Regsistrant is incomplete"; 
	} else {
		if ((f.reg_name_2.value == "Full Name" || f.reg_name_2.value == "") && ((event2 == 0) || (memstat2 == 0))) {
			badCount = badCount + 1;
		    msg = msg + "\nInformation for second Regsistrant is incomplete"; 
		}
	}
	if ((f.reg_name_3.value != "Full Name" && f.reg_name_3.value != "") && ((event3 > 0) || (memstat3 > 0))) {
		badCount = badCount + 1;
	    msg = msg + "\nInformation for third Regsistrant is incomplete"; 
	} else {
		if ((f.reg_name_3.value == "Full Name" || f.reg_name_3.value == "") && ((event3 == 0) || (memstat3 == 0))) {
			badCount = badCount + 1;
		    msg = msg + "\nInformation for third Regsistrant is incomplete"; 
		}
	}
	
	if (badCount == 0) {
    	return true;
    } else {
		alert (msg);
		return false;
	}
}
