/////////////////////////////////////////////////////////////////////////
//////////                      trim                           //////////
/////////////////////////////////////////////////////////////////////////
// Purpose:  Takes a given string, trims all spaces, tabs, carraige
//           restores and newline characters from its front and back,
//           and returns the trimmed string.
/////////////////////////////////////////////////////////////////////////
// Syntax:  trim(string)
//  
// Where 'string' is the string to be trimmed
//
// Returns:  the string with spaces, tabs, carrage returns & newline chars
//           trimmed from its front and back
/////////////////////////////////////////////////////////////////////////
function trim(targetString) {

  // Strip trailing blanks, tabs, newlines, and carraige returns
  while ( targetString.length > 0 && " \t\r\n".indexOf(targetString.charAt(targetString.length-1)) > -1 )
    targetString = targetString.substring(0, targetString.length-1);

  // Strip leading blanks, tabs, newlines, and carraige returns
  while ( targetString.length > 0 && " \t\r\n".indexOf(targetString.charAt(0)) > -1 )
    targetString = targetString.substring(1, targetString.length);

  return targetString;
}

