function get_neighborhoods(selected_id)
{
	var region = $("#region").val();

	if(region == '')
	{
		$("#neighborhood").html('<option value="all">Select a region first</option>');
		$("#neighborhood").attr("disabled", "disabled");
	}
	else
	{	
		$("#neighborhood").html('<option value="all">Please wait</option>');
		$("#neighborhood").attr("disabled", "disabled");
		
		$.getJSON("/contactus/get_neighborhoods/" + region, function(data)
		{
			$("#neighborhood").html('');
			$('<option value="">All neighborhoods</option>').appendTo("#neighborhood");
			$.each(data, function(index, neighborhood)
			{
				$('<option value="' + neighborhood.location_id + '">' + neighborhood.name + '</option>').appendTo("#neighborhood");
			});
			$("#neighborhood").removeAttr("disabled");
			
			if(selected_id)
			{
				$('#neighborhood').val(selected_id);
			}
		});
	}
}

function validate_form()
{
	var max_rent = $("#max_rent").val();
	var min_rent = $("#min_rent").val();

	if(parseInt(max_rent) < parseInt(min_rent))
	{
		alert("Please make sure the minimum rent is less than the maximum rent");
		return false;
	}
	else
	{
		return true;
	}
}

$(document).ready(function()
{	
	if(window.selected_id != undefined)
	{
		get_neighborhoods(selected_id);
	}
	else
	{
		get_neighborhoods();
	}
});
