﻿function ParseUSNumber(PhoneNumberInitialString) {
            var FmtStr="";
            var index = 0;
            var LimitCheck;

	if (PhoneNumberInitialString == "") {
	return FmtStr;
	}
            LimitCheck = PhoneNumberInitialString.length;
            while (index != LimitCheck)
                  {
                        if (isNaN(parseInt(PhoneNumberInitialString.charAt(index))))
                              { }
                        else
                              { FmtStr = FmtStr + PhoneNumberInitialString.charAt(index); }
                        index = index + 1;
                  }

    if (FmtStr.length < 10)
                  {
	alert("Wait! You are missing a few digits in your\nphone number. Please check it and try again.\nFormat using 10 digit area code and number\n\n            (555) 555-5555");        }

    if (FmtStr.length > 10)
                  {
	alert("Wait! You are have entered too many digits\nin your phone number. Please check it and try again.\nFormat using 10 digit area code and number\n\n            (555) 555-5555");        }


            if (FmtStr.length == 10)
                  {
                        FmtStr = "(" + FmtStr.substring(0,3) + ") " + FmtStr.substring(3,6) + "-" + FmtStr.substring(6,10);
                  }
            else
                  {
                        FmtStr=PhoneNumberInitialString;    }
            return FmtStr;
      }

