//email validation script
function emailCheck(emailStr) {

	var specialChars      = "\\(\\)<>@,;:\\$" + "\\\\" + '\"' + "\\.\\[\\]";
	var validChars        = "[^\\s" + specialChars + "]";
	var quotedUser        = '("[^"]*")';
	var atom              = validChars + '+';
	var word              = "(" + atom + "|" + quotedUser + ")";
	var userPat           = new RegExp("^" + word + "(\\." + word + ")*$");

	//begin checking address
	var em = emailStr.split('@');
	if(em.length > 2){
    alert('Please check your Email Address -- you have too many \"@\" characters in it.');
		return false;
  }

	var matchArray        = emailStr.match(/^([^@]+)@([-\.\w\[\]]+)$/);

	if (matchArray == null) {
		if(emailStr.indexOf('@') == -1){
			alert('Please check your Email Address -- you are missing the \"@\" character.');
			return false;
		}
		else{
  	  if(em[0].search(userPat) == -1){
 	  		alert('Please check your Email Address -- your username (what\'s before the \"@\") is missing or invalid.');
				return false;
			}
			else{
				alert('Please check your Email Address -- your domain (what\'s after the \"@\") is missing or invalid.');
				return false;
			}
		}
	}

	user                  = new String(matchArray[1]);
	domain                = new String(matchArray[2]);

	if (user.search(userPat) == -1) {
    alert('Please check your Email Address -- your username (what\'s before the \"@\") is missing or invalid.');
		return false;
	}

	// verify the domain
	re1 = /^((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	
	if(domain.search(re1) == -1){
    alert('Please check your Email Address -- your domain (what\'s after the \"@\") is missing or invalid.');
		return false;
  }
	
	// If we've gotten this far, everything's valid!
	return true;
}




//user alerts for req'd fields 

function checkrequired(which) {
	for (i=0;i<which.length;i++) {
		var tempobj = which.elements[i];
		if (tempobj.name.substring(0,9) == "required-") {
			if (((tempobj.type == "text" || tempobj.type == "textarea") && tempobj.value == '') || (tempobj.type.toString().charAt(0) == "s" && tempobj.selectedIndex == 0)) {
				var shortFieldName = tempobj.name.substring(9,30);
				var shortFieldName = shortFieldName.replace('_',' ');
				alert("Please make sure the \""+shortFieldName+"\" field was properly completed.");
				return false;
			}
		}
	}
	return true;
}

function etsValidate(email) {
	if (email == '') {
		alert("Please enter an e-mail address.");
		return false;
	}
	return true;
}

//validate radio button question - return true if something selected
function checkradio(formfield) {
	for (i=0;i<formfield.length;i++) {
		if (formfield[i].checked) {
			return true;
		}
	}
	return false;
}


