function countryChanged() {
	var countryId = $('#ProfileCountry').val();
	if (countryId != '') {
		$('#ProfileRegionSelect').html('<span class="ajax-loader"></span>');
		$.post("/users/getRegions/"+countryId+"?call=ajax", {},
			function(response) {
				setTimeout("finishCountryChanged('"+escape(response)+"')", 200);
	  		}
		);
	} else {
		$('#ProfileRegion').find('option').each(function(){
			if ($(this).val() != '') {
				$(this).remove();
			}
		});
		
		if ($('#ProfileCity').length == 0) {
			return;
		}
		$('#ProfileCity').find('option').each(function(){
			if ($(this).val() != '') {
				$(this).remove();
			}
		});
	}
	
}
function finishCountryChanged(response) {
	if (response != "") {
		$('#ProfileRegionDiv').html(unescape(response));
	}
}

function regionChanged() {
	var countryId = $('#ProfileCountry').val();
	var regionId = $('#ProfileRegion').val();
	if (countryId != '' && regionId != '') {
		if ($('#ProfileCitySelect').length > 0) {
			$('#ProfileCitySelect').html('<span class="ajax-loader"></span><br class="clear" />');
		}
		
		$.post("/users/getCities/"+countryId+'/'+regionId+'?call=ajax', {},
			function(response) {
				setTimeout("finishRegionChanged('"+escape(response)+"')", 200);
	  		}
		);
	} else {
		if ($('#ProfileCity').length == 0) {
			return;
		}
		$('#ProfileCity').find('option').each(function(){
			if ($(this).val() != '') {
				$(this).remove();
			}
		});
	}
	
}
function finishRegionChanged(response) {
	if (response != "") {
		$('#ProfileCityDiv').html(unescape(response));
	}
}

function cityChanged(elementChanged) {
	if (elementChanged == 'select') {
		$('#ProfileCityString').val('');
	} else if (elementChanged == 'string') {
		if ($('#ProfileCity')) {
			document.getElementById('ProfileCity').selectedIndex = 0;
		}
	}
}
/*---------------------[occupation]-----------------------*/
function onPersonOccupationMemberTypeChange() {
	var select = $('#PersonOccupationMemberType');
	if (select.val() != 'Professional') {
		$('#PersonOccupationTimeInIndustryDiv').hide();
		$('#PersonOccupationJobIndustryIdDiv').hide();
		$('#PersonOccupationOccupationDiv').hide();
		$('#PersonOccupationOccupationOtherDiv').hide();
	} else {
		$('#PersonOccupationTimeInIndustryDiv').show();
		$('#PersonOccupationJobIndustryIdDiv').show();
		$('#PersonOccupationOccupationDiv').show();
		if ($('#PersonOccupationOccupation').getSelectedText() == 'Other') {
			$('#PersonOccupationOccupationOtherDiv').show();
		}
	}

	if (select.val() == 'Other') {
		$('#PersonOccupationMemberTypeOtherDiv').show();
	} else {
		$('#PersonOccupationMemberTypeOtherDiv').hide();
	}
}
function onPersonOccupationOccupationChange() {
	var select = $('#PersonOccupationOccupation');
	if (select.getSelectedText() == 'Other') {
		$('#PersonOccupationOccupationOtherDiv').show();
	} else {
		$('#PersonOccupationOccupationOtherDiv').hide();
	}
}
$(document).ready(function(){
	onPersonOccupationMemberTypeChange();
	onPersonOccupationOccupationChange();
});
