var mapSearch;var MapSearch=Class.create();MapSearch.prototype={PROVINCE:0,DISTRICT:1,QUARTER:2,GRUPEDADVERTS:3,ADVERTGROUP:4,ADVERT:5,FLAT:"0",HOUSE:"1",ROOM:"2",PLOT:"3",PLACE:"4",OFFICE:"5",GARAGE:"6",PROVINCEZOOM:8,DISTRICTZOOM:11,initialize:function(D,A,E,C,F,B){YAHOO.util.Event.onDOMReady(function(){this.map=$(D);this.priceCtrlName=F;this.areaCtrlName=B;this.InitIcons();this.refreshBlock=false;this.advertType=this.GetTypeFromUrl();if(this.advertType==undefined){this.advertType=0}this.subType=$(A);this.yuiLoader=new YAHOO.util.YUILoader({require:["slider","container","animation","connection","paginator","json"],base:"/scripts/yui/",onSuccess:this.InitEnhControls.bind(this),onFailure:function(G){alert("error: "+YAHOO.lang.dump(G))}});this.yuiLoader.insert();this.province=new AjaxCombo(E,true);this.province.Reload("/ajax_handler.html","post",{mode:"provinces"});this.province.combo.onchange=this.OnProvinceChange.bind(this);this.district=new AjaxCombo(C,true);this.district.combo.onchange=this.OnDistrictChange.bind(this)}.bind(this))},OnProvinceChange:function(){enhData=this.province.GetEnhData();point=new GLatLng(enhData.Lat,enhData.Lng);this.map.setCenter(point,this.PROVINCEZOOM);this.district.Reload("/ajax_handler.html","post",{mode:"districts",teryt:enhData.Teryt})},OnDistrictChange:function(){enhData=this.district.GetEnhData();point=new GLatLng(enhData.Lat,enhData.Lng);this.map.setCenter(point,this.DISTRICTZOOM)},InitEnhControls:function(){this.priceLo=null;this.priceHi=null;this.areaLo=null;this.areaHi=null;this.loader=new YAHOO.widget.Panel("loader",{width:"400px",xy:[300,400],close:false,draggable:false,visible:false,zindex:1000,modal:true});this.loader.setBody("<div style='text-align:center;background-color:White;padding:50px 0;font-weight:bold;'><p>Trwa ładowanie</p><img src='/images/loader.gif' /></div>");this.loader.render(document.body);this.priceSlider=YAHOO.widget.Slider.getHorizDualSlider(this.priceCtrlName,this.priceCtrlName+"Min",this.priceCtrlName+"Max",300,5,[0,300]);this.priceSlider.subscribe("change",this.PriceSubscriber.bind(this));$(this.priceCtrlName+"ValMin").innerHTML=" od "+this.FormatCurrency(0);$(this.priceCtrlName+"ValMax").innerHTML="bez ograniczeń";this.priceSlider.subscribe("slideEnd",function(){this.Refresh(true)}.bind(this));this.areaSlider=YAHOO.widget.Slider.getHorizDualSlider(this.areaCtrlName,this.areaCtrlName+"Min",this.areaCtrlName+"Max",300,5,[0,300]);this.areaSlider.subscribe("change",this.AreaSubscriber.bind(this));$(this.areaCtrlName+"ValMin").innerHTML=" od "+0+"m<sup>2</sup>";$(this.areaCtrlName+"ValMax").innerHTML="bez ograniczeń";this.areaSlider.subscribe("slideEnd",function(){this.Refresh(true)}.bind(this));if(GBrowserIsCompatible()){this.map=new GMap2(this.map);this.map.setCenter(new GLatLng(52,20),6);this.map.addControl(new GLargeMapControl());this.map.addControl(new GMapTypeControl());this.map.addControl(new GScaleControl());this.actualType=this.PROVINCE;this.markers=[];this.subType.onchange=this.OnSubTypeChange.bind(this);GEvent.addListener(this.map,"moveend",this.Refresh.bind(this));this.RequestMarkers()}},PriceSubscriber:function(){factor=this.GetPriceFactor();this.priceLo=this.priceSlider.minVal*factor;$(this.priceCtrlName+"ValMin").innerHTML=" od "+this.FormatCurrency(this.priceLo);if(this.priceSlider.minVal==0){this.priceLo=null}if(this.priceSlider.maxVal!=300){this.priceHi=this.priceSlider.maxVal*factor;$(this.priceCtrlName+"ValMax").innerHTML=" do "+this.FormatCurrency(this.priceHi)}else{this.priceHi=null;$(this.priceCtrlName+"ValMax").innerHTML="bez ograniczeń"}},GetPriceFactor:function(){if(this.advertType==0){switch(this.subType.value){case this.FLAT:return 4000;case this.HOUSE:return 8000;case this.PLOT:return 2000;case this.PLACE:return 8000;case this.OFFICE:return 8000;case this.GARAGE:return 1000}}else{if(this.advertType==1){switch(this.subType.value){case this.FLAT:return 30;case this.HOUSE:return 100;case this.ROOM:return 10;case this.PLOT:return 100;case this.PLACE:return 150;case this.OFFICE:return 150;case this.GARAGE:return 10}}}return 0},AreaSubscriber:function(){factor=this.GetAreaFactor();this.areaLo=this.areaSlider.minVal*factor;$(this.areaCtrlName+"ValMin").innerHTML=" od "+this.areaLo+"m<sup>2</sup>";if(this.areaSlider.minVal==0){this.areaLo=null}if(this.areaSlider.maxVal!=300){this.areaHi=this.areaSlider.maxVal*factor;$(this.areaCtrlName+"ValMax").innerHTML=" do "+this.areaHi+"m<sup>2</sup>"}else{this.areaHi=null;$(this.areaCtrlName+"ValMax").innerHTML="bez ograniczeń"}},GetAreaFactor:function(){switch(this.subType.value){case this.FLAT:return 0.5;case this.HOUSE:return 2;case this.ROOM:return 0.2;case this.PLOT:return 100;case this.PLACE:return 10;case this.OFFICE:return 5;case this.GARAGE:return 0.2}return 0},OnSubTypeChange:function(){this.PriceSubscriber();this.AreaSubscriber();this.Refresh(true)},OnGroupedClick:function(B,A,C){this.loader.show();onSuccess=function(G,F){if(F[0].responseText!==undefined){F[0].argument.loader.hide();advertWindow=new YAHOO.widget.Panel("advertWindow",{width:"760px",xy:[100,200],close:true,draggable:true,zindex:1000,modal:false,visible:false,constraintoviewport:true});advertWindow.setHeader("<div class='tl'></div><span>"+F[0].argument.title+"</span><div class='tr'></div>");var H=YAHOO.namespace("adverts");try{H.data=YAHOO.lang.JSON.parse(F[0].responseText)}catch(E){alert("JSON Parse failed!");return }advertWindow.setBody("<div id='paging' style='text-align:right;padding: 5px 5px;'></div><div id='content'></div>");advertWindow.render(document.body);H.content=YAHOO.util.Dom.get("content");H.paginator=new YAHOO.widget.Paginator({rowsPerPage:1,totalRecords:H.data.length,containers:"paging",template:" {PreviousPageLink}&nbsp;{PageLinks}&nbsp;{NextPageLink}",previousPageLinkLabel:"poprzednia",nextPageLinkLabel:"następna",pageLinks:5});H.handlePagination=function(I){H.content.innerHTML=H.data[I.page-1];H.paginator.setState(I)};H.paginator.subscribe("changeRequest",H.handlePagination);H.paginator.render();H.handlePagination(H.paginator.getState());advertWindow.show()}};var D={failure:function(){alert("Communication error!")},customevents:{onSuccess:onSuccess},argument:{loader:this.loader,title:C}};request=YAHOO.util.Connect.asyncRequest("GET","/ajax_handler.html?mode=grouped&type="+this.advertType+"&subType="+this.subType.value+"&lng="+A+"&lat="+B+"&priceLo="+this.priceLo+"&priceHi="+this.priceHi+"&areaLo="+this.areaLo+"&areaHi="+this.areaHi,D);return 0},InitIcons:function(){this.houseGrpIco=new GIcon();this.houseGrpIco.image="/images/house_grp.gif";this.houseGrpIco.iconSize=new GSize(44,32);this.houseGrpIco.iconAnchor=new GPoint(22,16);this.houseIco=new GIcon();this.houseIco.image="/images/house.gif";this.houseIco.iconSize=new GSize(20,21);this.houseIco.iconAnchor=new GPoint(10,10);this.smallHouseGrpIco=new GIcon();this.smallHouseGrpIco.image="/images/small_house_grp.png";this.smallHouseGrpIco.iconSize=new GSize(28,20);this.smallHouseGrpIco.iconAnchor=new GPoint(14,10);this.smallHouseIco=new GIcon();this.smallHouseIco.image="/images/small_house.png";this.smallHouseIco.iconSize=new GSize(20,19);this.smallHouseIco.iconAnchor=new GPoint(10,10);this.smallHouseIco.infoWindowAnchor=new GPoint(13,10);this.icons=[];this.icons[this.PROVINCE]=this.houseGrpIco;this.icons[this.DISTRICT]=this.houseIco;this.icons[this.QUARTER]=this.houseIco;this.icons[this.GRUPEDADVERTS]=this.smallHouseGrpIco;this.icons[this.ADVERTGROUP]=this.smallHouseIco;this.icons[this.ADVERT]=this.smallHouseIco},GetTypeFromUrl:function(){url=window.location.href;splitted=url.split("/",4);if(splitted.length==4){if(splitted[3]=="sprzedaz"){return 0}else{if(splitted[3]=="wynajem"){return 1}}}},AddMarker:function(F,E,B,G,D){var A=new GLatLng(F,E);var C=new GMarker(A,{title:G,icon:this.icons[B]});if(D==null){onClick=function(){this.MarkerClick(A,B)}.bind(this);GEvent.addListener(C,"click",onClick)}else{onClick=function(){this.refreshBlock=true;C.openInfoWindowHtml(D);setTimeout(function(){this.refreshBlock=false}.bind(this),1000)}.bind(this);GEvent.addListener(C,"click",onClick)}this.markers.push(C)},MarkerClick:function(B,A){if(A==this.PROVINCE){zoom=this.PROVINCEZOOM}else{if(A==this.DISTRICT){zoom=this.DISTRICTZOOM}else{zoom=this.map.getZoom()+1}}this.map.setCenter(B,zoom)},AddMarkersToMap:function(){this.markers.each(this.AddMarkerToMap.bind(this))},AddMarkerToMap:function(A){this.map.addOverlay(A)},RequestMarkers:function(){this.loader.show();callback=function(A){this.markers.clear();this.map.clearOverlays();points=A.responseText.evalJSON(true);for(i=0;i<points.length;i++){if((points[i].Level!=this.ADVERT)&&(points[i].Level!=this.GRUPEDADVERTS)&&(points[i].Level!=this.ADVERTGROUP)){this.AddMarker(points[i].Lat,points[i].Lng,points[i].Level,points[i].Title+", "+points[i].AdvertCount+" ogłoszeń",null)}else{this.AddMarker(points[i].Lat,points[i].Lng,points[i].Level,points[i].Title,points[i].InnerHtml)}}this.AddMarkersToMap();this.loader.hide()}.bind(this);this.lastZoom=this.map.getZoom();this.lastBounds=this.map.getBounds();southWest=this.lastBounds.getSouthWest();northEast=this.lastBounds.getNorthEast();new Ajax.Request("/ajax_handler.html",{method:"get",parameters:{mode:"map",markerType:this.actualType,type:this.advertType,subType:this.subType.value,upLng:northEast.lng(),upLat:northEast.lat(),loLng:southWest.lng(),loLat:southWest.lat(),priceLo:this.priceLo,priceHi:this.priceHi,areaLo:this.areaLo,areaHi:this.areaHi},onSuccess:callback})},Refresh:function(A){actZoom=this.map.getZoom();if((this.refreshBlock==false)&&((this.lastZoom!=actZoom)||(A==true)||(this.IsEnoughToReload()==true))){if(actZoom<8){if((this.actualType!=this.PROVINCE)||(A==true)){this.actualType=this.PROVINCE;this.RequestMarkers()}}else{if((actZoom>=8)&&(actZoom<11)){this.actualType=this.DISTRICT;this.RequestMarkers()}else{if((actZoom>=11)&&(actZoom<13)){this.actualType=this.QUARTER;this.RequestMarkers()}else{this.actualType=this.ADVERT;this.RequestMarkers()}}}}},IsEnoughToReload:function(){actBounds=this.map.getBounds();actSouthWest=actBounds.getSouthWest();actNorthEast=actBounds.getNorthEast();lastSouthWest=this.lastBounds.getSouthWest();lastNorthEast=this.lastBounds.getNorthEast();lngSpan=Math.abs((actNorthEast.lng()-lastNorthEast.lng())/(actNorthEast.lng()-actSouthWest.lng()));latSpan=Math.abs((actNorthEast.lat()-lastNorthEast.lat())/(actNorthEast.lat()-actSouthWest.lat()));if((lngSpan>0.15)||(latSpan>0.15)){return true}else{return false}},FormatCurrency:function(A){A=A.toString().replace(/\$|\,/g,"");if(isNaN(A)){A="0"}sign=(A==(A=Math.abs(A)));A=Math.floor(A*100+0.50000000001);cents=A%100;A=Math.floor(A/100).toString();if(cents<10){cents="0"+cents}for(var B=0;B<Math.floor((A.length-(1+B))/3);B++){A=A.substring(0,A.length-(4*B+3))+" "+A.substring(A.length-(4*B+3))}return(((sign)?"":"-")+A+","+cents+" zł")}};function onFormLoad(){var A=document.createElement("script");A.type="text/javascript";A.src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAwmHN8rXGZ6Qgs5fHxkMS7hTngcU0BSfn6Z93tprThAS-riEDTxSM4OKtSyTsw45wVZ7fN8khyTylug&async=2&callback=GMapLoader";document.body.appendChild(A)}function GMapLoader(){mapSearch=new MapSearch("map","subType","province","district","price","area")}Event.observe(window,"load",onFormLoad);
