Javascript Replace doesn't work like .net
Java script replace only replaces the first instance. This function replaces all instances without going into a endless loop replacing the same 'toberep' and 'repwith'.
function xreplace(checkMe,toberep,repwith){
var temp = checkMe;
var i = temp.indexOf(toberep);
while(i > -1)
{
temp = temp.replace(toberep, repwith);
i = temp.indexOf(toberep, i + repwith.length + 1);
}
return temp;
}