// Add trim to strings:
function strtrim() {
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
String.prototype.trim = strtrim;
	
function isEmpty(iStr) {
	return (iStr == null || iStr == "" || iStr.trim() == "")
}

// valid email
function isValidEmail(sEmail) {
 // sEmail must contain at least one @ and at least one period, neither at beginning or end
	var iPos = sEmail.indexOf("@");
	if (iPos <= 0 || iPos == sEmail.length-1) {
		alert("Please enter a valid Email address.");
		return false;
	}
	iPos = sEmail.indexOf(".");
	if (iPos <= 0 || iPos == sEmail.length-1) {
		alert("Please enter a valid Email address.");
		return false;
	}
	return true;
}

// Valid info on contact form:
function isValidInput(frmForm) {
 // Name must be non-empty, and Phone must be at least 7 characters
 // If not empty, Email check isValidEmail
	var sName = frmForm.required_Name.value;
	if (isEmpty(sName)) {
		alert("Please enter your Name.");
		return false;
	}
	var sPhone =  frmForm.required_Phone.value;
	if (isEmpty(sPhone)) {
		alert("Please enter your Phone number.");
		return false;
	}
	if (sPhone.trim().length < 7) {
		alert("Please enter a valid Phone number.");
		return false;
	}
	var sEmail = frmForm.EmailFrom.value;
	if (!isEmpty(sEmail)) {
		if (!isValidEmail(sEmail)) {
			return false;
		}
	}
	return true;
}
