		var geocoder = new GClientGeocoder();
		var places;
		var isPLZ=false;
		var inCache=false;
		var cookieData=cookieToArray("hlp_geo");
		if(cookieData['f_address']){
			document.getElementById("f_address").value=cookieData['f_address'];
			document.getElementById("f_utme").value=cookieData["f_utme"];
			document.getElementById("f_utmn").value=cookieData["f_utmn"];
			document.getElementById("f_utmz").value=cookieData["f_utmz"];
			document.getElementById("f_utme_ln").value=cookieData["f_utme_ln"];
			document.getElementById("f_utmn_ln").value=cookieData["f_utmn_ln"];
			document.getElementById("f_utmz_ln").value=cookieData["f_utmz_ln"];
			document.getElementById("f_utme_rn").value=cookieData["f_utme_rn"];
			document.getElementById("f_utmn_rn").value=cookieData["f_utmn_rn"];
			document.getElementById("f_utmz_rn").value=cookieData["f_utmz_rn"];
			document.getElementById("ctr_code").value=cookieData["ctr_code"];
			getPlaces();
		}
		
		
		
		function setCache(toSet){
			var httpSetter;
			if(window.XMLHttpRequest){
				httpSetter = new XMLHttpRequest();
			}else if(window.ActiveXObject){
				try{
			
				 	httpSetter=new ActiveXObject("Msxml2.XMLHTTP");
				 }catch(e){
					
				 	httpSetter=new ActiveXObject("Microsoft.XMLHTTP");
				 }
				//httpSetter = new ActiveXObject("Microsoft.XMLHTTP");
			}
			
			try{
				httpSetter.open("POST" , "/acp/lib/gmapscache.php" , true);
				httpSetter.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				httpSetter.send("address="+toSet[1]+"&lat="+toSet[2]+"&lon="+toSet[3]+"&country_code="+toSet[4]+"&search_string="+document.getElementById("f_address").value+"&type=set");
			}catch(e){
				alert(e);
			}
		}
		
		function lookupGmapsCache(searchString){
			var http = null;
			if(window.XMLHttpRequest){
				http = new XMLHttpRequest();
			}else if(window.ActiveXObject){
				try{
			
				 	http=new ActiveXObject("Msxml2.XMLHTTP");
				 }catch(e){
					
				 	http=new ActiveXObject("Microsoft.XMLHTTP");
				 }
			}
			
			try{
				http.open("POST" , "/acp/lib/gmapscache.php" , false);
				http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				http.send("val="+searchString+"&type=get");
				if(http.responseText != "nope"){
					var cacheJSON=http.responseText;
					try{
					cacheJSON=eval("("+cacheJSON+")");
					inCache=true;
					}catch(e2){
						alert(e2);
					}
				}else{
					inCache=false;
				}
			}catch(e){
				alert(e);
			}
			
			if (inCache){
				cnt_cj=cacheJSON.length;
				for (var i=0; i<cnt_cj;i++){
					place=new Array();
					place[0]=i;
					place[1]=cacheJSON[i].gmaps_string;
					place[2]=cacheJSON[i].lat;
					place[3]=cacheJSON[i].lon;
					place[4]=cacheJSON[i].country_code;
					places.push(place);
					if(i<cnt_cj-1){
						setList(place, false);
					}else{
						setList(place, true);
					}
				}
			}
		
		}
		
		
		
		
		function getPlaces(){
      
			places=new Array();
			clearList();
			var lookup=document.getElementById('f_address').value;
			if(document.getElementById('inat')){
				if(document.getElementById('inat').checked==true){
					var inat="inat";
				}else{
					if(lookup.search(/(deutschland) | (germany)/i)==-1){
						lookup=lookup+", Deutschland";
					}
				}
			}else{
				if(lookup.search(/deutschland/i)==-1 && lookup.search(/germany/i)==-1){
						lookup=lookup+", Deutschland";
				}
			}
			if(document.getElementById("f_address").value.search(/^[0-9 ]*$/)==-1){
				isPLZ=false;
				lookupGmapsCache(lookup);
			}else{
				isPLZ=true;
				inCache=false;
			}
			if(!inCache)
      {
				geocoder.getLocations(
				lookup,
				evalResults
				)
			}
		}
			
		function evalResults(response){
			if (!response || response.Status.code != 200){
				alert("Address not found...");
			}else{
				var cnt=response.Placemark.length;
				for (var i=0 ; i < cnt ; i++){
					place=new Array(6);
					var val;
					place[0]=i;
					place[1]=response.Placemark[i].address;
					place[2]=response.Placemark[i].Point.coordinates[1];
					place[3]=response.Placemark[i].Point.coordinates[0];
					place[4]=response.Placemark[i].AddressDetails.Country.CountryNameCode;
					if(isPLZ==false){
						setCache(place);
					}
			        for (p in response.Placemark[i]){
						place[5]+=p;
					}
					places.push(place);
					if(i<cnt-1){
						setList(place, false);
					}else{
						setList(place, true);
					}
				}
			}
		}
		
		function clearList(){
			var toClear = document.getElementById('searchResults');
			var ll = toClear.length;
			for (i=0; i < ll; i++){
				toClear.options[toClear.length-1] = null;
			}
		}
		
		function setList(place , show){
      
			actList=document.getElementById('searchResults');
			var myOption = document.createElement("option");
			var myText = document.createTextNode(place[0]+"# "+place[1]);
			myOption.appendChild(myText);
			actList.appendChild(myOption);
			if (show){
				if(places.length<2){
					document.getElementById('more_results').style.display="none";
				}else{
					document.getElementById('more_results').style.display="block";
				}
				setSearchData();
			}
		}
		
		function setSearchData(){
			
			var actList=document.getElementById('searchResults');
			sNum=getSelection(actList);
			if(sNum){
				var selection = actList[sNum].text;
			}else{
				var selection = actList[0].text;
			}
			var index=parseInt(selection.substring(0,selection.indexOf('#')));
			LatLngToUTM(parseFloat(places[index][2]),parseFloat(places[index][3]));
			document.getElementById("ctr_code").value=places[index][4];
			document.getElementById("f_utme").value=parseInt(utml);
			document.getElementById("f_utmn").value=parseInt(utmb);
			document.getElementById("f_utmz").value=utmz;
			document.getElementById("f_utme_ln").value=parseInt(utml)+500000;
			document.getElementById("f_utmn_ln").value=parseInt(utmb);
			document.getElementById("f_utmz_ln").value=utmz-1;
			document.getElementById("f_utme_rn").value=parseInt(utml)-500000;
			document.getElementById("f_utmn_rn").value=parseInt(utmb);
			document.getElementById("f_utmz_rn").value=utmz+1;
			try{
			document.getElementById('overviewheader').style.display="none";
			document.getElementById('overviewbody').style.display="none";
			}catch(e){
			}
			getGeoEvents();
		}
		
		function getSelection(select){
			try{
			for(i=0;i<select.options.length;i++){
				if(select.options[i].selected==true){
					return i;
				}
			}
			}catch(ex){
				return false;
			}
			return false;
		}
		
		
		
		
		
		