
WLC.divNamePois="e_d_map_ct_poi";WLC.divNamePoiGoogleAttr="e_d_map_ct_poi_google_attr";WLC.divNameOwnPois="own_poi";WLC.currentPoiMarkers=new Array();WLC.poiMarkerIcons=new Array();WLC.tempCategory="";jQuery(function($){if(GBrowserIsCompatible()){WLC.setupPoiSearch();}
jQuery("button#searchOwnPoiMarkers").click(function(){WLC.searchOwnPoiMarkers();return false;});jQuery("button#deletePoi").click(function(){WLC.deletePoi();return false;});});WLC.setupPoiSearch=function(){gLocalSearch=new GlocalSearch();gLocalSearch.setResultSetSize(GSearch.LARGE_RESULTSET);WLC.setupPoiCheckboxes();}
WLC.setupPoiCheckboxes=function(){jQuery("#"+WLC.divNamePois+" :checkbox").click(function(){if(this.checked){WLC.searchPoiMarkers(jQuery(this).attr("value"));}else{WLC.hidePoiMarkers(jQuery(this).attr("value"));}});var cbs=jQuery("#"+WLC.divNamePois+" :checkbox");for(var i=0;i<cbs.length;i++){WLC.setupIcon(cbs[i],false);cbs[i].checked=false;}}
WLC.searchOwnPoiMarkers=function(){var tf=jQuery("#"+WLC.divNameOwnPois);if(jQuery(tf).attr("value")){var tfText="category: "+jQuery(tf).attr("value");WLC.hidePoiMarkers(WLC.tempCategory);WLC.setupIcon(tfText,true);WLC.searchPoiMarkers(tfText);WLC.tempCategory=tfText;}}
WLC.deletePoi=function(){WLC.hidePoiMarkers(WLC.tempCategory);jQuery("#"+WLC.divNameOwnPois).val("");}
WLC.setupIcon=function(control,ownPois){var icon=new GIcon();var cat="";if(ownPois){cat=control;icon.image=WLC.basePath+"/images/googleMaps/ico_pois_individual.png";}else{cat=jQuery(control).attr("value");icon.image=WLC.basePath+"/images/googleMaps/ico_pois_"+jQuery(control).attr("name")+".png";}
WLC.currentPoiMarkers[cat]=new Array;WLC.poiMarkerIcons[cat]=icon;icon.shadow=WLC.basePath+"/images/googleMaps/ico_pois_shadow.png";icon.iconSize=new GSize(35,35);icon.shadowSize=new GSize(52,29);icon.iconAnchor=new GPoint(16,34);icon.infoWindowAnchor=new GPoint(15,4);}
WLC.reloadPoiMarkers=function(){var cbs=jQuery("#"+WLC.divNamePois+" :checkbox");for(var i=0;i<cbs.length;i++){if(jQuery(cbs[i]).attr("checked")==true){WLC.showPoiMarkers(jQuery(cbs[i]).attr("value"));}}
WLC.searchOwnPoiMarkers();}
WLC.searchPoiMarkers=function(category){gLocalSearch.setCenterPoint(map);gLocalSearch.setSearchCompleteCallback(null,WLC.poiSearchCompleteCallback);gLocalSearch.execute(category);}
WLC.showPoiMarkers=function(category){if(WLC.currentPoiMarkers[category]){for(var i=0;i<WLC.currentPoiMarkers[category].length;i++){map.addOverlay(WLC.currentPoiMarkers[category][i])}}}
WLC.hidePoiMarkers=function(category){if(WLC.currentPoiMarkers[category]){for(var i=0;i<WLC.currentPoiMarkers[category].length;i++){map.removeOverlay(WLC.currentPoiMarkers[category][i])}
WLC.currentPoiMarkers[category]=[];}}
WLC.createPoiMarker=function(point,title,address,city,url,icon){var marker=new GMarker(point,icon);var html="<div id=\"e_flyout_poi\"><a href=\""+url+"\" target=\"_blank\"><strong>"+title+"</strong></a><br />"+address+"<br />"+city+"</div>";GEvent.addListener(marker,'click',function(){marker.openInfoWindowHtml(html);});return marker;}
WLC.poiSearchCompleteCallback=function(){if(gLocalSearch.results&&gLocalSearch.results.length>=1){var attribution=gLocalSearch.getAttribution();if(attribution){jQuery("#"+WLC.divNamePoiGoogleAttr).html(WLC.returnLabel('estate.detail.map.poi.googleFunction')+"&nbsp;");jQuery(attribution).css("display","inline");jQuery("#"+WLC.divNamePoiGoogleAttr).append(attribution);jQuery("#"+WLC.divNamePoiGoogleAttr+" a").attr("target","_blank");}else{jQuery("#"+WLC.divNamePoiGoogleAttr).html(WLC.returnLabel('estate.detail.map.poi.googleFunction'));}
var category=WLC.extractPoiCategory(gLocalSearch.results[0].url);if(category!=""){for(var i=0;i<gLocalSearch.results.length;i++){var result=gLocalSearch.results[i];var marker=WLC.createPoiMarker(new GLatLng(result.lat,result.lng),result.title,result.streetAddress,result.city,result.url,WLC.poiMarkerIcons[category]);WLC.currentPoiMarkers[category].push(marker);}
WLC.showPoiMarkers(category);}else{}}}
WLC.extractPoiCategory=function(query){var matching=query.match(/\&q=[\w+:%]+/);if(matching){return WLC.decodeUtf8(unescape(matching[0])).substr(3).replace(/\+/g," ");}else{return"";}}
WLC.decodeUtf8=function(utftext){var plaintext="";var i=0;var c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){plaintext+=String.fromCharCode(c);i++;}else if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);plaintext+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;}else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);plaintext+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}
return plaintext;}