function fmGetFormControl(elem) {
	if (elem == null) elem= event.srcElement;
  while (elem != null) {
		if (elem.className == "FormContainer") return elem;
		if (elem.tagName.toUpperCase() == "BODY") return null;
		if (elem.tagName.toUpperCase() == "FORM") return null;
	  elem= elem.parentElement;
  }
}
function UnicodeToUTF8(s)
{
	if (!s)
	{
		return "";
	}

	s = escape(s);

	s = s.replace(/%20/g, " ");
	s = s.replace(/%u(\w{4})/g,	"&#x$1;");
	s = s.replace(/%(\w{2})/g,	"&#x$1;");

	return s;
}

// Takes the UTF8 version of a string (that is stored in the database), converts those values
// into Unicode equivalents, and then unencodes the Unicode so the actual characters are used
function UTF8ToUnicode(s)
{
	// Check input param
	if (!s)
	{
		return "";
	}
	
	// Do the appropriate replacements
	s = s.replace(/&#x(\w{2});/g, function($0,$1) {
			return (unescape("%" + $1));});
	s = s.replace(/&#x(\w{4});/g, function($0,$1) {
			return (unescape("%u" + $1));});
	
	return s;
}

function ConvertUserTypeToLike(searchValue)
{
	var s = "";
	var sChar = "";
	var iLength = searchValue.length;

	for (var i = 0; i < iLength; i++)
	{
		sChar = searchValue.charAt(i);
		switch (sChar)
		{
			case "%":	s += "[%]";	break;
			case "_":	s += "[_]";	break;
			case "[":	s += "[[]";	break;
			case "*":	s += "%";	break;
			default:	s += sChar;	break;
		}
	}

	return s;
}

function GetNodeValue(input, searchName, bNoDecode)
{
	if (!input || !searchName)
	{
		return "";
	}

	var rootStart = input.indexOf('<' + searchName + '>');
	
	if (rootStart == -1)
	{
		// could be a node with attributes
		rootStart = input.indexOf('<' + searchName + ' ');

		if (rootStart == -1)
		{
			return "";
		}
	}
	
	var startIndex	= input.indexOf(">", rootStart) + 1;
	var endIndex = input.indexOf("</" + searchName + '>', startIndex);

	return bNoDecode ? input.substring(startIndex, endIndex) :
						decodeXml(input.substring(startIndex, endIndex));
}