function validatesub(me){
	with (me) {
		if(!isValidEmail(email.value)){return false;}
		if(!isValid(name.value,"Please enter your name.",1)){return false;}
		if(!isValid(address.value,"Please enter your address.",1)){return false;}
		if(!isValid(city.value,"Please enter your city.",1)){return false;}
		if(!isValid(state.value,"Please enter your state.",2)){return false;}
		if(!isValidNum(zip.value,"Please enter your 5 digit ZipCode.",5)){return false;}
		if(!isValidPhone(phone.value)){return false;}
	}
	return true;
}

function validateunsub(me){
	with (me) {
		if(!isValidEmail(email.value)){return false;}
	}
	return true;
}

function isValid(s,text,lmin) {
	s = s.replace(/ /g,"");
	if (s.length < lmin){
		alert(text);
		return false;
	}
	else
		return true;
}

function isValidNum(s,text) {
	s = s.replace(/ /g,"");
	if (s.length == 0 || isNaN(s)){
		alert(text);
		return false;
	}
	else
		return true;
}

function isValidNumE(s,text,len) {
	s = s.replace(/ /g,"");
	if (s.length != len || isNaN(s)){
		alert(text);
		return false;
	}
	else
		return true;
}

function isValidEmail (s) {
	if (s.length == 0) {
   		alert("You didn't enter an email address.");
		return false;
	}
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(s))) { 
       alert("Please enter a valid email address.");
	   return false;
    }
    else {
//test email for illegal characters
       var illegalChars=/[\(\)\<\>\,\;\:\\\"\[\]]/;
         if (s.match(illegalChars)) {
          alert("The email address contains illegal characters.");
		  return false;
       }
    }
	return true;    
}

function isValidPhone (s) {
	if (s.length == 0) {
   		alert("You didn't enter a phone number.\n");
		return false;
	}
	var stripped = s.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(stripped)) {
       alert("The phone number contains illegal characters.");
	   return false;
    }
    if (!(stripped.length == 10)) {
		alert("The phone number is the wrong length. Make sure you included an area code.\n");
		return false;
    } 
	return true;
}


function isValidUserPass(s){
	if (s.length < 6 || s.length > 10){
		alert("Username and Password must be between 6 and 10 characters.");
		return false;
	}
		return true;
}
