String.prototype.isPhoneNumber = function() {
	return /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/.test(this);
}
function formatPhone(theField) {
	if (theField.value.length > 0) {
		var Phone = theField.value.replace(/\D/g,"");
		if (Phone.length == 10) {
			theField.value = "(" + Phone.substring(0,3) + ")" + Phone.substring(3, 6) + "-" + Phone.substring(6, 10);
		} else if ((Phone.length == 11) && (Phone.substring(0,1) == "1")) {
			theField.value = "(" + Phone.substring(1,4) + ")" + Phone.substring(4, 7) + "-" + Phone.substring(7, 11);
		}
		if (theField.value.isPhoneNumber() == false) {
			alert(theField.value + " is an invalid phone number, please try again...");
			theField.focus();
			theField.select();
		}
	}
}
