function whenUnitTypeChecked()
{
	var unitTypeChecked = false;
	for (var j = 0; j < document.selectionForm.unitType.length; j++)
	{
		if (document.selectionForm.unitType[j].checked)
		{
			unitTypeChecked = true;
			break;
		}
	}
	if (unitTypeChecked)
	{
		document.selectionForm.unitTypeSearch[0].checked = false;
		document.selectionForm.unitTypeSearch[1].checked = true;
	}
	else
	{
		document.selectionForm.unitTypeSearch[0].checked = true;
		document.selectionForm.unitTypeSearch[1].checked = false;
	}
}

function whenNoPreferenceChecked()
{
	if (document.selectionForm.unitTypeSearch[0].checked)
	{
		for (var j =0; j < document.selectionForm.unitType.length; j++)
		{
			document.selectionForm.unitType[j].checked = false;
		}
	}
	if (document.selectionForm.locationSearch[0].checked)
	{
		document.selectionForm.city.value = "-1";
		document.selectionForm.zipcode.value ="";
	}
	if (document.selectionForm.locationSearch[1].checked)
	{
		document.selectionForm.zipcode.value ="";
	}
	if (document.selectionForm.locationSearch[2].checked)
	{
		document.selectionForm.city.value = "-1";
	}
}

function zipcodeInputClick()
{
	document.selectionForm.locationSearch[2].checked = true;
	document.selectionForm.city.value = "-1";
}

function locationInputClick()
{
	document.selectionForm.locationSearch[1].checked = true;
	document.selectionForm.zipcode.value ="";
}

function validateAndSubmitSelectionForm(SearchOption)
{
	var value;
	if (document.selectionForm.unitTypeSearch[1].checked)
	{
		var blnChecked = false;
		for (var i= 0; i < document.selectionForm.unitType.length; i++)
		{
			if (document.selectionForm.unitType[i].checked)
			{
				blnChecked = true;
				break;
			}
		}
		if (!blnChecked)
		{
				alert("Selecteer een onderdeel.");
				return;
		}
	}
	for (var j = 0; j < document.selectionForm.locationSearch.length; j++)
	{
		if (document.selectionForm.locationSearch[j].checked)
		{
			if (document.selectionForm.locationSearch[j].value == "byCity")
			{
				value = document.selectionForm.city.options[document.selectionForm.city.selectedIndex].value;
				if (value == "-1")
				{
					alert("Kies eerst een plaats.");
					return;
				}
			}
			else if (document.selectionForm.locationSearch[j].value == "byZip")
			{
				value = document.selectionForm.zipcode.value;
				if (value == "")
				{
					alert("Vul eerst een postcode in.");
					return;
				}
				var expression = /^(\d){4}(\s)?[a-zA-Z]{2}$/
				if(!expression.test(value))
				{
					alert("Geen geldige postcode. Formuleer je postcode als volgt: 1234 AB.");
					return;
				}
			}
			break;
		}
	}
	var tempUnitType = '';
	for (var k= 0; k < document.selectionForm.unitType.length; k++)
	{
		if (document.selectionForm.unitType[k].checked)
		{
			tempUnitType = tempUnitType + document.selectionForm.unitType[k].value + ';';
		}
		document.selectionForm.unitType[k].checked = false;
	}
	document.selectionForm.unitTypes.value = tempUnitType;

	document.selectionForm.submit();
}