// Returns a specified number of characters from a string (zero-based!)
function Mid(str, start, len) {
	// Make sure start and len are within proper bounds
	if (start < 0 || len < 0) return "";

	var iEnd, iLen = String(str).length;
	if (start + len > iLen)
		iEnd = iLen;
	else
		iEnd = start + len;

	return String(str).substring(start,iEnd);
}

// Returns string length
function Len(str) {
	return String(str).length;
}

// 
function InStr(strSearch, Searchpart){
	return strSearch.indexOf(Searchpart);
}

// Replace string in string
function Replace(string, text, by) {
	var strLength = string.length, txtLength = text.length;
	
	if ((strLength == 0) || (txtLength == 0)) return string;
	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;
	var newstr = string.substring(0,i) + by;
	if (i+txtLength < strLength) newstr += Replace(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}

// Replace char in string
function ReplaceChar(str, find, replacement) {
	var i, newstr = "";
	
	if (find.length = 1) {
		// Currently only works with single char replacement
		for (i = 0; i < str.length; i++){
			if (str.charAt(i) == find) {
				newstr += replacement;
			} else {
				newstr += str.charAt(i);
			} 
		}
		return newstr;
	} else {
		// Replace only first occurence
		return str.replace(find, replacement)
	}
}