String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};

function check_contact(form) {
	if (isBlank(form.first_name, "Please enter your first name")) { return false; }
	if (isBlank(form.last_name, "Please enter your last name")) { return false; }	
	if (isBlank(form.email, "Please fill in an email address.")) { return false; }
	if (!isValidAddress(form.email.value)) {
		alert("Please enter a valid e-mail address.");
		form.email.focus();
		form.email.select();
		return false;
	}
	
	return true;
}


function check_quote(form) {
	if (isBlank(form.name, "Please enter your name")) { return false; }	
	if (isBlank(form.email, "Please fill in an email address.")) { return false; }
	if (!isValidAddress(form.email.value)) {
		alert("Please enter a valid e-mail address.");
		form.email.focus();
		form.email.select();
		return false;
	}
	if (isBlank(form.phone, "Please enter your phone number")) { return false; }
	
	return true;
}


function isBlank(obj, message) {
	if (obj.value == "") {
		alert(message);
		obj.focus();
		return true;
	}
	
	return false;
}

function isValue(obj, value, message) {
	if (obj.value == value) {
		alert(message);
		obj.focus();
		return true;
	}
	
	return false;
}

function isValidAddress(addr) {
	index1 = addr.indexOf("@");
	if (index1 <= 0) {
		return false;
	}
	index2 = addr.indexOf(".", index1);
	if (index2 < index1) {
		return false;
	}
	
	//must be at least a period and 2 characters at the end
	if (index2 == addr.length-1 || index2 == addr.length-2) {
		return false;
	}
	return true;
}