function AgentSearchAdvancedSubmit(theForm) {
	var strCity			= theForm.plaats.value;
	var strZipcode		= theForm.postcode.value;
	var strAgent		= theForm.makelaar.value;
	var strDepartment	= theForm.kantoor.value;
	var blnSearchAgent	= theForm.search_for[0].checked;
	var blnSearchCity	= theForm.search_where[0].checked;
	var blnValidSearch	= false;

	if ( blnSearchCity ) {
		strZipcode	= "";
		strCity		= strCity.replace(/\\s+/g, ' ');
		strCity		= strCity.replace(/[^a-zA-Z0-9 ]/g, '');
		strCity		= strCity.replace(/^ /, '');
		strCity		= strCity.replace(/ $/, '');

		if ( strCity.length >= 2 ) {
			blnValidSearch = true;
		}

	}
	else {
		strCity		= "";
		strZipcode	= strZipcode.replace(/\\s+/g, ' ');
		strZipcode	= strZipcode.replace(/[^a-zA-Z0-9 ]/g, '');
		strZipcode	= strZipcode.replace(/^ /, '');
		strZipcode	= strZipcode.replace(/ $/, '');

		if ( strZipcode.length >= 2 ) {
			blnValidSearch = true;
		}
	}

	if ( blnSearchAgent ) {
		strDepartment	= "";
		strAgent		= strAgent.replace(/\\s+/g, ' ');
		strAgent		= strAgent.replace(/[^a-zA-Z0-9 ]/g, '');
		strAgent		= strAgent.replace(/^ /, '');
		strAgent		= strAgent.replace(/ $/, '');

		if ( strAgent.length >= 2 ) {
			blnValidSearch = true;
		}
	}
	else {
		strAgent		= "";
		strDepartment	= strDepartment.replace(/\\s+/g, ' ');
		strDepartment	= strDepartment.replace(/[^a-zA-Z0-9 ]/g, '');
		strDepartment	= strDepartment.replace(/^ /, '');
		strDepartment	= strDepartment.replace(/ $/, '');

		if ( strDepartment.length >= 2 ) {
			blnValidSearch = true;
		}
	}

	if ( blnValidSearch ) {
		theForm.submit();
	}
	else {
		alert("Niet alle zoek velden zijn correct ingevuld.");

		if (theForm.plaats.type == 'text') {
			theForm.plaats.value	= strCity;
		}
		theForm.postcode.value	= strZipcode;
		theForm.makelaar.value	= strAgent;
		theForm.kantoor.value	= strDepartment;
	}

}

function setActiveField(theForm, strField, intPosition) {
	theForm [strField][intPosition].checked=true;
}
