var tackePuta=[];var uputstvoPuta=[];var PSResults=[];var xTackePuta=[];var yTackePuta=[];var StartStreet=null;var EndStreet=null;var StartStreetX=null;var StartStreetY=null;var EndStreetX=null;var EndStreetY=null;function SetStart(x,y,par){indexPnt=null;tackePuta=[];uputstvoPuta=[];StartStreet=null;clearUputstvo();LeftPanel(3,0);sv(gi("progp1"),1);if(par){StartStreetX=x;StartStreetY=y;}else{if(objectClicked){StartStreetX=clickedObjectPoint.x;StartStreetY=clickedObjectPoint.y;}else{StartStreetX=getClickedLeftInMeter(clickedPoint.x);StartStreetY=getClickedTopInMeter(clickedPoint.y);}}executeAjaxRequest("Services/SearchPath.aspx?&act=addPoint&x="+StartStreetX+"&y="+StartStreetY+"&Uloga=0&Naziv=","findPathPoint(response, 1)","pathstart");}function findPathPoint(objectsXML,tip){try{var xmlDoc=XMLParser(objectsXML);if(xmlDoc){var p;var allP=xmlDoc.documentElement.getElementsByTagName("p");if(allP){var tP=allP[0];sP=new yObject();sP.Naziv=tP.getAttribute("Naziv");if(tip==1){sP.x=StartStreetX;sP.y=StartStreetY;StartStreet=sP;ClearRouteSearchText(put_text1);put_text1.value=StartStreet.Naziv;}else if(tip==2){sP.x=EndStreetX;sP.y=EndStreetY;EndStreet=sP;ClearRouteSearchText(put_text2);put_text2.value=EndStreet.Naziv;}var offX=(sP.x-getLeftInMeter())/z.mPerPX;if(offX<340){centriranjeMape=false;setTimeout("centerMap2("+(340-offX+20)+",0)",50);}clearPath();paintPath();sv(gi("progp1"),0);sv(gi("progp2"),0);if(StartStreet&&EndStreet)SearchPath();}}hideMenu();hideMenu2();}catch(ex){sv(gi("progp1"),0);sv(gi("progp2"),0);}}function SetEnd(x,y,par){indexPnt=null;tackePuta=[];uputstvoPuta=[];EndStreet=null;clearUputstvo();LeftPanel(3,0);sv(gi("progp2"),1);if(par){EndStreetX=x;EndStreetY=y;}else{if(objectClicked){EndStreetX=clickedObjectPoint.x;EndStreetY=clickedObjectPoint.y;}else{EndStreetX=getClickedLeftInMeter(clickedPoint.x);EndStreetY=getClickedTopInMeter(clickedPoint.y);}}executeAjaxRequest("Services/SearchPath.aspx?&act=addPoint&x="+EndStreetX+"&y="+EndStreetY+"&Uloga=0&Naziv=","findPathPoint(response, 2)","pathend");}function locatePathPoint(tip,x,y){var cX=getLeftInMeter()+getWidthInMeter()/2;var cY=getTopInMeter()+getHeightInMeter()/2;var centerMetX=cX/z.mPerPX;var centerMetY=cY/z.mPerPX;if(!IsFullMap()){centerMetX+=170;cX+=170*z.mPerPX;}var go=false;if(tip==1&&StartStreet){x=StartStreetX;y=StartStreetY;go=true;locateObjects(cX,cY,cX,cY);}else if(tip==2&&EndStreet){x=EndStreetX;y=EndStreetY;go=true;locateObjects(cX,cY,cX,cY);}if(tip!=1&&tip!=2&&x!=0&&y!=0)go=true;var dX=Math.round(centerMetX-x/z.mPerPX);var dY=Math.round(centerMetY-y/z.mPerPX);var w=getStyleWidth(mapContainer);var h=getStyleHeight(mapContainer);if(go){locateObjects(x,y,x,y);}}function PathSearch(tip){hideSrcObjectLayer(true);resetPathWOPoints();var srcput;if(tip==1){sv(gi("progp1"),1);srcput=ReplaceLatin(put_text1.value);}else if(tip==2){srcput=ReplaceLatin(put_text2.value);sv(gi("progp2"),1);}executeAjaxRequest("Services/SearchUni.aspx?act=src&src="+srcput+"&srct="+4+"&lang="+lang,"displayPathSearch(response, "+tip+")","pathsearch");}function resetPathWOPoints(){tackePuta=[];uputstvoPuta=[];PSResults=[];xTackePuta=[];yTackePuta=[];srcpath.innerHTML="";searchputr.innerHTML="";sv(searchputr,0);}function resetPath(){tackePuta=[];uputstvoPuta=[];PSResults=[];xTackePuta=[];yTackePuta=[];StartStreet=null;EndStreet=null;StartStreetX=null;StartStreetY=null;EndStreetX=null;EndStreetY=null;srcpath.innerHTML="";searchputr.innerHTML="";sv(searchputr,0);put_text1.value="";put_text2.value="";}function displayPathSearch(objectsXML,tip){try{PSResults=[];var xmlDoc=XMLParser(objectsXML);if(xmlDoc){var red;var sRed=xmlDoc.documentElement.getElementsByTagName("r");if(sRed){for(var i=0;i<sRed.length;i++){var tR=sRed[i];red=new yObject();red.RB=tR.getAttribute("RB");red.R1=tR.getAttribute("R1");red.R2=tR.getAttribute("R2");red.x=tR.getAttribute("X");red.y=tR.getAttribute("Y");PSResults[i]=red;}if(PSResults.length>1){SetPutSRVisibility(tip,1);displayPathSearchResults(tip);}else{SetPutSRVisibility(tip,0);var txt=PSResults[0].R1;if(PSResults[0].R2!=null)txt=txt+", "+PSResults[0].R2;if(tip==1){StartStreet=PSResults[0];StartStreet.Naziv=txt;StartStreet.x=PSResults[0].x;StartStreet.y=PSResults[0].y;StartStreetX=PSResults[0].x;StartStreetY=PSResults[0].y;put_text1.value=txt;locateObjects(StartStreet.x,StartStreet.y,StartStreet.x,StartStreet.y);if(EndStreet)SearchPath();}else if(tip==2){EndStreet=PSResults[0];EndStreet.Naziv=txt;EndStreet.x=PSResults[0].x;EndStreet.y=PSResults[0].y;EndStreetX=PSResults[0].x;EndStreetY=PSResults[0].y;put_text2.value=txt;locateObjects(EndStreet.x,EndStreet.y,EndStreet.x,EndStreet.y);if(StartStreet)SearchPath();}}sv(gi("progp1"),0);sv(gi("progp2"),0);}}}catch(ex){sv(gi("progp1"),0);sv(gi("progp2"),0);}}function SetPutSRVisibility(tip,visible){sv(putSR,visible);if(visible){if(tip==1){setStyleTop(putSR,29);setStyleTop(putw2,29+130+5);setStyleTop(putTip,29+130+5+29);}else if(tip==2){setStyleTop(putSR,25+24+5);setStyleTop(putw2,29);setStyleTop(putTip,29+130+5+29);}}else{setStyleTop(putw2,29);setStyleTop(putTip,29+29);}}function SearchAllResults(tip){SetPutSRVisibility(1,0);if(tip==1)tbsrc.value=put_text1.value;else if(tip==2)tbsrc.value=put_text2.value;SearchObjects('src',0);}function displayPathSearchResults(tip){try{putSR.innerHTML="";var mybody=document.getElementsByTagName("body")[0];mytable=document.createElement("table");mytablebody=document.createElement("tbody");mycurrent_row=document.createElement("tr");mycurrent_cell=document.createElement("td");mycurrent_cell.style.verticalAlign="top";mycurrent_cell.style.horizontalAlign="left";var naslov=document.createElement("div");var nS="Rezultati";var link="&nbsp;&nbsp;(<a style='color=#237dd7;text-decoration:underline;' href='javascript:SearchAllResults("+tip+");'>";if(lang=="en-us"){nS="Results";}if(PSResults.length>2){if(lang=="en-us"){link+="click here for more...</a>)";}else{link+="kliknite ovde za jo&#353;...</a>)";}nS+=link;}naslov.innerHTML=nS;naslov.style.width=220;naslov.style.fontWeight="bold";mycurrent_cell.appendChild(naslov);mycurrent_row.appendChild(mycurrent_cell);mytablebody.appendChild(mycurrent_row);for(var i=0;i<PSResults.length;i++){var sres=PSResults[i];mycurrent_row=document.createElement("tr");mycurrent_cell=document.createElement("td");mycurrent_cell.style.verticalAlign="top";mycurrent_cell.style.horizontalAlign="left";var txt=sres.R1;if(sres.R2!=null)txt=txt+", "+sres.R2;var naslov=document.createElement("div");naslov.innerHTML=txt;naslov.style.width=220;naslov.style.paddingLeft="10px";mycurrent_cell.appendChild(naslov);mycurrent_row.appendChild(mycurrent_cell);mycurrent_row.setAttribute("x",sres.x);mycurrent_row.setAttribute("y",sres.y);mycurrent_row.setAttribute("u",txt);mycurrent_row.setAttribute("t",tip);mycurrent_row.style.cursor="pointer";mycurrent_row.onclick=function(){if(this.getAttribute("t")=="1"){StartStreet=new yObject();StartStreet.Naziv=this.getAttribute("u");StartStreet.x=this.getAttribute("x");StartStreet.y=this.getAttribute("y");StartStreetX=this.getAttribute("x");StartStreetY=this.getAttribute("y");put_text1.value=this.getAttribute("u");locateObjects(StartStreet.x,StartStreet.y,StartStreet.x,StartStreet.y);}else if(this.getAttribute("t")=="2"){EndStreet=new yObject();EndStreet.Naziv=this.getAttribute("u");EndStreet.x=this.getAttribute("x");EndStreet.y=this.getAttribute("y");EndStreetX=this.getAttribute("x");EndStreetY=this.getAttribute("y");put_text2.value=this.getAttribute("u");locateObjects(EndStreet.x,EndStreet.y,EndStreet.x,EndStreet.y);}SetPutSRVisibility(1,0);if(StartStreet&&EndStreet)SearchPath();};mytablebody.appendChild(mycurrent_row);mytable.appendChild(mytablebody);mytable.setAttribute("cellSpacing","1");putSR.appendChild(mytable);}sv(putSR,1);}catch(ex){}}function ResetStart(){StartStreet=null;put_text1.value="";}function ResetEnd(){EndStreet=null;put_text2.value="";}function SearchPath(){ChangeBaner();sv(gi("progp1"),1);sv(gi("progp2"),1);executeAjaxRequest("Services/SearchPath.aspx?act=path&x1="+StartStreet.x+"&y1="+StartStreet.y+"&Naziv1=&x2="+EndStreet.x+"&y2="+EndStreet.y+"&Naziv2="+"&tip="+putSrcType,"displayPath(response)","path");}function displayPath(objectsXML){try{uputstvoPuta=[];tackePuta=[];var objlMaxX=0;var objlMaxY=0;var objlMinX=fullX;var objlMinY=fullY;var xmlDoc=XMLParser(objectsXML);if(xmlDoc){tackePuta=[];var tacka;var sveTacke=xmlDoc.documentElement.getElementsByTagName("p");if(sveTacke){for(var i=0;i<sveTacke.length;i++){var trenutnaTacka=sveTacke[i];tacka=new yObject();tacka.x=trenutnaTacka.getAttribute("x");tacka.y=trenutnaTacka.getAttribute("y");tackePuta[i]=tacka;if(parseInt(tacka.x)>objlMaxX)objlMaxX=parseInt(tacka.x);if(parseInt(tacka.y)>objlMaxY)objlMaxY=parseInt(tacka.y);if(parseInt(tacka.x)<objlMinX)objlMinX=parseInt(tacka.x);if(parseInt(tacka.y)<objlMinY)objlMinY=parseInt(tacka.y);}}uputstvoPuta=[];var uputstvo;var svaUputstva=xmlDoc.documentElement.getElementsByTagName("u");if(svaUputstva){var m=0;for(var i=0;i<svaUputstva.length;i++){var trenutnoUputstvo=svaUputstva[i];uputstvo=new yObject();uputstvo.Opis=trenutnoUputstvo.getAttribute("O");uputstvo.Pravac=trenutnoUputstvo.getAttribute("Pr");uputstvo.PravacTekst=trenutnoUputstvo.getAttribute("PrT");uputstvo.PredjeniPut=trenutnoUputstvo.getAttribute("PP");uputstvo.DaSePredjePut=trenutnoUputstvo.getAttribute("DSP");uputstvo.DFI=trenutnoUputstvo.getAttribute("IP");uputstvo.DLI=trenutnoUputstvo.getAttribute("IK");uputstvoPuta[i]=uputstvo;m++;}uputstvo1=new yObject();if(lang=="en-us")uputstvo1.Opis="Destination";else uputstvo1.Opis="Destinacija";uputstvo1.Pravac=0;uputstvo1.PravacTekst="";uputstvo1.PredjeniPut=parseInt(uputstvo.PredjeniPut)+parseInt(uputstvo.DaSePredjePut);uputstvo1.DaSePredjePut=0;uputstvo1.DFI=tackePuta.length-1;uputstvo1.DLI=tackePuta.length-1;uputstvoPuta[m]=uputstvo1;}displayUputstvo();if(tackePuta.length>0){locateObjects(objlMaxX,objlMaxY,objlMinX,objlMinY);}}sv(gi("progp1"),0);sv(gi("progp2"),0);}catch(ex){displayUputstvo();sv(gi("progp1"),0);sv(gi("progp2"),0);}}function clearUputstvo(){searchputr.innerHTML="";}function displayUputstvo(){try{searchputr.innerHTML="";var mybody=document.getElementsByTagName("body")[0];var suma=document.createElement("div");suma.style.width="100%";suma.style.margin="5px";suma.style.fontWeight="bold";if(uputstvoPuta.length>0){var uputstvo=uputstvoPuta[uputstvoPuta.length-1];if(lang=="en-us")suma.innerHTML="Total route length: "+uputstvo.PredjeniPut+"m";else suma.innerHTML="Ukupna du&#382;ina puta: "+uputstvo.PredjeniPut+"m";searchputr.appendChild(suma);}else{if(lang=="en-us")suma.innerHTML="No route found.";else suma.innerHTML="Putanja nije nadjena.";searchputr.appendChild(suma);return;}mtb=document.createElement("table");mtbb=document.createElement("tbody");var j=0;for(var i=0;i<uputstvoPuta.length;i++){var uputstvo=uputstvoPuta[i];var uputstvo1=uputstvoPuta[i+1];srednjaTacka=tackePuta[uputstvo.DFI];mr1=document.createElement("tr");mr1.style.width="290px";mc1=document.createElement("td");mc1.setAttribute("class","c1");if(isIe){mc1.style.verticalAlign="top";mc1.style.horizontalAlign="center";mc1.align="center";mc1.style.width="36px";mc1.style.clientWidth=36;}k=i+1;var image=document.createElement("img");var loc="Services/getIcon.aspx?file=";if(i==0){loc=loc+"prStart.gif";}else if(i<uputstvoPuta.length-1){loc="Services/GetRouteIcon.aspx?n="+k;}else if(i==uputstvoPuta.length-1){loc=loc+"prEnd.gif";}image.setAttribute("src",loc);image.style.width="20px";image.style.height="18px";mc1.appendChild(image);mr1.appendChild(mc1);mc2=document.createElement("td");mc2.setAttribute("class","c2");if(isIe){mc2.style.paddingTop="3px";mc2.style.paddingBottom="3px";mc2.style.paddingRight="8px";}var pravac=document.createElement("div");if(lang=="en-us"){if(uputstvo.Pravac==1)pravac.innerHTML='At '+uputstvo.PredjeniPut+'m keep straight '+uputstvo.DaSePredjePut+'m';if(uputstvo.Pravac==2)pravac.innerHTML='At '+uputstvo.PredjeniPut+'m go back '+uputstvo.DaSePredjePut+'m';if(uputstvo.Pravac==3)pravac.innerHTML='At '+uputstvo.PredjeniPut+'m turn left and continue '+uputstvo.DaSePredjePut+'m';if(uputstvo.Pravac==4)pravac.innerHTML='At '+uputstvo.PredjeniPut+'m turn right and continue '+uputstvo.DaSePredjePut+'m';}else{if(uputstvo.Pravac==1)pravac.innerHTML='Na '+uputstvo.PredjeniPut+'m nastavite pravo '+uputstvo.DaSePredjePut+'m';if(uputstvo.Pravac==2)pravac.innerHTML='Na '+uputstvo.PredjeniPut+'m idite nazad '+uputstvo.DaSePredjePut+'m';if(uputstvo.Pravac==3)pravac.innerHTML='Na '+uputstvo.PredjeniPut+'m skrenite levo i idite '+uputstvo.DaSePredjePut+'m';if(uputstvo.Pravac==4)pravac.innerHTML='Na '+uputstvo.PredjeniPut+'m skrenite desno i idite '+uputstvo.DaSePredjePut+'m';}pravac.style.width="100%";if(uputstvo.Pravac>=1&&uputstvo.Pravac<=4)mc2.appendChild(pravac);var opis=uputstvo.Opis;if(i>0){opis=uputstvoPuta[i-1].Opis+" -> "+uputstvo.Opis;}var naslov=document.createElement("div");naslov.innerHTML=opis;naslov.style.width="250px";mc2.appendChild(naslov);mr1.appendChild(mc2);mr1.setAttribute("x",srednjaTacka.x);mr1.setAttribute("y",srednjaTacka.y);mr1.setAttribute("index",k);mr1.style.cursor="pointer";mr1.onclick=function(){indexPnt=this.getAttribute("index");locatePathPoint(0,this.getAttribute("x"),this.getAttribute("y"));};mr1.style.height="30px";mtbb.appendChild(mr1);}mtb.appendChild(mtbb);mtb.style.width="100%";mtb.setAttribute("cellSpacing","0");searchputr.appendChild(mtb);sv(searchputr,1);}catch(ex){}}function clearPath(){srcpath.innerHTML="";}function paintPath(cela){try{if(put.style.visibility=="visible"){var ieput=gi("ieput");var gcput=gi("gcput");if(showFoundPath==true){setStyleLeft(srcpath,getStyleLeft(mainContainer));setStyleTop(srcpath,getStyleTop(mainContainer));sv(srcpath,1);var o=100*z.mPerPX;var left=getLeftInMeter()-o;var top=getTopInMeter()-o;var right=getLeftInMeter()+getWidthInMeter()+o;var bottom=getTopInMeter()+getHeightInMeter()+o;if(!cela){var pomX=(z.deltaX-centerPomX)*z.cellWidth;var pomY=(z.deltaY-centerPomY)*z.cellHeight;var points="";var x0=0;var y0=0;var inc=1;if(z.zoom>4)inc=3;if(z.zoom>7)inc=10;for(var i=0;i<tackePuta.length-inc;i+=inc){var point=tackePuta[i];var pointn=tackePuta[i+1];var x1=parseInt(point.x/z.mPerPX-pomX);var y1=parseInt(point.y/z.mPerPX-pomY);if(point.x>=left&&point.x<=right&&point.y>=top&&point.y<=bottom){if(x1!=x0||y1!=y0){points=points+x1+","+y1+" ";x0=x1;y0=y1;}}}if(points!=""){if(isIe){var iepath=document.createElement("v:polyline");iepath.id="ieput";iepath.setAttribute("obj","no");iepath.setAttribute("points",points);iepath.setAttribute("filled","false");var iepathstroke=document.createElement("v:stroke");iepathstroke.setAttribute("weight","5pt");iepathstroke.setAttribute("color","#237dd7");iepathstroke.setAttribute("opacity","50%");iepath.appendChild(iepathstroke);srcpath.appendChild(iepath);}else{var svg=document.createElementNS('http://www.w3.org/2000/svg','svg');svg.id="gcput";svg.setAttribute('width',document.body.clientWidth*2);svg.setAttribute('height',document.body.clientHeight*2);svg.style.cursor="pointer";svg.onmousemove=mouseMove;svg.onmousedown=mouseDown;svg.onmouseup=mouseUp;svg.onmousewheel=wheel;var path=document.createElementNS('http://www.w3.org/2000/svg','polyline');path.setAttributeNS(null,"fill","none");path.setAttributeNS(null,"stroke","#237dd7");path.setAttributeNS(null,"stroke-width","5");path.setAttributeNS(null,"stroke-opacity","0.5");path.setAttributeNS(null,"points",points);svg.appendChild(path);srcpath.appendChild(svg);srcpath.style.cursor="pointer";}}}var pomX1=(z.deltaX-centerPomX)*z.cellWidth;var pomY1=(z.deltaY-centerPomY)*z.cellHeight;for(var j=0;j<uputstvoPuta.length;j++){var sobject=tackePuta[uputstvoPuta[j].DFI];var newObject=document.createElement("img");newObject.className="object";newObject.setAttribute("x",sobject.x);newObject.setAttribute("y",sobject.y);newObject.setAttribute("s","pathpoint");var x=sobject.x/z.mPerPX-pomX1;var y=sobject.y/z.mPerPX-pomY1;var k=j+1;;if(j==0){DrawShadow(x,y);y-=25;newObject.setAttribute("src","Services/getIcon.aspx?file="+"prStart1.gif");}else if(j<uputstvoPuta.length-1){x-=10;y-=9;newObject.setAttribute("src","Services/GetRouteIcon.aspx?n="+k);newObject.style.width="20px";newObject.style.height="18px";}else if(j==uputstvoPuta.length-1){DrawShadow(x,y);y-=25;newObject.setAttribute("src","Services/getIcon.aspx?file="+"prEnd1.gif");}setStyleLeft(newObject,x);setStyleTop(newObject,y);newObject.oncontextmenu=showMenu;if(showFoundPath==true){srcpath.appendChild(newObject);}}if(StartStreet&&tackePuta.length==0){DrawPoint(StartStreet,"prStart1.gif");}if(EndStreet&&tackePuta.length==0){DrawPoint(EndStreet,"prEnd1.gif");}}}}catch(ex){}}function DrawPoint(point,ikona){if(showFoundPath==true){var pomX1=(z.deltaX-centerPomX)*z.cellWidth;var pomY1=(z.deltaY-centerPomY)*z.cellHeight;var newObject=document.createElement("img");newObject.className="object";var x=point.x/z.mPerPX-pomX1;var y=point.y/z.mPerPX-pomY1;newObject.setAttribute("src","Services/getIcon.aspx?file="+ikona);setStyleLeft(newObject,x);setStyleTop(newObject,y-25);newObject.setAttribute("x",point.x);newObject.setAttribute("y",point.y);newObject.oncontextmenu=showMenu;DrawShadow(x,y);srcpath.appendChild(newObject);}}function DrawShadow(x,y){var noS=document.createElement("img");noS.className="objectsh";noS.setAttribute("src","Services/getIcon.aspx?file=prShadow.gif");setStyleLeft(noS,x);setStyleTop(noS,y-25);srcpath.appendChild(noS);}