// replace all occurrences of strng with rep in a string
String.prototype.replace = function (strng, rep) {
var temparray = this.split(strng);
return temparray.join(rep);
}

(http://proto.layer51.com/d.aspx?f=17)