$(document).ready(function(){
	$("#form").submit(function() {
		var quantity = $("#quantity").val();
		var selectNabe = $("#selectNabe").val();
		if(selectNabe == 'none') {
			alert('Please select a Neighborhood');
			return false;
		}
		});
 //end form select
	//form plugin
	//$('#form').ajaxForm(function() {
	//	alert("Thanks!");
	//});
	//populates the dropdown
			$.ajax({
				type: "GET",
				url: "neighborhoods.xml",
				dataType: "xml",
				success: function(xml) {
					var select = $('#selectCity');
					$(xml).find('menuitem').each(function() {
						$(this).find('title').each(function() {
							var title = $(this).text();
							select.append("<option class='ddheader' value='"+title+"'>"+title+"</option>");
						});
					});
					select.children(":first").text("Select").attr("selected",true);
				}
			});
		/*			var select = $('#selectNabe');
					$(xml).find('menuitem').each(function(){
						$(this).find('value').each(function(){
							var value = $(this).text();
							select.append("<option class='ddindent' value='"+ value +"'>"+value+"</option>");
						});
					});
					select.children(":first").text("Select").attr("selected",true);
				}
			});*/
		$("#selectCity").blur(function() {
			
			
			var selectCity = $("#selectCity").val();
			
			$.ajax({
				type: "GET",
				url: "neighborhoods.xml",
				dataType: "xml",
				success: function(xml) {
					$(xml).find('menuitem').each(function() {
						var select = $('#selectNabe');
						
						var city = $(this).find('title').text();
						
						
						if(city == selectCity) {
							select.empty();
							$(this).find('value').each(function() {
								var value = $(this).text();
								select.append("<option class='ddindent' value='"+ value +"'>"+value+"</option>");

							});
						}
					});
				}
			});
		});
		
		//provides feedback based on number entered for taquerias



		$("#quantity").blur(function() {
				
				var quantity_value;
				quantity_value = $("#quantity").val();
				$("#errmsg").empty();
				$("#list").empty();
			
				if(quantity_value < 3)
					$("#errmsg").append("Come on! If you want a taco crawl, you got to do it right!  Got to at least 3!");
					
				else if(quantity_value > 6 && quantity_value < 21)
					$("#errmsg").append("Holy cow!  Quite the ambitious eater!  Wouldn't want to be sleeping next to you after that crawl."); 
				else if(quantity_value > 20)
					$("#errmsg").append("Sorry dude - the system can't handle anything greater than 20");
				else 
					$("#errmsg").append("That looks like a good number of taquerias for your taco crawl!");
					
			}); //end on blur
		
		

		});


