
function stateIdChanged()
{
	if ( document.searchForm.StateId.selectedIndex == 0 )
	{
		disableRegion( true )
		disableOtherFields( true )
	}
	else
	{
		disableRegion( false )
		showOptions(document.searchForm.StateId.value)
		disableOtherFields(document.searchForm.RegionId.selectedIndex <= 0)
	}
}
if(null != document.searchForm && "undefined" != typeof(document.searchForm))
{
	document.searchForm.StateId.options[ document.searchForm.StateId.selectedIndex ].value == "12" || document.searchForm.StateId.options[ document.searchForm.StateId.selectedIndex ].value == "3" || document.searchForm.StateId.options[ document.searchForm.StateId.selectedIndex ].value == "16"
}
function regionIdChanged()
{
	if ( document.searchForm.RegionId.selectedIndex == 0 )
	{
		disableOtherFields( true )
	}
	else
	{
		disableOtherFields( false )
	}
}

function disableRegion( bDisable )
{
	document.searchForm.RegionId.disabled = bDisable
	document.searchForm.RegionId.selectedIndex = 0
}

function disableOtherFields( bDisable )
{
	document.searchForm.RentLow.disabled = bDisable
	document.searchForm.RentHigh.disabled = bDisable
	document.searchForm.NumBedrooms.disabled = bDisable
	document.searchForm.PetFriendly.disabled = bDisable
	document.searchForm.Furnished.disabled = bDisable || (document.searchForm.StateId.options[ document.searchForm.StateId.selectedIndex ].value == "12" || document.searchForm.StateId.options[ document.searchForm.StateId.selectedIndex ].value == "3" || document.searchForm.StateId.options[ document.searchForm.StateId.selectedIndex ].value == "16")

	document.searchForm.RentLow.selectedIndex = 0
	document.searchForm.RentHigh.selectedIndex = 0
	document.searchForm.NumBedrooms.selectedIndex = 0
	document.searchForm.PetFriendly.checked = false
	document.searchForm.Furnished.checked = false
}

function formSubmit()
{
	if ( document.searchForm.RegionId.selectedIndex > 0 )
	{
		if ( ( document.searchForm.RentLow.selectedIndex > 0 && document.searchForm.RentHigh.selectedIndex > 0 ) && ( parseInt( document.searchForm.RentLow.options[ document.searchForm.RentLow.selectedIndex ].value ) > parseInt( document.searchForm.RentHigh.options[ document.searchForm.RentHigh.selectedIndex ].value ) ) )
		{
			alert('If you enter a rent range, the minimum must be equal to or lower than the maximum.');
		}
		else
		{
			document.searchForm.action = '/apartments/search-results.asp'
			document.searchForm.submit()
		}
	}
	else
	{
		document.searchForm.action = '/apartments/view-all-apartments.asp'
		document.searchForm.submit()
	}
}
