function formatPhone(fValue)
{
	var fValue   = fValue.replace(/[^0-9]/g, '').substring(0, 10);
	var newVal   = "";
	if (fValue.length > 0)
	{
		newVal = "(" + fValue.substring(0, 3);
	}
	if (fValue.length > 3)
	{
		newVal += ") " + fValue.substring(3, 6);
	}
	if (fValue.length > 6)
	{
		newVal += "-" + fValue.substring(6);
	}
	return newVal;
}





// This is the keypress handler that filters the user's input
function filter(field, event) {
		// Get the event object and character code in a portable way
		var e = event || window.event;         // Key event object
		var code = e.charCode || e.keyCode;    // What key was pressed

		// If this keystroke is a function key of any kind, do not filter it
		if (e.charCode == 0) return true;       // Function key (Firefox only)
		if (e.ctrlKey || e.altKey) return true; // Ctrl or Alt held down
		if (code < 32) return true;             // ASCII control character

		// Now look up information we need from this input element
		var allowed = "0123456789"; //this.getAttribute("allowed");     // Legal chars
/*
		var messageElement = null;                      // Message to hide/show
		var messageid = this.getAttribute("messageid"); // Message id, if any
		if (messageid)  // If there is a message id, get the element
				messageElement = document.getElementById(messageid);
	*/	
		// Convert the character code to a character
		var c = String.fromCharCode(code);
		
		// See if the character is in the set of allowed characters
		if (allowed.indexOf(c) != -1) {
				// If c is a legal character, hide the message, if any
				//if (messageElement) messageElement.style.visibility = "hidden";
				field.value = formatPhone(field.value + c);
				return false; // And accept the character
		}
		else {
				return false;

				// If c is not in the set of allowed characters, display message
				if (messageElement) messageElement.style.visibility = "visible";
				// And reject this keypress event
				if (e.preventDefault) e.preventDefault();
				if (e.returnValue) e.returnValue = false;
				return false;
		}
}








