function formatItem(row) {
        return row[1];
}
function formatResult(row) {
        return row[0];
}

$(document).ready(function(){
	$("#plz_ajax").autocomplete("plzortnameajax.php",{
minChars:2,
matchCase:0,
matchSubset:1,
matchContains:1,
cacheLength:0,
formatItem:formatItem,
formatResult:formatResult,
selectOnly:1,
mustMatch:1,
delay:200,
deferRequestBy:0,
max:99,
selectFirst:0,
width:300,
autoFill:0,
onItemSelect: function(event){ $("#plz_result").val($("#plz_ajax").val());
                               if($("#plz_ajax").val().length<5)
							     { //map_canvas.style.display="none";
								   directions.clear();
//								   directions.load("from: 63526 Erlensee, Am Rathaus 61, Germany to: 63526 Erlensee, Am Rathaus 61, Germany");
								   document.getElementById("distance_text1").firstChild.nodeValue="";
								   document.getElementById("distance_text").value="";
								   document.getElementById("distance_text_star").firstChild.nodeValue="";
								 }
							   else
							     { //map_canvas.style.display="block";
//								   var d=document.getElementById("directions");
								   directions.load("from: "+$("#plz_ajax").val()+", Deutschland to: Am Rathaus 61, 63526 Erlensee, Deutschland");
								   $.get('plzortnameajax_log.php?q=' + escape($("#plz_ajax").val()));
//								   directions.load("from: Hamburg, Germany to: 63526 Erlensee, Am Rathaus 61, Germany",{preserveViewport:false, locale:"de_DE"});
								 }
							 }
});
	$("#plz_ajax").change(function(){ $("#plz_input").val($(this).val());
	                               //map_canvas.style.display="none";
								   directions.clear();
								   document.getElementById("distance_text1").firstChild.nodeValue="";
								   document.getElementById("distance_text").value="";
								   document.getElementById("distance_text_star").firstChild.nodeValue="";
	                                });


//    $("#plz_ajax")[0].focus();
	$("#plz_ajax_map").autocomplete("plzortnameajax.php",{
minChars:2,
matchCase:0,
matchSubset:1,
matchContains:1,
cacheLength:0,
formatItem:formatItem,
formatResult:formatResult,
selectOnly:1,
mustMatch:1,
delay:200,
deferRequestBy:0,
max:99,
selectFirst:0,
width:300,
autoFill:0,
onItemSelect: function(event){ if($("#plz_ajax_map").val().length<5)
							     { map_canvas.style.display="none";
								   route.style.display="none";
								   directions.clear();
								   document.getElementById("distance_text1").firstChild.nodeValue="";
								   document.getElementById("distance_text").value="";
								 }
							   else
							     { map_canvas.style.display="block";
								   route.style.display="block";
								   directions.load("from: "+$("#plz_ajax_map").val()+", Deutschland to: Am Rathaus 61, 63526 Erlensee, Deutschland", {"preserveViewpoint": false});
								   $.get('plzortnameajax_log.php?q=' + escape($("#plz_ajax_map").val()));
								 }
							 }
});
	$("#plz_ajax_map").change(function(){
	                               map_canvas.style.display="none";
	                               route.style.display="none";
								   directions.clear();
								   document.getElementById("distance_text1").firstChild.nodeValue="";
								   document.getElementById("distance_text").value="";
	                                });

});

