﻿function fnReplace(sString, sToBeReplaced, sReplaceWith) {
	// Replaces sToBeReplaced with sReplaceWith in string
	var strLength = sString.length, txtLength = sToBeReplaced.length;
	if ((strLength == 0) || (txtLength == 0)) return sString;

	var i = sString.indexOf(sToBeReplaced);
	if ((!i) && (sToBeReplaced != sString.substring(0, txtLength))) return sString;
	if (i == -1) return sString;

	var newstr = sString.substring(0, i) + sReplaceWith;

	if (i+txtLength < strLength)
	    newstr += fnReplace(sString.substring(i+txtLength,strLength), sToBeReplaced, sReplaceWith);

	return newstr;
}

