function xml_get_field(xmldoc, field_name)
{
	var xml_array = xmldoc.getElementsByTagName(field_name);
	if( xml_array.length > 0 )
	{
		if( xml_array[0].firstChild != null )
		{

			// If the client is using mozilla, we fetch the xml element differently as Mozilla has a bug not allowing more than 4096 chars in each element.
			if( true == isMoz() )
			{
				return xml_array[0].textContent;
			}
			else
			{
				return xml_array[0].firstChild.nodeValue;
			}
		}
		else
		{
			return "";
		}
	}
	else
	{
		return "";
	}
}

/**
 * Returns true or false if browser is mozilla
 *
 * @return bool
 */
function isMoz()
{
	// Set the default value to false.
	var moz = false;

	if ( !document.layers )
	{
		// Is the browser Konquerer.
		konq = ( navigator.userAgent.indexOf( 'Konqueror' ) != -1 );

		// Is the browser Safari?
		saf = ( navigator.userAgent.indexOf( 'Safari' ) != -1 );

		// Is the browser Mozilla?
		moz = ( navigator.userAgent.indexOf( 'Gecko' ) != -1 && !saf && !konq);
	}

	return moz;
}

/**
 * Trim
 *
 * @param string str
 * @param string chars
 *
 * @return string
 */
function trim(str, chars)
{
    return ltrim(rtrim(str, chars), chars);
}

/**
 * Left Trim
 *
 * @param string str
 * @param string chars
 *
 * @return string
 */
function ltrim(str, chars)
{
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

/**
 * Right Trim
 *
 * @param string str
 * @param string chars
 *
 * @return string
 */
function rtrim(str, chars)
{
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/**
 * Restricts a form field with an id of field_id to be maxChars in length
 *
 * It should be called onkeyup and onchange from the form field declaration.
 *
 * If the form element with id of charsleft_text_id exists (usually a <span> element),
 * a count of how many characters can still be entered will be automatically displayed
 * inside that element.
 *
 * @param field_id				-- the id of the form field to limit the max characters on
 * @param charsleft_text_id		-- the id of the html element of where to display the number of characters remaining
 * @param maxChars				-- the maximum allowed characters
 * @param exclude_line_breaks 	-- if true, excludes line breaks from the count of total characters (defaults to false if ommitted)
 */
function checkMaxChars(field_id, charsleft_text_id, maxChars, exclude_line_breaks)
{
	var formField = document.getElementById(field_id);
	var length_of_line_breaks = 0;

	// Attempt to access the <span> element that contains the count of the number of characters left to enter.
	if( charsleft_text_id.length > 0 )
	{
		var charsLeftField = document.getElementById(charsleft_text_id);
	}


	var linebreak_count = 0;

	var check_text = formField.value.replace(/\r/g, "");

	charsLeftField.innerHTML = maxChars - check_text.length;
}
