function submitPhilipsForm(theElement, paramFilter)
{
    var theForm = null;
    var currElement = theElement;
    
    // loop through until we find the enclosing form element for this TD
    while (theForm == null) 
    {
    	var parentNode = currElement.parentNode;
    	var currForm = parentNode.getElementsByTagName("form");
    	
    	//alert(currForm[0]);
    	
    	if (currForm.length >0)
    	{
    		theForm = currForm[0];
    	}
    	else
    	{
    		currElement = parentNode;
    	}
    }
    
    var newElem = document.createElement('input');
    newElem.setAttribute('type','hidden');
    newElem.setAttribute('name',paramFilter);
    theForm.appendChild(newElem);

    //Test code!
    var secondaryRaceBoxes = document.getElementsByName("com.peopleclick.cp.formdata.CAND_RACE_TYPEID");
    if(secondaryRaceBoxes.length > 0)
    {
	checkSecondaryRace(secondaryRaceBoxes);
    }
   theForm.submit();
    
}

function submitPhilipsNamedForm(theForm, paramFilter)
{

    var newElem = document.createElement('input');
    newElem.setAttribute('type','hidden');
    newElem.setAttribute('name',paramFilter);
    theForm.appendChild(newElem);
    
    theForm.submit();
    
}

/* The following 3 functions (PopulateSearchForm, CleanFormItems, ClearSearchCriteria) do not appear to be in use any longer */
function PopulateSearchForm(elem, name)
{		
	ClearFormItems(elem, name);
	
	for(var a=0; a < elem.length; a++)
	{
		if(elem.options[a].selected == true)
		{
			if(elem.options[a].value != "-1")
			{
				var popped = false;
						
				for(var b=0; b < elem.form.elements.length; b++)
				{
					if(elem.form.elements[b].name == name)
					{
						// An element with this name exists. Check to see if it is empty.
						if(elem.form.elements[b].value.length < 1)
						{
							// This element is empty so we can populate with this value.
							elem.form.elements[b].value = elem.options[a].value;
							popped = true;
						}
					}
				}	
			
				if(popped != true)
				{
					// This value has no been populated yet, so we need to create a new element.
					var input = document.createElement("input");
					
					if(! document.all)
					{
						input.setAttribute("type", "hidden");
						input.setAttribute("name", name);
						input.setAttribute("id", id + name);					
						input.setAttribute("value", elem.options[a].value);					
					}
					else
					{
						input.type = "hidden";
						input.name = name;
						input.id = "id" + name;
						input.value = elem.options[a].value;
					}
					
					elem.form.appendChild(input);
				}		
			}
		}
	}
}


/* ClearFormItems()
 * Remove the values from the items we may need to populate.
 */
function ClearFormItems(elem, name)
{
	for(var i=0; i < elem.form.elements.length; i++)
	{
		if(elem.form.elements[i].name == name)
		{
			elem.form.elements[i].value = "";
		}
	}	
}


/* ClearSearchCriteria()
 * Clear the select boxes for salary grade and group that are related to the dummy domain
 * list fields.
 */
function ClearSearchCriteria(frm)
{
	frm.elements["com.peopleclick.cp.formdata.FLD_JOB_SEARCH_SALARY_GRADE"].selectedIndex = 0;
	frm.elements["com.peopleclick.cp.formdata.FLD_JOB_SEARCH_GROUP"].selectedIndex = 0;	
}

function checkSecondaryRace(secondaryRaceBoxes)
{
	// We're checking for a null again, just to be safe...

	if(secondaryRaceBoxes.length > 0)
	{
		var somethingChecked=false;
		for(var i=0; i<secondaryRaceBoxes.length; i++)
		{
			somethingChecked = secondaryRaceBoxes[i].checked | somethingChecked;
		}		
		//alert(somethingChecked);
		if(somethingChecked == false)
		{
			var defaultValue = document.getElementById("id-com.peopleclick.cp.formdata.CAND_RACE_TYPEID-1");
			if(defaultValue != null)
			{
				defaultValue.checked = true;
			}
		}
	}
	
}

/*	This function was added because, in order to maintain sublist filtering, we
   	had to keep the core field names on the search page.  However, before sending
	the search to the core code we have to rename these fields so that it doesn't
	send them off to FAST as is but rather uses what we specify in filter.py */

function convertSearchableFields()
{
	var fieldsToChange = ["FLD_JPM_FUNCTIONAL_AREA"];
	for(var i = 0; i< fieldsToChange.length; i++)
	{
		changeFields(fieldsToChange[i]);
	}

}

function changeFields(fieldName)
{
	var target = document.getElementById("com.peopleclick.cp.formdata." + fieldName);
	target.name = "nonsearchable." + fieldName;
}
