
var userHistory=[];var okToRecord=false;var currentPage=-1;var userTitle="User supplied location";var overlaysOn=true;var userPoint="";function BgsMarker(Point,Options,Info){this.Info=Info;GMarker.call(this,Point,Options);}
BgsMarker.prototype=new GMarker(new GLatLng(0,0));BgsMarker.prototype.initialize=function(map){this._map=map;GMarker.prototype.initialize.call(this,map);GEvent.addListener(this,"dblclick",this.onDblClick);GEvent.addListener(this,"click",this.onClick);GEvent.addListener(this,"mouseover",this.onMouseOver);GEvent.addListener(this,"mouseout",this.onMouseOut);};BgsMarker.prototype.onClick=function(){if(this.Info.URL.length>0){location.href=this.Info.URL;}else{alert("Sorry, no web page for this location.");}};BgsMarker.prototype.onMouseOver=function(){var str="";if(this.Info.Title.length>0&&this.Info.Comment.length>0){str="<b>"+this.Info.Title+":</b> "+this.Info.Comment;}else if(this.Info.Title.length>0){str="<b>"+this.Info.Title+"</b>";}
showComment(true,str);};BgsMarker.prototype.onMouseOut=function(){showComment(false,"");};BgsMarker.prototype.onDblClick=function(){this.Info.MapType=G_SATELLITE_MAP;this.Info.displayMap();};function BgsMapInfo(Map,Latitude,Longitude,Zoom,MapType){this.Map=Map;this.Latitude=Latitude||0;this.Longitude=Longitude||0;this.Zoom=Zoom||2;this.MapType=MapType||G_NORMAL_MAP;this.SiteID="";this.Title="";this.Comment="";this.URL="";this.Rank=1;this.Continent="";this.Country="";}
BgsMapInfo.prototype.displayMap=function(){try{this.Map.setCenter(new GLatLng(parseFloat(this.Latitude),parseFloat(this.Longitude)),parseInt(this.Zoom,10),this.MapType);recordNewSettings(this);}catch(e){alert("displayMap() Error: ("+e.name+"): "+e.message);}};function recordNewSettings(Info){if(okToRecord){currentPage++;userHistory[currentPage]=Info;if(userHistory.length>currentPage+1){userHistory=userHistory.slice(0,currentPage+1);}
adjustButtons();}}
function goBack(){var uLoc;if(currentPage>0){okToRecord=false;currentPage--;uLoc=userHistory[currentPage];uLoc.displayMap();adjustInterface(uLoc);okToRecord=true;}}
function goForward(){var uLoc;if(currentPage<userHistory.length-1){okToRecord=false;currentPage++;uLoc=userHistory[currentPage];uLoc.displayMap();adjustInterface(uLoc);okToRecord=true;}}
function adjustRegionList(arg){var foundOne=false;if(contSelect!==null){for(var i=1;i<contSelect.options.length;i++){if(contSelect.options[i].value==arg){contSelect.options[i].selected=true;foundOne=true;}else{contSelect.options[i].selected=false;}}
if(!foundOne){contSelect.selectedIndex=0;}}}
function adjustButtons(){var btnB=document.getElementById("btnBack");var btnF=document.getElementById("btnForward");if(btnB!==null&&btnF!==null){if(currentPage===0){btnB.disabled="disabled";}else{btnB.disabled="";}
if(currentPage<userHistory.length-1){btnF.disabled="";}else{btnF.disabled="disabled";}}}
function showComment(on,text){if(commentText===null||commentDiv===null){return;}
if(on&&text.length>0&&text.indexOf(userTitle)<0){commentText.innerHTML=text;commentDiv.style.visibility="visible";}else{commentText.innerHTML="";commentDiv.style.visibility="hidden";}}
function createBgsMarker(InfoIn){var icon=G_DEFAULT_ICON;try{icon=new GIcon(baseIcon);try{icon.image="/shared/labels/mm_20_"+colors[InfoIn.Rank]+".png";}catch(ex){icon.image="/shared/labels/mm_20_marker.png";}}catch(e){}
var mOpts={icon:icon};var tStr;if(InfoIn.Title.length>0&&InfoIn.Title!=userTitle&&InfoIn.Country.length>0){tStr=InfoIn.Title+" ["+InfoIn.Country+"]";mOpts={icon:icon,title:tStr};}else if(InfoIn.Title.length>0){mOpts={icon:icon,title:InfoIn.Title};}
var point=new GLatLng(parseFloat(InfoIn.Latitude),parseFloat(InfoIn.Longitude));var marker=new BgsMarker(point,mOpts,InfoIn);return marker;}
function findLocation(){var eg="";if(userPoint!==null&&userPoint.length>0){eg=userPoint;}
var pnt=prompt("Enter latitude, longitude (e.g. 44.553, -109.321)",eg);var pntSplit;var lat;var lng;var newLoc;var mk;if(pnt){userPoint=pnt;pnt=pnt.replace(/[A-Za-z]/g,"");pnt=pnt.replace(/\s/g,"");pntSplit=pnt.split(",");if(pnt.indexOf(",")<0&&pnt.indexOf("~")>0){pntSplit=pnt.split("~");}
if(pntSplit.length!=2){alert("Entry not valid. Enter two numeric values separated by a comma.");return;}
if(pntSplit[0].search(/[^0-9\.\-]/)>-1){pntSplit[0]=convertToDecimal(pntSplit[0]);}
if(pntSplit[1].search(/[^0-9\.\-]/)>-1){pntSplit[1]=convertToDecimal(pntSplit[1]);}
try{lat=parseFloat(pntSplit[0]);lng=parseFloat(pntSplit[1]);if(lat>90||lat<-90){alert("Latitude must be between -90 and 90.");return;}else if(lng>180||lng<-180){alert("Longitude must be between -180 and 180.");return;}
if(map!==null){newLoc=new BgsMapInfo(map,lat,lng,map.getZoom(),map.getCurrentMapType());newLoc.Continent="None";newLoc.Country="None";newLoc.Title=userTitle;newLoc.displayMap();mk=createBgsMarker(newLoc);map.addOverlay(mk);adjustInterface(newLoc);}}catch(err){alert(err.message);}}}
function convertToDecimal(arg){var argIn=arg;var dg="";var mn="";var sc="";var idx=0;var argSplit;var retVal;var valArray;try{while(!isNaN(arg.charAt(idx))){dg+=arg.charAt(idx);idx++;}
argIn=argIn.replace(dg,"");argIn=argIn.replace(/[^0-9\.]/g,"|");argSplit=argIn.split("|");for(i=0;i<argSplit.length;i++){if(isNaN(argSplit[i])||argSplit[i].length<1){}else if(mn.toString().length<1){mn=parseFloat(argSplit[i]);mn=parseFloat(mn/60.0);}else if(sc.toString().length<1){sc=parseFloat(argSplit[i]);sc=parseFloat(sc/6000.0);}}
retVal=0;valArray=[dg,mn,sc];for(v=0;v<valArray.length;v++){if(valArray[v].toString().length>0&&!isNaN(valArray[v])){retVal+=parseFloat(valArray[v]);}}
return retVal;}catch(err){alert("Cannot parse "+arg+": "+err.message);}}
function getXmlHttpRequestObject(){var req=false;if(window.XMLHttpRequest){try{req=new XMLHttpRequest();}catch(e){req=false;}}else if(window.ActiveXObject){try{req=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{req=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){req=false;}}}
return req;}
function getAjaxObject(rscFunction,baseURL,getString){var XmlHttpReq=getXmlHttpRequestObject();if(XmlHttpReq){XmlHttpReq.onreadystatechange=rscFunction;XmlHttpReq.open('get',baseURL+getString,true);XmlHttpReq.send('');return XmlHttpReq;}else{alert("getAjaxObject() Error: Could not instantiate XmlHttpReq");}}
function processReqChange(XmlHttpReq){if(XmlHttpReq){if(XmlHttpReq.readyState==4){if(XmlHttpReq.status==200){return true;}else{alert("There was a problem retrieving the XML data:\n"+
XmlHttpReq.statusText);}}
return false;}else{}}
