What is probably happening is the following:
+Your script searches for any occurences of "a"
+Your script finds "a" and replaces it with "b"
+Your script searches for "b"
+Your script finds "b", including the "b" that originally was an "a", and replaces it with "c".
The better way to replace letters where there is a possibility of the replacement letter being replaced itself (if that makes any sense outside of my head) is to just loop through each letter in the string.
e.g.
code:
var teststring = "Hello World";
var testarray = teststring.split(""); //convert string into an array
for(i=0;i<testarray.length;i++){
//do replacing here, get current character with testarray[i];
}
teststring = testarray.join(""); //convert array back to a string