
//var reNoMB = /  /g;
var reNoMB   = /  /;
var reNoB    = / /;
var repNoB   = "";
var repSnglB = " ";

// ***************************************************************************
// *                                                                         *
// * Function: trimNoMB( aStr )                                              *
// *                                                                         *
// * Description:                                                            *
// *   Removes leading/trailing blanks from aStr.                            *
// *                                                                         *
// * Dependencies:                                                           *
// *                                                                         *
// ***************************************************************************
function trimNoMB( aStr ) {
 var aTrimmedStr = "";

 if ( aStr.length == 0 ) { // If null string, then nothing to do
   return aStr;
 }
 else {                    // otherwise, remove leading & trailing blanks
   aTrimmedStr = trim( aStr );
   aTrimmedStr = NoMB( aTrimmedStr );

   return aTrimmedStr;
 }
}


// ***************************************************************************
// *                                                                         *
// * Function: NoMB( aStr )                                                  *
// *                                                                         *
// * Input(s):                                                               *
// *   aStr - string, which is to be modified                                *
// *                                                                         *
// * Description:                                                            *
// *   Change all occurrences of multiple blanks to a single blank.          *
// *                                                                         *
// ***************************************************************************
function NoMB( aStr ) {
  //                              in, re for replacement, replacement str
  var tempStr = iterativeReplace( aStr, reNoMB, repSnglB );
  return tempStr;
}

// ***************************************************************************
// *                                                                         *
// * Function: NoB( aStr )                                                   *
// *                                                                         *
// * Input(s):                                                               *
// *   aStr - string, remove all blanks from this string.                    *
// *                                                                         *
// * Description:                                                            *
// *   Remove all blanks from aStr & return it as the output value.          *
// *                                                                         *
// ***************************************************************************
function NoB( aStr ) {
 var tempStr = iterativeReplace( aStr, reNoB, repNoB );
 return tempStr;
}


// ***************************************************************************
// *                                                                         *
// * Function: NoD( aStr )                                                   *
// *                                                                         *
// * Input(s):                                                               *
// *   aStr - string                                                         *
// *                                                                         *
// * Description:                                                            *
// *   Remove all dashs from aStr & return it as the output value.           *
// *                                                                         *
// ***************************************************************************
function NoD( aStr ) {
 var tempStr = iterativeReplace( aStr, "-", "" );
 return tempStr;
}


// ***************************************************************************
// *                                                                         *
// * Function: iterativeReplace( aStr, re, repStr )                          *
// *                                                                         *
// * Input(s):                                                               *
// *   aStr - string, to be interatively replaced                            *
// *   re   - reg. exp., to drive the replacments                            *
// *   repStr - string, replacment string                                    *
// *                                                                         *
// * Description:                                                            *
// *   Based on re, substrings within aStr are replaced with repStr          *
// *   until RE's replace() results in no further change to aStr.            *
// *                                                                         *
// ***************************************************************************
function iterativeReplace( aStr, re, repStr ) {
 var strPrev = "", strCur = "";

 if ( aStr.length == 0 ) { // If null string, then nothing to do
   return aStr;
 }
 else {                    // otherwise, remove leading & trailing blanks
   strCur = aStr;
   while( strCur != strPrev ) {
     strPrev = strCur;
     strCur = strCur.replace( re, repStr );
   }
   return strCur;
 }
}


// ***************************************************************************
// *                                                                         *
// * Function: trim( aStr )                                                  *
// *                                                                         *
// * Input(s):                                                               *
// *   aStr - string, which is to be modified                                *
// *                                                                         *
// * Description:                                                            *
// *   Removes leading/trailing blanks from aStr.                            *
// *                                                                         *
// ***************************************************************************
function trim( aStr ) {
 var aTrimmedStr = "";

 if ( aStr.length == 0 ) { // If null string, then nothing to do
   return aStr;
 }
 else {                    // otherwise, remove leading & trailing blanks
   aTrimmedStr = trimLeading( aStr );
   aTrimmedStr = trimTrailing( aTrimmedStr );

   return aTrimmedStr;
 }
}


// ***************************************************************************
// *                                                                         *
// * Function: trimLeading( aStr )                                           *
// *                                                                         *
// * Input(s):                                                               *
// *   aStr - string, which is to be modified                                *
// *                                                                         *
// * Description:                                                            *
// *   Removes leading blanks from aStr.                                     *
// *                                                                         *
// ***************************************************************************
function trimLeading( aStr ) {
//while(''+this.value.charAt(0)==' ')this.value=this.value.substring(1,this.value.length);
 if ( aStr.length == 0 ) { // If null string, then nothing to do
   return aStr;
 }
 else {                    // otherwise, remove leading & trailing blanks
   while( ''+aStr.charAt( 0 ) == ' ' && aStr.length >= 1 ) {
     aStr = aStr.substring( 1 );
   }
 }
 return aStr;
}


// ***************************************************************************
// *                                                                         *
// * Function: trimTrailing( aStr )                                          *
// *                                                                         *
// * Input(s):                                                               *
// *   aStr - string, which is to be modified                                *
// *                                                                         *
// * Description:                                                            *
// *   Removes trailing blanks from aStr.                                    *
// *                                                                         *
// ***************************************************************************
function trimTrailing( aStr ) {
//while(''+this.value.charAt(this.value.length-1)==' ')this.value=this.value.substring(0,this.value.length-1);
 if ( aStr.length == 0 ) { // If null string, then nothing to do
   return aStr;
 }
 else {                    // otherwise, remove leading & trailing blanks
   while( ''+aStr.charAt( aStr.length-1 ) == ' ' && aStr.length >= 1  ) {
     aStr = aStr.substring( 0, aStr.length-1 );
   }
 }
 return aStr;
}
