function replace(main_string,search_string,replace_string) { var x ; var principal_string = main_string ; x = principal_string.indexOf(search_string,0) ; while( x != -1) { principal_string = principal_string.substring(0,x) + replace_string + principal_string.substring(x+search_string.length,principal_string.length) ; x = principal_string.indexOf(search_string,x) } return principal_string ; }