
var logEnabled=false;function GenericMap(){try{if(!GBrowserIsCompatible()){alert("Sorry, your browser is incompatible with Google Maps");return;}}catch(e){}}
GenericMap.prototype.init=function(){if(isDefined(this.map))return;if(logEnabled)GLog.write('map initialized');this.markers={};this.map=new GMap2(document.getElementById("map"));if(isDefined(this.grid)){this.grid.setMapApp(this);}
this.addControls();GEvent.bind(this.map,"moveend",this,this.onMapMoved);}
GenericMap.prototype.setUpdateHelper=function(updateHelper){this.updateHelper=updateHelper;}
GenericMap.prototype.setGrid=function(grid){this.grid=grid;}
GenericMap.prototype.setStatusDiv=function(statusDiv){this.statusDiv=statusDiv;}
GenericMap.prototype.setSearchRequestParams=function(searchRequestParams){this.searchRequestParams=searchRequestParams;}
GenericMap.prototype.handleGridColumnClick=function(column){if(isDefined(this.grid)){this.grid.handleColumnClick(column);}}
GenericMap.prototype.setPermaLink=function(centerLat,centerLng,zoomLevel,mapType){}
GenericMap.prototype.addControls=function(){if(this.map.getSize().width>380){if(!this.useCustomMapTypeControl){this.map.addControl(new GMapTypeControl());}
this.map.addControl(new GLargeMapControl());}else{if(!this.useCustomMapTypeControl){this.map.addControl(new GMapTypeControl(true));}
this.map.addControl(new GSmallMapControl());}
if(this.showOverviewMap){this.map.addControl(new GOverviewMapControl());}}
GenericMap.prototype.updateStatusDiv=function(state){var msg="";if(isDefined(this.statusDiv)){switch(state){case"PRUNED":msg="Too many locations to display. Zoom in to see more.";break;case"LOADING":msg="<img height='10' src='/images/loading_cir.gif'> Loading data.";break;case"NORESULTS":msg="<b>Sorry: No results returned.</b> Try revising your search.  Most courses are in US and Canada, with other countries coming soon.";break;case"NOEXACTMATCH":msg="<b>Error: </b> Could not find your exact location. Try revising your search.";break;case"":msg="Click an item below for more detail.";break;}
this.statusDiv.innerHTML=msg;}}
GenericMap.prototype.openInfoWindow=function(id){var marker=this.markers[id];try{this.map.removeOverlay(marker.rollover);}catch(e){}
safeOpenInfoWindowXslt(marker,marker.dom,marker.dom.getAttribute("infoStyle"));}
GenericMap.prototype.rollover=function(id){var marker=this.markers[id];if(!isDefined(this.rolloverMarker)){var icon=new GIcon(golfIconHover,'/golf/image/trans_hover.png');var hovermkr=new LiteMarker(marker.point,icon);hovermkr.png=true;this.rolloverMarker=hovermkr;this.map.addOverlay(this.rolloverMarker);}else{this.rolloverMarker.point=marker.point;this.rolloverMarker.redraw(true);this.rolloverMarker.show();}}
GenericMap.prototype.rollout=function(id){if(isDefined(this.rolloverMarker)){this.rolloverMarker.hide();}}
GenericMap.prototype.removeMapOverlays=function(){if(logEnabled)GLog.write('starting reset');for(var id in this.markers){try{var marker=this.markers[id];this.map.removeOverlay(marker);}catch(e){if(logEnabled)GLog.write("error with "+id+"  "+e);}}
if(logEnabled)GLog.write('halfway complete');if(isDefined(this.updateHelper))this.updateHelper.reset();this.markers={};if(logEnabled)GLog.write('reset complete');}
GenericMap.prototype.onMapMoved=function(){if(isDefined(this.updateHelper)){var status=this.updateHelper.needsUpdate(this.map.getBounds(),this.map.getZoom());if(logEnabled)GLog.write('map moved: '+status);if(status=="NOUPDATE")mapApp.updateStatusDiv("");if(status=="NOUPDATE_PRUNED")mapApp.updateStatusDiv("PRUNED");if(status=="UPDATE"||status=="UPDATE_PRUNED"){this.loadData(true);}
if(status=="ERASE"){this.loadData(true,false,true);}}
if(isDefined(this.grid)&&(status=="NOUPDATE"||status=="NOUPDATE_PRUNED")){if(logEnabled)GLog.write('starting grid update');this.grid.update();if(logEnabled)GLog.write('completed grid update');}}
GenericMap.prototype.makeQueryUrl=function(isUpdate){if(isUpdate){var sw=this.map.getBounds().getSouthWest();var ne=this.map.getBounds().getNorthEast();var url=this.searchRequestParams+"&bbox="+sw.lat()+","+sw.lng()+","+ne.lat()+","+ne.lng();return url;}
return this.searchRequestParams;}
GenericMap.prototype.avoidBrokenMap=function(point,zoomLevel,mapType,switchToMapType){var layer=mapType.getTileLayers()[0];var p1=mapType.getProjection().fromLatLngToPixel(point,zoomLevel);var tile=new GPoint(Math.floor(p1.x/mapType.getTileSize()),Math.floor(p1.y/mapType.getTileSize()));var tileUrl=layer.getTileUrl(tile,zoomLevel);var testImage=new Image();testImage.src=tileUrl;testImage.onerror=function(){mapApp.map.setMapType(switchToMapType);};}
GenericMap.prototype.zoomPoint=function(point,zoomLevel,mapType,runAfter){var layer=mapType.getTileLayers()[0];var p1=mapType.getProjection().fromLatLngToPixel(point,zoomLevel);var tile=new GPoint(Math.floor(p1.x/mapType.getTileSize()),Math.floor(p1.y/mapType.getTileSize()));var tileUrl=layer.getTileUrl(tile,zoomLevel);var testImage=new Image();this._testImage=testImage;testImage.onload=function(){success(point,zoomLevel,mapType,runAfter);};testImage.onerror=function(){failed(point,zoomLevel,mapType,runAfter);};testImage.onabort=function(){abort(point,zoomLevel,mapType,runAfter);};testImage.src=tileUrl;if(logEnabled)GLog.write("Trying to load "+tileUrl);}
function success(point,zoomLevel,mapType,runAfter){if(logEnabled)GLog.write("That tile exists "+zoomLevel);mapApp.map.setCenter(point,zoomLevel,mapType);if(isDefined(runAfter))runAfter();}
function failed(point,zoomLevel,mapType,runAfter){if(logEnabled)GLog.write("That tile does not exist "+zoomLevel);mapApp.zoomPoint(point,zoomLevel-1,mapType,runAfter);}
function abort(point,zoomLevel,mapType,runAfter){if(logEnabled)GLog.write("That tile was aborted "+zoomLevel);mapApp.zoomPoint(point,zoomLevel-1,mapType,runAfter);}
GenericMap.prototype.loadData=function(isUpdate,noCache,resetBeforeLoad){var mapApp=this;mapApp.updateStatusDiv("LOADING");var url=this.makeQueryUrl(isUpdate)+((isDefined(noCache)&&noCache)?"&_ts="+new Date().getTime():"");var request=GXmlHttp.create();request.open("GET",url,true);request.onreadystatechange=function(){if(request.readyState==4){if(logEnabled)GLog.write('got data xml');mapApp.init();if((isDefined(resetBeforeLoad)&&resetBeforeLoad))mapApp.removeMapOverlays();var xmlDoc=request.responseXML;var bounds=xmlDoc.documentElement.getElementsByTagName("bounds")[0];var center=xmlDoc.documentElement.getElementsByTagName("center")[0];var span=xmlDoc.documentElement.getElementsByTagName("span")[0];var gBounds=new GLatLngBounds(new GLatLng(parseFloat(bounds.getAttribute("minlat")),parseFloat(bounds.getAttribute("minlng"))),new GLatLng(parseFloat(bounds.getAttribute("maxlat")),parseFloat(bounds.getAttribute("maxlng"))));var gZoomLevel=mapApp.map.getBoundsZoomLevel(gBounds);var gCenter=new GLatLng(parseFloat(center.getAttribute("lat")),parseFloat(center.getAttribute("lng")));var isPruned=span.getAttribute("isPruned")=="true";var isNoExactMatch=span.getAttribute("noExactMatch")=="true";var isRadialSearch=span.getAttribute("isRadialSearch")=="true";if(isPruned){mapApp.updateStatusDiv("PRUNED");}
else{mapApp.updateStatusDiv("");}
if(isRadialSearch){if(gZoomLevel<15){gZoomLevel=gZoomLevel+1;}}
if(!isUpdate){mapApp.map.setCenter(gCenter,gZoomLevel);}else{gZoomLevel=mapApp.map.getZoom();}
var locations=xmlDoc.getElementsByTagName("location");if(locations.length==0&&!isUpdate){mapApp.updateStatusDiv("NORESULTS");}
if(isNoExactMatch){mapApp.updateStatusDiv("NOEXACTMATCH");}
var newLocations=0;for(var i=0;i<locations.length;i++){var id=locations[i].getAttribute("id");if(!isDefined(mapApp.markers[id])){var marker=mapApp.createMarker(locations[i]);mapApp.map.addOverlay(marker);mapApp.markers[id]=marker;newLocations++;}}
if(logEnabled)GLog.write('finished new locations '+newLocations+" new / "+locations.length);if(isDefined(mapApp.updateHelper)){mapApp.updateHelper.addScreen(gBounds,gZoomLevel,isPruned);}
if(isDefined(mapApp.grid)){mapApp.grid.update();}
if(locations.length==0&&!isUpdate){if(!isUpdate){if(isDefined(mapApp.updateHelper)){mapApp.updateHelper.addScreen(new GLatLngBounds(new GLatLng(-10,-10),new GLatLng(10,10)),3,false);}}}}}
request.send(null);}
GenericMap.prototype.createMarker=function(dom){return this.makeBxMarker(dom);}
GenericMap.prototype.makeBxMarker=function(dom){var mapApp=this;var pointElt=dom.getElementsByTagName("point");var point=new GLatLng(parseFloat(pointElt[0].getAttribute("lat")),parseFloat(pointElt[0].getAttribute("lng")));var iconClass=dom.getElementsByTagName("icon")[0].getAttribute("class");var id=dom.getAttribute("id");var image=dom.getElementsByTagName("icon")[0].getAttribute("image");var icon=new GIcon(this.getIconClassFromName(iconClass),image);var hoverText="";try{hoverText=dom.getElementsByTagName("hover")[0].firstChild.nodeValue;}catch(e){}
var marker=new GxMarker(point,icon,hoverText,this.map);marker.dom=dom;marker.id=id;marker.icon=icon;marker.point=point;GEvent.addListener(marker,"click",function(){mapApp.openInfoWindow(marker.id);});return marker;}
function isDefined(v){return(typeof v!='undefined');}
function isBlank(v){return!isDefined(v)||v=='';}
function safeOpenInfoWindowXslt(marker,location,xslUri,gmap){var html=document.createElement("div");var popups=location.getElementsByTagName("popup");if(popups.length==1){var text=popups[0].firstChild.nodeValue;html.innerHTML=text;marker.openInfoWindow(html);return;}
alert('trying to open'+marker+" , "+location+" , "+xslUri)
var request=GXmlHttp.create();request.open("GET",xslUri,true);request.onreadystatechange=function(){if(request.readyState==4){try{var text=request.responseText;alert('xslfile is '+text);var xmldoc=GXml.parse(text);var xformer=GXslt.create(xmldoc);if(logEnabled)GLog.write('xsl text is '+GXml.value(xmldoc));var html=document.createElement("div");alert('i2 xformer is '+xformer);var success=xformer.transformToHtml(location,html);alert('transform: '+success+'  rendered is '+html);alert('i3 text'+html);marker.openInfoWindow(html);}catch(e){alert('error '+e);}}};request.send(null);}
function processAddCam(c){window.location="/cams/addCamSplash.jsp?where="+c.lat()+","+c.lng();}
function modifyObject(id,type,params){if(!isDefined(type))type="weathermaps.weather.points.DataPoint";if(!isDefined(params))params="";window.open('/utils/showBean.jsp?_className='+type+'&id='+id+params,'_new','width=650,height=800,resizable=1,scrollbars=1');}
function getWindowHeightQuirks(){var myWidth=0,myHeight=0;if(typeof(window.innerWidth)=='number'){myWidth=window.innerWidth;myHeight=window.innerHeight;}else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){myWidth=document.documentElement.clientWidth;myHeight=document.documentElement.clientHeight;}else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){myWidth=document.body.clientWidth;myHeight=document.body.clientHeight;}
return myHeight;}
function getWindowHeight(){if(document.body){return document.body.offsetHeight;}
if(window.self&&self.innerHeight){return self.innerHeight;}
if(document.documentElement&&document.documentElement.clientHeight){return document.documentElement.clientHeight;}
return 0;}
function el(id){return document.getElementById(id);}
function resizeElt(e,border,minSize){if(!isDefined(e))return;if(!isDefined(border))border=10;if(!isDefined(border))minSize=400;var offset=0;for(var elem=e;elem!=null;elem=elem.offsetParent){offset+=elem.offsetTop;}
var windowHeight=getWindowHeightQuirks();var height=windowHeight-offset-border;if(height<minSize)height=minSize;if(height>=0){e.style.height=height+"px";}
return height;}
function resizeMap(){var offset=0;for(var elem=el("map");elem!=null;elem=elem.offsetParent){offset+=elem.offsetTop;}
var windowHeight=getWindowHeight();var height=windowHeight-offset-20;if(height>=0){el("map").style.height=height+"px";}}
function setCookieAsync(name,val){var url="/user/cookies/setCookies.jsp?"+name+"="+encodeURIComponent(val);var img=new Image();img.src=url;}
function inlineComments(div,id,className){var url='/user/feedback_popup.jsp?_noEmail=true&_commentWidth=25&_className='+className+'&_id='+id+'&_inline=true';var iframe='<iframe  src="'+url+'" width="250" height="150" frameborder="0" ></iframe>';div.innerHTML=iframe;}
var USA_BOUNDS=new GLatLngBounds(new GLatLng(24,-126),new GLatLng(50,-66));var FOG_BOUNDS=new GLatLngBounds(new GLatLng(36.4,-124.065),new GLatLng(39.1944,-120.792));GenericMap.prototype.getMapViewportQuery=function(){var bounds=this.map.getBounds();return"["+bounds.getSouthWest().lat()+","+bounds.getNorthEast().lat()+","+bounds.getSouthWest().lng()+","+bounds.getNorthEast().lng()+"]:"+mapApp.map.getZoom();}
function cookiesEnabled(){var cookieEnabled=(navigator.cookieEnabled)?true:false;if(typeof navigator.cookieEnabled=="undefined"&&!cookieEnabled){document.cookie="testcookie"
cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)?true:false;}
return cookieEnabled;}
function toggleFavoriteStar(obj,id){GDownloadUrl("/user/cookies/setStarFavorites.jsp?_toggleStarFavorite="+id,function(data,responseCode){obj.innerHTML=data;try{var oldIcon=mapApp.markers[id].icon.image;var newIcon=oldIcon.indexOf("_lit.png")==-1?oldIcon.replace(".png","_lit.png"):oldIcon.replace("_lit.png",".png");mapApp.markers[id].changeIcon(newIcon);}
catch(e){}});}