$(document).ready(function(){
	function formatResult(row) {
		return row[0].replace(/ <.+?>.+?<.+?>/gi, '');
	}
	$("#city_name").autocomplete(s_domain + tools_path + "search-location.php?mode=city", {
		width: 170,
		scrollHeight: 220,
		autoFill: false,
		mustMatch: true,
		matchContains: true,
		selectFirst: true,
		formatResult: formatResult
	});
	$("#city_name").result(function(event, data, formatted) {
		if (data){
			$('#city').val(data[1]);
		}
	});
	$("#city_name").blur(function(){
		var res = $(this).val();
		if ( !res ){
			$('#city').val('');
		}
	});

	$("#dep_name").autocomplete(s_domain + tools_path + "search-location.php?mode=dep", {
		width: 170,
		scrollHeight: 220,
		autoFill: false,
		mustMatch: true,
		matchContains: true,
		selectFirst: true
	});
	$("#dep_name").result(function(event, data, formatted) {
		if (data){
			$('#dep').val(data[1]);
		}
	});
	$("#dep_name").blur(function(){
		var res = $(this).val();
		if ( !res ){
			$('#dep').val('');
		}
	});

	$("#reg_name").autocomplete(s_domain + tools_path + "search-location.php?mode=reg", {
		width: 170,
		scrollHeight: 220,
		autoFill: false,
		mustMatch: true,
		matchContains: true,
		selectFirst: true
	});
	$("#reg_name").result(function(event, data, formatted) {
		if (data){
			$('#reg').val(data[1]);
		}
	});
	$("#reg_name").blur(function(){
		var res = $(this).val();
		if ( !res ){
			$('#reg').val('');
		}
	});
});