﻿var map=null;var mapMoved=false;var initialZoom=false;var minZoomLevel=4;var maxZoomLevel=15;var cpLatLongOld=null;var cpZoomOld=null;var panThresHold=100;var zoomThresHold=1;var maxCount=500;var maxCountPerRequest=500;var overallCount=0;var mapOverallCount=0;var mapExactCount=0;var mapNoStreetCount=0;var clusteredPinQuery="";var mapIsLoading=false;var mapViewRefresh=true;var mapBestView=null;var loadPins=true;var height=0;var width=0;var loading="<div class='loaderContent'><img class='loaderContentImg' alt='' src='../_images/v3/icons/icon_wait.gif' /><br />Einen Moment bitte...</div>";var listItem="";var detail="";var detailImage="<img src='{0}' alt='' width='{1}' height='{2}' />";var descForZoom="Bitte klicken Sie hier, um den Kartenausschnitt auf ein kleineres Gebiet zu begrenzen.";var errorToMuchHits="Ihre Suche ergibt mehr als 500 Ergebnisse. Bitte geben Sie weitere Suchkriterien an oder wechseln Sie zur Listenansicht.";var errorZeroHits="Ihr Suchergebnis umfasst {0} Treffer. Um die genaue Position dieser Immobilie{1} zu erfahren, kontaktieren Sie bitte den jeweiligen Anbieter.";var titleForZoom="<h3>Kartenausschnitt verkleinern</h3>";var titleForDetail="<h3>Objektdetails</h3>";var titleForList="<h3>Objekt&uuml;bersicht</h3>";var defaultMapModifier="Kartenausschnitt";var customLayer=null;function InitSpecific(){VEShape.prototype.GUID=null;VEShape.prototype.Count=0;VEShape.prototype.IsClustered=false;VEShape.prototype.IsLoaded=false;VEShape.prototype.BoundingRectangle=null;map.AttachEvent("onchangemapstyle",ChangeMapStyleHandler);map.AttachEvent("onmouseover",MouseEventHandler);height=$("div#iwMap").height();width=$("div#iwMap").width();$("a#aRefresh").click(function(){DoListView(true,1);});}function ShowPushpins(){if(mapIsLoading){return;}if(typeof validMap!="undefined"&&validMap){mapIsLoading=true;map.DeleteAllShapes();map.DeleteRoute();map.DeleteAllShapeLayers();clusteredPinQuery=getParameters();mapObjCount=0;$("#countObjects").html("keine");getClusteredPin(maxCount);}else{AddErrorLayer(errorToMuchHits);}$("#mapLoader").hide();}function DoListView(b,f){if(typeof b=="string"&&b!=""){var d=map.GetShapeByID(b);if(d!=null&&d.IsClustered){SetHiddenFields(d.BoundingRectangle,new VELatLong(d.Latitude,d.Longitude),getZoomLevel(null,true));}}else{if(typeof b=="boolean"&&b){var a=map.GetMapView();var c=map.GetCenter();var e=getZoomLevel();var g=map.GetShapeLayerByIndex(0);if(g!=null&&isFinite(g.Boundingbox.x1)&&isFinite(g.Boundingbox.x2)&&isFinite(g.Boundingbox.y1)&&isFinite(g.Boundingbox.y2)){a=g.GetBoundingRectangle();}SetHiddenFields(a,c,e);}}$("form").append("<input type='hidden' name='display' value='list' />").append("<input type='hidden' name='changeMode' value='true' />");if(typeof f!="undefined"){$("form").append("<input type='hidden' name='mm' value='"+f+"' />");}document.forms[0].submit();return false;}function ChangeMapStyleHandler(a){if(a.mapStyle==VEMapStyle.Birdseye||a.mapStyle==VEMapStyle.BirdseyeHybrid){map.HideAllShapeLayers();}else{map.ShowAllShapeLayers();}}function MouseEventHandler(c){if(c.elementID!=null){var a=map.GetShapeByID(c.elementID);var b=map.LatLongToPixel(new VELatLong(a.Latitude,a.Longitude),map.GetZoomLevel());if(a.IsClustered){if(b.x+22<width){b.x+=22;}if(b.y+8<height){b.y+=8;}if(!a.IsLoaded){setClusteredPinListDescription(a.GUID.slice(0,5).join(","),a,b);a.SetTitle(titleForList);a.IsLoaded=true;}}else{if(b.x+4<width){b.x+=4;}if(b.y+12<height){b.y+=12;}if(!a.IsLoaded){setObjectDescription(a.GUID.join(","),a,b);a.IsLoaded=true;}}map.ShowInfoBox(a,map.PixelToLatLong(b));}return true;}function ShapeHandler(b){if(b.elementID!=null){var a=map.GetShapeByID(b.elementID);if(a.IsClustered){map.SetCenterAndZoom(new VELatLong(a.Latitude,a.Longitude),getZoomLevel(null,true));setCurrentMapView();}else{if(a.GUID!=null){setCurrentMapView();$("form").append(String.Format("<input type='hidden' name='selectedGuid' value='{0}' />",a.GUID.join(",")));document.forms[0].submit();}}}}function getParameters(b){var a="";var c=window.location.href;if(typeof b!="undefined"){c=b;}if(c.indexOf("?")>-1){a=c.substr(c.indexOf("?"));}if(a.toLowerCase().indexOf("mapparam=")<0||$("input[id$='mapSearch']").val()=="true"){if($("input[id$='mapSearch']").val()=="true"){a=removeURLParam(a,"mapparam");a=removeURLParam(a,"mapsearch");}if(a!=""&&a!="?"){a+="&";}a+=GetMapParam();}if(typeof $("#NavigationBox").val()!="undefined"&&$("#NavigationBox").val()!=""){if(a!=""){a+="&";}a+="NavigationBox="+$("#NavigationBox").val();}return a;}function DoPanQuery(){return;}function DoZoomQuery(){return;}function getClusteredPin(maxcount,offset){if(clusteredPinQuery==""){clusteredPinQuery=getParameters();}if(clusteredPinQuery!=""&&typeof pinServiceUrl!="undefined"&&pinServiceUrl!=""){if(typeof offset=="undefined"){offset=0;}$.ajax({type:"POST",url:pinServiceUrl,data:'{ query: "'+clusteredPinQuery+'", count: "'+(maxcount>maxCountPerRequest?maxCountPerRequest:maxcount)+'", offset: "'+offset+'", mapWidth: "'+$("#iwMap").width()+'", mapHeight: "'+$("#iwMap").height()+'" }',contentType:"application/json; charset=utf-8",dataType:"json",success:function(result){if(result.d!=""){var data=eval("("+result.d+")");if(data!=null&&data.cp!=null&&data.cp.length>0){var shapeLayer=new VEShapeLayer();var clusteringOptions=new VEClusteringOptions();clusteringOptions.Callback=clusterCallback;shapeLayer.SetClusteringConfiguration(VEClusteringType.Grid,clusteringOptions);map.AddShapeLayer(shapeLayer);var shapes=new Array();for(var i=0;i<data.cp.length;i++){if(parseInt(data.cp[i].c)==0){continue;}var shape=new VEShape(VEShapeType.Pushpin,new VELatLong(data.cp[i].x,data.cp[i].y));var guid=new Array();if(data.cp[i].ex){for(var k=0;k<data.cp[i].id.length;k++){guid.push(data.cp[i].id[k]);}mapExactCount+=data.cp[i].c;mapOverallCount+=data.cp[i].c;}else{if(data.cp[i].sm){mapNoStreetCount=data.cp[i].c;mapOverallCount+=data.cp[i].c;}continue;}shape.GUID=guid;shape.Count=data.cp[i].c;shape.SetDescription(loading);shape.SetTitle(titleForDetail);shape.SetCustomIcon(getCustomIconHtmlDefinition(data.cp[i].c,data.cp[i].ex));shapes.push(shape);}shapeLayer.AddShape(shapes);mapBestView=shapeLayer.GetBoundingRectangle();overallCount+=data.oc;}}},error:function(){mapIsLoading=false;},complete:function(){offset=maxCountPerRequest+offset;if(overallCount>0){$("div#divRefresh,span#pinInfo").show();}else{$("div#divRefresh,span#pinInfo").hide();}if(overallCount>=maxcount||overallCount<offset){mapIsLoading=false;if(overallCount>maxcount){$("div#divRefreshContent").hide();AddErrorLayer(errorToMuchHits);}else{if(mapExactCount==0){$("div#divRefreshContent").hide();AddErrorLayer(String.Format(errorZeroHits,overallCount,overallCount>1?"n":""));}else{$("#overallCount").html(overallCount);$("#overallCountDesc").html(overallCount==1?"Objekt":"Objekten");$("#mapExactCount").html(mapExactCount);$("#mapExactCountDesc").html(mapExactCount==1?"Objekt":"Objekte");$("div#divRefreshContent").fadeIn("fast");if(typeof setBestView!="undefined"&&setBestView==true&&mapBestView!=null){map.SetMapView(mapBestView);}}}}else{getClusteredPin(maxcount,offset);}}});}}function getCustomIconHtmlDefinition(a,c){var b="misc";if(a==1&&c){b="single";}else{if(c){b="multi";}}return String.Format("<div class=\"pin_{0}\" onmouseover=\"$(this).removeClass('pin_{0}').addClass('pin_{0}_hover');\" onmouseout=\"$(this).removeClass('pin_{0}_hover').addClass('pin_{0}');\"><span class=\"text\">{1}</span></div>",b,!c||a>1?a:"");}function getObjectListItem(d,a,c){var b=String.Format(linkToDetail,c);if(typeof objectListItemDescription!="undefined"&&objectListItemDescription!=""){listItem=objectListItemDescription;}return String.Format(listItem,d,b,a);}function setClusteredPinListDescription(guid,shape,offset){if(typeof descServiceUrl!="undefined"&&descServiceUrl!=""){$.ajax({type:"POST",url:descServiceUrl,data:'{ guid: "'+guid+'" }',contentType:"application/json; charset=utf-8",dataType:"json",success:function(result){if(result.d!=""){var data=eval("("+result.d+")");var info="";if(data!=null&&data.o!=null&&data.o.length>0){for(var i=0;i<data.o.length;i++){info+=getObjectListItem(data.o[i].thumb,data.o[i].desc,data.o[i].id);}}info+=String.Format('<div class="h_05"></div><div class="w_220"><a href="#" onclick="DoListView({0}, 3);" class="arrow">Ergebnisliste mit allen Objekten aus diesem Gebiet anzeigen</a></div></div>',"'"+shape.GetID()+"'");map.HideInfoBox();shape.SetDescription(info);map.ShowInfoBox(shape,map.PixelToLatLong(offset));}}});}}function getObjectDetails(f,a,e,d,c){var b=String.Format(linkToDetail,e);if(typeof objectDetailsDescription!="undefined"&&objectDetailsDescription!=""){detail=objectDetailsDescription;}return String.Format(detail,f,b,a,d,c);}function setObjectDescription(guid,shape,offset){if(typeof descServiceUrl!="undefined"&&descServiceUrl!=""){$.ajax({type:"POST",url:descServiceUrl,data:'{ guid: "'+guid+'" }',contentType:"application/json; charset=utf-8",dataType:"json",success:function(result){if(result.d!=""){var data=eval("("+result.d+")");var info="";var Img=null;if(data!=null&&data.o!=null&&data.o.length>0){info+=getObjectDetails(data.o[0].thumb,data.o[0].desc,data.o[0].id,data.o[0].info,data.o[0].price);Img=new Image();Img.src=data.o[0].thumb;}map.HideInfoBox();shape.SetDescription(info);map.ShowInfoBox(shape,map.PixelToLatLong(offset));if(Img!=null){BindResizing(Img,220,165,shape);}}}});}}function clusterCallback(b){if(b.length==0){return;}for(var e=0;e<b.length;++e){var f=b[e];var a=f.GetClusterShape();var d=b[e].Shapes.length;if(d>1){a.IsClustered=true;a.GUID=new Array();for(var c=0;c<d;c++){for(var h=0;h<f.Shapes[c].GUID.length;h++){a.GUID.push(f.Shapes[c].GUID[h]);}a.Count+=f.Shapes[c].Count;}a.BoundingRectangle=GetClusterInfo(b[e].Shapes);a.SetDescription(loading);}a.SetCustomIcon(getCustomIconHtmlDefinition(d,true));}}function GetClusterInfo(c){if(typeof c=="undefined"||c==null||c.length==0){return null;}var d=parseFloat(c[0].Latitude);var a=parseFloat(c[0].Latitude);var f=parseFloat(c[0].Longitude);var g=parseFloat(c[0].Longitude);for(var b=1;b<c.length;b++){if(parseFloat(c[b].Latitude)>d){d=parseFloat(c[b].Latitude);}if(parseFloat(c[b].Latitude)<a){a=parseFloat(c[b].Latitude);}if(parseFloat(c[b].Longitude)>f){f=parseFloat(c[b].Longitude);}if(parseFloat(c[b].Longitude)<g){g=parseFloat(c[b].Longitude);}}var e=1e-05;return new VELatLongRectangle(new VELatLong(d+e,g-e),new VELatLong(a-e,f+e),new VELatLong(d+e,f+e),new VELatLong(a-e,g-e));}function AddErrorLayer(f){customLayer=document.createElement("p");$(customLayer).css({position:"absolute",top:"160px",left:"155px",width:"300px",height:"130px",padding:"5px",border:"#ccc 1px solid",zIndex:"100",backgroundColor:"#fff"});if($.browser.msie){$(customLayer).css("filter","alpha(opacity=80)");}else{$(customLayer).css({MozOpacity:"0.7",opacity:"0.8"});}var d=document.createElement("span");$(d).css({color:"#000",fontFamily:"tahoma",fontSize:"13px",lineHeight:"17px",fontWeight:"bold"});$(d).append("<br />").append(f).append("<br /><br />");var b=document.createElement("a");var c=removeURLParam(window.location.href,"display");$(b).attr("href",c).click(function(){window.location.href=c;}).css({padding:"0 0 0 14px",backgroundImage:"url(../_Images/V3/link/link_arrow_small.gif)",backgroundRepeat:"no-repeat",backgroundPosition:"0 3px"}).append("zur Listenansicht wechseln");$(d).append(b);var a=document.createElement("img");$(a).attr("src","../_Images/V3/layout_PopUp/icon_closewindow.gif").attr("alt","schließen").attr("title","schließen").click(function(){RemoveCustomLayer();}).css({cursor:"pointer"});var e=document.createElement("span");$(e).css({cssFloat:"right"}).append(a);$(customLayer).append(e).append(d);map.AddCustomLayer(customLayer);}function RemoveCustomLayer(){map.RemoveCustomLayer(customLayer);}function JumpToList(){window.location.href=IwAG.Base.removeURLParam(window.location.href,"display");}function BindResizing(e,d,a,b){if(typeof e=="undefined"||e==null){return;}if(!e.complete){setTimeout(function(){BindResizing(e,d,a,b);},100);}else{$(e).ImageResize({width:d,height:a});$("#detailImage").empty().append(e);var c=$("#objDetail").get(0).parentNode;if(c!=null){b.SetDescription(c.innerHTML);}}}
