
if(!SAPO.Geo||typeof(SAPO.Geo)=='undefined'){SAPO.namespace('Geo');}
SAPO.Geo.Map=function(options){if(SAPO.Exception&&typeof(SAPO.Exception)!='undefined'){this.exception=new SAPO.Exception('SAPO::Geo.Map');}else{this.exception=false;}
this.init(options);};SAPO.Geo.Map.prototype={map:null,init:function(){var options=SAPO.extendObj({"divid":null,"lat":g_pt_view.y,"lon":g_pt_view.x,"zoom":g_pt_view_zoom,"mapcontrol":"large","locator_callback":null,"extents_callback":null,"extents_callback_delay":10000,"navArea":true,"navAreaHeight":20},(arguments[0]||{}));this.options=options;var map=new GMap2(s$(options.divid),options.render_opts);map.setNavAreaVis(options.navArea,options.navAreaHeight);if(options.mapcontrol=="small"){map.addControl(new GSmallMapControl());}
else{map.addControl(new GLargeMapControl());}
map.centerAndZoom(new GLatLng(options.lat,options.lon),options.zoom);if(options.locator_callback){map.activate_locator(options.locator_callback);}
if(options.locator_marker){smaps_locator_marker=options.locator_marker;}
if(options.extents_callback){map.setExtentsCallback(options.extents_callback,options.extents_callback_delay);}
this.map=map;smaps_geomap=this;},addMarker:function(lat,lon,markerOptions,text){return g_GSMap1.addMarker(lat,lon,markerOptions,text);},centerAndZoom:function(lat,lon,zoom){this.map.centerAndZoom(new GLatLng(lat,lon),zoom);},getBoundsLatLng_centered:function(percent_option){if(!percent_option){percent_option=1.0;}
return this.map.getBoundsLatLng_centered(percent_option);},getLatitude:function(){return g_GSMap1.get_lat();},getLongitude:function(){return g_GSMap1.get_lon();},getZoom:function(){return g_GSMap1.gmap.getZoom();},getRadius:function(){return 0.5*GS_wms_tiles.get_resolution(g_GSMap1.get_zoom())*g_GSMap1.cols;},setClickCallback:function(function_name){_g_clickCallback=function_name;},getClickCoordinates:function(event){return smaps_mouse2point(event,0,0);},refreshMarkers:function(){smaps_map_pontos();},isRendered:function(){return g_GSMap1.is_rendered();},remove_marker:function(marker){smaps_remove_marker(marker);}};var g_gs_server='http://mapas.sapo.pt/';var g_smaps_page="";var g_css_server="http://js.sapo.pt";var g_gs_route_server="http://apps4.mapas.sapo.pt/caminhos2/servlet/ims_caminhos_servlet";var g_querydb_server="http://apps3.mapas.sapo.pt";var g_xsl_server=g_querydb_server;var g_layers_server=["http://apps1.mapas.sapo.pt","http://apps2.mapas.sapo.pt","http://apps3.mapas.sapo.pt","http://apps4.mapas.sapo.pt"];var g_xsl_files_server=g_gs_server;var g_copyr_img=g_css_server+"/Assets/Maps/Images/logomapas_api.png";var g_copyr_msg="";var g_lines_min=350;var g_img_server=['http://tiles1.imgs.sapo.pt','http://tiles2.imgs.sapo.pt','http://tiles3.imgs.sapo.pt','http://tiles4.imgs.sapo.pt'];var g_tiles_layout="no_ layout loaded";var g_stages=false;var gPan_percent=0.25;var g_percursos=true;var g_timer_extents_callback;var g_extents_callback_delay=5000;var g_itenerario=null;var g_line_size=10;var g_wms1_url="";var g_wms2_url="";var g_smaps_add_css=true;var g_smaps_escala_pix=100;var g_wms_tiled=false;var g_ie=navigator.userAgent.indexOf("MSIE")>0;var g_ffox=navigator.userAgent.indexOf("Firefox")>0;var g_ie_version=0;if(g_ie){var smaps_temp=navigator.appVersion.split("MSIE");g_ie_version=parseFloat(navigator.appVersion.split("MSIE")[1]);}
var g_ie6=g_ie&&(g_ie_version<7);var smaps_zoom_level_layers_base=6;var smaps_zoom_level_layers=2;var smaps_zoom_level_pharm_serv=smaps_zoom_level_layers_base;var g_smaps_limit_pois=20;var g_z_index_pt_opened=50;var g_z_index_pt_closed=40;var g_GSMap1;var _g_clickCallback=false;var g_smaps_label_layer=false;var g_pharm_at_service_on=false;var g_smaps_active_layers="";var g_last_open_pin=null;var smaps_minimap_start_opened=false;var smaps_geomap=null;var smaps_traffic_active=false;var smaps_pharmacies_active=false;var smaps_default_layers_active=true;var smaps_rss_layers={};var smaps_mouse_wheel=true;function smaps_new_node(){var node_name=arguments[0];var is_img=(node_name=='img');var node_src;if(g_ie){node_name='<'+node_name;var j=1;while(j<arguments.length){if(typeof(arguments[j])!="object"){if(is_img&&arguments[j]=='src'){node_src=arguments[j+1];}
node_name=node_name.concat(' '+arguments[j]+'="'+arguments[j+1]+'"');j+=2;}else{j++;}}
node_name=node_name.concat('/>');}
var node;if(is_img){node=new Image();if(g_ie){node.src=node_src;node=document.createElement(node_name);}}
else{node=document.createElement(node_name);}
var i=1;while(i<arguments.length){if(typeof(arguments[i])=="object"){node.appendChild(arguments[i]);i++;}else{if(g_ie!=1){if(is_img&&arguments[i]=='src'){node.src=arguments[i+1];}else{try{node.setAttribute(arguments[i],arguments[i+1]);}catch(e){alert(e+" "+arguments[i]+" "+arguments[i+1]);}}}
i+=2;}}
return node;}
function smaps_write_node(div,node){div.appendChild(node);}
function smaps_set_prop(node,name,val){node.setAttribute(name,val);}
function smaps_new_text_node(text){var tN=document.createTextNode(text);return tN;}
function smaps_set_node_html(node,text){node.innerHTML=text;return node;}
function smaps_dbg(txt){var div=s$("div_debug");if(div!==null){smaps_write_node(div,smaps_new_node('br'));smaps_write_node(div,smaps_new_text_node(txt));}}
function smaps_dbg_link(txt){var div=s$("div_debug");if(div!==null){smaps_write_node(div,smaps_new_node('br'));smaps_write_node(div,smaps_new_node("a","target","blank","href",txt,smaps_new_text_node(txt)));}}
function smaps_parse(v){if(typeof(v)!="number"){return parseFloat(v);}
return v;}
function smaps_roundLatLon(v){return Math.round(v*100000)/100000;}
var degree_lat=110822.601;var degree_lon=86464.0596;function lon_degrees_2_meters_aprox(width){return width*degree_lon;}
function lat_degrees_2_meters_aprox(height){return height*degree_lat;}
function meters_2_degrees_lon_aprox(width){return width/degree_lon;}
function meters_2_degrees_lat_aprox(height){return height/degree_lat;}
function smaps_js_request(url,id){var prev_node=s$(id);var _hf=smaps_new_node('script',"name",id,'src',url,"id",id);if(prev_node!==null){document.getElementsByTagName('head')[0].replaceChild(_hf,prev_node);}else{document.getElementsByTagName('head')[0].appendChild(_hf);}}
function smaps_add_css(url)
{var _hf=smaps_new_node('link',"rel","stylesheet",'type',"text/css","href",url);document.getElementsByTagName('head')[0].appendChild(_hf);}
function Mouse2point_xy(e,div_name){try{if(!e){e=window.event;}
var posx=0;var posy=0;if(e.pageX||e.pageY){posx=e.pageX;posy=e.pageY;}
else if(e.clientX||e.clientY){posx=e.clientX+document.body.scrollLeft+
document.documentElement.scrollLeft;posy=e.clientY+document.body.scrollTop+
document.documentElement.scrollTop;}
var div=s$(div_name);var sumY=0;var sumX=0;while(div.offsetParent!==null&&div.offsetParent!==div){sumY+=div.offsetTop;sumX+=div.offsetLeft;div=div.offsetParent;}
this.y=posy-sumY;this.x=posx-sumX;}catch(e){this.x=0;this.y=0;smaps_dbg("error Mouse2point_xy"+e);}}
function dec2rad(dec){var d=dec*Math.atan(1.0)/45.0;return d;}
function rad2dec(rad){var d=rad*45.0/Math.atan(1.0);return d;}
function gms2decimal(graus,minutos,segundos,bug){var d;if(graus>0){d=graus+(minutos/60.0)+(segundos/3600.0);}else{d=graus-(minutos/60.0)-(segundos/3600.0);}
if(typeof(bug)!="undefined"){window.prompt("gms2decimal: extra input:",bug);}
return smaps_roundLatLon(d);}
function Gms(graus_decimais){var neg=false;if(graus_decimais<0){graus_decimais=-graus_decimais;neg=true;}
this.graus=Math.floor(graus_decimais);graus_decimais=graus_decimais-this.graus;this.minutos=Math.floor(graus_decimais*60.0);graus_decimais=graus_decimais-(this.minutos/60.0);this.segundos=graus_decimais*3600.0;if(neg){this.graus=-this.graus;this.minutos=-this.minutos;this.segundos=-this.segundos;}}
var smaps_earth_radius=6378137.0;function smaps_lonToX(longitudeDegrees){var longitude=dec2rad(longitudeDegrees);return(smaps_earth_radius*longitude);}
function smaps_latToY(latitudeDegrees){var latitude=dec2rad(latitudeDegrees);var y=smaps_earth_radius/2.0*Math.log((1.0+Math.sin(latitude))/(1.0-Math.sin(latitude)));return y;}
function smaps_xToLon(x){var longRadians=x/smaps_earth_radius;var longDegrees=rad2dec(longRadians);var rotations=Math.floor((longDegrees+180)/360);var longitude=longDegrees-(rotations*360);return longitude;}
function smaps_yToLat(y){var latitude=(Math.PI/2)-
(2*Math.atan(Math.exp(-1.0*y/smaps_earth_radius)));return rad2dec(latitude);}
function conv_lat_lon_mercator_sphere(lat,lon){this.x=smaps_lonToX(lon);this.y=smaps_latToY(lat);}
function conv_xy_mercator_sphere_lat_lon(x,y){this.lat=smaps_yToLat(y);this.lon=smaps_xToLon(x);}
var g_map_ready=false;var g_pt_view=new GPoint(-8.12714,39.70453);var g_pt_view_zoom=5;var g_zoom_drag_height=100;var g_disable_locator_callback=false;var smaps_add_marker_mode=false;var smaps_locator_marker;var smaps_locator_marker_link=true;var smaps_widget=true;var g_draw_index=1;var GS_wms_tiles=new WMS_tiles_client();function GMap2(container,opts){var map;if(typeof(opts)!="undefined"){map=new GMap(container,opts.mapTypes,opts.size.width,opts.size.height);}else{map=new GMap(container,undefined,parseInt(container.offsetWidth,10),parseInt(container.offsetHeight,10));}
map.gmaps_version=2;map.getContainer=function(){return g_GSMap1.div;};map.addMapType=function(type){};map.removeMapType=function(type){};map.isLoaded=function(){return g_GSMap1.ready;};map.isRendered=function(){return g_GSMap1.is_rendered();};map.getCenter=function(){return map.getCenterLatLng();};map.getBounds=map.getBoundsLatLng;map.getSize=function(){return new GSize(g_GSMap1.cols,g_GSMap1.lines);};map.getZoom=function(){return 17-GS_wms_tiles.current_zoom;};map.setCenter=map.centerAndZoom;map.panTo=map.centerAtLatLng;map.panBy=function(){not_implemented("panBy");};map.setZoom=map.zoomTo;map.zoomIn=function(){map.zoomTo(GS_wms_tiles.current_zoom-1);};map.zoomOut=function(){map.zoomTo(GS_wms_tiles.current_zoom+1);};map.setCenterAndSpan=function(latLng,span){g_GSMap1.set_lat_lon_span(latLng.y,latLng.x,span.x);};map.setCenterAndWidth=function(latLng,width){g_GSMap1.set_lat_lon_width(latLng.y,latLng.x,width);};map.refresh=function(){smaps_refresh();};map.toUrlValue=function(){return g_GSMap1.toUrlValue();};map.toQueryValue=function(){return g_GSMap1.toQueryValue();};map.toPointsURL=function(){return g_GSMap1.toPointsURL();};map.toLink=function(separator){if(g_itenerario!==null){return separator+g_qparams.get_param();}else{return separator+this.toPointsURL();}};map.toLinkComplete=function(){return g_gs_server+g_smaps_page+this.toLink("?");};map.setCallback=function(fn){map._callback=fn;};map.setExtentsCallback=function(fn,delay){map._extents_callback=fn;map._extents_callback_delay=delay;};map.setSizeCallback=function(fn){map._size_callback=fn;};map.setNavAreaVis=function(bool,navAreaHeight){map.navAreaVis=bool;map.navAreaHeight=navAreaHeight;};map.retrieve_win_size=function(){map.win_width=document.documentElement.clientWidth;map.win_height=document.documentElement.clientHeight;};return map;}
function GMapOptions(){var size=0;var mapTypes=[];}
function GLatLng(lat,lon){var ll=new GPoint(lon,lat);ll.lng=function(){return this.x;};ll.lat=function(){return this.y;};ll.latRadians=function(){return this.y/180*Math.PI;};ll.lonRadians=function(){return this.x/180*Math.PI;};ll.equals=function(other){return this.x==other.x&&this.y==other.y;};ll.toUrlValue=function(){return g_gs_server+"?q="+lat+","+lon;};return ll;}
function GLatLngBounds(sw,ne){var b=new GBounds(sw.x,sw.y,ne.x,ne.y);b.equals=function(other){return this.minX==other.minX&&this.minY==other.minY&&this.maxX==other.maxX&&this.maxY==other.maxY;};b.contains=function(latlng){not_implemented("intersects");return false;};b.getSouthWest=function(latlng){return new GLatLng(this.minY,this.minX);};b.getNorthEast=function(latlng){return new GLatLng(this.maxY,this.maxX);};b.toSpan=function(){return new GLatLng(this.maxY-this.minY,this.maxX-this.minX);};return b;}
function GControl(){this.GSmallMapControl=GSmallMapControl;this.GLargeMapControl=GLargeMapControl;this.GSmallZoomControl=function(){};this.GScaleControl=function(){};this.GMapTypeControl=function(){};}
function GMapType(){this.getSpanZoomLevel=function(){return 0;};this.getBoundsZoomLevel=function(){return 0;};this.getName=function(){return"SAPO Mapas";};this.getProjection=function(){return"WGS84 UTM 29N";};this.getTileSize=function(){return 256;};this.getTileLayers=function(){return[];};this.getMinimumResolution=function(){return 0;};this.getMaximumResolution=function(){return 11;};this.getTextColor=function(){return"#000000";};this.getLinkColor=function(){return"#000000";};this.getErrorMessage=function(){return"";};this.getCopy=function(){return"@PTM.COM";};this.getUrlArg=function(){return"";};}
var G_NORMAL_MAP=0;var G_SATELLITE_MAP=1;var G_HYBRID_MAP=2;var G_DEFAULT_MAP_TYPES=3;var GEvent=new GEvent_instance();var const_id_small_control=1;var const_id_large_control=2;var g_map_control_type=const_id_large_control;function GMap(container,mapTypes,width,height){init_smaps_const();init_tiles_layout();this.gmaps_version=1;this.navAreaVis=true;var cols;if(typeof(width)=="undefined"){cols=parseInt(container.offsetWidth,10);}else{cols=width;}
if(typeof(cols)=="undefined"||cols===0){cols=200;}
var lines;if(typeof(height)=="undefined"){lines=parseInt(container.offsetHeight,10);}else{lines=height;}
if(typeof(lines)=="undefined"||lines===0){lines=150;}
this.draggingEnabled=function(){return true;};this.enableInfoWindow=function(){};this.disableInfoWindow=function(){};this.infoWindowEnabled=function(){return false;};this.addControl=function(control){if(!control.map_control_type){return;}
g_map_control_type=control.map_control_type;};this.getCenterLatLng=function(){return new GPoint(g_GSMap1.get_lon(),g_GSMap1.get_lat());};this.getBoundsLatLng=function(){if(g_GSMap1.is_rendered()){var w=g_GSMap1.get_span_lon()/2;var h=g_GSMap1.get_span_lat()/2;var lat=g_GSMap1.get_lat();var lon=g_GSMap1.get_lon();return new GBounds(lon-w,lat-h,lon+w,lat+h);}
else if(g_GSMap1.resolution!==0){var largura=g_GSMap1.resolution*g_GSMap1.cols;var altura=g_GSMap1.resolution*g_GSMap1.lines;var w_lon=meters_2_degrees_lon(largura);var h_lat=meters_2_degrees_lat(altura);return new GBounds(g_GSMap1._lon-0.5*w_lon,g_GSMap1._lat-0.5*h_lat,g_GSMap1._lon+0.5*w_lon,g_GSMap1._lat+0.5*h_lat);}};this.getSpanLatLng=function(){var bounds=this.getBoundsLatLng();return new GSize(bounds.maxX-bounds.minX,bounds.maxY-bounds.minY);};this.getBoundsLatLng_centered=function(percent){var bounds=this.getBoundsLatLng();var size=new GSize((bounds.maxX-bounds.minX)*percent*0.5,(bounds.maxY-bounds.minY)*percent*0.5);var mid=this.getCenterLatLng();return new GBounds(mid.x-size.width,mid.y-size.height,mid.x+size.width,mid.y+size.height);};this.getZoomLevel=function(){var z=g_GSMap1.get_zoom();if(this.gmaps_version==2){return 17-z;}
return z;};this.centerAtLatLng=function(latLng){g_GSMap1.set_lat_lon(latLng.y,latLng.x);};this.recenterOrPanToLatLng=function(latLng){g_GSMap1.set_lat_lon(latLng.y,latLng.x);};this.zoomTo=function(zoomLevel){var z=zoomLevel;if(this.gmaps_version==2){z=17-z;}
g_GSMap1.set_zoom(z);};this.centerAndZoom=function(latLng,zoomLevel){var z=zoomLevel;if(this.gmaps_version==2){z=17-z;}
g_GSMap1.set_lat_lon_zoom(latLng.y,latLng.x,z);};this.getMapTypes=function(){return[0,1,2];};this.getCurrentMapType=function(){return 0;};this.setMapType=function(mapType){};this.addOverlay=function(overlay){if(typeof(overlay)!="undefined"&&typeof(overlay._type)!="undefined"){if(overlay._type==1){add_ponto_marker(overlay);}}};this.clearOverlays=function(){smaps_del_markers();};this.activate_locator=function(callback_fn){g_locator_widget=true;g_percursos=false;g_results_per_win=5;g_locator_callback=callback_fn;if(g_smaps_add_css){smaps_add_css(g_css_server+"/Assets/Maps/geosapo_loc.css");}};this.render=function(){setTimeout(GSMap_render,500);};g_GSMap1=new GSMap(this,container,cols,lines);if(g_smaps_add_css){smaps_add_css(g_css_server+"/Assets/Maps/geosapo_api.css");}}
function GMarker(point,param1,param2){this.point=point;if(param1&&param1._type=="GMarkerOptions"){this.options=param1;}else{this.options=new GMarkerOptions();this.options.icon=param1;if(param2){this.options.clickable=!param2;}}
this._type=1;this.click_fn=null;this.html="";this.index=-1;this._set_html=function(str1){var str=smaps_trim(str1);var div=s$("callout_div_"+this.index);if(div!==null){div.innerHTML=str;g_a_pontos[this.index].titulo="";g_a_pontos[this.index].desc=str;}
this.html=str;};this.openInfoWindow=function(htmlElem){this._set_html(htmlElem.innerHTML);};this.openInfoWindowHtml=function(htmlStr){this._set_html(htmlStr);};this.openInfoWindowTabs=this.openInfoWindow;this.openInfoWindowTabsHtml=this.openInfoWindow;this.getIcon=function(){return this.options.icon;};this.getPoint=function(){return this.point;};}
function GMarkerOptions(){this._type="GMarkerOptions";this.title="";this.selected=false;this.visible=true;this.opened=false;this.editable=false;this.permanent=false;}
function GIcon(){}
function GEvent_instance(){this.addListener=function(source,eventName,listenerFn){if(typeof(source._type)!="undefined"&&source._type==1&&eventName=="click"){listenerFn(source);return new GEventListener();}};this.removeListener=function(listener){};this.clearListeners=function(source,eventName){};this.trigger=function(source,eventName){};this.bind=function(source,eventName,object,method){};this.addDomListener=this.addListener;this.clearInstanceListeners=this.clearListeners;this.bindDom=this.bind;}
function GEventListener(){}
function GPoint(x,y){this.x=x;this.y=y;this.equals=function(other){return this.x==other.x&&this.y==other.y;};this.toString=function(){return"x="+x+",y="+y;};}
function GSize(width,height){this.width=width;this.height=height;this.equals=function(other){return this.width==other.width&&this.height==other.height;};this.toString=function(){return"w="+width+",h="+height;};}
function GBounds(v1,v2,v3,v4){if(typeof(v3)=="undefined"){this.minX=smaps_roundLatLon(v1.x);this.minY=smaps_roundLatLon(v1.y);this.maxX=smaps_roundLatLon(v2.x);this.maxY=smaps_roundLatLon(v2.y);}
else{this.minX=smaps_roundLatLon(v1);this.minY=smaps_roundLatLon(v2);this.maxX=smaps_roundLatLon(v3);this.maxY=smaps_roundLatLon(v4);}
this.min=function(){return new GPoint(this.minX,this.minY);};this.max=function(){return new GPoint(this.maxX,this.maxY);};this.intersects=function(x0,y0,x1,y1){if(x0<this.minX){x0=this.minX;}
if(x1>this.maxX){x1=this.maxX;}
if(x0>x1){return false;}
if(y0<this.minY){y0=this.minY;}
if(y1>this.maxY){y1=this.maxY;}
if(y0>y1){return false;}
return true;};this.add=function(ext){if(ext.minX<this.minX){this.minX=ext.minX;}
if(ext.minY<this.minY){this.minY=ext.minY;}
if(ext.maxX>this.maxX){this.maxX=ext.maxX;}
if(ext.maxY>this.maxY){this.maxY=ext.maxY;}};}
function GSmallMapControl(){this.map_control_type=const_id_small_control;}
function GLargeMapControl(){this.map_control_type=const_id_large_control;}
function GSMap(gmap,div,cols,lines){this._lat=0;this._lon=0;this._zoom=0;this.div=div;this.cols=cols;this.lines=lines;this.resolution=0;this.gmap=gmap;this._rendered=false;this._set_is_rendered=function(){this._rendered=true;};this.is_rendered=function(){return this._rendered;};this.addMarker=function(lat,lon,markerOptions,text){var GmkOptions=new GMarkerOptions();for(property in markerOptions){GmkOptions[property]=markerOptions[property];}
if(GmkOptions.guid&&g_a_pontos_hash_map[GmkOptions.guid]){g_a_pontos_hash_map[GmkOptions.guid].options.layers_call_count=g_layers_call_count;return;}
if(GmkOptions.icon_selected&&GmkOptions.icon_selected.display_titles){GmkOptions.icon_selected.title="<img border='0' src='"+GmkOptions.icon_selected.image+"' width='"+GmkOptions.icon_selected.iconSize.width+"' height='"+GmkOptions.icon_selected.iconSize.height+"'/><span class='map_pin'>"+GmkOptions.title+"</span>";}
var marker=new GMarker(new GLatLng(lat,lon),GmkOptions);if(GmkOptions.guid){g_a_pontos_hash_map[GmkOptions.guid]=marker;}
marker.openInfoWindowHtml(text);this.gmap.addOverlay(marker);return marker;};this.redraw=function(){smaps_dbg("redraw:"+this._lat+" "+this._lon+" "+this._zoom);if(this.is_rendered()){navigate_to_async(this._lat,this._lon,this._zoom);}};this.set_zoom=function(zoomLevel){if(!GS_wms_tiles.location.has_zoom(zoomLevel)){return;}
this.resolution=(1<<zoomLevel)*GS_wms_tiles.zoom0_resolution;this._zoom=zoomLevel;this.redraw();};this.set_lat_lon=function(lat,lon){if(isNaN(lat)||isNaN(lon)){return false;}
this._lat=lat;this._lon=lon;this._zoom=this.get_zoom();this.redraw();return true;};this.set_lat_lon_zoom=function(lat,lon,zoom){if(isNaN(lat)||isNaN(lon)){return false;}
this._lat=lat;this._lon=lon;this.set_zoom(zoom);};this.get_zoom=function(){return GS_wms_tiles.current_zoom;};this.get_lon=function(){if(global_xform_params){return global_xform_params.lon;}
return this._lon;};this.get_lat=function(){if(global_xform_params){return global_xform_params.lat;}
return this._lat;};this.get_span_lon=function(){if(!this.is_rendered()){throw"Function valid only when the Map is rendered";}
return meters_2_degrees_lon(global_xform_params.w);};this.get_span_lat=function(){if(!this.is_rendered()){throw"Function valid only when the Map is rendered";}
return meters_2_degrees_lat(global_xform_params.h);};this.set_lat_lon_span=function(lat,lon,span){var span0=this.get_span_lon();var z=Math.floor(span/span0*this.get_zoom());this.set_lat_lon_zoom(lat,lon,z);};this.set_lat_lon_width=function(lat,lon,width){var z=GS_wms_tiles.get_zoom_res(width/this.cols);if(z>g_max_zoom){z=g_max_zoom;}
if(z<g_min_zoom){z=g_min_zoom;}
this.set_lat_lon_zoom(lat,lon,z);};this.toPointsURL=function(to_print){var tmp_a_pontos=g_a_pontos;var tmp_num_pontos=g_num_pontos;var layers=escape(smaps_get_normalized_layers());if(layers.length===0)layers="Z";var str="M="+smaps_roundLatLon(g_GSMap1.get_lat())+","+
smaps_roundLatLon(g_GSMap1.get_lon())+","+(17-g_GSMap1.get_zoom())+","+layers;for(var i=0;i<tmp_a_pontos.length;i++){if(tmp_a_pontos[i].obj.options.visible&&tmp_a_pontos[i].obj.options.selected&&!tmp_a_pontos[i].obj.options.guid&&!tmp_a_pontos[i].obj.options.permanent){var mk=tmp_a_pontos[i].obj;var txt1;if(typeof(to_print)=="undefined"){txt1=escape(escape(SAPO.Utility.String.utf8Encode(mk.options.title)));}else if(to_print){txt1=escape(escape(SAPO.Utility.String.utf8Encode(mk.options.title)));}else{txt1=escape(escape(escape(SAPO.Utility.String.utf8Encode(mk.options.title))));}
str=str+";"+mk.point.y+","+mk.point.x+","+txt1+","+(mk.options.opened?"1":"0");}}
if(tmp_a_pontos.length===0){return this.toCoordsValue();}
return str;};this.toUrlValue=function(to_print){return g_smaps_page+"#"+this.toPointsURL(to_print);};this.toCoordsValue=function(){return"c"+smaps_roundLatLon(g_GSMap1.get_lat())+"_"+
smaps_roundLatLon(g_GSMap1.get_lon())+"_"+(17-g_GSMap1.get_zoom());};this.toQueryValue=function(){return"#"+this.toCoordsValue();};}
function link_mapas_sapo_pt(){window.top.location.href="http://mapas.sapo.pt/"+g_GSMap1.toQueryValue();}
function GSMap_render(){smaps_dbg("GSMap_render");g_GSMap1._set_is_rendered(true);map_div(g_GSMap1.div,g_GSMap1._lat,g_GSMap1._lon,g_GSMap1.resolution*g_GSMap1.cols,g_GSMap1.cols,g_GSMap1.lines,"POI","rapido");}
var g_max_zoom=12;var g_min_zoom=1;var g_zoom_title=[];g_zoom_title[0]="Detalhe m&aacute;ximo";g_zoom_title[1]="Ruas";g_zoom_title[2]="Ruas principais";g_zoom_title[3]="Bairro";g_zoom_title[4]="Arredores";g_zoom_title[5]="Freguesias";g_zoom_title[6]="Concelho";g_zoom_title[7]="Cidades";g_zoom_title[8]="Distrito";g_zoom_title[9]="Regi&atilde;o";g_zoom_title[10]="Auto-estradas";g_zoom_title[11]="Distritos";g_zoom_title[12]="Pa&iacute;s";var g_a_pontos=[];var g_num_pontos=0;var g_smaps_serial=0;var g_layers_call_count=0;var g_a_pontos_hash_map=[];var smaps_const=null;function init_smaps_const(){smaps_const={img_marca:g_css_server+"/Assets/Maps/Images/mapas_pin1.png",img_marca_sel:g_css_server+"/Assets/Maps/Images/mapas_pin1.png",img_deselecionar:g_css_server+"/Assets/Maps/Images/bot_minimizar.gif",img_selecionar:g_css_server+"/Assets/Maps/Images/bot_maximizar.gif",window_offset_x:3,window_offset_y:27};g_grid_index=0;}
var g_img_marca_w=21;var g_img_marca_h=25;var g_img_marca_dx=10;var g_img_marca_dy=g_img_marca_h;var g_texto_deselecionar_ponto="Retirar alfinete";var g_texto_selecionar_ponto="Colocar alfinete";var g_grid_index=0;var g_locator_widget=false;var oficial_version=true;function smaps_del_markers(){g_num_pontos=0;g_a_pontos=[];g_a_pontos_hash_map=[];}
function add_ponto(titulo,lat,lon){g_a_pontos[g_num_pontos]={titulo:titulo,lat:lat,lon:lon,img:(smaps_const.img_marca),w:g_img_marca_w,h:g_img_marca_h};g_num_pontos++;}
function add_ponto_desc(titulo,lat,lon,desc){if(titulo===""&&desc===""){titulo="Ponto "+g_num_pontos;}
g_a_pontos[g_num_pontos]={titulo:titulo,lat:lat,lon:lon,img:(smaps_const.img_marca),w:g_img_marca_w,h:g_img_marca_h,desc:desc};g_num_pontos++;}
function add_ponto_img(titulo,lat,lon,desc,img,img_w,img_h){if(img===""){add_ponto_desc(titulo,lat,lon,desc);return;}
g_a_pontos[g_num_pontos]={titulo:titulo,lat:lat,lon:lon,img:img,w:img_w,h:img_h};g_num_pontos++;}
function add_ponto_obj(titulo,lat,lon,desc,img,img_w,img_h,marker){g_a_pontos[g_num_pontos]={titulo:titulo,lat:lat,lon:lon,img:img,w:img_w,h:img_h,obj:marker};marker.index=g_num_pontos;g_num_pontos++;}
function add_ponto_marker(marker){var img=(marker.options.icon)?marker.options.icon.image:"";var w,h,dx,dy;if(img!==""){w=(marker.options.icon.iconSize)?marker.options.icon.iconSize.width:0;h=(marker.options.icon.iconSize)?marker.options.icon.iconSize.height:0;dx=(marker.options.icon.iconAnchor)?marker.options.icon.iconAnchor.x:0;dy=(marker.options.icon.iconAnchor)?marker.options.icon.iconAnchor.y:0;dx_win=(marker.options.icon.infoWindowAnchor)?marker.options.icon.infoWindowAnchor.x:0;dy_win=(marker.options.icon.infoWindowAnchor)?marker.options.icon.infoWindowAnchor.y:0;}else{img=smaps_const.img_marca;w=g_img_marca_w;h=g_img_marca_h;}
g_a_pontos[g_num_pontos]={titulo:marker.options.title,lat:marker.point.y,lon:marker.point.x,desc:marker.html,img:img,w:w,h:h,obj:marker,dx:dx,dy:dy,dx_win:dx_win,dy_win:dy_win,index:g_num_pontos};marker.index=g_num_pontos;g_num_pontos++;}
var global_xform_params;function Xform_params(lat,lon,x,y,cols,lines,largura,pan_percent,nome_servico,tipo_percurso){this.largura=largura;this.lon=lon;this.lat=lat;this.cols=cols;this.lines=lines;this.x=x;this.y=y;this.w=this.largura;this.h=this.w*this.lines/this.cols;if(x){this.x0=x-0.5*this.w;this.y0=y-0.5*this.h;this.x1=x+0.5*this.w;this.y1=y+0.5*this.h;}
this.pan_percent=pan_percent;this.pan_cols=this.cols*this.pan_percent;this.pan_lines=this.lines*this.pan_percent;this.img2_cols=Math.round(this.cols*(1.0+2*this.pan_percent));this.img2_lines=Math.round(this.lines*(1.0+2*this.pan_percent));this.nome_servico=nome_servico;this.tipo_percurso=tipo_percurso;}
function Xform_point(pt_x,pt_y,xform_par){this.x=(pt_x-xform_par.x0)/xform_par.w;this.y=(pt_y-xform_par.y0)/xform_par.h;this.x=this.x*xform_par.cols;this.y=xform_par.lines-this.y*xform_par.lines;}
function Xform_point_inv(x,y,xform_par){this.x=xform_par.x0+(xform_par.w*x/xform_par.cols);this.y=xform_par.y0+(xform_par.h*(xform_par.lines-y)/xform_par.lines);}
var _map_pontos_timer=null;function timer_smaps_map_pontos(){if(_map_pontos_timer!==null)
clearTimeout(_map_pontos_timer);_map_pontos_timer=setTimeout(smaps_map_pontos,500);}
function clear_timer_smaps_map_pontos(){if(_map_pontos_timer!==null)
clearTimeout(_map_pontos_timer);}
function smaps_set_map_cursor(){var cur_msg=((g_ie)?'url( '+g_css_server+'/Assets/Maps/Images/hand.cur)':'url('+g_css_server+'/Assets/Maps/Images/cur_hand.gif), auto');s$('div_no_clip').style.cursor=cur_msg;}
function smaps_map_pontos(){if(!GS_wms_tiles.ready)
return;if(_map_pontos_timer!==null){clearTimeout(_map_pontos_timer);}
_map_pontos_timer=null;smaps_dbg("map_pontos");smaps_dbg(g_num_pontos);var ind=1;var div_pontos_old=s$("div_pontos_child");var div=smaps_new_node('div','id','div_pontos_child',"style",'overflow:visible;padding:0px;margin:0px;position:absolute;z-index:25;top:0px;left:0px;width:'+
global_xform_params.img2_cols+'px;height:'+global_xform_params.img2_lines+'px;');smaps_dbl_click_ffox(div,center_map);var div_parent=s$('div_pontos');smaps_write_node(div_parent,div);smaps_set_map_cursor();var lat=global_xform_params.lat;var lon=global_xform_params.lon;var largura=global_xform_params.largura;var cols=global_xform_params.cols;var lines=global_xform_params.lines;var div_cam=s$("div_des_cam");div_cam.innerHTML="";var img_sel,texto_sel;var zoom=g_GSMap1.get_zoom();var is_great_zoom=zoom<=smaps_zoom_level_layers_base;for(ind=g_num_pontos-1;ind>=0;ind--){var pt_a=g_a_pontos[ind];if(!pt_a.lat){continue;}
if(pt_a.obj.options.guid&&pt_a.obj.options.permanent&&!is_great_zoom)continue;if(typeof(pt_a.obj.options.minResolution)!="undefined"){if(pt_a.obj.options.minResolution<GS_wms_tiles.get_resolution(zoom))continue;}
if(typeof(pt_a.obj.options.visibility_fn)!="undefined"){pt_a.obj.options.visible=pt_a.obj.options.visibility_fn(pt_a.obj);}
if(pt_a.obj&&!pt_a.obj.options.visible){continue;}
pt_nome=pt_a.titulo?pt_a.titulo:"";pt_desc=(pt_a.desc)?pt_a.desc:"";var pt_lat=pt_a.lat;var pt_lon=pt_a.lon;var g_callout_small_cols=142;var g_callout_small_lines=105;var g_callout_big_cols=214;var locator_pin=pt_a.obj.options&&pt_a.obj.options.editable;var g_callout_big_lines=(locator_pin)?220:166;var big_callout=locator_pin||(lines>=1.3*g_callout_big_lines&&cols>=1.3*g_callout_big_cols);if(!locator_pin){if(pt_nome.toString().length+pt_desc.toString().length<40){big_callout=false;}}
var g_callout_lines=big_callout?g_callout_big_lines:g_callout_small_lines;var g_callout_cols=big_callout?g_callout_big_cols:g_callout_small_cols;var callout_Nborder=10;var callout_Sdiv_border=10;var callout_Sborder=callout_Sdiv_border+20;var callout_Wborder=10;var callout_Eborder=5;var callout_offset_x=big_callout?98:62;var callout_offset_y=0;var font_style=big_callout?'font-size:10px;font-family:sans-serif':'font-size:9px;font-family:sans-serif';var callout_css=big_callout?"callout_big":"callout_small";var callout_desc_class="callout_desc";if(locator_pin){callout_css="callout_widget";callout_desc_class="callout_desc_widget";}
var selected=false;pt_img_w=pt_a.w;pt_img_h=pt_a.h;if(pt_a.obj&&pt_a.obj.options.selected){if(pt_a.obj.options.icon_selected){pt_img=(!pt_a.obj.options.opened)?pt_a.obj.options.icon_selected.title:pt_a.obj.options.icon_selected.image;if(pt_a.obj.options.icon_selected&&pt_a.obj.options.icon_selected.iconSize){pt_img_w=pt_a.obj.options.icon_selected.iconSize.width;pt_img_h=pt_a.obj.options.icon_selected.iconSize.height;}
if(typeof(pt_img)=="undefined"){pt_img=pt_a.obj.options.icon_selected.image;}}else{pt_img=pt_a.img;}
img_sel=smaps_const.img_deselecionar;texto_sel=g_texto_deselecionar_ponto;selected=true;}else{pt_img=pt_a.img;img_sel=smaps_const.img_selecionar;texto_sel=g_texto_selecionar_ponto;}
var conv=new conv_lat_lon_mercator_sphere(pt_lat,pt_lon);var pt_x=conv.x;var pt_y=conv.y;var xform=new Xform_point(pt_x,pt_y,global_xform_params);var xp=Math.floor(xform.x);var yp=Math.floor(xform.y);if(typeof(pt_a.obj.options.matchlevel)!="undefined"){if(pt_a.obj.options.matchlevel<6&&zoom<=2){xp+=pt_a.obj.options.dx*(3-zoom);yp+=pt_a.obj.options.dy*(3-zoom);}}
if(typeof(pt_a.dx)!="undefined"){x=xp-pt_a.dx;y=yp-pt_a.dy;}else{x=Math.floor(xform.x-0.5*pt_img_w);y=Math.floor(xform.y+0.5*pt_img_h)-pt_img_h;}
var x_ponto=x+global_xform_params.pan_cols;var y_ponto=y+global_xform_params.pan_lines;if(x_ponto<0.0||x_ponto>=global_xform_params.img2_cols||y_ponto<0.0||y_ponto>=global_xform_params.img2_lines){continue;}
var pt_link1="smaps_callout("+ind+")";var pt_link0="smaps_esconde("+ind+")";var is_html=pt_img.indexOf("<")>=0||(pt_img.indexOf(".png")<=0&&pt_img.indexOf(".gif")<=0&&pt_img.indexOf(".jpg")<=0);var z_index_pt=g_z_index_pt_closed;if(pt_a.obj.options.opened){z_index_pt=g_z_index_pt_opened;}
var img_style="";var img_src=pt_img;if(!is_html&&g_ie6&&img_src.indexOf(".png")>=0){img_style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+pt_img+"', sizingMethod='scale')";img_src=g_css_server+"/Assets/Maps/Images/pngtransp.gif";}
var pt_nome_ie=locator_pin?"":pt_nome;if(!g_ie)pt_nome_ie="";var div_marker=smaps_new_node('div','id','mark'+ind,"style",'position:absolute;z-index:'+g_z_index_pt_closed+';padding:0px;margin:0px;top:'+y_ponto+'px;left:'+x_ponto+'px;width:'+pt_img_w+'px;height:'+pt_img_h+'px;border:0px',"ondblclick","smaps_nop()",smaps_new_node('a',"href","javascript:"+pt_link1,'onmouseover',"unregister_move()",'onmouseout',"smaps_register_move()",(!is_html)?smaps_new_node('img',"galleryimg","no","oncontextmenu","return false","src",img_src,"style",img_style,"align","top","width",pt_img_w,"height",pt_img_h,"border",0,"title",(pt_nome_ie)):smaps_set_node_html(smaps_new_node('div',"style","margin:0px auto"),pt_img)));var widget_location_bar_h=(g_locator_callback?25:5);var x_callout=xp-callout_offset_x;var y_callout=yp-g_callout_lines-callout_offset_y;if(typeof(pt_a.dx_win)!="undefined"){x_callout=x_callout+pt_a.dx_win-2;if(pt_a.dx){x_callout=x_callout-pt_a.dx;}
y_callout=y_callout+pt_a.dy_win;if(pt_a.dy){y_callout=y_callout-pt_a.dy;}}
if(y_callout<0){pt_a.navigate_dy=-y_callout;}else{pt_a.navigate_dy=0;}
if(x_callout+g_callout_cols>cols){pt_a.navigate_dx=x_callout+g_callout_cols-cols;}else if(x_callout<40){pt_a.navigate_dx=x_callout-40;}else{pt_a.navigate_dx=0;}
x_callout+=global_xform_params.pan_cols;y_callout+=global_xform_params.pan_lines;var opened=false;if(pt_a.obj.options&&pt_a.obj.options.opened){opened=true;}
if(pt_desc!==""){pt_desc="<p>"+pt_desc+"</p>";}
var desc_div=smaps_set_node_html(smaps_new_node('div'),(pt_nome!=="")?("<h1>"+pt_nome+'</h1>'+pt_desc):pt_desc);var div_apagar=smaps_new_node('dummy');if(pt_a.obj.options&&!pt_a.obj.options.guid&&!pt_a.obj.options.permanent){div_apagar=smaps_new_node('a','href',"javascript:apagar_ponto("+ind+")",smaps_new_node('img',"src",g_css_server+"/Assets/Maps/Images/bot_apagar.gif","title","Apagar"));}
var div_callout_ind=smaps_new_node('div','id','callout'+ind,"class",callout_css,"style",'visibility:'+(opened?'visible':'hidden')+';position:absolute;z-index:'+(z_index_pt+10)+';top:'+(y_callout)+'px;left:'+(x_callout)+'px;cursor:pointer;cursor:default;',"ondblclick","smaps_nop()",'onmouseover',"unregister_move()",'onmouseout',"smaps_register_move()",smaps_new_node('div','id','callout_div_'+ind,'class',callout_desc_class,"style",'position:absolute;top:'+callout_Nborder+'px;left:'+callout_Wborder+'px;border:0px;width:'+(g_callout_cols-callout_Wborder-callout_Eborder)+'px;height:'+(g_callout_lines-callout_Nborder-callout_Sborder)+'px',desc_div),smaps_new_node('div',"style",'position:absolute;top:'+(g_callout_lines-callout_Sborder)+'px;left:'+(g_callout_cols-callout_Eborder-30)+'px;border:0px;width:20px;height:15px;overflow:visible'),smaps_new_node('div','class','callout_content',"style",'position:absolute;overflow:hidden;top:'+(g_callout_lines-callout_Sborder)+'px;left:'+(g_callout_cols-18)+'px;border:0px;width:20px;height:15px',div_apagar),smaps_new_node('div',"style",'position:absolute;overflow:hidden;top:7px;left:'+(g_callout_cols-18)+'px;border:0px;width:20px;height:15px',smaps_new_node('a','href',"javascript:"+pt_link0,smaps_new_node('img',"src",g_css_server+"/Assets/Maps/Images/bot_fechar.gif","title","Fechar"))));smaps_dbl_click_ffox(div_callout_ind,smaps_nop);smaps_write_node(div,div_marker);smaps_write_node(div,div_callout_ind);}
s$("div_pontos_child").style.visibility="visible";if(div_pontos_old!==null){div_pontos_old.style.display="none";div_parent.removeChild(div_pontos_old);}
for(var i=0;i<g_num_pontos;i++){smaps_dbl_click_ffox('callout'+ind,smaps_nop);}
smaps_desenha();}
function smaps_dbl_click_ffox(element,fn){element.ondblclick=fn;if(element.captureEvents){element.captureEvents(Event.ONDBLCLICK);}}
function smaps_nop(e){try{if(!e){e=window.event;}
if(e.cancelBubble){e.returnValue=false;e.cancelBubble=true;}
if(e.preventDefault){e.preventDefault();e.stopPropagation();}}catch(e){}}
function muda_texto_ponto(ind){var txt=s$("textarea_"+ind).value;var pt_a=g_a_pontos[ind];pt_a.desc=txt;smaps_refresh();}
function smaps_map(div_name,lat00,lon00,largura00,cols00,lines00,nome_servico,tipo_percurso){var div=s$(div_name);var lat=smaps_parse(lat00);var lon=smaps_parse(lon00);var largura=smaps_parse(largura00);var cols=smaps_parse(cols00);var lines=smaps_parse(lines00);map_params_global=null;map_div(div,lat,lon,largura,cols,lines,nome_servico,tipo_percurso);}
var map_params_global=null;function Map_params(div0,lat0,lon0,largura0,cols0,lines0,nome_servico0,tipo_percurso0){this.div=div0;this.lat=lat0;this.lon=lon0;this.largura=largura0;this.cols=cols0;this.lines=lines0;this.nome_servico=nome_servico0;this.tipo_percurso=tipo_percurso0;}
function map_div(div,lat,lon,largura,cols,lines,nome_servico,tipo_percurso){_last_map_params=null;var mymap=s$("mymap");if(mymap!==null&&mymap.hasChildNodes()){mymap.innerHTML="";}
var div_tags=smaps_new_node('div');var div_tags_h=s$('tags_hidden');if(div_tags_h!==null){div_tags.innerHTML=div_tags_h.innerHTML;}
var div_btn_area;div_btn_area=smaps_new_node('div','id',"btnArea",div_tags);if(g_GSMap1.gmap.navAreaVis){var navArea=smaps_new_node('div','id',"navArea",div_btn_area,"style","width:"+(cols)+"px;overflow:hidden");smaps_write_node(div,navArea);smaps_dbg(g_GSMap1.gmap.navAreaHeight);lines=lines-g_GSMap1.gmap.navAreaHeight;}
var map_style="height:"+lines+"px;";smaps_write_node(div,smaps_new_node('div','id',"mapborder","style",map_style,smaps_new_node('div','id',"mapborder2",smaps_new_node('img','id','img_wheel',"style","position:absolute;left:"+(cols/2-55)+"px;top:"+(lines/2-41)+"px;z-index:0","src",g_css_server+"/Assets/Maps/Images/bigwheel_1.gif","galleryimg","no","oncontextmenu","return false"),smaps_new_node('div','id',"mymap"))));map_params_global=new Map_params(div,lat,lon,largura,cols,lines,nome_servico,tipo_percurso);map_div_continue();}
function map_div_continue(){var div_mymap=s$('mymap');if(div_mymap===null||(typeof(GS_wms_tiles)=="undefined"||!GS_wms_tiles.ready)){setTimeout(map_div_continue,250);}
else{if(g_GSMap1.gmap._size_callback){setTimeout(g_GSMap1.gmap._size_callback,100);}
var div_border=s$('mapborder');var w=parseInt(div_border.offsetWidth,10);var h=parseInt(div_border.offsetHeight,10);if(!w){w=map_params_global.cols;}
if(!h){w=map_params_global.lines;}
div_mymap.width=w+"px";div_mymap.height=h+"px";var lar=map_params_global.largura;map_params_global.largura=map_params_global.largura*w/map_params_global.cols;map_params_global.cols=w;map_params_global.lines=h;map_params_global.div=div_mymap;map_div_with_params();if(smaps_mouse_wheel){smaps_register_mouse_wheel();}}}
function smaps_register_mouse_wheel(){var mapdiv=s$("gsmap");if(mapdiv.addEventListener){mapdiv.addEventListener('DOMMouseScroll',wheel,false);}
mapdiv.onmousewheel=wheel;}
function map_div_with_params(){var div=map_params_global.div;var lat=map_params_global.lat;var lon=map_params_global.lon;var largura=map_params_global.largura;var cols=map_params_global.cols;var lines=map_params_global.lines;var nome_servico=map_params_global.nome_servico;var tipo_percurso=map_params_global.tipo_percurso;var tiles_zoom=0;var zoom_control=g_map_control_type;var str=""+window.location;tiles_zoom=GS_wms_tiles.get_zoom_res(largura/cols);largura=GS_wms_tiles.get_resolution_aprox(tiles_zoom)*cols;global_xform_params=new Xform_params(lat,lon,undefined,undefined,cols,lines,largura,gPan_percent,nome_servico,tipo_percurso);var div_desenho_caminho=smaps_new_node('div','id','div_des_cam',"style",'overflow:hidden;padding:0px;margin:0px;visibility:visible;position:absolute;z-index:20;top:0px;left:0px;width:'+global_xform_params.img2_cols+'px;height:'+global_xform_params.img2_lines+'px');var div_zoom;var zoom_mais=smaps_new_node('div',"style",'position:relative;top:5px;left:6px;width:17px;height:19px',smaps_new_node('a',"href","javascript:smaps_zoomin();",smaps_new_node('img',"src",g_css_server+"/Assets/Maps/Images/mais.gif","galleryimg","no","oncontextmenu","return false","border",0,"title","Maior detalhe")));var zoom_menos=smaps_new_node('div',"style",'position:relative;top:8px;left:6px;width:17px;height:16px',smaps_new_node('a',"href","javascript:smaps_zoomout();",smaps_new_node('img',"src",g_css_server+"/Assets/Maps/Images/menos.gif","galleryimg","no","oncontextmenu","return false","border",0,"align","top","title","Menor detalhe")));var zoom_drag_display="";if(zoom_control==const_id_small_control){zoom_drag_display="display:none;";div_zoom=smaps_new_node('div',"id","div_zoom","style",'position:absolute;z-index:25;top:2px;left:2px;visibility:hidden;width:35px;height:60px;',zoom_mais,zoom_menos);}else if(zoom_control==const_id_large_control){var style_caixa_zoom="position:absolute;top:0;left:0;";src_caixa_zoom=g_css_server+'/Assets/Maps/Images/caixa_zoom_linha.png';if(g_ie6&&src_caixa_zoom.indexOf(".png")>=0){style_caixa_zoom=style_caixa_zoom+"filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src_caixa_zoom+"', sizingMethod='scale')";src_caixa_zoom=g_css_server+"/Assets/Maps/Images/pngtransp.gif";}
div_zoom=smaps_new_node('div',"id","div_zoom","style",'position:absolute;z-index:25;top:7px;left:6px;visibility:hidden;width:32px;height:150px;overflow:visible;',smaps_new_node('img','width',32,'height',142,'src',src_caixa_zoom,'style',style_caixa_zoom),zoom_mais,'onmouseout','hide_zoom_titles()');}
var zoom_drag=smaps_new_node('div','id','zoom_drag',"style",zoom_drag_display+"position:absolute;z-index:30;top:20px;left:5px;cursor:pointer;cursor:hand;",smaps_new_node('img','id','zoom_drag_img','width','20','height',g_zoom_drag_height,'src',g_css_server+'/Assets/Maps/Images/pix.gif'));smaps_write_node(div_zoom,smaps_new_node('div','style','overflow:hidden;position:relative;width:5px;height:5px'));for(i=g_min_zoom;i<=g_max_zoom;i++){var zoom_title=smaps_new_node('div',"id","div_t"+i,"class",'zoom_title',"style",'visibility:hidden;position:absolute;top:-5px;left:20px;');zoom_title.innerHTML=g_zoom_title[i];smaps_write_node(div_zoom,smaps_new_node('div',"style",zoom_drag_display+'margin:0;padding:0;position:relative;top:5px;left:4px;width:20px;height:7px',smaps_new_node('div',"id","div_z"+i,"class","zoom_norm_ie"),zoom_title));}
smaps_write_node(div_zoom,zoom_drag);if(zoom_control==const_id_large_control){smaps_write_node(div_zoom,zoom_menos);}
var div_escala=smaps_new_node('div','id','div_escala',"style",'cursor:default;visibility:hidden;padding:0px;margin:0px;position:absolute;z-index:30;'+'top:'+(lines-22)+'px;left:7px;width:190px;height:12px',smaps_new_node('div','id','div_escala_0',"style",'position:absolute;top:0px;left:0px;width:20px;height:10px',smaps_new_text_node("0")),smaps_new_node('img',"src",g_css_server+"/Assets/Maps/Images/mapas_escala.gif","galleryimg","no","oncontextmenu","return false","border","0px","onmouseover","window.status=''","style",'visibility:visible;padding:0px;margin:0px;position:absolute;top:4px;left:8px;width:'+g_smaps_escala_pix+'px;height:6px',"alt","escala"),smaps_new_node('div','id','div_escala_1',"style",';position:absolute;top:0px;left:'+(g_smaps_escala_pix+10)+'px;width:80px;height:10px'));if(g_copyr_img!=""){var img_src=g_copyr_img;var img_style="";if(g_ie6&&img_src.indexOf(".png")>=0){img_style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\""+img_src+"\", sizingMethod=\"scale\")";img_src=g_css_server+"/Assets/Maps/Images/pngtransp.gif";}
var div_copy_child=smaps_new_node('div','maps_copyr',"class","gs_ok");smaps_set_node_html(div_copy_child,"<a style='font-size:0.9em' href='#' onclick='link_mapas_sapo_pt()'><img src='"+img_src+"' width='98' height='23' style='"+img_style+"'/></a></div>");div_copyr=smaps_new_node('div','id','div_copyr',"style",'visibility:visible;position:absolute;z-index:30;top:'+(lines-25)+'px;left:'+(cols-105)+'px;width:100px;height:20px;',smaps_new_node('div',"style","position:absolute;left:0px;top:0px",div_copy_child));}else if(g_copyr_msg!==""){div_copyr=smaps_new_node('div','id','div_copyr',"style",'visibility:visible;position:absolute;z-index:30;top:'+(lines-22)+'px;left:'+(cols-70)+'px;width:75px;height:20px;');smaps_set_node_html(div_copyr,g_copyr_msg);}else{div_copyr=smaps_new_node('dummy');}
var div_mapa_img,div_no_clip;div_mapa_img=smaps_new_node('div','id','div_grelha0',"style","visibility:hidden");var div_pontos=smaps_new_node('div','id','div_pontos',"style",'overflow:visible;padding:0px;margin:0px;position:absolute;z-index:25;top:0px;left:0px;width:'+
global_xform_params.img2_cols+'px;height:'+global_xform_params.img2_lines+'px;');div_no_clip=smaps_new_node('div','id','div_no_clip',"style",'overflow:visible;position:relative;top:-'+(global_xform_params.pan_lines)+'px;left:-'+(global_xform_params.pan_cols)+'px;'+'width:'+global_xform_params.img2_cols+'px;height:'+global_xform_params.img2_lines+'px',div_mapa_img,div_desenho_caminho,div_pontos);var div_mapa=smaps_new_node('div','id','smaps_div',"style",'overflow:hidden;position:absolute;z-index:10;padding:0px;margin:0px;top:0px;left:0px;width:'+cols+'px;height:'+lines+'px;border:0px',smaps_new_node('div','id','div_clip',"style",'visibility:visible;overflow:visible;position:relative;z-index:11;top:0px;left:0px;width:'+cols+'px;height:'+lines+'px',div_no_clip));var minimap_opened_style;var minimap_closed_style;if(smaps_widget){minimap_opened_style="display:none";minimap_closed_style="display:none";}else{minimap_opened_style=smaps_minimap_start_opened?"display:block":"display:none";minimap_closed_style=smaps_minimap_start_opened?"display:none":"display:block";}
var a_close_minimap=smaps_new_node('a',"href","#",smaps_new_node('img',"src","http://mapas.sapo.pt/images/bot_mapapq_fechar.gif","title","Minimizar mapa"));var div_minimap=smaps_new_node('div','id','minimap',"class","clearfix mapa-pq1","style",minimap_opened_style+";height:100px;position:absolute;z-index:30;top:6px;left:"+(cols-145)+"px",smaps_new_node('div',"class","mapa-ilhas","style","position:absolute",smaps_new_node('div','id','minimap_overview',"class","mapa-continente","title","Clique para centrar o mapa noutro local","style","position:absolute;left:0px;top:0px",smaps_new_node('div','id','minimap_feedback',"class","mapa-pq-feedback","style","position:absolute")),smaps_new_node('div',"class","mapa-pq-bot1","style","position:absolute;left:105px;top:0px",a_close_minimap)));div_minimap.onclick=smaps_click_overview;a_close_minimap.onclick=smaps_close_minimap;var div_minimap_closed=smaps_new_node('div','id','minimap_closed',"class","clearfix mapa-pq2","style",minimap_closed_style+";position:absolute;z-index:30;top:6px;left:"+(cols-36)+"px",smaps_new_node("a","href","javascript:smaps_open_minimap()",smaps_new_node("img","src","http://mapas.sapo.pt/images/bot_mapapq_abrir.gif","title","Maximizar mapa")));smaps_write_node(div,smaps_new_node("div","id","gsmap","style",'position:relative;z-index:10;padding:0px;margin:0px;top:0px;left:0px;width:'+cols+'px;height:'+lines+'px;overflow:hidden',div_mapa,div_escala,div_zoom,div_minimap,div_minimap_closed,div_copyr));GS_wms_tiles.get_map_tiles(lat,lon,tiles_zoom,global_xform_params.img2_cols,global_xform_params.img2_lines);if(g_locator_widget){var btn=smaps_new_node("div","id","gs_btn",smaps_new_node("a","href",'javascript:smaps_submitPesqForm()',smaps_new_text_node("Pesquisar")));var btn_aqui=smaps_new_node("div","id","gs_btn_aqui",smaps_new_node("a","href",'javascript:smaps_estou_aqui()',smaps_new_text_node("Estou aqui")));var btn_group=smaps_new_node('div','id','btn_group',btn,btn_aqui);smaps_write_node(div,smaps_new_node("div","id","div_loc_search","style","position:absolute; top:5px; left:45px; width:"+(cols-50)+"px;z-index:100;",smaps_new_node("span","class","gs_boxPesquisa",smaps_new_node("form","name","SearchForm","id","SearchForm","action","","onsubmit","smaps_pesquisa_geral();return false;",smaps_new_node("input","type","text","name","q","id","caixap","class","gs_inputtext"))),btn,btn_aqui));var navi=smaps_new_node("div","id","results-paginacao");smaps_set_node_html(navi,'<a id = "pg_ant" href="#" onclick="showMatches(\'ant\');" style = "visibility:hidden">&#0171; ant.&nbsp;</a>&nbsp;&nbsp;'+'<a id = "pg1" href="#" onclick="showMatches(1);" class = "selected" style = "visibility:hidden">1</a>&nbsp;&nbsp;'+'<a id = "pg2" href="#" onclick="showMatches(2);" style = "visibility:hidden">2</a>&nbsp;&nbsp;'+'<a id = "pg3" href="#" onclick="showMatches(3);" style = "visibility:hidden">3</a>&nbsp;&nbsp;'+'<a id = "pg4" href="#" onclick="showMatches(4);" style = "visibility:hidden">4</a>&nbsp;&nbsp;'+'<a id = "pg_seg" href="#" onclick="showMatches(\'seg\');" style = "visibility:hidden">&nbsp;seg.&#0187;</a>');smaps_write_node(div,smaps_new_node("div","id","results","class","gs_res_frame","style","background-color:white;visibility:hidden;position:absolute;top:5px;left:45px;width:"+(cols-90)+"px;height:300px;z-index:100;overflow:auto",smaps_new_node("div","id","matches"),navi,smaps_new_node('div',"style","position:absolute;top:5px;left:"+(cols-120)+"px;width:15px;height:15px;z-index:110",smaps_new_node('a','href',"javascript:smaps_hide_results( true)",smaps_new_node('img',"src",g_css_server+"/Assets/Maps/Images/fechar.gif","width",13,"height",13,"title","Fechar")))));}
if(g_stages&&s$("div_debug")===null){smaps_write_node(div,smaps_new_node("div","id","div_debug","style","visibility:hidden;position:absolute;top:0px;left:0px;width:"+cols+"px;height:"+(lines-50)+"px;z-index:1000;overflow:auto;background-color:white;text-align:left"));}
register_zoom_drag(s$("zoom_drag_img"));smaps_set_map_cursor();}
function smaps_close_minimap(e){s$("minimap").style.display="none";s$("minimap_closed").style.display="block";smaps_nop(e);return true;}
function smaps_open_minimap(){s$("minimap").style.display="block";s$("minimap_closed").style.display="none";smaps_update_minimap();}
var smaps_overview_bounds=null;function smaps_update_minimap(){if(s$("minimap").style.display!="block")return;var lat=smaps_geomap.getLatitude();var lon=smaps_geomap.getLongitude();var factor;if(g_GSMap1.get_zoom()==12){factor=3.0;}else{factor=2.0;}
var bounds=smaps_geomap.getBoundsLatLng_centered(factor);var dLat=0.5*100/125*(bounds.maxX-bounds.minX);var lat0=lat-dLat;var lat1=lat+dLat;var map_url="http://services.sapo.pt/Maps/GetMap?version=1.1.1&service=WMS&layers=concelhos&request=GetMap&width=125&height=100&transparent=true&bbox="+bounds.minX+","+lat0+","+bounds.maxX+","+lat1;smaps_dbg(map_url);s$('minimap_overview').style.background="url("+map_url+")";smaps_overview_bounds=new GBounds(bounds.minX,lat0,bounds.maxX,lat1);var boundsMap=smaps_geomap.getBoundsLatLng_centered(1.0);var ratiow=0.8*(boundsMap.maxX-boundsMap.minX)/(bounds.maxX-bounds.minX);var ratioh=1.1*(boundsMap.maxY-boundsMap.minY)/(lat1-lat0);var dx=parseInt(ratiow*125);var dy=parseInt(ratioh*100);s$("minimap_feedback").style.width=dx+"px";s$("minimap_feedback").style.height=dy+"px";s$("minimap_feedback").style.top=parseInt(0.5*(100-dy))+"px";s$("minimap_feedback").style.left=parseInt(0.5*(125-dx))+"px";}
function smaps_click_overview(e){if(s$("minimap").style.display!="block")return;if(!e)e=window.event;var xy=new Mouse2point_xy(e,"minimap_overview");smaps_dbg("overview:");smaps_dbg(xy.x);smaps_dbg(xy.y);var bounds=smaps_overview_bounds;var dLon=(bounds.maxX-bounds.minX);var dLat=(bounds.maxY-bounds.minY);var lon=bounds.minX+((xy.x-1)/125)*dLon;var lat=bounds.maxY-((xy.y-1)/100)*dLat;var zoom=g_GSMap1.get_zoom();smaps_geomap.centerAndZoom(lat,lon,17-zoom);}
var loading=false;function mapa_loaded(){if(s$("div_relogio").style.visibility!="visible"){s$("div_clip").style.visibility="visible";s$("div_zoom").style.visibility="visible";smaps_escala();smaps_register_move();}}
function smaps_callout(ind,prevent_bubble){if(typeof(g_a_pontos[ind].obj)!="undefined"){if(g_a_pontos[ind].obj.click_fn!==null){g_a_pontos[ind].obj.click_fn(g_a_pontos[ind].obj);return;}}
smaps_close_markers();if(!g_a_pontos[ind])return;if(!prevent_bubble&&g_a_pontos[ind].navigate_dy!==0||g_a_pontos[ind].navigate_dx!==0){smaps_drag(g_a_pontos[ind].navigate_dx/global_xform_params.cols,g_a_pontos[ind].navigate_dy/global_xform_params.lines);setTimeout("smaps_callout( "+ind+",true)",300);}else{try{if(s$("callout"+ind).style.visibility=="visible"){smaps_esconde(ind);return;}}catch(e){return;}
try{if(g_last_open_pin!==null&&g_last_open_pin!==ind){smaps_esconde(g_last_open_pin);}}catch(e){}
g_last_open_pin=ind;g_a_pontos[ind].obj.options.opened=true;s$("callout"+ind).style.zIndex=g_z_index_pt_opened;s$("callout"+ind).style.visibility="visible";}}
function smaps_esconde(ind){try{s$("callout"+ind).style.visibility="hidden";s$("callout"+ind).style.zIndex=g_z_index_pt_closed;var pt_a=g_a_pontos[ind];if(typeof(pt_a.obj)!="undefined"&&pt_a.obj.options&&pt_a.obj.options.opened){pt_a.obj.options.opened=false;}}catch(e){}}
function esconde_cam(){s$('caminho_frame').style.visibility='hidden';}
function smaps_escala(){var v=Math.round(global_xform_params.largura*g_smaps_escala_pix/global_xform_params.cols);var u=" m";if(v>=10000){v=Math.round(v/1000);u=" Km";}else if(v>=50){v=Math.round(v/10)*10;}
s$('div_escala_1').innerHTML=v+u;s$('div_escala').style.visibility="visible";}
function smaps_desenha(){if(loading||g_itenerario===null||!g_itenerario.segs){return;}
limpa_iten(false);var div_des_cam=s$("div_des_cam");if(g_ie)
s$("div_des_cam").style.display="block";div_des_cam.style.visibility="visible";div_des_cam.innerHTML="";div_des_cam.style.top="0px";div_des_cam.style.left="0px";var p1,p2;var i=1;var ruas=g_itenerario.segs;var x,y;var count=0;var z=17-g_GSMap1.gmap.getZoom();var len_discard=GS_wms_tiles.get_resolution(z)*20;var count_rua=0;var last_x,last_y;var polyline=[];for(i=0;i<ruas.length;i++){var rua=ruas[i];var step=1;if(rua.m<len_discard){step=rua.lines.length-1;}
if(!rua.extents.intersects(global_xform_params.x0,global_xform_params.y0,global_xform_params.x1,global_xform_params.y1)){continue;}
count_rua++;for(var j=0;j<rua.lines.length;j+=step){if(!rua.lines[j]){continue;}
x=rua.lines[j].x;y=rua.lines[j].y;p1=new Xform_point(x,y,global_xform_params);x=Math.round(p1.x+global_xform_params.pan_cols);y=Math.round(p1.y+global_xform_params.pan_lines);if(x!=last_x||y!=last_y){polyline[count]=x;polyline[count+1]=y;count+=2;}
last_x=x;last_y=y;}}
var points_str="";var width=10-2*z;if(width<3){width=3;}
var opacity=0.4;var polyline_color="#0000ff";if(g_ie){opacity=1.0;for(i=0;i<polyline.length;i+=2){points_str=points_str+polyline[i]+" "+polyline[i+1]+" ";}
div_des_cam.innerHTML=('<v:polyline points="'+points_str+'" strokecolor="'+polyline_color+'" strokeweight="'+width+'pt"><v:stroke opacity="'+opacity+'"/><v:fill on="false"/></v:polyline>');if(width>3){width=width-2;}else{width=2;}}else if(g_ffox){for(i=0;i<polyline.length;i+=2){points_str=points_str+polyline[i]+","+polyline[i+1]+" ";}
div_des_cam.style.visibility="visible";div_des_cam.innerHTML='<svg xmlns="http://www.w3.org/2000/svg"><polyline points="'+points_str+'" style="fill:none;stroke:'+polyline_color+';stroke-width:'+width+';stroke-opacity:'+opacity+'"/></svg>';setTimeout(svg_power_on_nodes,500);s$("div_des_cam").style.display="block";}
if(!g_ffox&&!smaps_print_version){s$("div_des_cam").style.opacity=opacity;if(g_ie)s$("div_des_cam").style.filter="alpha(opacity=40)";var jg=new jsGraphics(div_des_cam);if(!g_ie){jg.setPrintable(true);}
jg.setStroke(width+1);jg.setColor("blue");for(i=0;i<polyline.length-3;i+=2){jg.drawLine(polyline[i],polyline[i+1],polyline[i+2],polyline[i+3]);}
jg.paint();s$("div_des_cam").style.display="block";}}
function smaps_janela_mensagem(texto){s$('caminho_frame').style.visibility='visible';var linhas=s$('linhas');if(linhas!==null){s$('caminho').removeChild(linhas);}
s$('caminho').innerHTML=texto;s$('caminho').style.top=0;}
function smaps_iten_query(){try{tab_iten();}catch(e){}
if(!g_map_ready){setTimeout(smaps_iten_query,1000);}else{smaps_iten_query_cont();}}
function smaps_iten_query_cont(){try{var query=g_qparams.query;g_qparams.tipo_query=1;query=query.substring(2,query.length);var args=query.split(";");var pt1=args[1];var pt2=args[2];var modo=args[0];var do_print=args[3];var args1=pt1.split(",");var args2=pt2.split(",");var lat1=args1[0];var lon1=args1[1];var txt1=unescape(args1[2]);var lat2=args2[0];var lon2=args2[1];var txt2=unescape(args2[2]);var img=g_css_server+"/Assets/Maps/Images/bandeira_verde.gif";var mk1=gs_createMarker(txt1,"",new GPoint(lon1,lat1),img,img,23,28,12,30);mk1.options.selected=true;g_GSMap1.gmap.addOverlay(mk1);img=g_css_server+"/Assets/Maps/Images/bandeira_vermelha.gif";var mk2=gs_createMarker(txt2,"",new GPoint(lon2,lat2),img,img,23,28,12,30);mk2.options.selected=true;g_GSMap1.gmap.addOverlay(mk2);g_qparams.partida=mk1;g_qparams.chegada=mk2;g_qparams.print_version=(typeof(do_print)!=="undefined"&&do_print==="p");smaps_itenerario(modo,do_print);}catch(e){}}
function smaps_itenerario(mode_query){var mode="rapido";if(typeof(mode_query)!=="undefined"){mode=mode_query;}else{for(var i=0;i<=2;i++){if(s$("SearchForm_iten").tipocam[i].checked){mode=s$("SearchForm_iten").tipocam[i].value;}}}
g_qparams.modo=mode;g_smaps_serial=get_sec1970();var route_link=g_gs_route_server+"?js=yes&mode="+mode+"&pts=";route_link=route_link+g_qparams.partida.point.x+","+g_qparams.partida.point.y;route_link=route_link+","+g_qparams.chegada.point.x+","+g_qparams.chegada.point.y;smaps_dbg(route_link);g_qparams.cancel=false;_percurso_timeout=setTimeout(erro_percurso,20000);smaps_js_request(route_link,"script1");if(g_map_ready){smaps_dim_markers(true);}
try{s$('gs_pub').style.display="none";}catch(e){}
s$("group1_tab2").style.display="block";s$('iten_results').style.display='none';s$("percurso").style.display="block";s$('percurso').innerHTML="<center><img src='"+g_css_server+"/Assets/Maps/Images/bigwheel_1.gif'></center>";}
function erro_percurso(){percurso_callback({error_code:-4});}
_percurso_timeout=null;function percurso_callback(route_obj){if(_percurso_timeout!=null){clearTimeout(_percurso_timeout);_percurso_timeout=null;}else{return;}
s$('iten_results').style.display='none';s$("percurso").style.display="block";s$("group1_tab2").style.display="block";if(g_qparams.cancel){s$('percurso').style.display='none';return;}
s$('iten_voltar').style.display="block";s$("iten_resumo").style.display="block";s$(g_qparams.div_results).style.display="none";var txt="";if(route_obj&&route_obj.error_code){s$('percurso').innerHTML="";s$('percurso').style.display='none';percurso_note("iten_erro",smaps_msgs(route_obj.error_code));return;}
if(!route_obj||!route_obj.segs||!route_obj.total){s$('percurso').innerHTML="";s$('percurso').style.display='none';percurso_note("iten_erro","O serviço n&atilde;o est&aacute; disponível neste momento.");return;}
percurso_note("iten_erro");s$('a_itenzoom').style.visibility="hidden";var modo=g_qparams.modo;modo=(modo=="rapido")?"Mais r&aacute;pido de carro":((modo=="curto")?"Mais curto de carro":"Mais curto a p&eacute;");percurso_note_modo(modo);txt=txt+'<div id="percurso_table" style="height:100%"><table cellspacing="0" cellpadding="0">'+header_percurso();var ruas=route_obj.segs;var i;var i0=route_obj.inverted?(ruas.length-1):0;var i_plus=route_obj.inverted?-1:+1;var i1=route_obj.inverted?-1:ruas.length;var extents=null;for(i=i0;i!=i1;i+=i_plus){var rua=ruas[i];centroid_rua_percurso(rua,route_obj.inverted);if(extents===null){extents=new GBounds(rua.extents.minX,rua.extents.minY,rua.extents.maxX,rua.extents.maxY);}else{extents.add(rua.extents);}
if(rua.st===""&&rua.dir===0){continue;}
var len_plus=0;for(var j=i+i_plus;j!=i1;j+=i_plus){if(j<0||j>ruas.length-1){break;}
if(ruas[j].st===""&&ruas[j].dir===0){len_plus+=ruas[j].m;}
else{break;}}
txt=txt+trata_rua_percurso(i,ruas[i],route_obj.inverted,len_plus);}
txt=txt+footer_percurso(i)+'</table>';percurso_msg(txt);var dist=route_obj.total.m;var m=dist;var unit="m";if(route_obj.total.m>=1000){unit="Km";dist=Math.floor(dist/100)/10;}
var t=route_obj.total.s;var t0=Math.floor(t/3600);var min=Math.floor((t-t0*3600)/60);if(t0>0&&min<10){min="0"+min;}
percurso_note("iten_sum",dist+" "+unit+" em "+((t0>0)?(t0+"h"):"")+min+" min");g_itenerario=route_obj;smaps_desenha();var x0=extents.minX;var y0=extents.minY;var x1=extents.maxX;var y1=extents.maxY;var y=(y0+y1)/2;var x=(x0+x1)/2;var dx=Math.abs(x0-x1);var dy=Math.abs(y0-y1);var len=(dx>dy)?dx:dy;len=len*2.0;var z=GS_wms_tiles.get_zoom_res(len/g_GSMap1.cols);smaps_dbg("z:"+z);var conv=new conv_xy_mercator_sphere_lat_lon(x,y);g_iten_view=new Smaps_View(conv.lat,conv.lon,z);g_GSMap1.set_lat_lon_zoom(conv.lat,conv.lon,z);setTimeout(smaps_iten_zoomed,2000);try{s$('group1_tab2').style.display="block";s$("guardar_mapa").style.display="none";s$("guardar_iten").style.display="block";}catch(e){}
g_qparams.query="";smaps_stats("itinerario","percurso",g_qparams.partida.options.title+" "+g_qparams.chegada.options.title);}
function smaps_print_copy(){if(g_itenerario&&document.getElementById('percurso_table')===null){setTimeout(smaps_print_copy,1000);return;}
var url="index_print.php?itin="+(g_itenerario?"1":"0");window.open(url,"maps_print","menubar=no,width=750,height=950");}
function smaps_iten_zoomed(){g_qparams.iten_zoomed=g_GSMap1.toQueryValue();}
function iten_navigate_to(lat,lon,zoom){navigate_to_async(lat,lon,zoom);}
function scroll_into_map(){try{s$("mapAPI").scrollIntoView();}catch(e){}}
function iten_zoom(){if(g_iten_view!==null){g_GSMap1.set_lat_lon_zoom(g_iten_view.lat,g_iten_view.lon,g_iten_view.zoom);s$('a_itenzoom').style.visibility="hidden";}else{smaps_refresh();}}
function smaps_msgs(msg_code){switch(msg_code){case 0:case-1:case-2:case-4:return"N&atilde;o foi poss&iacute;vel calcular um percurso entre os pontos indicados.";case-3:return"N&atilde;o foi encontrado um percurso completo entre os pontos indicados";case 1:return"A partida ou a chegada est&atilde;o numa &aacute;rea com restri&ccedil;&otilde;es de circula&ccedil;&atilde;o autom&oacute;vel";default:return"";}}
function smaps_iten_voltar(){g_qparams.cancel=true;s$('iten_voltar').style.display="none";s$('iten_results').style.display="none";s$('iten_resumo').style.display="none";s$('iten_modo').style.display="none";s$('percurso').style.display="none";s$('gs_pub').className="screen";s$('esquerda').className="screen";s$('direita').className="screen";activa_banner();smaps_stats("Itinerario","voltar","");s$('percurso_print').style.display="none";s$('caixa_partida').focus();if(g_map_ready){smaps_dim_markers();}
iten_zoom();s$('esquerda').style.display="block";}
function limpa_percurso(){smaps_dim_markers();limpa_iten(true);setTimeout(smaps_refresh,1000);try{s$("guardar_mapa").style.display="block";s$("guardar_iten").style.display="none";}catch(e){}}
function limpa_percurso_anterior(){smaps_dim_markers();limpa_iten(true);}
function limpa_iten(format){if(format){g_itenerario=null;}
try{var div_des_cam=s$("div_des_cam");var children=div_des_cam.childNodes;for(var i=0;i<children.length;i++){div_des_cam.removeChild(children[i]);}
s$("div_des_cam").style.display="none";s$("div_des_cam").style.visibility="hidden";}catch(e){}}
function header_percurso(){var img=g_css_server+"/Assets/Maps/Images/bandeira_verde.gif";var pt=g_qparams.partida.point;var z=2;var stripe='stripe';var title=g_qparams.partida.html?SAPO.Utility.String.stripTags(g_qparams.partida.html):"";var st=g_qparams.partida.options.title+" "+((typeof(desc)!=="undefined")?desc:"");var a_href='<a title="'+title+'" href="javascript:iten_navigate_to('+pt.y+', '+pt.x+', '+z+')">';if(typeof(g_qparams.partida_ascii)!="undefined")
s$("caixa_partida").value=g_qparams.partida_ascii;return'<tr class="separator itinbegin '+stripe+'"><td class="td img">'+a_href+'<img src="'+img+'" alt="partida"/></a></td>'+'<td class="td dir">'+a_href+st+'</a><br/></td><td class="td km"></td></tr>';}
function footer_percurso(i){var img=g_css_server+"/Assets/Maps/Images/bandeira_vermelha.gif";var pt=g_qparams.chegada.point;var z=2;var stripe='';if((i%2)==1){stripe='stripe';}
var title=g_qparams.chegada.html?SAPO.Utility.String.stripTags(g_qparams.chegada.html):"";var st=g_qparams.chegada.options.title+" "+((typeof(desc)!=="undefined")?desc:"");var a_href='<a title="'+title+'" href="javascript:iten_navigate_to('+pt.y+', '+pt.x+', '+z+')">';if(typeof(g_qparams.chegada_ascii)!="undefined")
s$("caixa_chegada").value=g_qparams.chegada_ascii;return'<tr class="separator itinend '+stripe+'"><td class="td img">'+a_href+'<img src="'+img+'" alt="chegada"/></a></td>'+'<td class="td dir">'+a_href+st+'</a><br/></td><td class="td km"></td></tr>';}
function trata_rua_percurso(i,rua,inverted,len_plus){if(!rua||!rua.lines||!rua.lines[0]||!rua.m){return"";}
var pt=new GLatLng(0,0);pt.x=rua.lon;pt.y=rua.lat;var len=parseFloat(rua.m)+len_plus;var z=(len>500)?3:1;var unit="m";var dist=len/1000;if(len>1000){len=Math.floor(len/100)/10;unit="Km";}
var img="frente.gif";if(rua.dir>0){img="esquerda.gif";}
else if(rua.dir<0){img="direita.gif";}
var stripe='';if((i%2)==1){stripe='stripe';}
var str_dir=((rua.dir===0)?"Continue":((rua.dir>0)?"Vire &agrave; esquerda":"Vire &agrave; direita"));var st=str_dir+(rua.st?(" para "+rua.st):"");var a_href='<a href="#" onclick="iten_navigate_to('+pt.y+', '+pt.x+', '+z+')">';return'<tr class="separator '+stripe+'"><td class="td img">'+a_href+'<img src="'+g_css_server+'/Assets/Maps/Images/'+img+'" alt="'+str_dir+'"/></a></td>'+'<td class="td dir">'+a_href+st+'</a><br/></td><td class="td km">'+len+'<br />'+unit+'</td></tr>';}
function percurso_msg(msg){s$('percurso').innerHTML=msg;}
function percurso_note_modo(msg){s$("SearchForm_iten_radios").tipocam2[0].checked=(g_qparams.modo=="rapido");s$("SearchForm_iten_radios").tipocam2[1].checked=(g_qparams.modo=="curto");s$("SearchForm_iten_radios").tipocam2[2].checked=(g_qparams.modo=="apeado");s$("SearchForm_iten").tipocam[0].checked=(g_qparams.modo=="rapido");s$("SearchForm_iten").tipocam[1].checked=(g_qparams.modo=="curto");s$("SearchForm_iten").tipocam[2].checked=(g_qparams.modo=="apeado");s$("iten_modo").style.display="block";}
function percurso_note(id,msg){if(typeof(msg)!=="undefined"){s$(id+"_txt").innerHTML=msg;s$(id).style.display="block";s$(id+"_txt").style.display="block";}else{s$(id).style.display="none";s$(id+"_txt").style.display="none";}}
function percurso_msg_old(msg){smaps_dbg(msg);s$('caminho').innerHTML=msg;s$('caminho').style.top=0;}
function centroid_rua_percurso(rua,inverted){if(typeof(rua.lat)=="undefined"||typeof(rua.lon)=="undefined"){var x,y;if(!inverted){x=rua.lines[0].x;y=rua.lines[0].y;}else{x=rua.lines[rua.lines.length-1].x;y=rua.lines[rua.lines.length-1].y;}
var conv=new conv_xy_mercator_sphere_lat_lon(x,y);rua.lat=conv.lat;rua.lon=conv.lon;var x0=rua.lines[0].x;var x1=rua.lines[rua.lines.length-1].x;var y0=rua.lines[0].y;var y1=rua.lines[rua.lines.length-1].y;var minx=(x0<x1)?x0:x1;var maxx=(x0>x1)?x0:x1;var miny=(y0<y1)?y0:y1;var maxy=(y0>y1)?y0:y1;rua.extents=new GBounds(minx,miny,maxx,maxy);}}
function smaps_sel_ponto(ind){var pt_a=g_a_pontos[ind];if(!pt_a.obj){return;}
pt_a.obj.options.selected=!pt_a.obj.options.selected;if(pt_a.obj.options.selected){img_sel=smaps_const.img_deselecionar;texto_sel=g_texto_deselecionar_ponto;}else{img_sel=smaps_const.img_selecionar;texto_sel=g_texto_selecionar_ponto;}
var img=s$("imgsel"+ind);if(img===null){return;}
img.src=img_sel;img.title=texto_sel;smaps_refresh();}
function apagar_ponto(ind){try{var pt_a=g_a_pontos[ind];if(!pt_a.obj){return;}
smaps_remove_marker(pt_a.obj);}catch(e){}}
function smaps_remove_marker(marker){try{marker.options.visible=!marker.options.visible;if(marker.options.guid){g_a_pontos_hash_map[marker.options.guid]=false;}
smaps_map_pontos();}catch(e){}}
var scroolling=false;var scroll_layer=null;var timerScroll=null;function smaps_scroll(spd){if(!scroolling){return;}
var direction=null;var layer=s$(scroll_layer);var page=layer.style;var y_pos=parseInt(page.top,10);var speed=spd;if(speed<0){direction="up";speed=-speed;}else{direction="dn";}
var new_top;if(direction=="dn"){new_top=(y_pos-(speed));}else if(direction=="up"&&y_pos<speed){new_top=(y_pos+(speed));}else{return;}
page.top=new_top+"px";timerScroll=setTimeout("smaps_scroll("+spd+")",100);}
function stopScroll(){scroolling=false;clearTimeout(timerScroll);}
function startScroll(layer,spd){scroolling=true;scroll_layer=layer;smaps_scroll(spd);}
var last_top=0;var last_left=0;var smaps_moved=false;var smaps_moving=false;var zooming=false;var g_last_drag_x=0;var g_last_drag_y=0;function smaps_drag(xx,yy,e){if(loading){return;}
var px=xx*global_xform_params.cols;var py=yy*global_xform_params.lines;px=Math.round(px);py=Math.round(py);g_last_drag_x=-px;g_last_drag_y=py;if(-1<px&&px<1&&-1<py&&py<1){loading=false;return;}
smaps_moved=false;var layer=s$("div_clip");var page=layer.style;if(!smaps_moved){last_top=parseInt(page.top,10);last_left=parseInt(page.left,10);page.top=(last_top+py)+"px";page.left=(last_left-px)+"px";}
var largura;var zoom;GS_wms_tiles.get_map_tiles(global_xform_params.lat,global_xform_params.lon,GS_wms_tiles.current_zoom,global_xform_params.img2_cols,global_xform_params.img2_lines,undefined,px,py);}
function smaps_wait(){smaps_dbg("wait");s$('img_wheel').style.visibility="visible";unregister_move();}
function smaps_reset_drag(){var layer=s$("div_clip");var page;try{page=layer.style;page.top="0px";page.left="0px";var div_pontos=s$("div_pontos_child");div_pontos.style.top=g_last_drag_y+"px";div_pontos.style.left=g_last_drag_x+"px";var div_des_cam=s$("div_des_cam");div_des_cam.style.top=g_last_drag_y+"px";div_des_cam.style.left=g_last_drag_x+"px";g_last_drag_x=0;g_last_drag_y=0;}catch(e){}}
function mapa_replaced(){smaps_dbg("replaced");if(loading===false){return;}
if(g_itenerario!==null){s$("div_des_cam").style.visibility="visible";}
s$("div_zoom").style.visibility="visible";loading=false;smaps_moved=false;smaps_moving=false;zooming=false;smaps_escala();smaps_register_move();window.status="";smaps_map_pontos();zoom_tiles_callback(GS_wms_tiles.current_zoom);s$('img_wheel').style.visibility="hidden";if(g_GSMap1.gmap._callback){g_GSMap1.gmap._callback();}}
function smaps_zoomin(){if(loading){return;}
var zoom=GS_wms_tiles.get_zoom_res(global_xform_params.largura/global_xform_params.cols)-1;if(!GS_wms_tiles.location.has_zoom(zoom)){return;}
zoom_tiles_async(zoom);smaps_stats("mapa","zoomIn",zoom);}
function smaps_zoomout(){if(loading){return;}
var zoom=GS_wms_tiles.get_zoom_res(global_xform_params.largura/global_xform_params.cols)+1;if(!GS_wms_tiles.location.has_zoom(zoom)){return;}
zoom_tiles_async(zoom);smaps_stats("mapa","zoomIn",zoom);}
function show_zoom(tiles_zoom){for(i=g_min_zoom;i<=g_max_zoom;i++){s$("div_z"+i).className="zoom_norm_ie";}
s$("div_z"+tiles_zoom).className="zoom_sel_ie";}
function hide_zoom_titles(){for(i=g_min_zoom;i<=g_max_zoom;i++){s$("div_t"+i).style.visibility='hidden';}}
var g_last_zoom=-1;function zoom_tiles_async(zoom){if(zooming||loading){return;}
try{if(!GS_wms_tiles.location.has_zoom(zoom)){return;}
var lat1=global_xform_params.lat;var lon1=global_xform_params.lon;zooming=true;GS_wms_tiles.get_map_tiles(lat1,lon1,zoom,global_xform_params.img2_cols,global_xform_params.img2_lines,undefined);}catch(e){}}
function smaps_refresh(){if(g_GSMap1.is_rendered()){zoom_tiles_async(GS_wms_tiles.current_zoom);}}
function navigate_to_async(lat1,lon1,zoom){if(!g_map_ready||zooming||loading){return;}
zooming=true;GS_wms_tiles.get_map_tiles(lat1,lon1,zoom,global_xform_params.img2_cols,global_xform_params.img2_lines,undefined);}
function zoom_tiles_callback(zoom){show_zoom(zoom);g_last_zoom=zoom;}
var move_last_x,move_last_y;function smaps_move(e){if(!smaps_moving){return;}
if(!e){e=window.event;}
var layer=s$("div_clip");var page=layer.style;var left=parseInt(page.left,10);var top=parseInt(page.top,10);var x=e.clientX;var y=e.clientY;if(!smaps_moved){last_top=top;last_left=left;}
var dx=x-move_last_x;var dy=y-move_last_y;var fixed_move_dx=global_xform_params.cols;var fixed_move_dy=global_xform_params.lines;if(dx!==0){page.left=(left+dx)+"px";}
if(dy!==0){page.top=(top+dy)+"px";}
move_last_x=x;move_last_y=y;if(dx!==0||dy!==0){smaps_moved=true;}}
function smaps_disable_rbutton(e){try{if(!e){e=window.event;}
if(e.which&&e.which!=1){return false;}
if(e.button&&e.button!=1){if(g_ie){e.cancelBubble=true;}
return false;}}catch(x){return true;}
return true;}
function smaps_move_start(e){if(smaps_add_marker_mode){smaps_click_ponto(e);clearTimeout(_smaps_click_ponto_timeout);smaps_add_marker_mode=false;return true;}
if(loading){return true;}
if(!e){e=window.event;}
if(!smaps_disable_rbutton(e)){return false;}
smaps_dbg("move_start");move_last_x=e.clientX;move_last_y=e.clientY;smaps_moving=true;smaps_moved=false;return true;}
function smaps_move_end(e){if(!smaps_moving||!smaps_moved){smaps_moving=false;return true;}
smaps_moving=false;var layer=s$("div_clip");var page=layer.style;var left=parseInt(page.left,10);var top=parseInt(page.top,10);var fixed_move_dx=global_xform_params.cols;var fixed_move_dy=global_xform_params.lines;smaps_drag(-(left-last_left)/fixed_move_dx,(top-last_top)/fixed_move_dy,e);}
function smaps_mouse2point(e,dx,dy){if(!g_GSMap1){return null;}
var xy=new Mouse2point_xy(e,"gsmap");xy.x+=dx;xy.y+=dy;var xform=new Xform_point_inv((xy.x),(xy.y),global_xform_params);var conv=new conv_xy_mercator_sphere_lat_lon(xform.x,xform.y);return new GPoint(conv.lon,conv.lat);}
var _last_location_index=null;var _smaps_click_ponto_timeout=null;function smaps_estou_aqui(){smaps_add_marker_mode=true;var cur=g_ie?"url("+g_css_server+"/Assets/Maps/Images/pin.cur)":'url('+g_css_server+'/Assets/Maps/Images/pin.cur), auto';if(!smaps_widget){s$("wraper_mapas").style.cursor=cur;}
s$("div_no_clip").style.cursor=cur;_smaps_click_ponto_timeout=setTimeout(cancel_estou_aqui,10000);window.document.onkeyup=function(e){var e=window.event||e;if(e.keyCode==27){cancel_estou_aqui();}}}
function cancel_estou_aqui(){smaps_add_marker_mode=false;if(!smaps_widget){s$("wraper_mapas").style.cursor="default";}
s$("div_no_clip").style.cursor="default";}
function smaps_click_ponto(e){if(!e){e=window.event;}
if(!g_ie&&e.target.id!="div_pontos_child"){return false;}
s$("div_no_clip").style.cursor="pointer";var p=smaps_mouse2point(e,0,0);if(p===null){return false;}
return marca_ponto(p.y,p.x);}
function estou_aqui_task(){if(g_disable_locator_callback){return false;}
g_disable_locator_callback=false;return marca_ponto(global_xform_params.lat,global_xform_params.lon);}
var _smaps_pin_tit_del=true;var _smaps_pin_desc_del=true;function marca_ponto(lat,lon){var point=new GPoint(lon,lat);var txt="",desc="";var editable=true;if(!smaps_locator_marker){txt="T&iacute;tulo:<br/><form onsubmit='return false;'><input type='text' style='width:170px' maxlength='80' id='pin_tit' onclick='smaps_apaga_tit()'/>";if(smaps_locator_marker_link){desc="Descri&ccedil;&atilde;o:<br/><textarea rows='1' id='pin_desc' maxlength='80' style='width:175px' onclick='smaps_apaga_desc()' wrap='physical' onKeyDown='smaps_textCounter(this,null,150)' onKeyUp='smaps_textCounter(this,null,150)'></textarea>";desc=desc+"<br clear='all'/><span id='pin_link'>Link:</span><a id='pin_ok' href='javascript:create_marker_link("+lat+","+lon+")'><img src='"+g_css_server+"/Assets/Maps/Images/caixa_ok.gif'/></a>"+"<br clear='all'/><input type='text' id='div_copy' readonly='readonly'/>"+"<div id='pin_copy'><a href='javascript:copy_marker_clipboard("+lat+","+lon+")'>Copiar link</a></div><div id='pin_fim'><a href='javascript:terminar_pin("+lat+","+lon+")'>Fim</a></div></form>";}else{desc="Descri&ccedil;&atilde;o:<br/><textarea rows='4' id='pin_desc' maxlength='120' style='width:170px' onclick='smaps_apaga_desc()' wrap='physical' onKeyDown='smaps_textCounter(this,null,150)' onKeyUp='smaps_textCounter(this,null,150)'></textarea>";desc=desc+"<br/><a href='javascript:terminar_pin("+lat+","+lon+")'><img id='marcador_ok' align='right' src='"+g_css_server+"/Assets/Maps/Images/bot_ok.gif'/></a></form>";}}else{txt=smaps_locator_marker.title;desc=smaps_locator_marker.description;editable=false;}
_smaps_pin_tit_del=true;_smaps_pin_desc_del=true;if(g_locator_widget&&_last_location_index!==null){apagar_ponto(_last_location_index);}
_last_location_index=g_num_pontos;var marker=gs_createMarker(txt,desc,point,smaps_const.img_marca,smaps_const.img_marca_sel,g_img_marca_w,g_img_marca_h,g_img_marca_dx,g_img_marca_dy);marker.options.selected=true;marker.options.editable=editable;g_GSMap1.gmap.addOverlay(marker);setTimeout(smaps_open_pin,500);smaps_refresh();if(typeof(g_locator_callback)=="function"){g_locator_callback(lat,lon);}
if(!smaps_widget){s$("wraper_mapas").style.cursor="default";}
smaps_set_map_cursor();return false;}
function smaps_textCounter(field,cntfield,maxlimit){if(field.value.length>maxlimit){field.value=field.value.substring(0,maxlimit);}else if(cntfield!==null){cntfield.value=maxlimit-field.value.length;}}
function smaps_open_pin(){smaps_callout(_last_location_index);}
function smaps_apaga_tit(){if(!_smaps_pin_tit_del){return;}
s$('pin_tit').value="";_smaps_pin_tit_del=false;}
function smaps_apaga_desc(){if(!_smaps_pin_desc_del){return;}
s$('pin_desc').value="";_smaps_pin_desc_del=false;}
function create_marker_link(lat,lon){var txt=s$('pin_tit').value;var desc=s$('pin_desc').value;var div=s$("div_copy");div.style.visibility="visible";var z=(17-GS_wms_tiles.current_zoom);if(txt.length===0&&desc.length===0){div.value=g_gs_server+g_smaps_page+"?q="+lat+","+lon+","+z;}else{div.value=g_gs_server+g_smaps_page+"?W="+lat+","+lon+","+z+","+escape(escape(txt))+","+escape(escape(desc));}}
function copy_marker_clipboard(lat,lon){var div=s$("div_copy");create_marker_link(lat,lon);smaps_copy(div);}
function terminar_pin(lat,lon){var point=new GPoint(lon,lat);var txt=s$('pin_tit').value;var desc=s$('pin_desc').value;var marker=gs_createMarker(txt,desc,point,smaps_const.img_marca,smaps_const.img_marca_sel,g_img_marca_w,g_img_marca_h,g_img_marca_dx,g_img_marca_dy);marker.options.selected=true;marker.options.opened=true;g_GSMap1.gmap.addOverlay(marker);apagar_ponto(_last_location_index);_last_location_index=null;}
function center_map(e){g_disable_locator_callback=true;if(!e){e=window.event;}
var p=smaps_mouse2point(e,0,0);if(p===null){return;}
var z=g_GSMap1.get_zoom();if(z>0){z--;}
g_GSMap1.set_lat_lon_zoom(p.y,p.x,z);smaps_stats("mapa","doubleclick","");}
function smaps_register_move(){var div=s$("div_clip");smaps_moving=false;smaps_moved=false;if(g_ie){div.ondragstart=function(){return false;};div.onmousedown=smaps_move_start;div.onmousemove=smaps_move;div.onmouseup=smaps_move_end;div.onmouseout=smaps_move_end;}else{div.onmousedown=smaps_move_start;div.onmousemove=smaps_move;div.onmouseup=smaps_move_end;div.onmouseout=smaps_move_end;oncontextmenu=function(){return false;};}}
function unregister_move(){try{var div=s$("div_clip");if(g_ie){div.onmousemove=null;div.onmousedown=null;div.onmouseup=null;div.onmouseout=null;}else{div.onmousemove=null;div.onmousedown=smaps_disable_rbutton;div.onmouseup=null;div.onmouseout=null;}}catch(e){}}
var skip_tags="input,textarea";function select_if_form(e){if(!e){e=window.event;}
if(skip_tags.indexOf(e.target.tagName.toLowerCase())<0){return false;}}
function smaps_disable_select(){if(g_stages){return;}
if(typeof document.onselectstart!="undefined"){document.onselectstart=function(){return false;};}else if(!g_ie){document.onmousedown=select_if_form;document.onmouseup=function(){return true;};}}
function smaps_enable_select(){if(g_ie&&typeof document.onselectstart!="undefined"){document.onselectstart=function(){return true;};}}
function WMS_tiles_client(){this.ready=false;this.zoom0_resolution=0;this.request_pixels=0;this.pixels=0;this.no_inset_zoom=0;this.old_png_extension=false;this.location=null;this.insets=[];this.num_insets=0;this.current_zoom=-1;this.current_location=null;this.current_tiles_zoom=null;this.add_location=function(loc){this.location=loc;};this.add_inset=function(inset){this.insets[this.num_insets]=inset;this.num_insets++;};this.get_resolution_aprox=function(zoom){return this.zoom0_resolution*(1<<parseInt(zoom,10));};this.get_resolution=function(zoom){return this.get_resolution_aprox(zoom);};this.get_zoom_res=function(resolution){return Math.ceil(Math.log(resolution/this.zoom0_resolution)/Math.LN2);};this.get_map_tiles=_get_map_tiles;this.lon_degrees_2_meters=function(width){return width*this.current_tiles_zoom.degree_lon;};this.lat_degrees_2_meters=function(height){return height*this.current_tiles_zoom.degree_lat;};this.meters_2_degrees_lon=function(width){return width/this.current_tiles_zoom.degree_lon;};this.meters_2_degrees_lat=function(height){return height/this.current_tiles_zoom.degree_lat;};this.intersects_insets=function(x1,y1,x2,y2){for(var i=0;i<this.num_insets;i++){if(this.insets[i].intersects(x1,y1,x2,y2)){return true;}}
return false;};}
function Wms_tiles_location(id0,bounds0,min_zoom0,max_zoom0,degree_lat0,degree_lon0){this.id=id0;this.bounds=bounds0;this.min_zoom=min_zoom0;this.max_zoom=max_zoom0;this.zooms=[];this.degree_lat=degree_lat0;this.degree_lon=degree_lon0;this.center=new GPoint((this.bounds.minX+this.bounds.maxX)/2.0,(this.bounds.minY+this.bounds.maxY)/2.0);smaps_dbg("center");smaps_dbg(this.center.x);smaps_dbg(this.center.y);this.get_existing_zoom=function(zoom){if(zoom<this.max_zoom){return this.max_zoom;}
if(zoom>this.min_zoom){return this.min_zoom;}
return zoom;};this.has_zoom=function(zoom){return(this.max_zoom<=zoom&&zoom<=this.min_zoom);};this.square_distance_to_center=function(x,y){return(this.center.x-x)*(this.center.x-x)+(this.center.y-y)*(this.center.y-y);};this.intersects=function(lat0,lon0,lat1,lon1){if(lon0<this.bounds.minX){lon0=this.bounds.minX;}
if(lon1>this.bounds.maxX){lon1=this.bounds.maxX;}
if(lon0>lon1){return false;}
if(lat0<this.bounds.minY){lat0=this.bounds.minY;}
if(lat1>this.bounds.maxY){lat1=this.bounds.maxY;}
if(lat0>lat1){return false;}
return true;};}
function Wms_tiles_zoom(zoom_level0,tiles_x0,tiles_y0,len_tile_cs_web_x0,len_tile_cs_web_y0,pixels,len_tile_wms0,degree_lat,degree_lon){this.zoom_level=zoom_level0;this.tiles_x=tiles_x0;this.tiles_y=tiles_y0;this.len_tile_cs_web_x=len_tile_cs_web_x0;this.len_tile_cs_web_y=len_tile_cs_web_y0;this.res_tile_cs_web_x=this.len_tile_cs_web_x/pixels;this.res_tile_cs_web_y=this.len_tile_cs_web_y/pixels;this.len_tile_wms=len_tile_wms0;this.degree_lon=degree_lon;this.degree_lat=degree_lat;this.resolution=this.len_tile_wms/pixels;this.intersects=function(tx,ty){return(tx>=0&&ty>=0&&tx<this.tiles_x&&ty<this.tiles_y);};}
function Wms_tiles_inset(x1,y1,x2,y2){this.minX=x1;this.minY=y1;this.maxX=x2;this.maxY=y2;this.intersects=function(x0,y0,x1,y1){if(x0<this.minX){x0=this.minX;}
if(x1>this.maxX){x1=this.maxX;}
if(x0>x1){return false;}
if(y0<this.minY){y0=this.minY;}
if(y1>this.maxY){y1=this.maxY;}
if(y0>y1){return false;}
return true;};}
var _last_tile_W_int;var _last_tile_N_int;var _num_tiles_to_load;var _last_map_params=null;var _img_void=null;function _get_map_tiles(lat,lon,zoom,cols,lines,callback_fn,px,py){smaps_dbg("get_map_tiles0");lat=smaps_parse(lat);lon=smaps_parse(lon);zoom=smaps_parse(zoom);cols=smaps_parse(cols);lines=smaps_parse(lines);lat=smaps_roundLatLon(lat);lon=smaps_roundLatLon(lon);if(!px&&_last_map_params!=null){if(lat==_last_map_params.lat&&lon==_last_map_params.lon&&zoom==_last_map_params.zoom&&cols==_last_map_params.cols&&lines==_last_map_params.lines){loading=true;g_map_ready=true;mapa_replaced();return;}}
_last_map_params={lat:lat,lon:lon,zoom:zoom,cols:cols,lines:lines};smaps_dbg("get_map_tiles");g_map_ready=false;if(zooming){s$("div_pontos_child").style.visibility="hidden";s$("div_des_cam").style.display="none";s$("div_des_cam").style.visibility="hidden";}
var pixels=GS_wms_tiles.pixels;g_draw_index++;try{if(zoom!=GS_wms_tiles.location.min_zoom){s$("div_acores").style.visibility="hidden";s$("div_madeira").style.visibility="hidden";}else{s$("div_acores").style.visibility="visible";s$("div_madeira").style.visibility="visible";}}catch(e){}
var x;var y;var conv=new conv_lat_lon_mercator_sphere(lat,lon);x=conv.x;y=conv.y;smaps_dbg("lat, lon");smaps_dbg(lat);smaps_dbg(lon);if(px||py){x+=px*GS_wms_tiles.current_tiles_zoom.resolution;y+=py*GS_wms_tiles.current_tiles_zoom.resolution;}
smaps_dbg("x, y");smaps_dbg(x);smaps_dbg(y);loading=true;var location1=this.location;if(location1===null){smaps_dbg("As coordenadas est&atilde;o numa &aacute;rea n&atilde;o abrangida");zooming=false;loading=false;return null;}
if(!location1.has_zoom(zoom)){smaps_dbg("O nivel de zoom especificado n&atilde;o est&aacute; coberto");zoom=location1.get_existing_zoom(zoom);}
smaps_wait();var ntiles_group=GS_wms_tiles.request_pixels/pixels;var tiles_zoom=location1.zooms[zoom];GS_wms_tiles.current_zoom=zoom;GS_wms_tiles.current_location=location1;GS_wms_tiles.current_tiles_zoom=tiles_zoom;var res=GS_wms_tiles.get_resolution(zoom);var w2=res*cols/2;var h2=res*lines/2;var x_W=x-w2;var x_E=x+w2;var y_S=y-h2;var y_N=y+h2;var tile_W=(x_W-location1.bounds.minX)/tiles_zoom.len_tile_cs_web_x;var tile_N=(y_N-location1.bounds.minY)/tiles_zoom.len_tile_cs_web_y;var tile_E=(x_E-location1.bounds.minX)/tiles_zoom.len_tile_cs_web_x;var tile_S=(y_S-location1.bounds.minY)/tiles_zoom.len_tile_cs_web_y;var tile_W_int=Math.floor(tile_W);var tile_E_int=Math.floor(tile_E);var tile_N_int=Math.floor(tile_N);var tile_S_int=Math.floor(tile_S);var num_map_tiles_x=tile_E_int-tile_W_int+1;var num_map_tiles_y=tile_N_int-tile_S_int+1;var tile_W_int_x=location1.bounds.minX+tile_W_int*tiles_zoom.len_tile_cs_web_x;var tile_N_int_y=location1.bounds.minY+(tile_N_int+1)*tiles_zoom.len_tile_cs_web_y;var map_tiles=s$("div_grelha"+g_grid_index);var x_offset_old;var y_offset_old;try{x_offset_old=parseInt(map_tiles.style.left,10);y_offset_old=parseInt(map_tiles.style.top,10);}catch(e){g_grid_index=0;}
if(g_grid_index===0){x_offset_old=0;y_offset_old=0;g_last_zoom=-1;}
var pix_offset_tile_W;var pix_offset_tile_N;var lat1;var lon1;var x1;var y1;if(typeof(px)=="undefined"){pix_offset_tile_W=-Math.round((x_W-tile_W_int_x)/tiles_zoom.res_tile_cs_web_x);pix_offset_tile_N=-Math.round((tile_N_int_y-y_N)/tiles_zoom.res_tile_cs_web_y);lat1=lat;lon1=lon;x1=x;y1=y;}else{pix_offset_tile_W=Math.round((x_offset_old-px)+(tile_W_int-_last_tile_W_int)*pixels);pix_offset_tile_N=Math.round((y_offset_old+py)+(_last_tile_N_int-tile_N_int)*pixels);var exact_pix_offset_tile_W=-Math.round((x_W-tile_W_int_x)/tiles_zoom.res_tile_cs_web_x);var exact_pix_offset_tile_N=-Math.round((tile_N_int_y-y_N)/tiles_zoom.res_tile_cs_web_y);y1=y+(pix_offset_tile_N-exact_pix_offset_tile_N)*tiles_zoom.res_tile_cs_web_y;x1=x-(pix_offset_tile_W-exact_pix_offset_tile_W)*tiles_zoom.res_tile_cs_web_x;var conv=new conv_xy_mercator_sphere_lat_lon(x1,y1);lat1=conv.lat;lon1=conv.lon;}
global_xform_params=new Xform_params(lat1,lon1,x1,y1,global_xform_params.cols,global_xform_params.lines,res*global_xform_params.cols,gPan_percent,global_xform_params.nome_servico,global_xform_params.tipo_percurso);_last_tile_W_int=tile_W_int;_last_tile_N_int=tile_N_int;var grelha_top=pix_offset_tile_N+'px';var grelha_left=pix_offset_tile_W+'px';var grelha_w=num_map_tiles_x*pixels;var grelha_h=num_map_tiles_y*pixels;var div_grelha;if(g_last_zoom!=zoom){g_grid_index++;var str='position:relative;top:'+grelha_top+';left:'+grelha_left+';width:'+grelha_w+'px;'+'height:'+grelha_h+'px;';div_grelha=smaps_new_node('div','id','div_grelha'+g_grid_index,'style',str);}else{div_grelha=map_tiles;div_grelha.style.top=grelha_top;div_grelha.style.left=grelha_left;smaps_reset_drag();}
var ty,tx,div,div_name,row,col,src,srcLabels,top_str,left_str;_num_tiles_to_load=(tile_N_int-tile_S_int+1)*(tile_E_int-tile_W_int+1);var current_zIndex=(10+(g_draw_index%2));var last_zIndex=(10+((g_draw_index-1)%2));var tile_x0,tile_y0,tile_x1,tile_y1;var src_void=g_img_server[0]+'/loc_'+location1.id+'/void.png';if(_img_void==null){_img_void=new Image();_img_void.src=src_void;}
if(!g_wms_tiled&&g_wms1_url!==""){try{s$('div_clip').removeChild(s$('wms_map1'));s$('div_clip').removeChild(s$('wms_map2'));}catch(e){}
tile_x0=global_xform_params.x0;tile_y0=global_xform_params.y0;tile_x1=global_xform_params.x1;tile_y1=global_xform_params.y1;src=g_wms1_url+"BBOX="+global_xform_params.x0+","+global_xform_params.y0+","+
global_xform_params.x1+","+global_xform_params.y1+"&width="+global_xform_params.cols+"&height="+global_xform_params.lines;smaps_dbg(src);str='position:absolute;top:0'+';left:0'+';width:'+cols+'px'+';height:'+lines+'px'+';z-index:'+current_zIndex;img1=smaps_new_node('img',"galleryimg","no","oncontextmenu","return false",'src',src,"align","top","border",0,"width",global_xform_params.cols,"height",global_xform_params.lines,"onmousedown",'return  smaps_disable_rbutton()',"onmouseup",'return  smaps_disable_rbutton()',"ondblclick","center_map()");div1=smaps_new_node('div','id',"wms_map1",'style',str,img1);s$('div_clip').appendChild(div1);if(g_wms2_url!==""){src2=g_wms2_url+"BBOX="+global_xform_params.x0+","+global_xform_params.y0+","+
global_xform_params.x1+","+global_xform_params.y1+"&width="+global_xform_params.cols+"&height="+global_xform_params.lines;smaps_dbg(src2);img2=smaps_new_node('img',"galleryimg","no","oncontextmenu","return false",'src',src2,"align","top","border",0,"width",global_xform_params.cols,"height",global_xform_params.lines,"onmousedown",'return  smaps_disable_rbutton()',"onmouseup",'return  smaps_disable_rbutton()',"ondblclick","center_map()");div2=smaps_new_node('div','id',"wms_map2",'style',str,img2);s$('div_clip').appendChild(div2);}}
else{smaps_tiles_bounds=[];var tiles_bounds_i=0;for(ty=tile_S_int;ty<=tile_N_int;ty++){for(tx=tile_W_int;tx<=tile_E_int;tx++){tile_x0=location1.bounds.minX+(tx)*tiles_zoom.len_tile_cs_web_x;tile_y0=location1.bounds.minY+(ty)*tiles_zoom.len_tile_cs_web_y;tile_x1=location1.bounds.minX+(tx+1)*tiles_zoom.len_tile_cs_web_x;tile_y1=location1.bounds.minY+(ty+1)*tiles_zoom.len_tile_cs_web_y;var has_tile=(tx>=0&&ty>=0&&tx<tiles_zoom.tiles_x&&ty<tiles_zoom.tiles_y&&location1.intersects(tile_y0,tile_x0,tile_y1,tile_x1));if(has_tile&&zoom<GS_wms_tiles.no_inset_zoom){has_tile=GS_wms_tiles.intersects_insets(tile_x0,tile_y0,tile_x1,tile_y1);}
var src;if(has_tile)
{x=tx%ntiles_group;col=(tx-x)/ntiles_group;y=ty%ntiles_group;row=(ty-y)/ntiles_group;var server_idx=((x+y)%g_img_server.length);var server_idx_layers=((x+y)%g_layers_server.length);setTimeout("smaps_layers( "+server_idx_layers+", "+tile_x0+", "+tile_y0+", "+tile_x1+", "+tile_y1+","+g_draw_index+","+tiles_bounds_i+")",500);tiles_bounds_i++;if(!g_wms_tiled){src=g_img_server[server_idx]+'/loc_'+location1.id+'/zoom_'+zoom+'/row_'+row+'/map_col_'+col+'_'+y+'_'+x+'.png';}else{src=g_wms1_url+"BBOX="+tile_x0+","+tile_y0+","+tile_x1+","+tile_y1+"&width="+pixels+"&height="+pixels;}
if(g_smaps_label_layer){if(!g_wms_tiled){srcLabels=g_img_server[server_idx]+'/loc_'+location1.id+'_L/zoom_'+zoom+'/row_'+row+'/map_col_'+col+'_'+y+'_'+x+'.png';}else{srcLabels=g_wms2_url+"BBOX="+tile_x0+","+tile_y0+","+tile_x1+","+tile_y1+"&width="+pixels+"&height="+pixels;}}
smaps_dbg(src);div_name="z"+zoom+'r'+row+'c'+col+'y'+y+'x'+x;div=s$(div_name);}else{src=src_void;div=null;div_name="void";}
top_str=""+(parseInt((tile_N_int-ty)*pixels,10)+'px');left_str=""+(parseInt((tx-tile_W_int)*pixels,10)+'px');if(div===null){str='position:absolute;top:'+top_str+';left:'+left_str+';width:'+pixels+'px'+';height:'+pixels+'px'+';z-index:'+current_zIndex;div=smaps_new_node('div','id',div_name,'style',str,smaps_new_node('img',"galleryimg","no","oncontextmenu","return false",'src',src,"align","top","border",0,"width",pixels,"height",pixels,"onmousedown",'return  smaps_disable_rbutton()',"onmouseup",'return  smaps_disable_rbutton()',"ondblclick","center_map()"));div_grelha.appendChild(div);if(div_name!="void"&&g_smaps_label_layer){var style=(!g_ie6)?"":"filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+srcLabels+"', sizingMethod='scale')";var divLabels=smaps_new_node('div','id',div_name+"L",'style',str,smaps_new_node('img','src',(!g_ie6)?srcLabels:g_css_server+"/Assets/Maps/Images/pngtransp.gif","align","top","border",0,"width",pixels,"height",pixels,"style",style,"galleryimg","no","oncontextmenu","return false","onmousedown",'return  smaps_disable_rbutton()',"onmouseup",'return  smaps_disable_rbutton()',"ondblclick","center_map()"));div_grelha.appendChild(divLabels);}}else{div.style.top=top_str;div.style.left=left_str;div.style.zIndex=current_zIndex;div.style.visibility="visible";if(g_smaps_label_layer){div2=s$(div_name+"L");div2.style.top=top_str;div2.style.left=left_str;div2.style.zIndex=current_zIndex;div2.style.visibility="visible";}}}}}
setTimeout(mapa_replaced,100);smaps_update_minimap();g_disable_locator_callback=false;if(g_last_zoom!=zoom){map_tiles.style.visibility="hidden";s$('div_no_clip').replaceChild(div_grelha,map_tiles);smaps_reset_drag();}else{var children=div_grelha.childNodes;for(var i=0;i<children.length;i++){if(children[i].style.zIndex!=current_zIndex&&children[i].style.zIndex!==""){children[i].style.visibility="hidden";}}}
g_map_ready=true;if(callback_fn){callback_fn();}
if(g_GSMap1.gmap._extents_callback){if(g_timer_extents_callback){clearTimeout(g_timer_extents_callback);}
g_timer_extents_callback=setTimeout(extents_callback_event,g_GSMap1.gmap._extents_callback_delay);}
if(g_qparams.tipo_query>0){if(g_qparams.iten_zoomed!==""){s$('a_itenzoom').style.visibility="visible";}}
if(_g_clickCallback){var mapdiv=s$("gsmap");if(mapdiv.addEventListener){mapdiv.addEventListener('DOMMouseUp',_g_clickCallback,false);}
mapdiv.onmouseup=_g_clickCallback;_g_clickCallback=false;}
if(!smaps_widget){smaps_layers_interface_update();}}
function smaps_add_layer_markers(Markers){var max_desc_len=150;g_layers_call_count++;if(Markers.rss!==undefined){for(var i=0;i<Markers.rss.channel.item.length;i++){var mk=Markers.rss.channel.item[i];var lat=mk['geo:lat'];var lon=mk['geo:lon'];if(!lat||!lon){continue;}
var base=mk['gis:base'];var full_desc=mk.description;var re=new RegExp("<[^>]*>","g");full_desc=full_desc.replace(re," ");full_desc=lTrim(full_desc);if(full_desc.length<max_desc_len){var freg=mk['gis:parish'];var conc=mk['gis:municipality'];var email=mk['gis:email'];var phone=mk['gis:phone'];var category=mk['category'];if(category.indexOf(mk.title)<0){full_desc="("+category+") <br/>"+full_desc;}
if(full_desc.indexOf(freg)<0){full_desc=full_desc+" <br/>"+freg;}
if(full_desc.indexOf(conc)<0){full_desc=full_desc+" <br/>"+conc;}
if(email&&email.length>0){full_desc=full_desc+" <br/>email: "+email;}
if(phone&&phone.length>0){full_desc=full_desc+" <br/>T: "+phone;}}else{var idx=full_desc.indexOf(" ",max_desc_len);if(idx<0)idx=max_desc_len;full_desc=full_desc.substring(0,idx)+"...";}
if(mk.link&&mk.link.length>0){var url_simple=mk.link.replace(new RegExp("/http.[:]\/\/","g"),"");if(mk.link.indexOf("://")<=0)mk.link="http://"+mk.link;if(!full_desc||full_desc.length===0){full_desc="»";}
full_desc=full_desc+"<br/><div style='float:left'><a  title='Site' href='"+mk.link+"' target='_blank'>Site</a></div>";}
var marker_opts={title:mk.title,selected:false,opened:false,guid:mk['guid'],layers_call_count:g_layers_call_count,permanent:true};var icon={iconSize:{width:16,height:16},infoWindowAnchor:{x:0,y:0},iconAnchor:{x:8,y:0}};icon.image=mk['gis:icon'];if(base=='f'&&mk['gis:layer']){marker_opts.category=mk['gis:layer'].toLowerCase();if(icon.image.length==0){icon.image="icon_"+marker_opts.category+".gif";}}
if(icon.image.length===0){icon.image=g_gs_server+"images/icone_sapo.png";if(base=='t'){icon.image=g_gs_server+"images/message.png";}}else icon.image=g_gs_server+"images/layers/"+icon.image;if(typeof(Markers.icon)!="undefined"){icon=SAPO.extendObj(icon,Markers.icon);}
marker_opts.icon=marker_opts.icon_selected=icon;if(mk['gis:minResolution'].length>0){marker_opts.minResolution=parseFloat(mk['gis:minResolution']);}else{marker_opts.minResolution=2.0;}
marker_opts.matchlevel=parseInt(mk['gis:matchlevel']);if(marker_opts.matchlevel<6){continue;}
g_GSMap1.addMarker(lat,lon,marker_opts,full_desc);}}
timer_smaps_map_pontos();}
function extents_callback_event(){var bounds=g_GSMap1.gmap.getBoundsLatLng(0.9);g_GSMap1.gmap._extents_callback(bounds.minX,bounds.minY,bounds.maxX,bounds.maxY);}
function init_tiles_layout(){var params=g_tiles_layout.params;var location1=params.location;var id=location1.id;var request_pixels=location1.request_pixels;var pixels=location1.pixels;var max_zoom=location1.max_zoom;GS_wms_tiles.zoom0_resolution=location1.zoom0_resolution;GS_wms_tiles.request_pixels=request_pixels;GS_wms_tiles.pixels=pixels;var dbl=params.double_image_size;GS_wms_tiles.no_inset_zoom=location1.no_inset_zoom;var num_insets=location1.num_insets;var x1,y1,x2,y2;for(var i=0;i<num_insets;i++){var g_inset=location1.insets[i];x1=g_inset.x1w;y1=g_inset.y1w;x2=g_inset.x2w;y2=g_inset.y2w;GS_wms_tiles.add_inset(new Wms_tiles_inset(x1,y1,x2,y2));}
var xtiles=g_tiles_layout.tiles;var lon_unit_meters=xtiles.unit_meters;var lat_unit_meters=xtiles.unit_meters;if(lon_unit_meters===0){lon_unit_meters=degree_lon;}
if(lat_unit_meters===0){lat_unit_meters=degree_lat;}
x1=xtiles.x1;y1=xtiles.y1;x2=xtiles.x2;y2=xtiles.y2;var num_zooms=g_max_zoom-g_min_zoom+1;var min_zoom=g_max_zoom;var wms_tiles_loc=new Wms_tiles_location(id,new GBounds(x1,y1,x2,y2),min_zoom,max_zoom,lat_unit_meters,lon_unit_meters);for(var z=0;z<num_zooms;z++){var zoom=xtiles.zooms[z];var zoom_level=zoom.level;var tiles_x=zoom.tiles_x;var tiles_y=zoom.tiles_y;var len_tile_cs_web_x=zoom.length_tile;var len_tile_cs_web_y=zoom.length_tile;var len_tile_wms=zoom.length_tile;wms_tiles_loc.zooms[zoom_level]=new Wms_tiles_zoom(zoom_level,tiles_x,tiles_y,len_tile_cs_web_x,len_tile_cs_web_y,pixels,len_tile_wms,lat_unit_meters,lon_unit_meters);}
GS_wms_tiles.add_location(wms_tiles_loc);GS_wms_tiles.ready=true;}
function lon_degrees_2_meters(width){if(typeof(GS_wms_tiles)!="undefined"&&GS_wms_tiles.ready&&GS_wms_tiles.current_location!==null&&GS_wms_tiles.current_tiles_zoom!==null){return GS_wms_tiles.lon_degrees_2_meters(width);}
return lon_degrees_2_meters_aprox(width);}
function lat_degrees_2_meters(height){if(typeof(GS_wms_tiles)!="undefined"&&GS_wms_tiles.ready&&GS_wms_tiles.current_location!==null&&GS_wms_tiles.current_tiles_zoom!==null){return GS_wms_tiles.lat_degrees_2_meters(height);}
return lat_degrees_2_meters_aprox(height);}
function meters_2_degrees_lon(width){if(typeof(GS_wms_tiles)!="undefined"&&GS_wms_tiles.ready&&GS_wms_tiles.current_location!==null&&GS_wms_tiles.current_tiles_zoom!==null){return GS_wms_tiles.meters_2_degrees_lon(width);}
return meters_2_degrees_lon_aprox(width);}
function meters_2_degrees_lat(height){if(typeof(GS_wms_tiles)!="undefined"&&GS_wms_tiles.ready&&GS_wms_tiles.current_location!==null&&GS_wms_tiles.current_tiles_zoom!==null){return GS_wms_tiles.meters_2_degrees_lat(height);}
return meters_2_degrees_lat_aprox(height);}
function not_implemented(name){try{window.defaultStatus="Uma das funções chamadas não estão implementadas neste API:"+name;}catch(e){}}
function smaps_toogle_debug()
{var div=s$("div_debug");if(div!==null){if(div.style.visibility=="hidden"){div.style.visibility="visible";}else{div.style.visibility="hidden";}}}
function gs_createMarker(tit,text,point,icon_style,selected_icon_style,sizex,sizey,anchorx,anchory,selected_icon_title){var icon=new GIcon();icon.image=icon_style?icon_style:smaps_const.img_marca;icon.iconSize=icon_style?new GSize(sizex,sizey):new GSize(g_img_marca_w,g_img_marca_h);icon.infoWindowAnchor=new GPoint(smaps_const.window_offset_x,smaps_const.window_offset_y);icon.iconAnchor=icon_style?new GPoint(anchorx,anchory):new GPoint(g_img_marca_dx,g_img_marca_dy);var opts=new GMarkerOptions();opts.icon=icon;var marker=new GMarker(point,opts);GEvent.addListener(marker,"click",function(marker){marker.openInfoWindowHtml(text);marker.options.opened=false;});marker.options.title=tit;marker.options.icon_selected=new GIcon();marker.options.icon_selected.title=marker.options.icon_selected.image=selected_icon_style?selected_icon_style:smaps_const.img_marca_sel;return marker;}
function register_zoom_drag(div){if(g_ie){div.ondragstart=function(){return false;};div.onclick=zoom_drag_up;div.onmousedown=zoom_drag_down;div.onmousemove=zoom_drag_move;div.onmouseup=zoom_drag_up;}else{div.onmousedown=zoom_drag_down;div.onmousemove=zoom_drag_move;div.onmouseup=zoom_drag_up;}
div.onmouseout=zoom_drag_up;}
var _zoom_dragging=false;function zoom_drag_down(e){if(!e){e=window.event;}
if(!e){return false;}
if(!g_ie&&e.preventDefault){e.preventDefault();}
_zoom_dragging=true;return true;}
function zoom_drag_move(e,interval){if(!g_ie){s$("zoom_drag_img").onmouseup=zoom_drag_up;}
if(!e){e=window.event;}
if(!e){return false;}
var zoom=smaps_get_zoom(e);set_zoom_title(e,zoom);if(_zoom_dragging){show_zoom(zoom);}
return true;}
function zoom_drag_up(e){if(!e){e=window.event;}
if(!e){return false;}
if(!_zoom_dragging){return true;}
var zoom=smaps_get_zoom(e);s$("zoom_drag_img").onmouseup=null;_zoom_dragging=false;zoom_tiles_async(zoom);smaps_stats("mapa","zoom_drag","");return true;}
function smaps_get_zoom(e){var xy=new Mouse2point_xy(e,"zoom_drag_img");var zoom=parseInt(((xy.y)/g_zoom_drag_height*(g_max_zoom+2))-1,10);zoom++;if(zoom<g_min_zoom){zoom=g_min_zoom;}
if(zoom>g_max_zoom){zoom=g_max_zoom;}
return zoom;}
var _last_zoom_title=-1;function set_zoom_title(e,zoom){if(typeof(zoom)=="undefined"){zoom=smaps_get_zoom(e);}
if(zoom!=_last_zoom_title&&_last_zoom_title>=0){hide_zoom_title(_last_zoom_title);}
_last_zoom_title=zoom;s$("div_t"+zoom).style.visibility='visible';}
function hide_last_zoom_title(e){_zoom_dragging=false;hide_zoom_title(_last_zoom_title);return true;}
function hide_zoom_title(zoom){if(typeof(zoom)!="undefined"){try{s$("div_t"+zoom).style.visibility='hidden';}catch(e){}}}
var xMinBound=-1;var yMinBound=-1;var xMaxBound=1;var yMaxBound=1;var g_matches_text="";var pontos_pesquisa=[];var smaps_filter="allnotmedia";var g_query;var g_qparams={query:"",tipo_query:-1,div_results:'results',div_matches:'matches',div_pages:'results-paginacao',div_pg_ant:'pg_ant',div_pg:'pg',div_pg_seg:'pg_seg',partida:null,chegada:null,modo:"rapido",cancel:false,iten_zoomed:"",print_version:false,get_param:function(to_print){var txt1,txt2;if(typeof(to_print)=="undefined"){txt1=escape(escape(SAPO.Utility.String.utf8Encode(this.partida.options.title)));txt2=escape(escape(SAPO.Utility.String.utf8Encode(this.chegada.options.title)));}
else if(to_print){txt1=escape(escape(SAPO.Utility.String.utf8Encode(this.partida.options.title)));txt2=escape(escape(SAPO.Utility.String.utf8Encode(this.chegada.options.title)));}else{txt1=escape(escape(escape(SAPO.Utility.String.utf8Encode(this.partida.options.title))));txt2=escape(escape(escape(SAPO.Utility.String.utf8Encode(this.chegada.options.title))));}
return"P="+this.modo+";"+
this.partida.point.y+","+
this.partida.point.x+","+
txt1+";"+
this.chegada.point.y+","+
this.chegada.point.x+","+
txt2+(to_print?";p":"");},get_url:function(to_print){return g_smaps_page+"?"+this.get_param(to_print);}};var g_results_per_win=10;var g_num_wins=1;var g_locator_callback;var g_area_visivel=false;var _g_pesq_timeout;var g_matches_index=1;var smaps_print_version=false;var g_iten_view=null;function Smaps_View(lat,lon,zoom){this.lat=lat;this.lon=lon;this.zoom=zoom;}
function smaps_pesquisa(text){try{s$("iten_matches").innerHTML="";s$("iten_results").style.display="none";}catch(e){}
g_qparams.tipo_query=0;var area_vis=false;try{area_vis=s$("SearchForm").area[1].checked;}catch(e){}
g_qparams.div_results='results';g_qparams.div_matches='matches';g_qparams.div_pages='results-paginacao';g_qparams.div_pg_ant='pg_ant';g_qparams.div_pg='pg';g_qparams.div_pg_seg='pg_seg';smaps_pesq_form(text,area_vis,g_qparams.tipo_query,smaps_filter);}
function smaps_pesquisa_geral(query){if(typeof(query)!="undefined"){s$('caixap').value=query;}else{query=s$('caixap').value;}
if(!g_map_ready){setTimeout(smaps_submitMapOrServForm,1000);}else{smaps_submitMapOrServForm();}}
function smaps_submitMapOrServForm(){if(!g_map_ready){setTimeout(smaps_submitMapOrServForm,1000);}else{smaps_pesquisa(s$("caixap").value);}}
function smaps_pesq_partida(){s$("matches").innerHTML="";s$("results").style.display="none";s$("percurso").style.display="none";percurso_note("iten_erro");g_qparams.tipo_query=1;g_qparams.div_results='iten_results';g_qparams.div_matches='iten_matches';g_qparams.div_pages='results-paginacao-itin';g_qparams.div_pg_ant='iten_pg_ant';g_qparams.div_pg='iten_pg';g_qparams.div_pg_seg='iten_pg_seg';g_qparams.iten_zoomed="";var em=smaps_trim(s$("caixa_partida").value);var em2=smaps_trim(s$("caixa_chegada").value);if(em.length<2){g_query=em;smaps_pesq_vazia("Por favor indique a partida");return;}
if(em2.length<2){g_query=em2;smaps_pesq_vazia("Por favor indique a chegada");return;}
smaps_pesq_form(em,false,g_qparams.tipo_query,"allnotmedia");}
function smaps_pesq_chegada(){g_qparams.tipo_query=2;g_qparams.div_results='iten_results';g_qparams.div_matches='iten_matches';g_qparams.div_pages='results-paginacao-itin';g_qparams.div_pg_ant='iten_pg_ant';g_qparams.div_pg='iten_pg';g_qparams.div_pg_seg='iten_pg_seg';var em=smaps_trim(s$("caixa_chegada").value);smaps_pesq_form(em,false,g_qparams.tipo_query,"allnotmedia");}
function smaps_pesq_form(query,area_vis,tipo_caixa,filter){g_matches_text="";g_query=query;if(g_query.length===0){return;}
if(g_query.length<2){smaps_pesq_vazia("Por favor introduza mais texto");return;}
if(tipo_caixa===0){if(g_query.toLowerCase().match(/^a\u00E7ores/)||g_query.toLowerCase().match(/^azores/)){smaps_acores();smaps_hide_results(false);return;}
if(g_query.toLowerCase().match(/^madeira/)){smaps_madeira();smaps_hide_results(false);return;}}else{s$('percurso').innerHTML="";percurso_note("iten_erro");s$("iten_modo").style.display="none";percurso_note("iten_sum");s$("iten_texto_pesq").innerHTML=(tipo_caixa==1)?"partida":"chegada";s$("pesqIten_opcoes").style.display="none";}
s$(g_qparams.div_pg_ant).style.visibility="hidden";s$(g_qparams.div_pg+'1').style.visibility="hidden";s$(g_qparams.div_pg+'2').style.visibility="hidden";s$(g_qparams.div_pg+'3').style.visibility="hidden";s$(g_qparams.div_pg+'4').style.visibility="hidden";s$(g_qparams.div_pg_seg).style.visibility="hidden";var re=new RegExp("'","g");g_query=g_query.replace(re,"´");try{if(!g_locator_widget)
s$(g_qparams.div_pages).style.display="none";}catch(e){}
if(tipo_caixa===0&&(g_query.indexOf("http://")>=0)){smaps_parseQuery("S="+query);return;}
else if(tipo_caixa===0&&smaps_parseQuery("q="+g_query)){s$(g_qparams.div_matches).innerHTML="";smaps_setCursor(1);smaps_stats("mapas","pesquisa_latlon",g_query);smaps_hide_results(false);return;}else{smaps_setCursor(2);s$(g_qparams.div_matches).innerHTML="<center><img src='"+g_css_server+"/Assets/Maps/Images/bigwheel_1.gif'></center>";g_area_visivel=g_locator_widget?false:(area_vis);if(g_area_visivel){get_bounds();}
var callback;callback="smaps_pesq_callback";g_smaps_serial=get_sec1970();var srvlt_url=g_querydb_server+"/queryGIS/servlet/queryGIS?max="+(g_results_per_win*g_num_wins)+"&cb="+callback+"&q="+escape(g_query)+"&f="+filter+
(!g_area_visivel?"":("&xMin="+xMinBound+"&yMin="+yMinBound+"&xMax="+xMaxBound+"&yMax="+yMaxBound))+"&i="+g_smaps_serial;smaps_dbg(srvlt_url);smaps_js_request(srvlt_url,"script1");if(tipo_caixa===0){smaps_stats("mapas","pesquisa_"+((filter.indexOf("allpois")>0)?"servicos":"geral"),g_query);}}}
function smaps_pesq_callback(result){g_matches_text=result;showMatches(1);}
function smaps_parseRSSQuery(query){if(!g_GSMap1||!g_GSMap1.is_rendered()){setTimeout("smaps_parseRSSQuery(\""+query+"\")",500);return;}
if(query&&query.indexOf("S=")===0){return smaps_getRSS_Markers(query.substring(2,query.length),"smaps_add_markers");}else{return false;}}
function smaps_getRSS_Markers(rss,callback_name){return smaps_getRSS_Markers_xsl(rss,callback_name,null,300);}
function smaps_getRSS_Markers_xsl(rss,callback_name,xsl,expires_sec,server_idx){smaps_dbg_link(rss);var jrss_url;if(!xsl||xsl===null){jrss_url="http://services.sapo.pt/Transformer/RSSOrAtomToJSON?url="+SAPO.Utility.String.utf8Encode(rss)+"&jsonCallback="+callback_name;}
else{xsl_server=(typeof(server_idx)!="undefined")?g_layers_server[server_idx]:g_xsl_server;jrss_url=xsl_server+"/xsl_servlet/servlet/xsl_servlet?expires="+expires_sec+"&cb="+callback_name+"&xml="+
encodeURIComponent(rss)+"&xsl="+encodeURIComponent(xsl);}
smaps_dbg_link(jrss_url);smaps_js_request(jrss_url,"script_jrss");try{}catch(e){}
return true;}
function smaps_addRSS_Markers_xsl_byRadius(key,rss,callback_name,xsl,expires_sec,zoom_required){smaps_rss_layers[key]={rss:rss,callback_name:callback_name,xsl:xsl,expires_sec:expires_sec,zoom_required:zoom_required};}
function smaps_getRSS_Markers_xsl_byRadius(tile_bounds_obj,rss,callback_name,xsl,expires_sec){var bounds=tile_bounds_obj.tile_bounds.boundsLL;var server_idx=tile_bounds_obj.server_idx;var boundsXY=tile_bounds_obj.tile_bounds.boundsXY;lon=(bounds.maxX+bounds.minX)*0.5;lat=(bounds.maxY+bounds.minY)*0.5;lat=smaps_roundLatLon(lat);lon=smaps_roundLatLon(lon);var dx=(boundsXY.maxX-boundsXY.minX);var dy=(boundsXY.maxY-boundsXY.minY);radius=0.5*Math.sqrt((dx*dx)+(dy*dy));dx=0.5*dx;dy=0.5*dy;var re=new RegExp("\\?","g");rss=rss.replace(re,"?latitude="+lat+"&longitude="+lon+"&radius="+radius+"&");smaps_getRSS_Markers_xsl(rss,callback_name,xsl,expires_sec,server_idx);}
var smaps_tiles_bounds=[];function smaps_layers(server_idx,x0,y0,x1,y1,draw_index,tiles_bounds_index){smaps_dbg("smaps_layers");if((g_draw_index-draw_index)>0)
return;var xform0=new conv_xy_mercator_sphere_lat_lon(x0,y0);var xform1=new conv_xy_mercator_sphere_lat_lon(x1,y1);var bounds=new GBounds(xform0.lon,xform0.lat,xform1.lon,xform1.lat);var boundsXY=new GBounds(x0,y0,x1,y1);var tile_bounds={boundsLL:bounds,boundsXY:boundsXY};smaps_tiles_bounds[tiles_bounds_index]={"tile_bounds":tile_bounds,"server_idx":server_idx};smaps_layers_part2(smaps_tiles_bounds[tiles_bounds_index]);}
function smaps_layers_part2(tile_bounds_obj){var minRes=GS_wms_tiles.get_resolution(GS_wms_tiles.current_zoom);if(GS_wms_tiles.current_zoom<=smaps_zoom_level_layers_base){if(smaps_default_layers_active){smaps_layers_call("",g_smaps_limit_pois,tile_bounds_obj,minRes);}
if(g_pharm_at_service_on){smaps_pharm_at_service(tile_bounds_obj);}}
if(GS_wms_tiles.current_zoom<=smaps_zoom_level_layers){var layers=smaps_get_normalized_layers();smaps_dbg("layers="+layers);if(layers.length>0){var layers_a=layers.split("-");smaps_dbg("#layers="+layers_a.length);for(var i=0;i<layers_a.length;i++){if(layers_a[i]!==""){smaps_layers_call(layers_a[i],g_smaps_limit_pois,tile_bounds_obj,minRes);if(typeof(add_option)=="function"){add_option("option_"+layers_a[i]);}}}}}
for(key in smaps_rss_layers){if(!smaps_rss_layers[key])break;var obj=smaps_rss_layers[key];if(GS_wms_tiles.current_zoom<=(17-obj.zoom_required)){smaps_getRSS_Markers_xsl_byRadius(tile_bounds_obj,obj.rss,obj.callback_name,obj.xsl,obj.expires_sec);}}}
function smaps_get_normalized_layers(){var layers=g_smaps_active_layers;var re=new RegExp("--","g");layers=layers.replace(re,"-");if(smaps_traffic_active)
layers=layers+"-transito-";if(smaps_pharmacies_active)
layers=layers+"-farmacias-"
return layers;}
function smaps_layers_call(layer,limit_pois,tile_bounds_obj,minRes){var bounds=tile_bounds_obj.tile_bounds.boundsLL;var server_idx=tile_bounds_obj.server_idx;if(layer.match("/^farmacias/")){return;}
var markers_url=g_layers_server[server_idx]+"/AjaxLayers/servlet/AjaxLayers?layers="+layer+"&x0="+bounds.minX+"&y0="+bounds.minY+"&x1="+bounds.maxX+"&y1="+bounds.maxY+"&limit="+limit_pois+"&minRes="+minRes+"&cb=smaps_add_layer_markers";smaps_dbg_link(markers_url);smaps_js_request(markers_url,"script_layers");}
function smaps_refresh_layers(){smaps_dbg("smaps_refresh_layers");for(var i=0;i<smaps_tiles_bounds.length;i++){smaps_layers_part2(smaps_tiles_bounds[i]);}}
var _smaps_refresh_layers_timeout=false;function smaps_refresh_layers_timer(){smaps_dbg("smaps_refresh_layers_timer");smaps_refresh_layers_timer_del();_smaps_refresh_layers_timeout=setTimeout(smaps_refresh_layers,500);}
function smaps_refresh_layers_timer_del(){if(_smaps_refresh_layers_timeout)
clearTimeout(_smaps_refresh_layers_timeout);_smaps_refresh_layers_timeout=false;}
function smaps_layers_add(layer){if(g_smaps_active_layers.indexOf(layer)>=0)
return;g_smaps_active_layers=g_smaps_active_layers+"-"+layer+"-";smaps_refresh_layers_timer();}
function smaps_layers_remove(layer){var re=new RegExp(layer,"g");g_smaps_active_layers=g_smaps_active_layers.replace(re,"");g_smaps_active_layers=smaps_get_normalized_layers();smaps_dim_markers_category(layer);}
function smaps_parseQuery(query,mark){if(smaps_parseRSSQuery(query)){return true;}
var put_marker=(mark!==0);var coords_query=(query.indexOf("q=")===0);var text_query=(query.indexOf("t=")===0);var widget_query=(query.indexOf("W=")===0);var cities_query=widget_query||(query.indexOf("L=")===0);var points_query=(query.indexOf("M=")===0);if(put_marker&&query.indexOf("P=")===0){g_qparams.query=query;smaps_iten_query();return true;}
if(!coords_query&&!cities_query&&!points_query&&!text_query){return false;}
query=query.substring(2,query.length);if(text_query&&smaps_trim(query).length>0){smaps_pesquisa_geral(query);return true;}
var coords=query.split(";");var valid_query=false;for(i=0;i<coords.length;i++){query=coords[i];var args=query.split(",");var point=null;var comma_pos=query.indexOf(',');if(args.length<2){continue;}else{var lat=args[0];var lon=args[1];if(args.length>2){var zoom=17-7;var txt="";var desc="";var opened=false;if(cities_query){if(widget_query){zoom=args[2];}else{var criterio=args[2];if(!isNaN(criterio)){if(cities_query){zoom=17-(9-criterio);}else{zoom=criterio;}}}
if(args.length>3){txt=unescape(args[3]);}
if(args.length>4){desc=unescape(args[4]);}}else{if(args.length>2&&points_query){if(i==0){g_smaps_active_layers=unescape(args[3]);if(g_smaps_active_layers.length<2||g_smaps_active_layers==="undefined"){g_smaps_active_layers="";}
if(g_smaps_active_layers.indexOf("-farmacias-")>=0){add_option("option_farmacias");}
if(g_smaps_active_layers.indexOf("-transito-")>=0){add_option("option_transito");}}else{txt=unescape(unescape(args[2]));}}else{txt="lat: "+lat+"<br/>lon: "+lon;}
if(args.length>3&&points_query){opened=parseInt(args[3])>0;}
if(!points_query||(points_query&&i===0)){zoom=args[2];}}
if(!isNaN(lat)&&!isNaN(lon)&&!isNaN(zoom)){point=new GPoint(lon,lat);valid_query=true;if(put_marker&&(!points_query||i>0)){var mk=gs_createMarker(txt,desc,point,smaps_const.img_marca,smaps_const.img_marca_sel,g_img_marca_w,g_img_marca_h,g_img_marca_dx,g_img_marca_dy);mk.options.opened=opened;mk.options.selected=true;g_GSMap1.gmap.addOverlay(mk);}
if(i===0){g_GSMap1.gmap.centerAndZoom(point,zoom);}}
else{continue;}}
else{if(!isNaN(lat)&&!isNaN(lon)){valid_query=true;point=new GPoint(lon,lat);if(i===0){g_GSMap1.gmap.centerAndZoom(point,17-6);}
if(put_marker&&(!points_query||i>0)){mk=gs_createMarker("Coordenadas","lat: "+lat+"<br/>lon: "+lon,point,smaps_const.img_marca,smaps_const.img_marca_sel,g_img_marca_w,g_img_marca_h,g_img_marca_dx,g_img_marca_dy);mk.options.opened=true;mk.options.selected=true;g_GSMap1.gmap.addOverlay(mk);}}
else{continue;}}}}
return valid_query;}
function get_bounds(){var bounds=g_GSMap1.gmap.getBoundsLatLng(0.99);var width=bounds.maxX-bounds.minX;var height=bounds.maxY-bounds.minY;xMinBound=bounds.minX;yMinBound=bounds.minY;xMaxBound=bounds.maxX;yMaxBound=bounds.maxY;}
function smaps_focus(index,zoom){if(!g_map_ready){return;}
var i=0;if((index%g_results_per_win)===0){i=g_results_per_win;}else{i=index%g_results_per_win;}
var x=pontos_pesquisa[i-1].marker.point.x;var y=pontos_pesquisa[i-1].marker.point.y;point=new GPoint(x,y);if(zoom>=0){g_GSMap1.gmap.centerAndZoom(point,zoom);}
var rotate_banner=g_locator_widget||(g_qparams.tipo_query==0);if(rotate_banner){smaps_hide_results(!rotate_banner);}
if(g_qparams.tipo_query==1){try{g_qparams.partida.options.selected=false;}catch(e){}}
if(g_qparams.tipo_query==2){try{g_qparams.chegada.options.selected=false;}catch(e){}}
var marker=pontos_pesquisa[i-1].marker;marker.options.opened=(g_qparams.tipo_query===0);marker.options.selected=true;marker.options.visible=true;var desc,icon;if(g_qparams.tipo_query==1){icon=new GIcon();icon.image=g_css_server+"/Assets/Maps/Images/bandeira_verde.gif";icon.iconSize=new GSize(23,28);icon.infoWindowAnchor=new GPoint(smaps_const.window_offset_x,smaps_const.window_offset_y);icon.iconAnchor=new GPoint(12,30);pontos_pesquisa[i-1].marker.options.icon_selected=icon;g_qparams.partida=pontos_pesquisa[i-1].marker;g_qparams.partida_ascii=pontos_pesquisa[i-1].nome_ascii;smaps_pesq_chegada();}
else if(g_qparams.tipo_query==2){icon=new GIcon();icon.image=g_css_server+"/Assets/Maps/Images/bandeira_vermelha.gif";icon.iconSize=new GSize(23,28);icon.infoWindowAnchor=new GPoint(smaps_const.window_offset_x,smaps_const.window_offset_y);icon.iconAnchor=new GPoint(12,30);pontos_pesquisa[i-1].marker.options.icon_selected=icon;g_qparams.chegada=pontos_pesquisa[i-1].marker;g_qparams.chegada_ascii=pontos_pesquisa[i-1].nome_ascii;smaps_itenerario();}
smaps_dim_markers(true);timer_smaps_map_pontos();}
function smaps_pesq_vazia(exception){if(!exception&&g_matches_text===""){exception='N&atilde;o foi poss&iacute;vel obter resposta';}
var area_txt="";if(g_query.indexOf(" em ")<0){area_txt=g_area_visivel?"na &aacute;rea vis&iacute;vel":"em Portugal";}
smaps_hide_results(false);var msg;if(exception){if(g_query.length>0)
msg='N&atilde;o foi poss&iacute;vel pesquisar por: <b>'+g_query+'</b><br>'+exception;else
msg=exception;}else{msg="A sua pesquisa por: <b>"+g_query+"<br>"+area_txt+"</b> n&atilde;o devolveu qualquer resultado."+(g_area_visivel?" Experimente pesquisar em Portugal.":"");}
if(g_qparams.tipo_query>0){s$("pesqIten_opcoes").style.display="none";s$("iten_resumo").style.display="none";}
s$(g_qparams.div_matches).innerHTML=smaps_msg_results((exception?"icone_impossivel.gif":"warning.gif"),msg);show_results();smaps_setCursor(1);try{s$(g_qparams.div_pages).style.display="none";}catch(e){}
try{if(g_qparams.tipo_query>0){s$('iten_voltar').style.display="block";}}catch(e){}}
function smaps_msg_results(img_warn,msg){var imgs;var styles;if(g_ie6){imgs="";styles="style='padding-left:10px;'";}else{imgs='<span class="iten_erro"><img src="'+g_css_server+'/Assets/Maps/Images/'+img_warn+'"/></span>';styles="";}
return imgs+"<div class='iten_erro_txt' "+styles+">"+msg+"</div>";}
function high_number_div(divname){s$(divname).style.backgroundColor='#7d9b15';s$(divname).style.color='white';}
function dim_number_div(divname){s$(divname).style.backgroundColor='';s$(divname).style.color='#374C41';}
function showMatches(index){if(!g_map_ready){return;}
var resultPesq;var points="";var point,marker;var nome,morada,telefone,photo,tipo;dim_number_div(g_qparams.div_pg+'1');dim_number_div(g_qparams.div_pg+'2');dim_number_div(g_qparams.div_pg+'3');dim_number_div(g_qparams.div_pg+'4');if(index=="ant"){index=g_matches_index-1;}
if(index=="seg"){index=g_matches_index+1;}
g_matches_index=index;high_number_div(g_qparams.div_pg+index);smaps_hide_results(true);if(g_matches_text.length===0){smaps_pesq_vazia();return;}
var lowerBound=(0+((index-1)*g_results_per_win));var upperBound=(g_results_per_win+((index-1)*g_results_per_win));smaps_pagingControl(g_matches_text.length);if(upperBound>g_matches_text.length){upperBound=g_matches_text.length;}
smaps_dim_markers(true);var sortudo=false;var anyword=false;var pesquisa_em=false;var freg_conc_txt;var first=index==1;for(var i=lowerBound;i<upperBound;i++){var xml=g_matches_text[i];var lon=xml.lon;var lat=xml.lat;var nome=unescape(xml.nome);var morada=unescape(xml.morada);var telefone=unescape(xml.telefone);var photo=unescape(xml.photo);var tipo=xml.tipo;var zoom=xml.z;var anyword=anyword||smaps_trim(""+xml.anyw)=="true";var freguesia=unescape(xml.freguesia);var concelho=unescape(xml.concelho);var distrito=unescape(xml.distrito);var criterio=0;var is_loc=(tipo.toLowerCase()=="localidades");try{criterio=parseInt(xml.criterio);}catch(e){}
if(is_loc){if(criterio>=1&&criterio<=2){freguesia=concelho=distrito="";tipo="Cidade";}
if(criterio==3){freguesia="";tipo="Cidade";}
else if(criterio==4){tipo="Vila";freguesia="";}
else if(criterio==5){tipo="Vila";}}
pesquisa_em=pesquisa_em||smaps_trim(""+xml.em)!=="";var email=""+unescape(xml.email);var net=""+unescape(xml.net);var tags=""+unescape(xml.tags);var desc="";var zipcode=(xml.zipcode.length>4)?(xml.zipcode.substring(0,4)+"-"+xml.zipcode.substring(4)):"";point=new GPoint(lon,lat);if(upperBound==1){sortudo=true;}
if(first){if(nome.toLowerCase()==g_query.toLowerCase()){sortudo=true;}
first=false;}else{if(nome.toLowerCase()==g_query.toLowerCase())sortudo=false;}
if(tags.indexOf("allmedia")>=0){desc=xml.pubdate;}
if(is_loc&&distrito==concelho){concelho="";}
if(is_loc&&concelho==freguesia){freguesia="";}
freg_conc_txt=((freguesia!=="")?("<span title='freguesia'>"+freguesia+". </span>"):"")+
((concelho!=="")?("<span title='concelho'>"+concelho+". </span>"):"")+
((freguesia==""&&distrito!=="")?("<span title='distrito'>"+distrito+". </span>"):"");var email_data="";var net_data="";if(!g_locator_widget&&telefone!==""){telefone="Tel.:"+telefone+"<br/>";}
if(!g_locator_widget&&net!==""){var url_simple=net.replace(new RegExp("/http.[:]\/\/","g"),"");if(net.indexOf("://")<0){net="http://"+net;}
net_data="<div style='float:left'><a title='Site' target='_blank' href='"+net+"'>Site</a></div>";}
var email_sep="";if(!g_locator_widget&&email!==""){if(net!==""){email_sep="&nbsp;|&nbsp;";}
email_data="<a href='mailto:"+email+"'>Enviar email</a>";}
var num=i+1;var num_left=7,num_size=12;if(num>9){num_left=4;num_size=11;}
var img_style="";var img_src=smaps_const.img_marca;if(g_ie6&&img_src.indexOf(".png")>=0){img_style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\""+img_src+"\", sizingMethod=\"scale\")";img_src=g_css_server+"/Assets/Maps/Images/pngtransp.gif";}
var no_sel="<div id='alfinete' style='position:absolute;z-index:20'><img width='"+g_img_marca_w+"' height='"+g_img_marca_h+"' src='"+img_src+"' style='"+img_style+"'></div><div id='number_div' style='position:absolute;left:"+num_left+"px;top:2px;z-index:25;font-size:"+num_size+"px;'>"+num+"</div>";smaps_dbg(no_sel);nome_pequeno=nome.substring(0,59);if(g_qparams.tipo_query>0){zoom=-1;}
var html='<li id="gs_title"><a style="font-weight:bold" href="javascript:smaps_focus('+xml.i+','+zoom+')">'+nome+'</a><br />('+tipo+') '+freg_conc_txt+'<br /></li>';var re;if(nome.length>59){nome_pequeno=nome_pequeno+".";re=new RegExp(nome,"g");html=html.replace(re,nome_pequeno);re=new RegExp("<a ","g");html=html.replace(re,"<a title='"+nome+"' ");}
var desc_marker=(is_loc||tipo.toLowerCase()=="ruas")?freg_conc_txt:("("+tipo+")<br/>"+morada+"<br/>"+zipcode+"<br/>"+freg_conc_txt+"<br/>"+telefone+net_data+email_sep+email_data+desc);marker=gs_createMarker(nome_pequeno,desc_marker,point,no_sel,smaps_const.img_marca_sel,g_img_marca_w,g_img_marca_h,g_img_marca_dx,g_img_marca_dy,(is_loc?undefined:("<div class='gs_mark_img'><img src='"+smaps_const.img_marca_sel+"' border='0'/></div><div class='gs_mark'><span>"+nome_pequeno+"</span></div>")));g_GSMap1.gmap.addOverlay(marker);pontos_pesquisa[i-lowerBound]={indice:((i%g_results_per_win)+1),marker:marker,nome_ascii:xml.nome_ascii};if(i==lowerBound){re=new RegExp("<li ","g");html=html.replace(re,"<li value="+num+" ");}
points=points+html;}
if(g_qparams.tipo_query===0&&!g_locator_callback){document.forms.SearchForm.area[1].checked=g_area_visivel;document.forms.SearchForm.area[0].checked=!g_area_visivel;}
if(!sortudo){show_results();}else{smaps_hide_results(false);}
if(g_qparams.tipo_query===0||!sortudo){var _msg=(anyword?("N&atilde;o foram encontrados registos para a pesquisa <b>"+g_query+"</b>, queria dizer?"):"");var _msg2="";if(upperBound==(g_results_per_win*g_num_wins)){_msg2="Foram encontrados demasiados resultados, por favor refine a pesquisa";}
s$(g_qparams.div_matches).innerHTML=((_msg!="")?smaps_msg_results('warning.gif',_msg):"")+"<div><ol>"+points+"</ol></div>"+
((_msg2!="")?smaps_msg_results('warning.gif',_msg2):"");if(g_qparams.tipo_query>0){s$("pesqIten_opcoes").style.display="block";}}else{s$("pesqIten_opcoes").style.display="none";}
smaps_setCursor(1);if(g_qparams.tipo_query===0||upperBound!=1){smaps_refresh();}
if(sortudo){smaps_focus(1,g_qparams.tipo_query===0?zoom:-1);}}
function smaps_submitPesqForm(){if(!g_map_ready){setTimeout(smaps_submitPesqForm,1000);}else{smaps_pesquisa(s$("caixap").value);}}
function smaps_enter_key(evt){if(!evt){evt=window.event;}
var keyCode=evt?(evt.which?evt.which:evt.keyCode):event.keyCode;if(keyCode==13){smaps_submitPesqForm();}}
function submitItenForm(){if(!g_map_ready){setTimeout(submitItenForm,1000);}else{limpa_percurso_anterior();smaps_pesq_partida();}}
function smaps_setCursor(flag){if(flag==1){document.body.style.cursor="default";}else if(flag==2){document.body.style.cursor="wait";}}
function smaps_pagingControl(size){try{size=Math.ceil(size/g_results_per_win);switch(size){case 1:s$(g_qparams.div_pages).style.display="none";break;case 2:s$(g_qparams.div_pages).style.display="block";s$(g_qparams.div_pg+'1').style.visibility="visible";s$(g_qparams.div_pg+'2').style.visibility="visible";s$(g_qparams.div_pg+'3').style.visibility="hidden";s$(g_qparams.div_pg+'4').style.visibility="hidden";break;case 3:s$(g_qparams.div_pages).style.display="block";s$(g_qparams.div_pg+'1').style.visibility="visible";s$(g_qparams.div_pg+'2').style.visibility="visible";s$(g_qparams.div_pg+'3').style.visibility="visible";s$(g_qparams.div_pg+'4').style.visibility="hidden";break;case 4:s$(g_qparams.div_pages).style.display="block";s$(g_qparams.div_pg+'1').style.visibility="visible";s$(g_qparams.div_pg+'2').style.visibility="visible";s$(g_qparams.div_pg+'3').style.visibility="visible";s$(g_qparams.div_pg+'4').style.visibility="visible";break;default:break;}
s$(g_qparams.div_pg_ant).style.visibility=(g_matches_index>1)?"visible":"hidden";s$(g_qparams.div_pg_seg).style.visibility=(g_matches_index<size)?"visible":"hidden";}catch(e){}}
function smaps_dim_markers(dont_dim_markers_selected,exclude_index){var tmp_a_pontos=g_a_pontos;var tmp_num_pontos=g_num_pontos;g_num_pontos=0;g_a_pontos=[];smaps_dbg("smaps_dim_markers "+dont_dim_markers_selected?1:0);smaps_dbg(g_layers_call_count);for(var i=0;i<tmp_a_pontos.length;i++){if(tmp_a_pontos[i].obj.options.layers_call_count&&(g_layers_call_count-tmp_a_pontos[i].obj.options.layers_call_count<50)){g_a_pontos[g_num_pontos]=tmp_a_pontos[i];g_num_pontos++;}else if(tmp_a_pontos[i].obj.options.guid){g_a_pontos_hash_map[tmp_a_pontos[i].obj.options.guid]=false;}else if((exclude_index===i)||tmp_a_pontos[i].obj.options.permanent||(dont_dim_markers_selected&&tmp_a_pontos[i].obj.options.selected)){g_a_pontos[g_num_pontos]=tmp_a_pontos[i];g_num_pontos++;}}
smaps_dbg("g_num_pontos");smaps_dbg(g_num_pontos);}
function smaps_close_markers(){for(var i=0;i<g_a_pontos.length;i++){if(g_a_pontos[i].obj.options.opened){smaps_esconde(i);}}}
function smaps_dim_markers_category(category){var tmp_a_pontos=g_a_pontos;var tmp_num_pontos=g_num_pontos;g_num_pontos=0;g_a_pontos=[];smaps_dbg("smaps_dim_markers_category");for(var i=0;i<tmp_a_pontos.length;i++){if(tmp_a_pontos[i].obj.options.category!==category){g_a_pontos[g_num_pontos]=tmp_a_pontos[i];g_num_pontos++;}else if(tmp_a_pontos[i].obj.options.guid){g_a_pontos_hash_map[tmp_a_pontos[i].obj.options.guid]=false;}}
smaps_dbg("g_num_pontos");smaps_dbg(g_num_pontos);timer_smaps_map_pontos();}
function show_results(){if(g_locator_widget){s$(g_qparams.div_results).style.visibility="visible";}else{s$(g_qparams.div_results).style.display="block";s$('iten_voltar').style.display="block";if(g_qparams.tipo_query>0){s$('iten_voltar').style.display="block";}
s$('exPesqMaps').style.display="none";if(g_qparams.tipo_query===0){s$('group1_tab1').style.display="block";s$('group1_tab2').style.display="none";}else{s$('group1_tab2').style.display="block";s$('group1_tab1').style.display="none";}
smaps_dbg("hide_banner");try{s$('gs_pub').style.display="none";}catch(e){}}}
function smaps_hide_results(dont_rotate_banner){smaps_dbg("hide_results "+dont_rotate_banner);if(g_locator_widget){s$(g_qparams.div_results).style.visibility="hidden";}else{if(g_qparams.tipo_query===0){s$("iten_results").style.display="none";s$("results").style.display="none";try{s$("pdfdiv").style.display="none";}catch(e){}}}
s$(g_qparams.div_pg_ant).style.visibility="hidden";s$(g_qparams.div_pg+'1').style.visibility="hidden";s$(g_qparams.div_pg+'2').style.visibility="hidden";s$(g_qparams.div_pg+'3').style.visibility="hidden";s$(g_qparams.div_pg+'4').style.visibility="hidden";s$(g_qparams.div_pg_seg).style.visibility="hidden";try{s$('exPesqMaps').style.display="block";s$('group1_tab1').style.display="none";s$('group1_tab2').style.display="none";if(!dont_rotate_banner){if(g_qparams.tipo_query===0){activa_banner();smaps_stats("mapa","limpaResultados","");}}}catch(e){}}
function smaps_photo(nome,url){s$('photo_div').style.visibility="visible";s$('photo_frame').innerHTML="<center><a href='"+url+"' target='_blank'><img id='photo_img' src='"+url+"' title='Ampliar'/></a><br/>"+nome+"<br/><a class='gs_ok' href='#' onclick='close_photo()' style='float:none'>&nbsp;Fechar </a></center>";}
function close_photo(){s$('photo_div').style.visibility="hidden";}
function lTrim(value){var re=/\s*((\S+\s*)*)/;return value.replace(re,"$1");}
function rTrim(value){var re=/((\s*\S+)*)\s*/;return value.replace(re,"$1");}
function smaps_trim(value){return lTrim(rTrim(value));}
function smaps_continente(){navigate_to_async(g_pt_view.y,g_pt_view.x,17-g_pt_view_zoom);smaps_stats("mapa","Continente","");}
function smaps_acores(){navigate_to_async(38.30,-28.0,12);smaps_stats("mapa","Acores","");}
function smaps_acores_W(){navigate_to_async(39.52923,-31.15977,9);smaps_stats("mapa","Acores_ocidental","");}
function smaps_acores_cent(){navigate_to_async(38.68878,-28.10579,10);smaps_stats("mapa","Acores_central","");}
function smaps_acores_E(){navigate_to_async(37.44683,-25.4002,10);smaps_stats("mapa","Acores_oriental","");}
function smaps_madeira(){navigate_to_async(32.80484,-16.87739,9);smaps_stats("mapa","Madeira","");}
function get_sec1970(){var d=new Date();d=(d.valueOf())/1000;d=Math.floor(d);return d;}
function muda_iten(){var modo;for(var i=0;i<=2;i++){if(s$("SearchForm_iten_radios").tipocam2[i].checked){modo=s$("SearchForm_iten_radios").tipocam2[i].value;}}
s$('iten_resumo').style.display="none";smaps_itenerario(modo);}
function smaps_stats(){}
function roda_banner_if_visible(){}
function roda_banner(){}
function activa_banner(){}
function mostra_banner_agora(){}
function smaps_wheel(delta,event){if(delta<0){smaps_zoomout();}else{if(g_ie)center_map(event);else smaps_zoomin();}}
function wheel(event){if(!smaps_mouse_wheel){event.returnValue=true;}
var delta=0;if(!event){event=window.event;}
if(event.wheelDelta){delta=event.wheelDelta/120;}else if(event.detail){delta=-event.detail/3;}
if(delta){smaps_wheel(delta,event);}
if(event.preventDefault){event.preventDefault();}
event.returnValue=false;}
function smaps_page_dim(){var x,y;if(self.innerHeight)
{x=self.innerWidth;y=self.innerHeight;}
else if(document.documentElement&&document.documentElement.clientHeight)
{x=document.documentElement.clientWidth;y=document.documentElement.clientHeight;}
else if(document.body)
{x=document.body.clientWidth;y=document.body.clientHeight;}
this.width=x;this.height=y;}
String.prototype.capitalize=function(){return this.replace(/\w+/g,function(a){return a.charAt(0).toUpperCase()+a.substr(1).toLowerCase();});};svg_power_on_nodes=function(){var SVG={root:'svg',ns:'http://www.w3.org/2000/svg',elements:['a','animate','animateColor','animateMotion','animateTransform','circle','defs','desc','ellipse','font-face','font-face-name','font-face-src','g','glyph','hkern','image','linearGradient','line','metadata','missing-glyph','mpath','path','polygon','polyline','radialGradient','rect','set','stop','switch','text','title','use'],attributes:['accent-height','accumulate','additive','alphabetic','arabic-form','ascent','attributeName','attributeType','baseProfile','bbox','begin','by','calcMode','cap-height','class','color','color-rendering','content','cx','cy','d','descent','display','dur','end','fill','fill-rule','font-family','font-size','font-stretch','font-style','font-variant','font-weight','from','fx','fy','g1','g2','glyph-name','hanging','height','horiz-adv-x','horiz-origin-x','id','ideographic','k','keyPoints','keySplines','keyTimes','lang','mathematical','max','min','name','offset','opacity','origin','overline-position','overline-thickness','panose-1','path','pathLength','points','preserveAspectRatio','r','repeatCount','repeatDur','requiredExtensions','requiredFeatures','restart','rotate','rx','ry','slope','stemh','stemv','stop-color','stop-opacity','strikethrough-position','strikethrough-thickness','stroke','stroke-dasharray','stroke-dashoffset','stroke-linecap','stroke-linejoin','stroke-miterlimit','stroke-width','style','systemLanguage','target','text-anchor','to','transform','type','u1','u2','underline-position','underline-thickness','unicode','unicode-range','units-per-em','values','version','viewBox','visibility','width','widths','x','x-height','x1','x2','y','y1','y2','zoomAndPan','stroke-opacity','fill-opacity']};function deepcopy(module,source,dest,nsmap){for(var i=0;i<source.attributes.length;i++){var oldattr=source.attributes[i];var colon=oldattr.name.indexOf(':');if(colon==-1){for(var j=0;j<module.attributes.length;j++){if(module.attributes[j].toLowerCase()!=oldattr.name){continue;}
dest.setAttribute(module.attributes[j],oldattr.value);break;}}else{var prefix=oldattr.name.slice(0,colon);var name=oldattr.name.slice(colon+1);if(prefix=='xmlns'){var oldmap=nsmap;nsmap={};for(var property in oldmap){nsmap[property]=oldmap[property];}
nsmap[name]=oldattr.value;}else{for(var ns in nsmap){if(ns==prefix){dest.setAttributeNS(nsmap[prefix],name,oldattr.value);}}}}}
var newchild;for(i=0;i<source.childNodes.length;i++){var oldchild=source.childNodes[i];if(oldchild.nodeType==1){for(j=0;j<module.elements.length;j++){if(module.elements[j].toUpperCase()!=oldchild.nodeName){continue;}
newchild=document.createElementNS(module.ns,module.elements[j]);deepcopy(module,oldchild,newchild,nsmap);dest.appendChild(newchild);break;}}else if(oldchild.nodeType==3){newchild=document.createTextNode(oldchild.nodeValue);dest.appendChild(newchild);}}}
var modules=[SVG];for(var i=0;i<modules.length;i++){var module=modules[i];var roots=document.getElementsByTagName(module.root);for(var j=0;j<roots.length;j++){var source=roots[j];if(document.createElementNS){if(source.__proto__!=HTMLUnknownElement.prototype){continue;}
if(source.getAttribute('xmlns')!=module.ns){continue;}
var dest=document.createElementNS(module.ns,module.root);deepcopy(module,source,dest,{});source.parentNode.insertBefore(dest,source);source.parentNode.removeChild(source);}else{var img=document.createElement('img');img.src=module.root+' image';img.title=module.root+' image';source.parentNode.insertBefore(img,source);}}}};function smaps_copy(inElement){if(inElement.createTextRange){var range=inElement.createTextRange();if(range){range.execCommand('Copy');}}else{var flashcopier='flashcopier';if(!document.getElementById(flashcopier)){var divholder=document.createElement('div');divholder.id=flashcopier;document.body.appendChild(divholder);}
document.getElementById(flashcopier).innerHTML='';var divinfo='<embed id="fla" src="'+g_css_server+'/Assets/Maps/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';document.getElementById(flashcopier).innerHTML=divinfo;}}
g_tiles_layout={params:{extents:{y1:-1.5538711096309215E7,y2:1.5538711096309219E7,x1:-2.0037508342789244E7,x2:2.0037508342789244E7,coord_sys:"wgs84_latlon",web_map_coord_sys:"mercator_sphere"},location:{id:"PT_R3p1",wms_coord_sys:"mercator_sphere",pixels:500,request_pixels:2000,no_inset_zoom:9,max_zoom:1,zoom0_resolution:0.5,num_insets:5,name:"Portugal",insets:[{desc:"0",y1:36.909932,y2:42.15832,x1:-9.53718,x2:-6.168897,y1w:4426559.8943102155,y2w:5184724.593718397,x1w:-1061674.0212037927,x2w:-686718.4727961529},{desc:"1",y1:32.58705,y2:33.12639,x1:-17.29485,x2:-16.27719,y1w:3840619.1612522407,y2w:3912092.163366932,x1w:-1925253.8953460476,x2w:-1811968.5023453648},{desc:"2",y1:39.35359,y2:39.73596,x1:-31.26338,x2:-31.08339,y1w:4772447.609596271,y2w:4827646.565692395,x1w:-3480223.5420766133,x2w:-3460187.146928732},{desc:"3",y1:38.22869,y2:39.10171,x1:-28.77118,x2:-27.04117,y1w:4611782.603200273,y2w:4736251.146671323,x1w:-3202793.1071216166,x2w:-3010209.2748543457},{desc:"4",y1:36.92642,y2:37.91283,x1:-25.87564,x2:-25.0,y1w:4428855.64067201,y2w:4567118.923522131,x1w:-2880463.068750061,x2w:-2782987.269831839}]}},tiles:{x1:-2.0037508342789244E7,y1:-1.5538711096309215E7,x2:2.0037508342789244E7,y2:1.5538711096309219E7,unit_meters:0,num_zooms:13,zooms:[{level:12,tiles_x:40,tiles_y:32,length_tile:1024000.0},{level:11,tiles_x:80,tiles_y:64,length_tile:512000.0},{level:10,tiles_x:160,tiles_y:124,length_tile:256000.0},{level:9,tiles_x:316,tiles_y:244,length_tile:128000.0},{level:8,tiles_x:628,tiles_y:488,length_tile:64000.0},{level:7,tiles_x:1256,tiles_y:972,length_tile:32000.0},{level:6,tiles_x:2508,tiles_y:1944,length_tile:16000.0},{level:5,tiles_x:5012,tiles_y:3888,length_tile:8000.0},{level:4,tiles_x:10020,tiles_y:7772,length_tile:4000.0},{level:3,tiles_x:20040,tiles_y:15540,length_tile:2000.0},{level:2,tiles_x:40076,tiles_y:31080,length_tile:1000.0},{level:1,tiles_x:80152,tiles_y:62156,length_tile:500.0},{level:0,tiles_x:160304,tiles_y:124312,length_tile:250.0}]}};