function formatPhone()
{
     var theCount = 0;
     var theString = document.contact.Phone.value;
     var newString = "";
     var myString = theString;
     var theLen = myString.length;
     for ( var i = 0 ; i < theLen ; i++ )
     {
     // Character codes for ints 1 - 9 are 48 - 57
          if ( (myString.charCodeAt(i) >= 48 ) && (myString.charCodeAt(i) <= 57) )
          newString = newString + myString.charAt(i);   
     }
// Now the validation to determine that the remaining string is 9 characters.
     if (newString.length == 10 )
     {
// Now the string has been stripped of other chars it can be reformatted to ###-##-#### 
          var newLen = newString.length;
          var newPhone = "";
          for ( var i = 0 ; i < newLen ; i++ )
          {
              if ( i == 2 ) { newPhone = "(" + newPhone + newString.charAt(i) + ") "; }
else if ( i == 5 )  { newPhone = newPhone + newString.charAt(i) + "-"; }
else{
                    newPhone = newPhone + newString.charAt(i);
               }
          }
          document.contact.Phone.value = newPhone;
          return true;
     }else{
          alert("The phone number you entered "+newString+" does not contain the correct number of digits");
	    document.contact.Phone.value='';
          document.contact.Phone.focus();
          return false;
     }
}
