
function downloadCities(select_field)
{
	//alert(Form.serialize("search_form"));
	
	new Ajax.Request("main.php?module=search_franchisees", { 
					 onSuccess : cities_list,
					 onFailure : function(resp) { alert("There's been an error."); },
					 parameters : Form.serialize("search_form")+"&ajax_call=get_cities"  } );;
}

function cities_list(resp, jsonObj) 
{
	removeAllOptions($("city"));
	addOption($("city"),'(ALL)','0');
	$H(jsonObj.cities_array).each( function(item) 
		{  
			addOption($("city"),item.value,item.value, (current_city==item.value?true:false));
		}
	 );
	removeAllOptions($("city_district"));
	addOption($("city_district"),'(ALL)','0');
	downloadDistricts($("city"));
}

function downloadDistricts(select_field)
{
	new Ajax.Request("main.php?module=search_franchisees", { 
					 onSuccess : districts_list,
					 onFailure : function(resp) { alert("There's been an error."); },
					 parameters : Form.serialize("search_form")+"&ajax_call=get_districts"  } );
}

function districts_list(resp, jsonObj) 
{
	
	removeAllOptions($("city_district"));
	addOption($("city_district"),'(ALL)','0');
	if (!jsonObj.cities_districts_array.length) {
		$("city_district_row").hide();
		return;
	}
	$("city_district_row").show();
	$H(jsonObj.cities_districts_array).each( function(item) 
		{  
			addOption($("city_district"),item.value,item.value, (current_city_district==item.value?true:false));
		}
	 );
}