function numbersOnly($str) {
	$s = $str.replace(/\D/g,"");
	return $s;
}

function checkEmail($f) {
// optional 2nd argument: "quiet" suppresses alert messages	
	$str = $f.value;
	filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
	if (!filter.test($str) && $str.length > 0) {
		if (arguments[1]!="quiet") {
			errorBubble("<b>Sorry!</b><br />There appears to be a problem with your email address.");
		}
		return false;
	} else {
		return true;
	}
}

function checkPhone($f) {
// optional 2nd argument: "quiet" suppresses alert messages
	$str = $f.value;
	$s = "";
	if ($str.length>0) {
		// remove all non-numbers
		$s = numbersOnly($str);
		if ($s.length != 10) {
			if (arguments[1]!="quiet") {
				errorBubble("<b>Sorry!</b><br />There appears to be a problem with your Phone Number.");
			}
		}
		$str = "(" + $s.substr(0,3) + ") " + $s.substr(3,3) + "-" + $s.substr(6);
	}
	return $str;
}

function proper($str) {
	return $str.substr(0,1).toUpperCase() + $str.substr(1).toLowerCase();
}
	
function checkForm(f) {
	errorFlag = false;
	message = "Sorry, there appears to be a problem with your form submission.\n\n";
// name
	if (f.elements["name"].value.length < 3) {
		errorFlag = true;
		message += " - Please enter your name.\n";
	}
	
// company
	if (f.elements["company"].value.length < 3) {
		errorFlag = true;
		message += " - Please enter your company name.\n";
	}
	
// Check phone # for valid characters
	temp = checkPhone(f.elements["phone"],"quiet");
	if (temp.length < 14) {
		message += " - Please enter your 10 digit phone number.\n";
		errorFlag = true;
	}
		
// Check for valid email syntax
	if (!checkEmail(f.elements["email"],"quiet") || f.elements["email"].value.length < 1) {
		errorFlag = true;
		message += " - Please enter a valid email address.\n";
	}
	
// comments
/*	if (f.elements["comments"].value.length < 10) {
		errorFlag = true;
		message += " - Please provide your campaign details or comments.";
	}
*/
	
// Final routine	
	if (errorFlag) {
		alert(message);
		return false;
	} else {
		return true;
	}
}
