<!--
function cleanString(s) {
	var ch;
	var sout = "";

	for (var i = 0; i < s.length; i++) {
		// walk through the string and remove all non-digits
		ch = s.charAt(i);
		if ((ch >= "0") && (ch <= "9")) {
			sout += ch;
		}
	}

	return sout;
}

function checkphone(ctrl) {
	var phonein = ctrl.value;
	var phoneout = "";

	phoneout = cleanString(phonein);

	// format main number	
	if (phoneout.length == 10) {
		phoneout = "(" + phoneout.substring(0,3) + ") " + phoneout.substring(3,6) + "-" + phoneout.substring(6,10);
	} else {
		if (phoneout.length == 7) {
			phoneout = phoneout.substring(0,3) + "-" + phoneout.substring(3,7);
		} else {
			if ((phoneout.length == 11) && (phoneout.charAt(0) == "1")) {
				// remove the leading 1
				phoneout = "(" + phoneout.substring(1,4) + ") " + phoneout.substring(4,7) + "-" + phoneout.substring(7,11);
			}
		}
	}
	ctrl.value = phoneout;
}
//-->