function getCriteriaStatement(frm) {
	var debug
	debug = false
	//debug = true
	
	var criteriaStatement = ""
	var orderStatement = ""


	//alert ("building the string")

	var criteriaChar = ""		// set the start character to be an empty string
	var orderChar = ""		// set the start character to be an empty string
	var programString = "" // for accumulating program source values

	// iterate through all elements in the form and add their values to the criteria string
	for (elementsIndex = 0; elementsIndex < frm.elements.length; elementsIndex++)
	{
		myObject = frm.elements[elementsIndex]

		// if the next element has value
		if (myObject.value != "")
		{
			//alert ("myobject" + myObject.name)

			// if the next element is the correct type, add it to the criteria string
			switch (myObject.type)
			{

				case "text":
					switch (myObject.name)
					{
						case "keywords":
							keyString=""
							if (myObject.value != "")
							{
								keyString = myObject.value
								keyWords = keyString.split(",")
								keySearch = "%" + keyWords.join("%|%") + "%|"
								criteriaStatement += criteriaChar + "@" + myObject.name + "='" + keySearch
							}
							break
						case "minDate":
							criteriaStatement += criteriaChar + "@min_created_on='" + myObject.value
							break
						case "maxDate":
							criteriaStatement += criteriaChar + "@max_created_on='" + myObject.value
							break
						default:
							criteriaStatement += criteriaChar + "@" + myObject.name + "='" + myObject.value
					}
					criteriaChar = "', " // set the start character to be close quote and apostraphy (',)
					break
					
				case "select-one":

					for (optionsIndex = 0; optionsIndex < myObject.length; optionsIndex++)
						{
							if (myObject.options[optionsIndex].selected == true)
							{
									if ((myObject.name == "weekdays") || (myObject.name == "before_after"))
									{
											criteriaStatement += criteriaChar + "@" + myObject.name + "='" + myObject.options[optionsIndex].value
											criteriaChar = "', " // set the start character to be close quote and apostraphy (',)
									}
									else
									{
									criteriaStatement += criteriaChar + "@" + myObject.name + "='" + myObject.options[optionsIndex].value
									criteriaChar = "', " // set the start character to be close quote and apostraphy (',)
									}
							}
						}
					break

				case "select-multiple":
					if (myObject.name == "selectedColumns")
					{
						// do nothing
					}
					
					else
					{
						criteriaStatement += criteriaChar + "@" + myObject.name + "='"
						criteriaChar = "" // set the start character to be an empty string
						for (optionsIndex = 0; optionsIndex < myObject.length; optionsIndex++)
						{
							if (myObject.options[optionsIndex].selected == true)
							{
								criteriaStatement += criteriaChar + myObject.options[optionsIndex].value
								criteriaChar = "|" // set the start character to be a pipe (|)
							}
						}
						criteriaStatement += criteriaChar // add the final pipe
						criteriaChar = "', " // set the start character to be close quote and apostraphy (',)
					}
					break
									
				case "checkbox":
					if ((myObject.checked == true) && (myObject.value != ""))
					{
						if ((myObject.name == "service_area") || (myObject.name == "specific_hours") || (myObject.name == "office_location") || (myObject.name == "registration_date"))
						{
							//ignore
						}
						else if (myObject.name == "weekdays")
						{
								if (specific_hours.checked == true)
								{
									criteriaStatement += criteriaChar + "@" + myObject.name + "='" + myObject.value
									criteriaChar = "', " // set the start character to be close quote and apostraphy (',)
								}
						}
						else
						{
							criteriaStatement += criteriaChar + "@" + myObject.name + "='" + myObject.value
							criteriaChar = "', " // set the start character to be close quote and apostraphy (',)

						}
					}					
					break

				case "radio":
					if ((myObject.checked == true) && (myObject.value != ""))
					{	
						criteriaStatement += criteriaChar + "@" + myObject.name + "='" + myObject.value
						criteriaChar = "', " // set the start character to be close quote and apostraphy (',)
					}					
					break


					
				case "textarea":
					keyString=""
					if (myObject.value != "")
					{
						keyString = myObject.value
						keyWords = keyString.split(",")
						keySearch = "%" + keyWords.join("%|%") + "%|"
						
						criteriaStatement += criteriaChar + "@" + myObject.name + "='" + keySearch
						criteriaChar = "', " // set the start character to be close quote and apostraphy (',)
					}
					break
				case "hidden":
					if ((myObject.name == "status") || (myObject.name == "searchable") || (myObject.name == "hide_private")) {
						criteriaStatement += criteriaChar + "@" + myObject.name + "='" + myObject.value
						criteriaChar = "', " // set the start character to be close quote and apostraphy (',)
					}
				default:
					// do nothing
			}
		}
	}

	
	// Add the final quote character (')
	if (criteriaStatement != "")
	{	

		if (criteriaStatement.substring(criteriaStatement.length - 4,criteriaStatement.length)=="null")
		{
		}
		else
		{
			criteriaStatement += "'"
		}
	}
	else
	{
		criteriaStatement = "no search criteria"
	}
	if (orderStatement != "") orderStatement += "'"	
		else orderStatment = "no sorting"
		
//	alert (criteriaStatement)
//	alert (orderStatement)
		
	return criteriaStatement
	
}
