
function isset(varname) {
if(typeof( window[ varname ] ) != "undefined") return true;
else return false;
}

$(function(){

	link = ajaxURL('properties', 'city.html');

	$("input[name='city']").autocomplete(link,{ 
	multiple: true,
    cacheLength: 300,
	max: 300,
    width:420,
    minChars: 3,  
    delay: 10, 
    noCache: false,
   
    mustMatch: false,
    

    formatItem: function(row, i, max) { 
        return row[0] + ", gm." + row[1] + ", pow." + row[2] + ", woj." + row[3];
    }, 
    formatMatch: function(row, i, max) { 
        return row[0]; 
    }, 
    formatResult: function(row) { 

        return row[0]; 
        
    } 
}).result(function(event, item) {

	
	//var id = $("input[name='city']").index(this);
	
	$("#loadingInfo").hide();
	
	$("#cityError").hide();
	

	if(item){ 
		$(this).parents('form').find("input[name='cityId']").val(item[4]);	
		$(this).parents('form').find(".loadingInfo").hide();
	}
	
	
	checkDistrict(this);

});
	

		
		//$(".loadingInfo").hide();
		
		


/*	
	$(".cityClass").bind("keypress", function(e) {
		
		var city = $("input[name='city']").val();

		$('#loadingInfo').css('display','block');
		$('#loadingInfo').html('Wpisz minimum 3 znaki i wybierz miasto z listy podpowiedzi.');
		


		if (e.keyCode == 13)
    	{	
			if(city.length>3)
			{
				$("#loadingInfo").hide();
			}
    	}

		
	});
       
*/

});


function checkDistrict(current)
{
	if($(current).parents('form').find(".districts").length !== 0) 
	{
		loadDistricts(current);
	}
}




function AutocompleteLoading(obj)
{
	if(obj.value.length>3)
	{
		$('#loadingInfo').css('display','block');
		$('#loadingInfo').html('Wczytywanie danych... Proszę czekać.');
	}
}


function AutocompleteLoadComplete()
{
	$("#loadingInfo").hide();
}


