function validName(theAddr) {
	if (theAddr.length < 3) {
		return false;
	}
	return true;
}
	
	
function validEmail(email) {
		invalidChars = " /:,;"
		if (email == "") {
			return false;
		}
		for (i=0; i<invalidChars.length; i++) {
			badChar = invalidChars.charAt(i);
			if (email.indexOf(badChar,0) != -1) {
				return false;
			}
		}
		atPos = email.indexOf("@",1);
		if (atPos == -1) {
			return false;
		}
		if (email.indexOf("@",atPos+1) != -1) {
			return false;
		}
		periodPos = email.indexOf(".",atPos)
		if (periodPos == -1) {
			return false;
		}
		if (periodPos+3 > email.length)	{
			return false;
		}
		return true;
}
 
		
function validPhone(ph) {
	if (ph < " ") {
		return false;	
    } 
	Nbrs = 0;
	validChars = "+()1234567890-eExXtT. ";
	for (z=0; z<ph.length; z++) { 
		charOK=false;
		for (i=0; i<validChars.length; i++) {
				if (ph.charAt(z)== validChars.charAt(i) ) {
					charOK=true;
					break;
				} 
		}
		if (!charOK)  return false;
		Nbrs++;
	}
	
	if (Nbrs < 10) {
		return false;
	}			
	return true;
}
		
		
		
function submitIt(theForm) { 
		if (!(validName(theForm.firstname.value)) ) {
			alert("Please enter your first name");
			theForm.firstname.focus();
			theForm.firstname.select();
			return false;
		}
		
		if (!(validName(theForm.lastname.value)) ) {
			alert("Please enter your last name");
			theForm.lastname.focus();
			theForm.lastname.select();
			return false;
		}
		
	if (theForm.phone.value.length > 0 ) {
		if (!(validPhone(theForm.phone.value))) {
			alert("Please enter your valid phone number\n like (xxx) xxx-xxxx");
			theForm.phone.focus();
			theForm.phone.select();
			return false;
		} 
	}
		if (!(validEmail(theForm.email.value))) {
			alert("Please enter your valid email address\nso we may contact you");
			theForm.email.focus();
			theForm.email.select();
			return false;
		} 
	 
		if (theForm.fax.value.length > 0 ) {
			if (!(validPhone(theForm.fax.value))) {
				alert("Please enter your valid fax number\n like (xxx) xxx-xxxx\nor leave blank");
				theForm.fax.focus();
				theForm.fax.select();
				return false;
			} 
		} 
	return true;
}
 
