
function URLEncode(input) {
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
	"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
	"abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var plaintext = input;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++) {
		var ch = plaintext.charAt(i);
		if (ch == " ") {
			encoded += "+";				// x-www-urlencoded, rather than %20
		} else {
			if (SAFECHARS.indexOf(ch) != -1) {
				encoded += ch;
			} else {
				var charCode = ch.charCodeAt(0);
				if (charCode > 255) {
					alert("Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" + "(URL encoding only supports 8-bit characters.)\n" + "A space (+) will be substituted.");
					encoded += "+";
				} else {
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 15);
					encoded += HEX.charAt(charCode & 15);
				}
			}
		}
	} // for
	document.URLForm.F2.value = encoded;
	return false;
}
/** 
		 * Remove white space from either side of a string
		 **/
function trimAll(sString) {
	while (sString.substring(0, 1) == " ") {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length - 1, sString.length) == " ") {
		sString = sString.substring(0, sString.length - 1);
	}
	return sString;
}

/**
 * Count the number of words in a given input
 **/
function countWords(this_field) {
	var char_count = this_field.value.length;
	var fullStr = this_field.value + " ";
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var splitString = cleanedStr.split(" ");
	var word_count = splitString.length - 1;
	if (fullStr.length < 2) {
		word_count = 0;
	}
	if (word_count == 1) {
		wordOrWords = " word";
	} else {
		wordOrWords = " words";
	}
	if (char_count == 1) {
		charOrChars = " character";
	} else {
		charOrChars = " characters";
	}

	return word_count;
}

