// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function clean_word_string(to_do)
{
	// replace newlines with spaces
	var re = /\n/g;
	to_do = to_do.replace(re, " ");
	var re = /\r/g;
	to_do = to_do.replace(re, " ");

	// replace tabs with spaces
	var re = /\t/g;
	to_do = to_do.replace(re, " ");

	re = /  /g; // two spaces
	// collapse any multiple spaces to single spaces
	while (to_do.indexOf("  ") != -1)
		to_do = to_do.replace(re, " ");

	// trim off leading spaces
	while (to_do.charAt(0) == " ")
		to_do = to_do.substring(1);
	return to_do;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function clean_and_trim_ends(s)
{
	// \t,\n to spaces, spaces singularized, leading spaces trimmed
	s = top.clean_word_string(s);
	s = trim_ends(s);
	return s;	
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function trim_ends(s)
{
	var c1

	// trim leading end
	while (true)
	{
		if (s.length == 0)
			break;
		c1 = s.charAt(0);
		if (c1 == " " || c1 == "\n" || c1 == "\t" || c1 == "\r")		
			s = s.substring(1);
		else
			break;
	}

	// trim trailing end
	while (true)
	{
		if (s.length == 0)
			break;
		c1 = s.charAt(s.length - 1);
		if (c1 == " " || c1 == "\n" || c1 == "\t" || c1 == "\r")		
			s = s.substring(0, s.length - 1);
		else
			break;
	}

	return s;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function only(str, oclist)
{
	for (var i = 0; i <= str.length; i++)
		if (oclist.indexOf(str.charAt(i)) == -1)
			return false;
	return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
