// DynamicMonograming.js

// This function returns a string that has the specified capitalization performed.
// cap_type specifies what type of capitalization to use.  Valid values are:
//
//   U - Uppercase
//   L - Lowercase
//   P - Proper case (first letter upper, the rest lower)
//   N - No change to capitalization (default if none specified)
//
// EXAMPLES:
//
//    enforce_capitalization("Test String", "U")
// returns:
//    TEST STRING
//
//    enforce_capitalization("Test String", "P")
// returns:
//    Test string
//

function enforce_capitalization(input_string, cap_type) {
  try {
    // Verify we have a string object
    var text_full = new String(input_string);
    cap_type = new String(cap_type);
    cap_type = cap_type.toUpperCase();
    switch(cap_type) {
      case "L":
        // Lowercase
        return(text_full.toLowerCase());
        break;
      
      case "U":
        // Uppercase
        return(text_full.toUpperCase());
        break;
        
      case "P":
        // Proper case
        return(text_full.toLowerCase().replace(/^(.)|\s(.)/g, 
          function($1) { return $1.toUpperCase(); }));
        break;
        
      case "N":
      default:
        // No change - do nothing and return input unchanged
        return(input_string);
    }
    
    return(text_full);
  } catch(e) {}
  
  // We have an error. Return the original string.
  return(input_string);
}


