﻿function selectCities(menu){
	$(document).ready(function(){
	
		$.ajax({
		        type: 'GET',
				url: '../xml/states.xml',
				dataType: 'xml',
				success: function(xml){
					var selected = $('#' + menu).val();

/*This function will have 2 pieces:
	The first piece will handle if the user clicks on the first panel. (parentMenu) is passed as the parameter.
		when this occurs, we search through the xml document and pick out the series whose name attribute
		matches the selected item.
		
		we loop through to each model node and pull the name attribute from that.
		for each model node, we will create an <option> element with that model name
*/

					if(menu == "RENT_destination"){
						$(xml).find("state").each(function(xml){
							if($(this).attr("name") == selected){
								$('#RENT_closestcity').empty();
								
								$(this).find("city").each(function(){
									var cityName = $(this).text();
									var htmlOutput = "<option id='"+cityName+"' value='"+cityName+"' >"+ cityName +"</option>";
									$('#RENT_closestcity').append(htmlOutput);
									
									});
									
								}

							});

						}
		

//=======================================================================================================================
					
				}//close success function for ajax();
			
			});//close ajax() function;

	});//close jquery wrapper;

}//close selectCities() function;