
function stringFilter(str) {
	// Characters leave
	filteredValues = "1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var i;
	var returnString = "";
	for (i = 0; i < str.length; i++) {  // Search through string and append to unfiltered values to returnString.
		var c = str.charAt(i);
		if (filteredValues.indexOf(c) >= 0) returnString += c;
	}
	return returnString;
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}



function replace( str, from, to ) {
	var idx = str.indexOf( from );

	while ( idx > -1 ) {
		str = str.replace( from, to );
		idx = str.indexOf( from );
	}

	return str;
}



// Zero padding
function pad0(string, newlength) {
  var pad = "";
  var len = newlength-String(string).length;
  var i;
  for (i = 0; i<len; i++) {
    pad += "0";
  }
  return pad+string;
}




function capitalizeMe(str) {
	var val = str;
	newVal = '';
	val = val.split(' ');
	for(var c=0; c < val.length; c++) {
		newVal += val[c].substring(0,1).toUpperCase() + val[c].substring(1,val[c].length).toLowerCase() + ' ';
	}
	return newVal.substring(0,newVal.length-1);
}




// Fixes some charcode issues
function fixContent(html) {
    html = html.replace(new RegExp('<(p|hr|table|tr|td|ol|ul|object|embed|li|blockquote)', 'gi'),'\n<$1');
    html = html.replace(new RegExp('<\/(p|ol|ul|li|table|tr|td|blockquote|object)>', 'gi'),'</$1>\n');
    html = tinyMCE.regexpReplace(html, '<br />','<br />\n','gi');
    html = tinyMCE.regexpReplace(html, '\n\n','\n','gi');
    return html;
}



// Checks length, returns false if length is reached or too much
function CheckLength(obj, maxlength) {
	if (obj.value.length >= parseInt(maxlength)) {
		return false;
	}
	return true;
}

