var adrSearch=null,ADR_SEARCH_URL="AdrWs/matchAddressWS.ashx",ADR_INP_CITY="inputBy",ADR_INP_ROAD="inputVej",ADR_RES_ROAD="selectVej";function SetUpAddressSearch(){with(document){adrSearch=new adropslag(ADR_SEARCH_URL,"",getElementById(ADR_INP_CITY),getElementById(ADR_INP_ROAD),"",getElementById(ADR_RES_ROAD));adrSearch.onhusnrchange=onHusnrChange;adrSearch.onMessage=OnMessage;adrSearch.onSelectionChange=OnSelectionChange}}function onHusnrChange(){}function OnMessage(c,b,d,a){switch(b){case-1:document.getElementById("DivText").innerHTML=a!=""?a:"&nbsp;";break;default:document.getElementById("ErrText").innerHTML=a!=""?a:"&nbsp;"}}function OnSelectionChange(b){if(b.selStreetList.options.length==0){var a=100;x=b.x;y=b.y;viewport.mapCtrl.zoomToExtent(new OpenLayers.Bounds(x-a,y-a,x+a,y+a))}return false}function AdrDoFind(){adrSearch.onGoFind()}function AdrClear(){adrSearch.inpCityName.value="";adrSearch.inpStreetName.value="";adrSearch.selStreetList.length=0;adrSearch.selStreetList.style.visibility="hidden";document.getElementById("ErrText").innerHTML="&nbsp;";document.getElementById("DivText").innerHTML="&nbsp;"}var _adrobj=null,_MunCode="";function adrOnFocus(){with(_adrobj){focusCtl=1;timerCount=0}}function adrOnBlur(){_adrobj.focusCtl=0}function DoCheckAdrVid(tstvid){with(_adrobj){var vej=tstvid==""&&inpStreetName?inpStreetName.value:"",cit=inpCityName?inpCityName.value:"",pnr="",hnr="";vej=vej.replace(/(^\s*|\s*$)/g,"");cit=cit.replace(/(^\s*|\s*$)/g,"");var re=/(\s*[,\s]\s*\d{1,3}(\s*([A-Z|a-z]{1,2}))?)$/g,komChk,ok=true;while(ok){komChk=vej.match(/\s*,/g);if(komChk){var x=vej.match(re);if(x)if(x.index==komChk.index)ok=false;if(ok)vej=vej.substring(0,komChk.index)}else ok=false}var hnrChk=(" "+vej).match(re);if(hnrChk){var h=hnrChk[0];vej=vej.substring(0,vej.length-h.length);hnr=h.replace(",","").replace(/\s*/g,"")}else vej=vej.replace(/[\%\*]$/,"");var re=/^\d{0,3}[\d\%\*]\s*/,pnrChk=(cit+" ").match(re);if(pnrChk){var p=pnrChk[0];cit=cit.substring(p.length,cit.length);pnr=p.replace(/\s*[\%\*]?/g,"")}if(tstvid==""&&vej==""&&hnr==""&&pnr==""&&cit=="")onMessage&&onMessage(_adrobj,1,0,"Intet kriterie indtastet!!");else if(vej!=chkvej||hnr!=chkhnr||pnr!=chkpnr||cit!=chkcit){adrShowDropdown(false);loadPage(1,"?PostCode="+pnr+"&CityName="+cit+"&VejId="+tstvid+"&StreetName="+vej+"&HusNr="+hnr+"&MaxCnt="+MaxCnt+"&MaxSel="+MaxSel);chkcit=cit;chkpnr=pnr;chkvej=vej;chkhnr=hnr;onMessage&&onMessage(_adrobj,0,0,"");focusCtl=2}}}function DoCheckAdr(){with(_adrobj)(inpStreetName.value.length>0||inpCityName.value.length>0)&&DoCheckAdrVid("")}function adrTimerEvent(){with(_adrobj)if(focusCtl==1){timerCount+=1;dropdownTimeout<=timerCount&&DoCheckAdr()}}function adrShowDropdown(a){if(_adrobj.onChangeDropDownState)_adrobj.onChangeDropDownState(a);_adrobj.selStreetList.style.visibility=a?"visible":"hidden"}function adrClearStreetName(){with(_adrobj)selStreetList.length=0}function adrStreetListOnClick(){with(_adrobj){if(selStreetList.options.length==0)return;var sx=selStreetList.selectedIndex;if(sx<0)return;var cit,pnr=postnr[sx],vid=selStreetList.options[sx].value,vej=selStreetList.options[sx].text,hnr;ix=vej.indexOf("(");if(0<ix){pnr=vej.substring(ix+1,ix+5);cit=vej.substring(ix+6,vej.length-1);var ix2=ix-1;ix--;while(0<=ix2&&vej.substring(ix2-1,ix2)!=" ")ix2--;hnr=vej.substring(ix2,ix);vej=vej.substring(0,ix2-1);chkpnr=pnr;chkcit=cit;chkvej=vej;chkhnr=hnr;if(hnr=="*")hnr="";else{adrClearStreetName();adrShowDropdown(false);onMessage&&onMessage(_adrobj,-1,0,"")}}if(pnr!="")cit=pnr+" "+cit;inpCityName.value=cit;if(hnr!="")vej=vej+" "+hnr;inpStreetName.value=vej;if(selStreetList.options.length!=1)hnr==""&&DoCheckAdrVid(vid);x=coords[sx][0];y=coords[sx][1];var komk_vejk=coords[sx][2];chkkomnr=komk_vejk.substr(0,4);chkvejkod=komk_vejk.substring(4);if(chkcit.indexOf(",")==-1){chkpostby="";chkby=chkcit}else{var tmp=[];tmp=chkcit.split(", ");chkpostby=tmp[0];chkby=tmp[1]}onSelectionChange&&onSelectionChange(_adrobj)}}function adrStreetListOnKeyUp(b){var a=window.event?window.event.keyCode:b.which;a==13&&adrStreetListOnClick()}function adrLoadPage(requestno,funcname){var a=document.body;a.style.cursor="wait";with(_adrobj){var s=url+funcname;if(_MunCode!="")s+="&MunCode="+_MunCode;request=requestno;iframe.src=s;lastUrl=s}}function adrCheckEnter(a){var key=window.event?window.event.keyCode:a.which;with(_adrobj)if(key==13){if(request!=0)return false;DoCheckAdr()}else{focusCtl=1;timerCount=0}}function adrFillList(a,optionText,optionValue){with(a){var ix=length;options[ix]=new Option;options[ix].text=optionText;options[ix].value=optionValue}}function adrMoveList(list){var res=window.frames.iframe1.document.getElementById("resultList");if(res){var a=res.options.length;_adrobj.postnr.length=a;for(var ix=0;ix<a;ix++)with(res.options[ix]){var elm=res.options[ix],txt=elm.text,dx=txt.indexOf("(");if(0<dx)_adrobj.postnr[ix]=txt.slice(dx+1,dx+5);adrFillList(list,txt,elm.value)}}res=window.frames.iframe1.document.getElementById("status");if(res)with(_adrobj)status=res.innerHTML;res=window.frames.iframe1.document.getElementById("message");if(res)with(_adrobj)message=res.innerHTML;with(_adrobj)onMessage&&onMessage(_adrobj,-1,0,message);_adrobj.coords=window.frames.iframe1.koords}function onAsyncResult(){var ok,c,a=document.body;a.style.cursor="auto";with(_adrobj){switch(request){case 1:adrClearStreetName();adrMoveList(selStreetList,"iframe1");ok=0<selStreetList.length;if(!ok){if(0==parseInt(status))onMessage&&onMessage(_adrobj,2,0,"Ingen veje opfylder det givne kriterie");else onMessage&&onMessage(_adrobj,3,status,"Kriteriet ikke sn\u00e6vert nok, "+status+" passede, specificer n\u00f8jere");return}if(selStreetList.length==1){selStreetList.selectedIndex=0;adrStreetListOnClick()}else useDropdown&&adrShowDropdown(ok)}request=0}}function adropslag(f,e,c,b,d,a){if(_adrobj)throw"Programming concept error: cannot initialize 2 instances of [adropslag] object.";this.url=f;this.maxlist=150;this.useDropdown=false;this.iframe=document.createElement("iframe");this.iframe.style.visibility="hidden";this.iframe.id="iframe1";this.iframe.name="iframe1";document.body.appendChild(this.iframe);this.inpCityName=c;this.inpStreetName=b;this.selStreetList=a;_adrobj=this;if(e){e.onkeyup=adrCheckEnter;e.onfocus=adrOnFocus;e.onblur=adrOnBlur}if(c){c.onkeyup=adrCheckEnter;c.onfocus=adrOnFocus;c.onblur=adrOnBlur}if(b){b.onkeyup=adrCheckEnter;b.onfocus=adrOnFocus;b.onblur=adrOnBlur}if(d){d.onkeyup=adrCheckEnter;d.onfocus=adrOnFocus;d.onblur=adrOnBlur}if(a){a.onclick=adrStreetListOnClick;a.onkeyup=adrStreetListOnKeyUp;this.useDropdown=a.style.visibility.toLowerCase()=="hidden"}this.loadPage=adrLoadPage;this.timerCount=0;this.request=0;this.chkcit="";this.chkpnr="";this.chkvej="";this.chkhnr="";this.chkkomnr="";this.chkvejkod="";this.chkpostby="";this.chkby="";this.x=0;this.y=0;this.coords=[];this.focusCtl=0;this.onhusnrchange=null;this.onChangeDropDownState=null;this.onSelectionChange=null;this.timerTick=1e3;this.dropdownTimeout=4;this.postnr=[];this.lastUrl="";this.status="";this.message="";this.onMessage=null;this.onGoFind=DoCheckAdr;this.MaxSel="";this.MaxCnt="";setInterval(adrTimerEvent,this.timerTick)};
