/*
*	File Name: filterValidation.js
*	Methods:
*	--validateFilter() - David Montgomery 24/09/08
*	--getValueFromSelect() David Montgomery 24/09/08
*	--filterSubmit() David Montgomery 24/09/08
*/

/*
*
*	This method will check to ensure that at least 1 search section
*   has been completed.  If no search criteria has been entered
*   then a suitable text key will be returned.
*/
function validateFilter(id)
{
	//get the selected value for the id
	idValueSelected = getValueFromSelect(document.getElementById(id));

	if(idValueSelected == '')
	{

		return "No filter criteria has been specified";

	}

}

/*
*
*	Retrieves the value of the option selected
*/
function getValueFromSelect(select)
{
	if(select == null || select.nodeName != "SELECT")
	{
		return null;
	}
	
	for(var i=0; i<select.options.length; i++)
	{
		if(select.options[i].selected)
		{
			return select.options[i].value;
		}
	}
	
}

/*
*
*	This method is called whenever the user submits a
*   filter.  A popup will be shown if there is
*   an error with the filter criteria.
*/
function filterSubmit(id)
{
	var errorKey = validateFilter(id);
	if(errorKey != null)
	{
		openPopUp(document.getElementById("noFilterMsg").value, errorKey, "error");
		return false;
	}
	else
	{
		return true;
	}
	
}
