replace string(s)


  
  // Funtion to replaces all occurances of substring substr1 with substr2 within strng
  // if type == 0 straight string replacement
  // if type == 1 assumes padded strings and replaces whole words only
  // if type == 2 non case sensitive assumes padded strings to compare whole word only
  // if type == 3 non case sensitive straight string replacement
  
          var RPstrg = "";
  
          function replaceStr( strng, substr1, substr2, type){
                  var pntr = -1; aString = strng;
                  if( type == 0 ){  
                          if( strng.indexOf( substr1 ) >= 0 ){ pntr = strng.indexOf( substr1 );        }
                  } else if( type == 1 ){ 
                          if( strng.indexOf( " "+ substr1 +" " ) >= 0 ){ pntr = strng.indexOf( " " + substr1 + " " ) + 1; }        
                  } else if( type == 2 ){ 
                          bstrng = strng.toUpperCase();
                          bsubstr1 = substr1.toUpperCase();
                          if( bstrng.indexOf( " "+ bsubstr1 +" " )>= 0 ){ pntr = bstrng.indexOf( " " + bsubstr1 + " " ) + 1; }        
                  } else {
                          bstrng = strng.toUpperCase();
                          bsubstr1 = substr1.toUpperCase();
                          if( bstrng.indexOf( bsubstr1 ) >= 0 ){ pntr = bstrng.indexOf( bsubstr1 ); }        
                  }
                  if( pntr >= 0 ){
                          RPstrg += strng.substring( 0, pntr ) + substr2;
                          aString = strng.substring(pntr + substr1.length, strng.length );
                          if( aString.length > 0 ){ replaceStr( aString, substr1, substr2, type ); }
                  }
                  aString =  RPstrg + aString;
                  RPstrg = "";
                  return aString;
          }