// email
function checkEmail (strng) {

	if (strng == "") return "Please enter a valid email address.\n";
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) return "Please enter a valid email address.\n";
	else {
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
		if (strng.match(illegalChars)) return "Please enter a valid email address.\n";
	}
	
	return "";

}


// phone number - strip out delimiters and check for 10 digits
function checkPhone (strng, required) {
	
	if (strng == "" && required == true) return "Please enter a valid phone number.\n";
	else if (strng == "") return "";
	
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped)))return "Please enter a valid phone number.\n";
	if (!(stripped.length == 10)) return "Please enter a valid phone number.\n";
	
	return "";

}

// phone number - strip out delimiters and check for 5 or 9 digits
function checkZIP (strng) {
	
	if (strng == "") return "Please enter a valid zip code.\n";
	
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) return "Please enter a valid zip code.";
	if ((stripped.length != 5) && (stripped.length != 9)) return "Please enter a valid zip code.\n";
	
	return "";

} 


// non-empty textbox
function isEmpty(strng, fieldName) {

	if (strng.length == 0) return "Please enter your " + fieldName +".\n"
	
	return "";

}

// form validation button
function validateMoreInfoForm(theForm) {
	
    var why = "";
    
    why += isEmpty(theForm.Name.value, "name");
	why += isEmpty(theForm.Address.value, "address");
	why += isEmpty(theForm.City.value, "city");
	why += isEmpty(theForm.State.value, "state");
	why += checkZIP(theForm.Zip.value);
	
	why += checkEmail(theForm.Email.value);
    why += checkPhone(theForm.Phone.value, false);
    
    if (why != "") {
       alert(why);
       return false;
    }
	
return true;

}