//****************************************************************************

function formMgmt_FindFormOfUniqueWidgetID(inWidgetID){

	var theResult = "";

	for(var i = 0, max = document.forms.length; i < max; i++){

		if(document.forms[i][inWidgetID] != undefined){

			theResult = document.forms[i];

			break;
		}
	}

	if(theResult == "undefined" || theResult == undefined)
		alert(inWidgetID + " couldnt be found in formMgmt_FindFormOfUniqueWidgetID()!");

	return theResult;
}


function formMgmt_CheckboxIsChecked(inFormName, inCheckboxName)
{
	var theResult = false;
	var theCheckbox = document.forms[inFormName].elements[inCheckboxName];
	
	if(theCheckbox.checked)
	{
		theResult = true;
	}
	
	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_GetCheckboxCheckedStateAsInt(inFormName, inCheckboxName)
{
	var theResult = formMgmt_CheckboxIsChecked(inFormName, inCheckboxName) ? 1 : 0;

	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_SetCheckboxCheckedStateFromInt(inFormName, inCheckboxName, inInt)
{
	if(inInt && inInt.toString && inInt.toString() == "1")
	{
		formMgmt_CheckCheckbox(inFormName, inCheckboxName);
	}
	else
	{
		formMgmt_UncheckCheckbox(inFormName, inCheckboxName);
	}
}

/* **************************************************************************************************** */

function formMgmt_CheckCheckbox(inFormName, inCheckboxName)
{
	var theCheckbox = document.forms[inFormName].elements[inCheckboxName];
	
	if(theCheckbox)
	{
		theCheckbox.checked = true;
	}
}

/* **************************************************************************************************** */

function formMgmt_UncheckCheckbox(inFormName, inCheckboxName)
{
	var theCheckbox = document.forms[inFormName].elements[inCheckboxName];
	
	if(theCheckbox)
	{
		theCheckbox.checked = false;
	}
}

/* **************************************************************************************************** */

function formMgmt_ToggleCheckbox(inFormName, inCheckboxName)
{
	if(formMgmt_CheckboxIsChecked(inFormName, inCheckboxName))
	{
		formMgmt_CheckCheckbox(inFormName, inCheckboxName);
	}
	else
	{
		formMgmt_UncheckCheckbox(inFormName, inCheckboxName);
	}
}

/* **************************************************************************************************** */

function formMgmt_GetCheckboxValue(inFormName, inCheckboxName)
{
	var theResult = "";
	var theCheckbox = document.forms[inFormName].elements[inCheckboxName];
	
	if(theCheckbox.checked)
	{
		theResult = theCheckbox.value;
	}
	
	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_DeleteSelectedListEntry(inFormName, inOptionName){

	var theOptionSet = document.forms[inFormName][inOptionName];
	formMgmt_DeleteListEntry(inFormName, inOptionName,  theOptionSet.selectedIndex);

}

/* **************************************************************************************************** */

function formMgmt_FillListFromArray(inFormName, inOptionName, inArray){

	formMgmt_DeleteAllListEntries(inFormName, inOptionName);

	for(var i = 0, max = inArray.length; i < max; i++){

		document.forms[inFormName][inOptionName][i] = new Option(inArray[i], inArray[i]);
	}
}

/* **************************************************************************************************** */

function formMgmt_FillListFromArrays(inFormName, inOptionName, inTextArray, inValueArray){

	var max1 = inTextArray.length;
	var max2 = inValueArray.length;
	var theOptions = document.forms[inFormName].elements[inOptionName].options;
	
	if(max1 != max2)
		alert("max1 = max2 in formMgmt_FillListFromArrays()!");
		
	formMgmt_DeleteAllListEntries(inFormName, inOptionName);

	for(var i = 0; i < max1 && i < max2; i++){

		theOptions[i] = new Option(unescape(inTextArray[i]), inValueArray[i]);	
	}
}

/* **************************************************************************************************** */

function formMgmt_NewListEntryAfterSelected(inFormName, inOptionName, inValue){

	formMgmt_NewListEntryAfterSelectedB(inFormName, inOptionName, inValue, inValue);
}

/* **************************************************************************************************** */

function formMgmt_NewListEntryAfterSelectedB(inFormName, inOptionName, inText, inValue){

	var theOptionSet = document.forms[inFormName].elements[inOptionName];
	var selIndex = theOptionSet.selectedIndex;
	
	formMgmt_NewListEntryAtIndexB(inFormName, inOptionName, selIndex + 1, inText, inValue);
	
}

/* **************************************************************************************************** */

function formMgmt_NewListEntryAtIndex(inFormName, inOptionName, inAtIndex, inValue){

	formMgmt_NewListEntryAtIndexB(inFormName, inOptionName, inAtIndex, inValue, inValue);
}

/* **************************************************************************************************** */

function formMgmt_NewListEntryAtIndexB(inFormName, inOptionName, inAtIndex, inText, inValue){

	var theOptionSet = document.forms[inFormName][inOptionName].options;
	var nOptions = theOptionSet.length;

	if(inAtIndex < 0 || inAtIndex > theOptionSet.length){
		alert("inAtIndex was bad in formMgmt_NewListEntryAtIndexB()");
		return;
	}
	
	// Add an option at end
	theOptionSet[nOptions++] = new Option("duh", "duh");


// Make room for the new option
	for(var i = nOptions - 1; i > inAtIndex; i--){

		theOptionSet[i].text = theOptionSet[i - 1].text;
		theOptionSet[i].value = theOptionSet[i - 1].value;
	}

	theOptionSet[inAtIndex].text = unescape(inText);
	theOptionSet[inAtIndex].value = inValue;

	// set the selectedIndex to the new item.
	// Opera wants a delay or it creates a ghost option.
	if(navigator.appName.indexOf("Opera") > -1)
		window.setTimeout("document.forms['" + inFormName + "'].elements['" + inOptionName + "'].selectedIndex =" + inAtIndex, 5);
	else
		theOptionSet.selectedIndex = inAtIndex;
}

/* **************************************************************************************************** */

function formMgmt_GetFirstSelectedListValue(inFormName, inOptionName){

	var theOptionSet = document.forms[inFormName].elements[inOptionName];
	var theOptions = theOptionSet.options;
	var nOptions = theOptionSet.length;
	var theResult = null;

	// Loop options until we find selected
	for(var i = 0; i < nOptions && theResult == null; i++){

		if(theOptions[i].selected == true)
		{
			theResult = theOptions[i].value;	
		}
	}

	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_ListSelectItemIndexes(inFormName, inOptionName, inIndexArray){

	var theOptionSet = document.forms[inFormName].elements[inOptionName];
	var theOptions = theOptionSet.options;

	inIndexArray.sort(formMgmt_SortNumbersFunc);

	// Loop options until we find selected
	for(var i = 0; i < theOptionSet.length; i++){

		if(formMgmt_ValueInArray(i, inIndexArray))
		{
			// We should select this item
			theOptions[i].setAttribute("selected", "1");	
		}
		else
		{
			// We should unselect this item
			theOptions[i].removeAttribute("selected");
			//theOptions[i].selected = "0";		
		}
	}
	
	//if(inIndexArray.length == 1)
	//	theOptionSet.selectedIndex = 0;
}

/* **************************************************************************************************** */

function formMgmt_SortNumbersFunc(a, b) 
{ 
	return a - b;
}

/* **************************************************************************************************** */
// Note: This will return true for function prototypes and xxx 

function formMgmt_ValueInArray(inValue, inArray) 
{
	for(var i in inArray)
	{
		if(inArray[i]=== inValue)
		{
			return true;
		}
	}
	
	return false;
}


/* **************************************************************************************************** */

function formMgmt_DeleteListEntry(inFormName, inOptionName, inEntryIndex){

	var newArr = new Array();
	var theOptionSet = document.forms[inFormName][inOptionName];

	if(inEntryIndex < 0 || inEntryIndex >= theOptionSet.length){

		if(inEntryIndex == -1)
			alert("Select an entry before you try to delete it!");
		else if(inEntryIndex > 0)
			alert("Invalid entry index in formMgmt_DeleteListEntry()!");
		return;
	}

	for(var i = inEntryIndex; ((i + 1) < theOptionSet.length); i++){

		formMgmt_SwapListEntryValues(inFormName, inOptionName, i, i + 1);
	}

	theOptionSet[theOptionSet.length - 1] = null;

	if(inEntryIndex > 0)
		theOptionSet.selectedIndex = inEntryIndex - 1;

}

/* **************************************************************************************************** */

function formMgmt_SwapListEntryValues(inFormName, inOptionName, inFirstIndex, inSecondIndex){

	var theOptionSet = document.forms[inFormName][inOptionName];
	var swapText = "";
	var swapValue = "";

	if(inFirstIndex < 0 || inFirstIndex >= theOptionSet.length){

		alert("Invalid inFirstIndex in formMgmt_SwapListEntryValues()! inFirstIndex = " + inFirstIndex);
		return;
	}

	if(inSecondIndex < 0 || inSecondIndex >= theOptionSet.length){

		alert("Invalid inSecondIndex in formMgmt_SwapListEntryValues()! inSecondIndex = " + inSecondIndex);
		return;
	}

	swapText = theOptionSet[inFirstIndex].text;
	swapValue = theOptionSet[inFirstIndex].value;

	theOptionSet[inFirstIndex].text = theOptionSet[inSecondIndex].text;
	theOptionSet[inFirstIndex].value = theOptionSet[inSecondIndex].value;

	theOptionSet[inSecondIndex].text = swapText;
	theOptionSet[inSecondIndex].value = swapValue;
}


/* **************************************************************************************************** */

function formMgmt_DeleteAllListEntries(inFormName, inOptionName){
		
	var theOptionSet = document.forms[inFormName][inOptionName];
	theOptionSet.options.length = 0;
	
	/*
	for(var i = theOptionSet.length - 1; i >= 0; i--){
	
		theOptionSet.options[i] = null;
	}
	*/
}

/* **************************************************************************************************** */

function formMgmt_MoveSelectedListEntryUp(inFormName, inOptionName){

	var theOptionSet = document.forms[inFormName][inOptionName];
	var selIndex = theOptionSet.selectedIndex;

	if(selIndex > 0){
		var swapText = theOptionSet[selIndex].text;
		var swapValue = theOptionSet[selIndex].value;

		theOptionSet[selIndex].text = theOptionSet[selIndex - 1].text;
		theOptionSet[selIndex].value = theOptionSet[selIndex - 1].value;

		theOptionSet[selIndex - 1].text = swapText;
		theOptionSet[selIndex - 1].value = swapValue;

		theOptionSet.selectedIndex = selIndex - 1;
	}


}

/* **************************************************************************************************** */

function formMgmt_MoveSelectedListEntryDown(inFormName, inOptionName){

	var theOptionSet = document.forms[inFormName][inOptionName];
	var selIndex = theOptionSet.selectedIndex;

	if(selIndex < theOptionSet.length - 1){

		var swapText = theOptionSet[selIndex].text;
		var swapValue = theOptionSet[selIndex].value;

		theOptionSet[selIndex].text = theOptionSet[selIndex + 1].text;
		theOptionSet[selIndex].value = theOptionSet[selIndex + 1].value;

		theOptionSet[selIndex + 1].text = swapText;
		theOptionSet[selIndex + 1].value = swapValue;

		theOptionSet.selectedIndex = selIndex + 1;
	}
}

/* **************************************************************************************************** */

function formMgmt_GetListEntriesTextArray(inFormName, inOptionName){

	var theOptionSet = document.forms[inFormName][inOptionName];
	var theResult = new Array();

	for(var i = 0, max = theOptionSet.length; i < max; i++){

		theResult[i] = theResult + theOptionSet[i].text;
	}

	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_GetListEntriesValueArray(inFormName, inOptionName){

	var theOptionSet = document.forms[inFormName].elements[inOptionName];
	var theResult = new Array();

	for(var i = 0, max = theOptionSet.length; i < max; i++){

		theResult[i] = theOptionSet[i].value;
	}

	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_GetListValueIndex(inFormName, inOptionName, inValue){

	var theOptionSet = document.forms[inFormName][inOptionName];
	var theResult = -1;

	for(var i = 0, max = theOptionSet.length; i < max; i++){

		if(theOptionSet[i].value == inValue){
			theResult = i;
			break;
		}
	}

	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_SetSelectedListText(inFormName, inOptionName, inText){

	formMgmt_SetListText(inFormName, inOptionName, document.forms[inFormName].elements[inOptionName].selectedIndex, inText);
}

/* **************************************************************************************************** */

function formMgmt_SetSelectedListValue(inFormName, inOptionName, inValue){

	formMgmt_SetListValue(inFormName, inOptionName, document.forms[inFormName].elements[inOptionName].selectedIndex, inValue);
}

/* **************************************************************************************************** */

function formMgmt_SetListText(inFormName, inOptionName, inOptionIndex, inText){

	var theOptionSet = document.forms[inFormName].elements[inOptionName];

	if(inOptionIndex >= 0 && inOptionIndex < theOptionSet.length && theOptionSet.options[inOptionIndex].text != inText)
	{
		theOptionSet.options[inOptionIndex].text = inText;
	}
}

/* **************************************************************************************************** */

function formMgmt_SetListValue(inFormName, inOptionName, inOptionIndex, inValue){

	var theOptionSet = document.forms[inFormName].elements[inOptionName];

	if(inOptionIndex >= 0 && inOptionIndex < theOptionSet.length  && theOptionSet.options[inOptionIndex].value != inValue)
	{
		theOptionSet.options[inOptionIndex].value = inValue;
	}
}
/* **************************************************************************************************** */

function formMgmt_GetPopSelectedText(inOptionName){

	var theForm = formMgmt_FindFormOfUniqueWidgetID(inOptionName);
	var selIndex = theForm.elements[inOptionName].selectedIndex;
	var theResult = "";

	if(selIndex > -1)
		theResult = theForm.elements[inOptionName].options[selIndex].text;

	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_GetPopSelectedOrFirstText(inOptionName){

	var theForm = formMgmt_FindFormOfUniqueWidgetID(inOptionName);
	var selIndex = theForm.elements[inOptionName].selectedIndex;
	var theResult = "";

	if(selIndex > -1)
	{
		theResult = theForm.elements[inOptionName].options[selIndex].text;
	}
	else if(theForm.elements[inOptionName].options.length > 0)
	{
		theResult = theForm.elements[inOptionName].options[0].text;
	}
	
	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_GetPopSelectedIndex(inOptionName){

	var theResult = null;
	var theButton = document.getElementById(inOptionName);
	
	if(theButton && (theButton.selectedIndex != undefined))
	{
		theResult = theButton.selectedIndex;
	}
	else
	{
		alert("formManagement.js error with " + inOptionName + ": button: " + theButton + ", selectedIndex: " + theButton.selectedIndex);
	}
	
	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_GetPopSelectedValue(inOptionName){

	var theForm = formMgmt_FindFormOfUniqueWidgetID(inOptionName);
	var selIndex = theForm.elements[inOptionName].selectedIndex;
	var theResult = "";

	if(selIndex > -1)
		theResult = theForm.elements[inOptionName].options[selIndex].value;

	if(theResult == undefined || theResult == "undefined")
	{	alert("formMgmt_GetPopSelectedValue  can't find select  " + inOptionName);}
	
	return theResult;
}
/* **************************************************************************************************** */

function formMgmt_GetPopSelectedOrFirstValue(inOptionName){

	var theForm = formMgmt_FindFormOfUniqueWidgetID(inOptionName);
	var selIndex = theForm.elements[inOptionName].selectedIndex;
	var theResult = "";

	if(selIndex > -1)
	{
		theResult = theForm.elements[inOptionName].options[selIndex].value;
	}
	else if(theForm.elements[inOptionName].options.length > 0)
	{
		theResult = theForm.elements[inOptionName].options[0].value;
	}
	
	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_GetFormPopSelectedValue(inFormName, inOptionName){

	var theForm = document.forms[inFormName];
	var selIndex = theForm.elements[inOptionName].selectedIndex;
	var theResult = "";

	if(selIndex > -1)
		theResult = theForm.elements[inOptionName].options[selIndex].value;

	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_GetPopTextForValue(inFormName, inOptionName, inValue){

	var theResult = "";
	var theOption = document.forms[inFormName][inOptionName].options;
	
	for(var i = 0, max = theOption.length; i < max; i++){
		
		if(theOption[i].value == inValue){
			
			theResult = theOption[i].text;
			break;	
		}	
	}

	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_GetRadioValue(inFormName, inRadioName){

	var radioBtns = document.forms[inFormName][inRadioName];
	var theResult = "";

	for(var i = 0, max = radioBtns.length; i < max; i++){
		
		if(radioBtns[i].checked){
			
			theResult = radioBtns[i].value;
			break;	
		}	
	}

	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_SetRadioValue(inFormName, inRadioName, inValue){

	var radioBtns = document.forms[inFormName][inRadioName];
	
	if(!radioBtns || !radioBtns.length || radioBtns.length == undefined)
	{
		alert("Couldn't find radio " + inRadioName + " of form " + inFormName + " in formMgmt_SetRadioValue()");
		return;
	}
	for(var i = 0, max = radioBtns.length; i < max; i++){
		
		if(radioBtns[i].value == inValue){
			
			radioBtns[i].checked = true;
			break;	
		}	
	}
}

/* **************************************************************************************************** */
/* If value is not found in the options, sets selectedIndex to -1 */
function formMgmt_SetPopSelectedValue(inOptionName, inValue){

	var theForm = formMgmt_FindFormOfUniqueWidgetID(inOptionName);
	var theOptions = theForm.elements[inOptionName].options;
	var theIndex = -1;
	
	for(var i = 0, max = theOptions.length; i < max; i++){

		if(theOptions[i].value == inValue){
			theIndex = i;
			break;
		}
	}

	theForm.elements[inOptionName].selectedIndex = theIndex;
}

/* **************************************************************************************************** */
/* If value is not found in the options, sets selectedIndex to -1 */

function formMgmt_SetFormPopSelectedValue(inFormName, inOptionName, inValue){

	var theIndex = -1;
	var theForm = document.forms[inFormName];
	var theOptions = theForm.elements[inOptionName].options;
	
	for(var i = 0, max = theOptions.length; i < max; i++){

		if(theOptions[i].value == inValue){
			theIndex = i;
			break;
		}
	}

	theForm.elements[inOptionName].selectedIndex = theIndex;
}

/* **************************************************************************************************** */

function formMgmt_GetTextFieldValue(inFieldID){

	var textField = formMgmt_GetElementByID(inFieldID);
	if(!textField) alert("No text field " + inFieldID + " was found!");
	var theResult = textField.value;

	return theResult;
}

/* **************************************************************************************************** */

function formMgmt_SetTextFieldValue(inFieldID, inValue){

	var theForm = formMgmt_FindFormOfUniqueWidgetID(inFieldID);
	theForm[inFieldID].value = inValue;

}

/*****************************************************************************************************************************/

function formMgmt_ToggleElementVisibility(inElementID){
	
	var isVisible = formMgmt_IsElementVisible(inElementID);
	
	if(isVisible){
		formMgmt_HideElement(inElementID);
	}
	else{
		formMgmt_ShowElement(inElementID);
	}
}

/*****************************************************************************************************************************/

function formMgmt_SetElementVisibility(inElementID, inVisibility){
	
	if(inVisibility){
		formMgmt_ShowElement(inElementID);
	}
	else{
		formMgmt_HideElement(inElementID);
	}
}

/*****************************************************************************************************************************/

function formMgmt_ShowElement(inElementID){
	
	var theElement = formMgmt_GetElementByID(inElementID);

	if(theElement){
		
		formMgmt_ShowDOMObject(theElement);
	}
	else{
		alert("Element '" + inElementID + "' wasn't found in formMgmt_ShowElement()!");
	}
}

/*****************************************************************************************************************************/

function formMgmt_HideElement(inElementID){
	
	var theElement = formMgmt_GetElementByID(inElementID);
	
	if(theElement){
		
		formMgmt_HideDOMObject(theElement);
	}
	else{
		alert("Element '" + inElementID + "' wasn't found in formMgmt_HideElement()!");
	}
}

/*****************************************************************************************************************************/
function formMgmt_GetComputedStyle(inDOMObject, inStyleAttribute)
{
	var theResult = null;
	
	if(inDOMObject.currentStyle && inDOMObject.currentStyle[inStyleAttribute])
	{
		theResult = inDOMObject.currentStyle[inStyleAttribute];
	}
	else if (inDOMObject.style[inStyleAttribute]) 
	{
		// inline style property
		theResult = inDOMObject.style[inStyleAttribute];
	} 
	else if(document.defaultView && document.defaultView.getComputedStyle)
	{
		var theView = document.defaultView;
		var theStyle = theView.getComputedStyle(inDOMObject, "");
		
		if(theStyle)
			theResult = theStyle.getPropertyValue(inStyleAttribute);
	}
	
	return theResult;
}

/*****************************************************************************************************************************/

function formMgmt_ShowDOMObject(inObject){
	
	var inlineTags = new Array("span","input","select");
	var tableRowTags = new Array("tr");
	var tableRowGroupTags = new Array("tbody");
	
	if(inObject){
		
		var tag = inObject.tagName.toLowerCase();
		
		if(formMgmt_ValueInArray(tag, inlineTags))
		{
			inObject.style.display = "inline";
		}
		else if(formMgmt_ValueInArray(tag, tableRowTags))
		{
			inObject.style.display = "table-row";
		}
		else if(formMgmt_ValueInArray(tag, tableRowGroupTags) && navigator.appName.indexOf("Internet Explorer") == -1)
		{
			inObject.style.display = "table-row-group";
		}
		else
		{
			inObject.style.display = "block";	
		}
		/*
		var currDisplay = formMgmt_GetComputedStyle(inObject, "display");
		var latentDisplay = inObject.getAttribute("latentDisplay");

		// Only change display type if we're undisplayed
		if(currDisplay == null || currDisplay == "none")
		{
			inObject.style.display = latentDisplay != null ? latentDisplay : "block";  
		}
		*/
		inObject.style.visibility = "visible"; 
	}
	else{
		alert("Bad stuff in formMgmt_ShowDOMObject!");
	}
}


/*****************************************************************************************************************************/

function formMgmt_HideDOMObject(inObject){
	
	var s = formMgmt_GetComputedStyle(inObject, "display");
	
	if(s != null && s != "none") 
	{
		inObject.setAttribute("latentDisplay", s);
	}
	else
	{
		inObject.removeAttribute("latentDisplay");
	}
	
	if(inObject){
		
		// Should use "setAttribute()"
		inObject.style.display = "none";  
		inObject.style.visibility = "hidden"; 
	}
	else{
		alert("Bad stuff in formMgmt_HideDOMObject!");
	}
}

/*****************************************************************************************************************************/

function formMgmt_GetAttribute(inObject, inAttributeName){
	
	var theResult = null;
	
	if(inObject.getAttribute){
		
		theResult = inObject.getAttribute(inAttributeName); 
	}
	else if(inObject[inAttributeName]){
		theResult = inObject[inAttributeName]; 
	}
	
	if(theResult == null){
		
		/*
		var errorMsg = "NULL result in formMgmt_GetAttribute() for attribute \"" + inAttributeName + "\"\n";
		if(inObject["id"])
			errorMsg += "inObject.id: \"" + inObject.id + "\"";
		else if(inObject["name"])
			errorMsg += "inObject.name: \"" + inObject.name + "\"";
		alert(errorMsg);
		*/
	}
	return theResult;
}

/*****************************************************************************************************************************/

function formMgmt_SetAttribute(inObject, inAttributeName, inAttributeValue){
	
	if(inObject.setAttribute){
		
		inObject.setAttribute(inAttributeName, inAttributeValue); 
	}
	else if(inObject[inAttributeName]){
		inObject[inAttributeName] = inAttributeValue; 
	}
	else{
		var errorMsg = "Could not access attribute \"" + inAttributeName + "\"\n";
		if(inObject["id"])
			errorMsg += "inObject.id: \"" + inObject.id + "\"";
		else if(inObject["name"])
			errorMsg += "inObject.name: \"" + inObject.name + "\"";
		alert(errorMsg);
	}
}

//***********************************************************************************

function formMgmt_SetTextNodeContent(inNodeID, inContent){
	
	var textNodeContainer = document.getElementById(inNodeID);
	
	if(textNodeContainer){
		
		var textNode = textNodeContainer.firstChild;
		if(textNode){
			textNode.nodeValue = inContent;
		}
		else{
			textNodeContainer.appendChild(document.createTextNode(inContent));
		}
	}
}

/*****************************************************************************************************************************/

function formMgmt_IsElementVisible(inElementID){
	
	var theResult = true;
	var theElement = formMgmt_GetElementByID(inElementID);
	
	if(theElement != null){
	
		if((theElement.style.display && theElement.style.display == "none") || ! theElement.style.display || (theElement.style.visibility && theElement.style.visibility == "hidden"))
			theResult = false;
	}
	else{
		alert("Element '" + inElementID + "' wasn't found in formMgmt_IsElementVisible()!");
	}
	
	return theResult;
}

/*****************************************************************************************************************************/

function formMgmt_GetElementByID(inElementID){
	
	var theResult = null;
	
	if(document.getElementById){
		
		theResult = document.getElementById(inElementID);
	}
	else if(document.all){
		
		theResult = document.all.item(inElementID);
	}
	
	return theResult;
}

/*****************************************************************************************************************************/

function formMgmt_SetImageByElementVisibility(inElementID, inImageID, inVisibleImage, inHiddenImage){
	
	var isVisible = formMgmt_IsElementVisible(inElementID);
	var theImage = formMgmt_GetElementByID(inImageID);

	if(theImage){
		
		var currImgPath = theImage.src;
		var currImgName = currImgPath.substr(currImgPath.lastIndexOf("\/") + 1, currImgPath.length - 1);
		var newImgName = isVisible ? inVisibleImage : inHiddenImage;
		var newImgPath = currImgPath.substr(0, currImgPath.lastIndexOf("\/") + 1) + newImgName;
		theImage.src = newImgPath;
	}
	
}

/*****************************************************************************************************************************/

/*****************************************************************************************************************************/

function formMgmt_SetElementVisibilityByCheckedValue(inCheckboxID, inElementID)
{
	var theCheckbox = formMgmt_GetElementByID(inCheckboxID);
	
	if(theCheckbox && theCheckbox.checked)
	{
		formMgmt_ShowElement(inElementID);	
	}
	else
	{
		formMgmt_HideElement(inElementID);
	}
}

/*****************************************************************************************************************************/

function formMgmt_SetElementVisibilityByUncheckedValue(inCheckboxID, inElementID)
{
	var theCheckbox = formMgmt_GetElementByID(inCheckboxID);
	
	if(theCheckbox && theCheckbox.checked)
	{
		formMgmt_HideElement(inElementID);	
	}
	else
	{
		formMgmt_ShowElement(inElementID);
	}
}

/*****************************************************************************************************************************/
function formMgmt_SetElementVisibilityBySelectedValue(inSelectID, inSelectValue, inElementID)
{
	var selectedValue = formMgmt_GetPopSelectedValue(inSelectID);
	
	if(selectedValue == inSelectValue)
	{
		formMgmt_ShowElement(inElementID);	
	}
	else
	{
		formMgmt_HideElement(inElementID);
	}
}