$(document).ready(function() {
	function makeAjaxRequest(objSelect, strRequestUri, strElementId, booAllOption) {
		var strAppend = '';
		if(booAllOption) {
			strAppend = '/booAllOption/1'
		}

        //alert(HOST_ROOT + strRequestUri + objSelect.value + strAppend);

		$.getJSON(
			HOST_ROOT + strRequestUri + objSelect.value + strAppend,
			function(objData) {
				$('#' + strElementId).html(objData.strOptionsHtml);
			}
		);
	}

	$('#intIndustryId').change(function() { populateSectors(this, 'intSectorId', true); });
	$('#industryId').change(function() { populateSectors(this, 'sectorId', false); });

	function populateSectors(objSelect, strElementId, booAllOption) {
		makeAjaxRequest(objSelect, 'ajax/sector-by-industry/intIndustryId/', strElementId, booAllOption);
	}

	$('#intCountryId').change(function() { populateCounties(this, 'intCountyId', true); });
	$('#countryId').change(function() { populateCounties(this, 'countyId', false); });

	function populateCounties(objSelect, strElementId, booAllOption) {
		makeAjaxRequest(objSelect, 'ajax/county-by-country/intCountryId/', strElementId, booAllOption)
	}

	$('#intCountyId').change(function() { populateCities(this, 'intCityId', true); });
	$('#countyId').change(function() { populateCities(this, 'cityId', false) });

	function populateCities(objSelect, strElementId, booAllOption) {
		makeAjaxRequest(objSelect, 'ajax/city-by-county/intCountyId/', strElementId, booAllOption);
	}
});