function tinymce_custom_cleanup (type, content) {
	switch (type) {
		case 'insert_to_editor':
		case 'get_from_editor':
		case 'submit_content':
			var str = content;
		
			// strip all tags except for the allowed set
			str = str.replace (/<(\/?(b|i|u|a|br|em|strong|p|ul|ol|li|span|sub|sup|blockquote)\b[^>]*)>/ig, "\x01$1\x02");
			str = str.replace (/<[^>]*>/ig, "");
			str = str.replace (/\x01([^\x02]*)\x02/ig, "<$1>");
			
			// replace all attributes on all tags except "a", "span", and "p"
			str = str.replace (/<([^asp]\w*) [^>]*>/ig, "<$1>");
			
			// remove lone nbsp
			str = ">" + str;
			str = str.replace (/(>\s*)&nbsp;(\s*<)/ig, "$1$2");
			str = str.substr(1);
		
			// convert double BR tags to P tags
			str = str.replace (/<br>\s*<br>/ig, "</p><p>");
		
			// remove empty p tags
			str = str.replace(/<p><\/p>/ig, "");	

			//if (str != content) {alert(str);}
	
			return (str);
		break;
		default:
			return content;
		break;
	}
}
