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 check_int_quote(form) {
	if (isBlank(form.cust_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; }

	if (form.current_site.value){
		if (!isValidDomain(form.current_site.value)){
			alert("Please enter a valid site url.");
			form.current_site.focus();
			form.current_site.select();
			return false;
		}	
	}
	if (form.current_domain.value){
		if (!isValidDomain(form.current_domain.value)){
			alert("Please enter a valid domain name.");
			form.current_domain.focus();
			form.current_domain.select();
			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;
}

function isValidDomain(domain) {
	var dot = domain.lastIndexOf(".");
	if (dot <= 0) {
		return false;
	}
	//must be at least a period and 2 characters at the end
	if (dot == domain.length-1 || dot == domain.length-2 || dot < domain.length-5) {
		return false;
	}
	return true;
}



