
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	
	var errorString="";
	
	function checkField(f, txt) {
	
		if (f.value==null || f.value=="")
		{
			errorString += txt + "\n";
		}
	}

	
	function validateZIP(field, txt) {
		var valid = "0123456789-";
		var hyphencount = 0;
		
		if (field.value.length!=5 && field.value.length!=10) {
			errorString += "Please enter your 5 digit or 5 digit+4 " + txt + " zip code.\n";
		}
		for (var i=0; i < field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (temp == "-") hyphencount++;
		if (valid.indexOf(temp) == "-1") {
			errorString += "Invalid characters in your " + txt + " zip code.\n";
		}
		if ((hyphencount > 1) || ((field.value.length==10) && ""+field.value.charAt(5)!="-")) {
			errorString += "The hyphen character should be used with a properly formatted 5 digit+four " + txt + " zip code, like '12345-6789'.\n";
		   }
		}
	}
	
	function validateEmail(field) {
		var returnval=emailfilter.test(field.value)
		if (returnval==false)
		{
			errorString += "Please enter a valid email address.\n";
		}
	}
	
	function validatePhone(field, txt) {
	
		var stripped = field.value.replace(/[\(\)\.\-\ ]/g, '');    

	   	if (field.value == "") {
			errorString += "Please enter a " + txt + " phone number.\n";
	    } else if (isNaN(parseInt(stripped))) {
	        errorString += "The " + txt + " phone number contains illegal characters.\n";
	    } else if (!(stripped.length == 10)) {
		
			// allow the 1st number to be 1
			if ((stripped.substr(0,1) == '1') && (stripped.length == 11)) return true;
			
			errorString += "The " + txt + " phone number is the wrong length. Make sure you included an area code.\n";
	    }		
	}
	
	
	function checkJoinOnlineForm(e){

		// name
		checkField(e.firstname, "Please enter your first name.");
		checkField(e.lastname, "Please enter your last name.");
		checkField(e.affiliation, "Please enter the institution you are affiliated with.");
		
		// email
		validateEmail(e.email);
		
		// address
		
		/***
		checkField(e.businessaddressline1, "Please enter your business street address.");
		checkField(e.businesscity, "Please enter your business city.");		
		if (e.businessstate.value == "0")
		{
			errorString += "Please enter your business state.\n";
		}			
		validateZIP(e.businesszip, "business");
		validatePhone(e.businessphone, "business");
		***/
		checkField(e.homeaddressline1, "Please enter your home street address.");
		checkField(e.homecity, "Please enter your home city.");		
		if (e.homestate.value == "0")
		{
			errorString += "Please enter your home state.\n";
		}			
		validateZIP(e.homezip, "home");
		validatePhone(e.homephone, "home");
		
		if (errorString != "")
		{
			alert(errorString);
			errorString = "";
			return false;
		}
		else
			return true;
		
	}

	
	function checkRegisterOnlineForm(e) {
		return checkJoinOnlineForm(e);
	}