function FormatPhoneNumber(number_string, format_string) {
 num_of_x = 0;
 for (i = 0; i < format_string.length; i++) {
   if (format_string.charAt(i) == 'x') {
     num_of_x++;
   }
 }
 if (number_string.length != num_of_x) {
    if (number_string.length == 11) {
        //prefix = number_string.substr(0, 1);
        area_code = number_string.substr(1, 3);
        phone_num_prefix = number_string.substr(4, 3);
        phone_num_suffix = number_string.substr(7, 4);
        formatted_string = area_code+'-'+phone_num_prefix+'-'+phone_num_suffix;
        
        return formatted_string;
    } else {
        return number_string;
    }
 }
 else {
   formatted_string = "";
   pos = 0;
   for (i = 0; i < format_string.length; i++) {
     if (format_string.charAt(i) == 'x') {
       formatted_string += number_string.charAt(pos);
       pos++;
     }
     else {
       formatted_string += format_string.charAt(i);
     }
   }
   return formatted_string;
 }
}
