	$(function() {
				
		function UpdateDistricts(province) {
			$.ajax({
                type: "GET",
                url: base_url + "powiaty/get/" + province ,
                dataType: "xml",
                success: function(xml) {
                	 $("#district").children().each(function() {
						$(this).remove();
                    });
                    $(xml).find('district').each(function(){
                    	$("#district").append('<option value="'+ $(this).attr("id") +'">' + $(this).text() + '</option>'); 
                    }); 
                }
            }); // end $.ajax
            
		} // end UpdateDistricts

//		$("#city").autocomplete(base_url + "powiaty/podpowiedz/" + $("#city").attr("value"));
		
		$("#province").change(function() {
			$("#district").attr("disabled", false);
			UpdateDistricts($("#province").attr("value"));
		});
				
		$("#city").keyup(function() {
			CheckCity();
		});

		$("#city").focus(function() {
			CheckCity();
		});

		$("#city").click(function() {
			CheckCity();
		});

		$("#city").change(function() {
			CheckCity();
		});
		
		function CheckCity() {
			var c = $("#city").attr("value");
			var p = $("#province").attr("value");
			$.ajax({
                type: "POST",
                data: {
					province: p,
					city: c
				},
//                url: base_url + "powiaty/miasto/" + province + "/" + city + "/" + Math.random(),
				url: base_url + "powiaty/miasto/" + Math.random(),
                dataType: "xml",
                success: function(xml) {
                    $(xml).find('exists').each(function(){
                    	if($(this).text() == 'true') {
                    		$("#distance").attr("disabled", false);
                    	}
                    	 else {
                    		 $("#distance").attr("disabled", true);
                    	 }
                    		
                         
                    }); 
                }
            }); // end $.ajax
		}
		
	});
