// MFZ: Autovervollständigung der freien Ortseingabefelder
function autocomplete(targetfield) {
	$(targetfield).unbind().autocomplete();
	$(targetfield).autocomplete("getcity.php", {
	    formatItem: function(row) {
	    	var returnstr = row[0] + " " + row[1];
	    	//if (row[2] != "D") returnstr = returnstr + row[2];
	        return returnstr;
	    },
	    formatResult: function(row) {
	        return row[0] + " " + row[1];
	    },
	    max:25,
	    selectFirst:true,
	    cacheLength:1,
	    matchContains:true,
	    width:350
	});
}

// PN: Autovervollständigung der freien Ortseingabefelder
function getcities(targetfield) {
	$(targetfield).unbind().autocomplete();
	$(targetfield).autocomplete("getcity_orttlref2.php", {
	    formatItem: function(row) {
	    	var returnstr = row[0] + " " + row[1];
	    	//if (row[2] != "D") returnstr = returnstr + row[2];
	        return returnstr;
	    },
	    formatResult: function(row) {
	        return row[0] + " " + row[1];
	    },
	    max:20,
	    selectFirst:true,
	    cacheLength:1,
	    matchContains:true,
	    width:350
	});
}

// Ermittelt die Orte im Umkreis von 150km um den Abfahrtsort
// (parameter "value": PLZ und/oder Ortsname, um den herum gesucht wird)
kgs = "";
function getcitiesambit(targetfield, value, ambitkm) {
	$(targetfield).unbind().autocomplete();
	$(targetfield).autocomplete("getcity_orttlref2.php", {
	    formatItem: function(row) {
	    	var returnstr = row[0] + " " + row[1];
	    	//if (row[2] != "D") returnstr = returnstr + row[2];
	        return returnstr;
	    },
	    formatResult: function(row) {
	        return row[0] + " " + row[1];
	    },
	    max:20,
	    selectFirst:true,
	    cacheLength:1,
	    matchContains:true,
	    width:350,
   		extraParams: {ambit:value, ambitkm:ambitkm }
	});
}

// Ermittelt die Orte in einem Landkreis
// (parameter "value": erste 5 Stellen des KGS)
function getcitiesdistrict(targetfield, value) {
	$(targetfield).unbind().autocomplete();
	$(targetfield).autocomplete("getcity_orttlref2.php", {
	    formatItem: function(row) {
	    	var returnstr = row[0] + " " + row[1];
	    	//if (row[2] != "D") returnstr = returnstr + row[2];
	        return returnstr;
	    },
	    formatResult: function(row) {
	        return row[0] + " " + row[1];
	    },
	    max:20,
	    selectFirst:true,
	    cacheLength:1,
	    matchContains:true,
	    width:350,
   		extraParams: {district:value}
	});
}

// Ermittelt die Orte in einem Bundesland
// (parameter "value": erste 2 Stellen des KGS)
function getcitiescountry(targetfield, value) {
	$(targetfield).unbind().autocomplete();
	$(targetfield).autocomplete("getcity_orttlref2.php", {
	    formatItem: function(row) {
	    	var returnstr = row[0] + " " + row[1];
	    	//if (row[2] != "D") returnstr = returnstr + row[2];
	        return returnstr;
	    },
	    formatResult: function(row) {
	        return row[0] + " " + row[1];
	    },
	    max:20,
	    selectFirst:true,
	    cacheLength:1,
	    matchContains:true,
	    width:350,
   		extraParams: {country:value}
	});
}

