function fAnchorPosition(dv,pt)
{
 try
 {
  var anchor;
  eval("anchor="+dv.getAttribute("Anchor"));
  if(anchor.Right)
   dv.style.left = (pt.x-(parseInt(dv.offsetWidth)+anchor.Right)) + 'px';
  else if(anchor.Left)
   dv.style.left = (pt.x+anchor.Left) + 'px';
  else 
   dv.style.left = (pt.x) + 'px';
  if(anchor.Bottom)
   dv.style.top = (pt.y-(parseInt(dv.offsetHeight)+anchor.Bottom)) + 'px';
  else if(anchor.Top)
   dv.style.top = (pt.y+anchor.Top) + 'px';
  else
   dv.style.top = (pt.y) + 'px';
 }
 catch(e)
 {
  dv.style.left = (pt.x-(parseInt(dv.offsetWidth))) + 'px';
  dv.style.top = (pt.y-(parseInt(dv.offsetHeight))) + 'px';
 }
}
function clsUSGMaps(dvmap) //->google.maps
{
 this.Zoom=9;
 this.dvMap=dvmap;
 this.ActiveView=null; // - Default to hViewCourses
 this.hViews={/*hViewCourses, hhViewCourseEdit,hViewPlacements,hViewPlacementsEdit,hView3DPhoto*/}
// Private Events
  this.onPanelChange=function(){}
//?  this.fAddListener=function(hPanel,key,func)
//?  this.fRemoveListener=function(hPanel,key,func)
//?  this.fStopListener=function(hPanel,key)
 this.HoldEvents=false;
 this.EditMode=false;
 this.fEventHandler=function(ev,key){if(this.ActiveView && this.ActiveView["fOn"+key] && typeof(this.ActiveView["fOn"+key])=="function"){return this.ActiveView["fOn"+key](ev);};return false;}
 this.fMsg=function(msg,secs)
 {
  if(msg==null)
  {
   fGDs("dvMsgBox").display="none";
   return;
  }
  fGDs("dvMsgBox").display="";
  fGD("dvMsgBox").innerHTML=msg;
  window.setTimeout(function(){USGMaps.fMsg();},secs||4000);
 }
 this.fAddView=function(name,hview)
 {
  if(this.hViews[name])
  {
   this.hViews[name].onUnload();
   delete(this.hViews[name]);
  }
  this.hViews[name]=hview;
  this.hViews[name].onLoad();
 }
 this.fActivateView=function(name)
 {
  if(this.hViews[name])
  {
// ??? FIRST HANDLE OLD ACTIVE VIEW
   this.ActiveView=this.hViews[name];
   this.hViews[name].onActivate(this.map);
  }
 };
 this.MapOptions={center:new this.LatLng(0,0),scrollwheel:true,zoom:2,mapTypeId:this.MapTypeId.HYBRID};
 this.fToggleRotate=function()
 {
  var dv=fGD(this.dvMap);
  var ll=this.map.getCenter();
  if(this.MapOptions.scrollwheel)
  {
   var sq=Math.ceil(Math.sqrt(Math.pow(dv.offsetHeight,2)+Math.pow(dv.offsetWidth,2)))
   dv.style.left=(0-parseInt((sq-dv.offsetWidth)/2))+"px";
   dv.style.top=(0-parseInt((sq-dv.offsetHeight)/2))+"px";
   dv.style.width=sq+"px";
   dv.style.height=sq+"px";
   this.event.trigger(this.map,"resize");
   this.map.panTo(ll);
   this.map.setOptions({scrollwheel:this.MapOptions.scrollwheel=false})
  }
  else 
  {
   dv.style.width="";
   dv.style.height="";
   dv.style.left="0px";
   dv.style.top="0px";
   this.event.trigger(this.map,"resize");
   this.map.panTo(ll);
   doRotate(dv,0);
   this.map.setOptions({scrollwheel:this.MapOptions.scrollwheel=true})
  }
 }
 this.fDeactivateView=function(name)
 {
// ??? NEW ACTIVE VIEW ??
  if(this.hViews[name])
   this.hViews[name].onActivate();
 }
 this.fAddMap=function(dvmap) 
 {
  if(dvmap)
  {
   if(this.dvMap!=null && this.dvMap!=dvmap)
   {
    document.getElementById(this.dvMap).style.display="none";
   } 
   this.dvMap=dvmap;
  }
  // Start locatiion and zoom is in the dvmap
  var el=document.getElementById(this.dvMap)
  if(el.getAttribute("lat")!=null && el.getAttribute("lng")!=null)
  {
   this.MapOptions.center = new this.LatLng(el.getAttribute("lat"),el.getAttribute("lng"));
   if(el.getAttribute("zoom")!=null)
    this.MapOptions.zoom=parseInt(el.getAttribute("zoom"));
   if(el.getAttribute("maptypeid")!=null)
    this.MapOptions.mapTypeId=el.getAttribute("maptypeid");
  }
  this.map = new this.Map(el, this.MapOptions);
  this.map.lastclick=this.map.getCenter();
  // Map Events
  var gmaps=this;
  this.infoWindow = new clsInfoWindow(this);
  this.event.addListener(gmaps.map,"idle", function(ev)
  {
   if(gmaps.HoldEvents==true) return; gmaps.fEventHandler(ev,"idle");

  });
  this.event.addListener(gmaps.map,"rightclick", function(ev){if(gmaps.HoldEvents==true) return; return gmaps.fEventHandler(ev,"rightclick");});
  this.event.addListener(gmaps.map, 'click', function(ev)
  {
   gmaps.infoWindow.close();
   if(!gmaps.HoldEvents && gmaps.fCaptureClicks)
    gmaps.fCaptureClicks(ev);
  });
  this.event.addListener(this.infoWindow, 'closeclick', function()
  {
   if(gmaps.infoWindow.Marker!=null)
   {
    gmaps.infoWindow.Marker.fInfoWindowClosing(gmaps);
    gmaps.infoWindow.Marker=null;
   }
  });  
 }
 this.fAdvClick=function(id)
 {
  fClientServerMsg("Recording Advertisement Click Through");
  fAjaxCall({async:true,url:"/include/USGSave.asp?AdvClick="+id,fcallback:function(req)
   {
    try
    {
     fClientServerMsg();
     fDebug(req.responseText);
    }
    catch(e)
    {
     fDebug("Content Load Error :"+e.description);
    }
   }
  });
 }
 this.fContentLoader = function(elid,obj,groupid)
 {
  var url="";
  var method=null;
  var content=null;
  var gmaps=this;
  if(groupid)
  {
   var el=fGD(elid);
   var togglegroup=el.getAttribute("togglegroup");
   if(togglegroup!=null && togglegroup==groupid)
   {
    if(el.style.display=="none")
     el.style.display="";
    else
     el.style.display="none";
//    el.setAttribute("togglegroup","");
    return;
   }
   if(groupid)
   {
    el.style.display="";
    el.setAttribute("togglegroup",groupid);
   }
  }
  if(obj.hCourse==null)
  {
   if(this.hCourse)
    obj.CourseID=this.hCourse.CourseID;
   else
   {
    var hcourse=this.ActiveView.fFirstCourse();
    if(hcourse)
     obj.CourseID=hcourse.CourseID;
    else // default to The Reserve
     obj.CourseID=18115;
   }
  }
  if(elid=="dvWhatsNew")
  {
   var bnds=this.map.getBounds();
   obj.Name+="?Bounds="+fSerialize({SW:{y:bnds.getSouthWest().lat(),x:bnds.getSouthWest().lng()},NE:{y:bnds.getNorthEast().lat(),x:bnds.getNorthEast().lng()}});
  }
  url="/include/USGContent.asp?Section="+fSerialize(obj);
  fClientServerMsg("Loading Page ");
  fAjaxCall({async:true,method:method,content:content,url:url,fcallback:function(req)
   {
    try
    {
     fGD(elid).innerHTML=req.responseText;
    }
    catch(e)
    {
     fDebug("Content Load Error :"+e.description);
    }
    fClientServerMsg();
   }
  });
 }
 this.fCourseDataLoaded=function(hobj)
 {
  USGMaps.fMsg(fSerialize(hobj));
 }
 this.fMapCourse=function(cid,lat,lng,obj)
 {
  if(this.hCourse)
   this.hCourse.fClose(this,1);
  if(this.ActiveView.hCourseMarkers[String(cid)])
   this.ActiveView.hCourseMarkers[String(cid)].fLoadHoleTeeYards(this);
  else
  {
   fClientServerMsg("Loading Course For Mapping ");
   var gmaps=this;
   this.map.panTo(new this.LatLng(lat,lng));
   this.map.setZoom(16);
   window.setTimeout(function()
   {
    if(gmaps.ActiveView.hCourseMarkers[String(cid)]==null)
    {
     fClientServerMsg("Loading Course For Mapping, Please Wait ");
     window.setTimeout(function()
     {
      for(var cid in gmaps.ActiveView.hCourseMarkers)
      {
       if(gmaps.ActiveView.hCourseMarkers[cid].getPosition().lat()==lat)
        break;
      }
      if(gmaps.ActiveView.hCourseMarkers[String(cid)])
      {
       gmaps.ActiveView.hCourseMarkers[String(cid)].fLoadHoleTeeYards(gmaps);
      } 
      else
      {
       USGMaps.fMsg("Could Not Load Geo Data To Map Holes\nPlease perform this step manually.");
      }
     },2000);
    }
    else if(gmaps.ActiveView.hCourseMarkers[String(cid)])
    {
     gmaps.ActiveView.hCourseMarkers[String(cid)].fLoadHoleTeeYards(gmaps);
    }
   },2000);
  }
 }
 this.fOpenInfoWindow = function(marker)
 {
  marker.fInfoWindowOpening(this);
  this.ActiveView.fCourseMarkerOpened(marker);
 };
 this.aClicks=[];
 this.fCaptureClicks=function(ev)
 {
  this.aClicks.push({lat:ev.latLng.lat(),lng:ev.latLng.lng()});
  fDebug();
  fDebug(fSerialize(this.aClicks));
 } 
 this.fQuitCapture=function()
 {
  if(this.hCourse)
  {
   this.hCourse.fClose(this)
  }
 }
 this.fSaveCapture=function()
 {
  if(this.hCourse)
  {
   this.hCourse.fSaveCapture(this);
  }
 }
 this.fHoleOptionsWindow=function(options)
 {
  var dv=fGD("dvHoleOptionsWorkArea");
  dv.innerHTML=options.content;
  fGDs("dvHoleOptions").display="";
  fGD("spnHoleOptionsCloseButton").onclick=function(){fGDs("dvHoleOptions").display="none";};
 }
 this.hTour=
 {
  Type:"Map"
  ,hObj:null
  ,Action:"Stop"
  ,TimerID:null
  ,ListenerID:null
  ,MapReady:0
  ,fTourAction:function(action)
  {
   var htour=this;
   if(htour.hObj==null)
   {
    htour.hObj=USGMaps.hCourse._Marker;
    action="Play";
   }
   if(htour.hObj==null)
   {
    fGDs("dvTourUtilityToggle").display="none";
    USGMaps.event.removeListener(htour.ListenerID);
    htour.ListenerID=null;
    if(htour.TimerID != null)
    {
     window.clearInterval(htour.TimerID);
     htour.TimerID=null;
     USGMaps.fMsg("Oh! This is not good. There is no tour object but the timer is still going!!!");
    }
    else
    {
     USGMaps.fMsg("Oops! You don't have a tour started yet.\nSoon, you can find one in \"What's New\"");
    }
    USGMaps.HoldEvents=false;
    return;
   }
   else if(htour.hObj!=USGMaps.hCourse._Marker)
   {
    USGMaps.fMsg("Oops! Something went wrong!"
    +"\nWe may have solved it. Please try that again.");
    htour.hObj=USGMaps.hCourse._Marker;
    return;
   }
   if(action=="Stop")
   {
    if(htour.TimerID)
     window.clearInterval(htour.TimerID);
    htour.TimerID=null;
    USGMaps.event.removeListener(htour.ListenerID);
    htour.ListenerID=null;
    USGMaps.HoldEvents=false;
    fGD("aUSGTour_Pause").className=fGD("aUSGTour_Pause").className.replace(/butbi2p2/,"butbo2p2");
    fGD("aUSGTour_Play").className=fGD("aUSGTour_Play").className.replace(/butbi2p2/,"butbo2p2");
    htour.hObj=null;
    return;
   }
   if(action=="Play")
   {
    fGD("aUSGTour_Play").className=fGD("aUSGTour_"+action).className.replace(/butbo2p2/,"butbi2p2");
    fGD("aUSGTour_Pause").className=fGD("aUSGTour_Pause").className.replace(/butbi2p2/,"butbo2p2");
    if(htour.TimerID == null)
    {
     USGMaps.map.setZoom(USGMaps.hCourse.BoundsZoom);
     USGMaps.map.panTo(htour.hObj.getPosition());
     USGMaps.fMsg(USGMaps.hCourse.Name+"<br>Course Tour",3000);
     USGMaps.hCourse.fActive(1,{Hole:"1"});
    }
   }
   else if(htour.Action=="Pause")
   {
    fGD("aUSGTour_Pause").className=fGD("aUSGTour_"+action).className.replace(/butbo2p2/,"butbi2p2");
    fGD("aUSGTour_Play").className=fGD("aUSGTour_Play").className.replace(/butbi2p2/,"butbo2p2");
   }
   htour.Action=action;
//   fDebug();
   htour.hObj.fTourStep(htour);
   htour.MapReady=2;
   if(htour.TimerID == null)
   {
    htour.TimerID=window.setInterval(function(){if(--htour.MapReady <= 0) htour.fTourAction(htour.Action);},3000);
    USGMaps.HoldEvents=true;
    htour.ListenerID=USGMaps.event.addListener(USGMaps.map,"idle", function(ev)
    {
     htour.MapReady=0;
    });
   }
  }
 };
 this.fTour=function(action,htour)
 {
  if(htour==null)
   htour=this.hTour;
  fDebug("You pressed "+action);
  htour.fTourAction(action);
 }

 this.hMember=
 {
  LoggedIn:"",
  Status:"",
  Name:"",
  screenName:"",
  LoginID:"",
  ID:0,
  GeoEnabled:true,
  hPartners:{Twitter:null,FaceBook:null},
  hManaged:{},
  fManager:function(cid,tablename)
  {
   if(tablename==null)
    tablename="Course";
   if(cid == null)
   {
    if(USGMaps.hCourse==null)
     return false;
    cid=USGMaps.hCourse.CourseID;
   }
   if(this.hManaged["0"])
    return true;
   for(var c in this.hManaged)
   {
    if(c==cid && this.hManaged[c].TableName==tablename)
     return true;
   }
   return false;
  }
 }
 this.fLoggedIn=function()
 {
  if(this.hMember.LoggedIn)
   return this.hMember;
  for(var p in this.hMember.hPartners)
  {
   if(this.hMember.hPartners[p] != null)
    return this.hMember;
  }
  fGDs("btnCourseEditsSave").display="none";
  return null;
 }
 this.fMembers=function(params)
 {
  var url="/include/USGQuery.asp?Members="+(params?fSerialize(params):"{}");
//  USGMaps.fMsg(unescape(url));
  if(params == null)
  {
   fToggle('dvSignOn');
   if(fGDs('dvSignOn').display=="none")
    return;
  } 
  else 
  {
   if(params!=null && params.LogOut==null && params.LoginID==this.hMember.LoginID)
    return;
   this.hMember.LoginID=params.LoginID;
  }
  fAjaxCall({async:true,url:url,fcallback:function(req)
   {
    try
    {
     fGDs('dvSignOn').display="";
     fGD("dvSignOn").innerHTML=req.responseText;
    }
    catch(e)
    {
     fDebug("Load fMembers Error :"+e.description);
    }
    fClientServerMsg();
   }
  });
 }
 this.fShowLogins=function(dv,msg)
 {
  var aLogins=[];
  if(msg != null)
   aLogins.push(msg);
  aLogins.push("<br>You are "); 
  aLogins.push("<br>"+(this.hMember.LoggedIn?"":" NOT ") +" logged in to USGolfers.");
  for(var p in this.hMember.hPartners)
   aLogins.push("<br>"+(this.hMember.hPartners[p]?"":" NOT ") +" logged in to "+p+".");
  fGD("spnLoginMsg").innerHTML="<h3>"+aLogins.join("")+"</h3>";
 }
 this.fLogin=function ()
 {
  var loginid=String(fGD("inpLoginID").value).replace(/ /g,"");
  var pw=String(fGD("inpPassword").value).replace(/ /g,"");
  if(loginid != fGD("inpLoginID").value || pw!=fGD("inpPassword").value )
   USGMaps.fMsg("That won't work. Please try again.");
  else
  {
   fClientServerMsg("Member Login ...");
   this.fMembers({Login:1,LoginID:loginid,PW:pw});
  }
 }
 this.fTWLogin=function (obj)
 {
  if(obj && obj.data)
  {
   this.hMember.hPartners.Twitter=obj;
   this.hMember.Name=obj.data('screen_name');
   this.hMember.LoginID="Twitter_"+obj.data("id");
   this.hMember.ContactName=obj.data('name');
   this.hMember.GeoEnabled=obj.data("geo_enabled");
   var params={
    Login:1
    ,Name:obj.data('screen_name')
    ,LoginID:"Twitter_"+obj.data("id")
    ,PW:"TWT_"+obj.data("id")+"_TWT"
   };
   this.fMembers(params);
  }
 }
 this.fSendTweet=function(plain,html)
 {
  /* Sending a Tweet */
//  USGMaps.fMsg("Do I now have to send this or was it just a notifier? Tweet Sent :"+plain);
  twttr.anywhere
  (function (T)
   {
    var aTxt=[];
    for(var a in T )
     aTxt.push(a+":"+T[a]);
     fDebug(aTxt);
   }
  );
 }
 this.fTweetLatLng=function()
 {
  USGMaps.fMsg("Tweeting the current Lat Lng Coordinates");
 }
 this.fFBLogInOut = function (fb,callback)
 {
  var url;
  var script=null;

  if(fb==null)
  {
   fDebug("Not Logged In");
   // Log out FACEBOOK_USER Session on USGolfers.com
   url="http://www.USGolfers.com/include/FaceBook/default.asp?FB={}";
   this.hMember.hPartners.FaceBook=null;
   FB.hObj=null;
//   script=1;
  }
  else
  {
   if(fb)
   {
   // Log in FACEBOOK_USER Session on USGolfers.com
    var aTxt=[];
    for(var i in fb) 
     aTxt.push(i+":'"+fb[i]+"'");
    fDebug(aTxt); 
    url="http://www.USGolfers.com/include/FaceBook/default.asp?VAR=FB.hObj&FB={"+escape(aTxt.join(","))+"}";
  //  script=1;

    this.hMember.LoginID="FaceBook_"+fb.uid;
    this.hMember.hPartners.FaceBook=fb;
   }
   else
   {
    url="http://www.USGolfers.com/include/FaceBook/FBQuery.asp?TOK="+escape(FB._session.access_token)+"&unit="+FB._session.uid;
   }
   fDebug(url);
   fClientServerMsg("FaceBook Session Change "+((fb!=null)?"Logged In":"Logged Out"));
   fAjaxCall
   (
    {
     async:true,url:url,fcallback:function(req)
     {
      try
      {
       fClientServerMsg();
//       fDebug(req.responseText);
       eval(req.responseText);
       if(req.status != 200)
       {
        fDebug("fFBLogInOut Status :"+req.status);
       }
       if(FB.hObj)
       {
//        fDebug(USGMaps.hMember.ID+":"+FB.hObj.id)
        USGMaps.hMember.Name=FB.hObj.name;
        USGMaps.hMember.screenName=FB.hObj.first_name;
        FB.hObj=null;
       }
       if(callback)
        callback(req.responseText);
      }
      catch(e)
      {
       fDebug("fFBLogInOut Load Error :"+e.description);
      }
     }
    }
   );
  }
 }
 return this;
}
function clsUSGView() // ->USGMaps.prototype.OverlayView
{
 this.GMaps=null;
// Private Events
 this.onLoad=function(){};
 this.onUnload=function(){};
 this.onActivate=function(map){this.setMap(map);};
 this.onDeActivate=function(){this.setMap(null)};
 this.fSearch=function(el){}
 this.onAdd=function(){}
 this.draw=function(){}
 return this;
}
function clsViewCourses(gmaps)//->clsUSGView
{
 this.Filter="";
 this.GMaps=gmaps;
 this.hCourseMarkers={};
 this.hCountMarkers ={};
 this.OpenhCourse=null;
 this.fGetProjection=function(){return this.getProjection();}
 this.fCourseMarkerOpened=function(marker)
 {
  this.OpenhCourse=marker.hCourse;
 }
 this.fFirstCourse = function()
 {
  if(this.OpenhCourse)
   return this.OpenhCourse;
  for(var c in this.hCourseMarkers)
   return this.hCourseMarkers[c].hCourse;
  return null;
 }
 this.fSearch=function(el)
 {
  var FieldID=el.getAttribute("field");
  var Field=fGD(FieldID);
  var aFilters=[];
  var aFields=[];
  var hSearch={};
  if(Field)
  // Single Field Search
   aFields.push({getAttribute:function(fld){return FieldID;},value:Field.value,tagName:Field.tagName});
  else 
   aFields=fGD("dvSearch").getElementsByTagName("input");
  for(var f=0;f<aFields.length;f++)
  {
   FieldID=aFields[f].getAttribute("field");
   if(FieldID==null)
    continue;
   Field=fGD(FieldID);
   if(Field==null)
    continue;
   if(el.value=="Clear")
   {
    Field.value="";
    if(Field.tagName=="SELECT")
     for(var o=1;o<Field.options.length;o++)
      Field.options[o].selected=false;
    continue;
   }
   if(el.value=="Go" || el.value=="Filter")
   {
    if(Field.tagName=="SELECT")
    {
     var aClass=[];
     for(var o=1;o<Field.options.length;o++)
     {
      if(Field.options[o].selected)
      {
       aClass.push("'"+Field.options[o].value+"'");
      }
     }
     if(aClass.length>0)
      aFilters.push("\""+FieldID.replace(/Course_/,"")+" IN ("+aClass.join(", ")+")\"");
    }
    else
    {
     if(String(Field.value).replace(/ /g,"").length==0)
      continue;
     if(String(Field.value).indexOf("*") < 0)
      aFilters.push("\""+FieldID.replace(/Course_/,"")+"='"+Field.value+"'\"");
     else
      aFilters.push("\""+FieldID.replace(/Course_/,"")+" LIKE '"+Field.value+"'\"");
    }
   }
  }
  if(el.value=="Clear")
   return;

  if(aFilters.length==0)
  {
   USGMaps.fMsg("Enter one or more values to filter on.");
   return;
  }
  if(el.value=="Filter")
  {
   if(!el.checked)
   {
    USGMaps.fMsg("Filtering is disabled.");
    this.Filter="";
    return;
   }
   USGMaps.fMsg("Filtering is enabled.");
  }
  Field=fGD("SearchFilter");
  if(Field.checked)
   this.Filter="["+aFilters.join(",")+"]";
  var Bounds=this.GMaps.map.getBounds();
  var url="/include/USGQuery.asp?InBounds="
  +"{"
  +"Grid:{"
  +"Call:'fAddToList'"
  +",SW:{y:"+Bounds.getSouthWest().lat()+",x:"+Bounds.getSouthWest().lng()+"},NE:{y:"+Bounds.getNorthEast().lat()+",x:"+Bounds.getNorthEast().lng()+"}"
  +"}}"
  +"&Filter=["+aFilters.join(",")+"]";
  fGDs("dvSearch").display="none";
  fCourseList(this,url);
 }
 this.fCourseInfo=function(tab,cid,marker)
 {
  var url="";
  var method=null;
  var content=null;
  if(tab=="ScoreCard")
   url="/include/ScoreCard.asp?Section="+tab+"&CourseID="+cid;
  else
   url="/include/USGQuery.asp?Section="+tab+"&CourseID="+cid;
  fClientServerMsg("Loading Information "+tab);
  fAjaxCall({async:true,method:method,content:content,url:url,fcallback:function(req)
   {
    try
    {
     fGD("dvCourseWorkArea").innerHTML=req.responseText;
    }
    catch(e)
    {
     fDebug("Load fCourseInfo Error :"+e.description);
    }
    fClientServerMsg();
   }
  });
 }
 this.fCreateCourseMarker=function(gmaps,hsh)
 {
  if(this.hCourseMarkers[String(hsh.CourseID)]==null)
  {
   var hcourse=new clsCourse(hsh);
   this.hCourseMarkers[String(hsh.CourseID)]=new clsCourseMarker(gmaps,hcourse);
  }
  else
   this.hCourseMarkers[String(hsh.CourseID)].OnMap=true;
 }
 this.fCreateCountMarker=function(gmaps,hsh)
 {
  if(this.hCountMarkers[String(hsh.Grid)]==null)
  {
   this.hCountMarkers[String(hsh.Grid)]=new clsCountMarker(gmaps,hsh);
  }
 }

// Overridden google functions
 this.onAdd=function()
 {
 }
 this.onRemove=function()
 {
 }
 this.draw=function()
 {
 }
 this.fOnrightclick=function(ev)
 {
  var dv=fGD("dvSearch");
  dv.style.display="";
  var ll = this.getProjection().fromLatLngToContainerPixel(ev.latLng);
  fAnchorPosition(dv,ll)
 }
 this.fOnidle=function(ev)
 {
  var view=this;
  if(this.OnidleID != null)
   window.clearTimeout(this.OnidleID);
  this.OnidleID=window.setTimeout(function(){view.fLoadOnIdle(ev);},2000);
 }  
 this.fLoadOnIdle=function(ev)
 { 
  this.OnidleID=null;
  var bounds = this.map.getBounds();
  var SW=bounds.getSouthWest(),NE=bounds.getNorthEast();
  var SWlng=SW.lng();
  if(SWlng>NE.lng())
  {
   SWlng=-180.0;
  }
  var ctr=this.map.getCenter();
  // Break the map into grids and call courses for each grid
  // If a grid has more than 20 courses create the group for that grid instead
  var zoom=this.map.getZoom();
 /* 
 Zoom
 15+  1x1=1  100/1=100
 14+  2x2=4  100/4=25
 13+  3x3=9  100/9=12 
 12+  4x4=16 100/16=7 
 11   5x5=25 100/25=4
 */
  var MAXCOURSES = 200;
  var hGrid={Rows:parseInt(Math.min(5,Math.max(1,Math.ceil(22/zoom)))),Cols:parseInt(Math.min(6,Math.max(1,Math.ceil(22/zoom))))};
  if(zoom>14)
    hGrid={Top:MAXCOURSES/4,Rows:2,Cols:2};
  else if(zoom>12)
    hGrid={Top:MAXCOURSES/8,Rows:3,Cols:3};
  else if(zoom>9)
    hGrid={Top:MAXCOURSES/10,Rows:4,Cols:4};
  else 
    hGrid={Top:MAXCOURSES/25,Rows:5,Cols:5};
  var cellwidth = Math.abs((NE.lng()-SWlng)/hGrid.Cols);
  var cellheight = Math.abs((NE.lat()-SW.lat())/hGrid.Rows);
  var url;
  var aGrids=[];
  for(var c=1,lng=SWlng;c<=hGrid.Cols;c++)
  {
   for(var r=1,lat=SW.lat();r<=hGrid.Rows;r++)
   {
    aGrids.push("'"+r+"_"+c+"':{Grid:'"+c+"_"+r+"'"
      +",Top:"+hGrid.Top+",SW:{x:"
      +lng+",y:"
      +lat+"},NE:{x:"
      +(lng+cellwidth)+",y:"
      +(lat+cellheight)+"},CTR:{x:"
      +(lng+cellwidth/2)+",y:"+(lat+cellheight/2)+"}}");
    lat+=cellheight;
   }
   lng+=cellwidth;
  }
  url="/include/USGQuery.asp?Markers={}";
  var content="Markers={"+aGrids.join(',')+"}"
  +(this.Filter?("&Filter="+this.Filter):"")
  +"";
//fDebug();
//fDebug(url+"\n"+content);
  for(var m in this.hCourseMarkers)
  {
   if(this.hCourseMarkers[m].fCanDelete())
    this.hCourseMarkers[m].OnMap=false;
  }
  for(var m in this.hCountMarkers)
  {
   this.hCountMarkers[m].fOnDelete();
   this.hCountMarkers[m].setMap(null);
   delete(this.hCountMarkers[m]);
  }
  var view=this;
  fClientServerMsg("Locating Courses ");
  fAjaxCall({async:true,url:url,content:content,method:"post",fcallback:function(req)
   {
//    USGMaps.fMsg(req.responseText);
    eval(req.responseText);
    for(var m in view.hCourseMarkers)
    {
     if(view.hCourseMarkers[m].OnMap!=true)
     {
      if(!view.hCourseMarkers[m].fOnDelete())
      {
       view.hCourseMarkers[m].setMap(null);
       delete(view.hCourseMarkers[m]);
      }
     }
    }
    fClientServerMsg();
   }
  });
 }
 return false;
}
// Change To CourseInfoWindow
function clsInfoWindow(gmaps) // ->USGMaps.prototype.InfoWindow 
{
 this.setOptions(
  {
   maxWidth:500,
   pixelOffset:new gmaps.Size(19,-58),
   disableAutoPan:false,
   content:''
   +'<div '
   +' id=dvCourse width=450 height=300'
   +' class="bdr op9" '
   +' style="width:450px; height:300px;" CourseID="" Anchor="{Right:14,Bottom:-150}">'
   +' <div id="dvCourseTabs">&nbsp;</div>'
   +' <div id="dvCourseWorkArea" >&nbsp;</div>'
   +' <a href="#" id="aZoomToCourse" style="position:absolute;top:0px;right:10px;cursor:help;padding:2px;" title="Click to zoom to this course">Zoom In</a>'
   +'</div>'
  }
 ); 
 return this;
}
function clsOverlay(howner)
{
 this.hOwner=howner;
 this.bCanDeleteFlag=true;
 this.fCanDelete=function(){return this.bCanDeleteFlag;}
 this.fMarkDelete=function(flg){if(flg==null)flg=true;return this.bCanDeleteFlag=flg;}
 this.fClearDelete=function(){return this.bCanDeleteFlag=false;}
 this.fOnDelete=function(gmaps)
 {
 }
 return this;
}
function clsMapTileOverlay(gmaps,howner)//->clsUSGMaps.ImageMapType
{
 this.clsOverlay=clsOverlay;
 this.clsOverlay(howner);
 return this;
}
function clsRectangleOverlay(gmaps,howner)//->clsUSGMaps.Rectangle
{
 this.clsOverlay=clsOverlay;
 this.clsOverlay(howner);
 return this;
}
function clsCircleOverlay(gmaps,howner)//->clsUSGMaps.Circle
{
 this.clsOverlay=clsOverlay;
 this.clsOverlay(howner);
 return this;
}
function clsPolylineOverlay(gmaps,howner)//->clsUSGMaps.Polyline
{
 this.clsOverlay=clsOverlay;
 this.clsOverlay(howner);
 return this;
}
function clsPolygonOverlay(gmaps,howner)//->clsUSGMaps.Polygon
{
 this.clsOverlay=clsOverlay;
 this.clsOverlay(howner);
 return this;
}
function clsMarker()//->clsUSGMaps.Marker
{
 this.bCanDeleteFlag=true;
 this.fCanDelete=function(){return this.bCanDeleteFlag;}
 this.fMarkDelete=function(flg){if(flg==null)flg=true;return this.bCanDeleteFlag=flg;}
 this.fClearDelete=function(){return this.bCanDeleteFlag=false;}
 this.fOnDelete=function(gmaps)
 {
  if(gmaps==null)
   gmaps=USGMaps;
  this.setMap(null);
  gmaps.event.clearInstanceListeners(this)
 }
 this.fInfoWindowClosing=function(gmaps)
 {
//  this.fOnDelete();
 }; 
 this.fInfoWindowOpening=function(gmaps)
 {
  if(gmaps==null)
   gmaps=USGMaps;
  var markerLatLng = this.getPosition();
  this.fClearDelete();
  gmaps.HoldEvents=true;
  gmaps.infoWindow.Marker=this;
  gmaps.infoWindow.setPosition(this.getPosition());
  gmaps.infoWindow.open(gmaps.map);
 }
 this.fTourStep=null;
 return this;
}
function clsCaptureMarker(howner)//->clsMarker
{
 this.distance=0;
 this.hOwner=howner;
 //this.fLatLng=function(){return {lat:0,lng:0};}
 this.fSetPosition=function(latlng)
 {
  //Call to update the fLatLng
  this.fLatLng(latlng);
//  this.fLatLng().lat=latlng.lat();
//  this.fLatLng().lng=latlng.lng();
  this.setPosition(latlng);
 }
 this.fSetVisibility=function(visibility,gmaps)
 {
  if(this.hOwner)
  {
   this.hOwner._visible=visibility;
   this.setMap(gmaps.map);
  }
 }
 this.fCaptureMarkerSetup=function(gmaps,howner)
 {
  var marker=this;
  this.hOwner=howner;
 }
 this.fDistance=function(hfromlatlng,hlatlng)
 {
  if(hlatlng==null)
   hlatlng=this.fLatLng();

  return this.distance=fDistance(hfromlatlng.lat,hfromlatlng.lng,hlatlng.lat,hlatlng.lng);
 }
 this.fAddListeners=function(gmaps)
 {
  var marker=this;
  gmaps.event.clearInstanceListeners(marker);
  gmaps.event.addListener(marker,"rightclick",function(ev){gmaps.map.panTo(this.getPosition());gmaps.map.setZoom(20);});
  if(marker.fOnRightClickMarker)
   gmaps.event.addListener(marker,"rightclick",function(ev){marker.fOnRightClickMarker(ev);});
  if(marker.fOnClickMarker)
   gmaps.event.addListener(marker,"click",function(ev){marker.fOnClickMarker(ev);});
  if(marker.fOnDragMarker)
   gmaps.event.addListener(marker,"drag",function(ev){marker.fOnDragMarker(ev);});
  if(marker.fOnDragStartMarker)
   gmaps.event.addListener(marker,"dragstart",function(ev){marker.fOnDragStartMarker(ev);});
  if(marker.fOnDragEndMarker)
   gmaps.event.addListener(marker,"dragend",function(ev){marker.fOnDragEndMarker(ev);});
  if(marker.fOnMouseOver)
   gmaps.event.addListener(marker,"mouseover",function(ev){marker.fOnMouseOver(ev);});
  if(marker.fOnMouseOut)
   gmaps.event.addListener(marker,"mouseout",function(ev){marker.fOnMouseOut(ev);});
 }
 this.fOnMouseOver=function(ev)
 {
  this.fDrawCaptureMsg();
 }
 this.fOnMouseOut=function(ev)
 {
  if(USGMaps.hCourse)
  {
   var hactive=USGMaps.hCourse.fActive();
  }
 }
 this.fOnDragMarker=function(ev)
 {
  this.fSetPosition(ev.latLng);
  this.fDrawCaptureMsg(null);
 }
 this.fOnDragStartMarker=function(ev)
 {
  var hactive=USGMaps.hCourse.fActive(this.Shot,this.hOwner);
 }
 this.fOnDragEndMarker=function(ev)
 {
  try
  {
   if(USGMaps.hCourse.fHoleMarkers(this.hOwner.Hole).GreenMarker)
    USGMaps.hCourse.fHoleMarkers(this.hOwner.Hole).GreenMarker.fBuildPolyline();
  }
  catch(e){fDebug("fOnDragEndMarker :"+this.hOwner.Hole+" : "+e.description);}
 }
 return this;
}
function clsTeeCaptureMarker(gmaps,howner,shot)
{
 this.Shot=shot;// Shots starts from the Tee(1)
 this.fCaptureMarkerSetup(gmaps,howner);
 this.fLatLng=function(latlng)
 {
  if(latlng)
  {
   howner.TeeLat=latlng.lat();
   howner.TeeLng=latlng.lng();
  }
  return {lat:howner.TeeLat,lng:howner.TeeLng};
 }
 this.setOptions({
   position: new gmaps.LatLng(howner.TeeLat,howner.TeeLng),
   draggable: true,
   visible: true,
   icon: new gmaps.MarkerImage(hFlagImages.fTee(this.hOwner.Tee,this.hOwner.Position),null,null,new gmaps.Point(5,5)),
   cursor:"help",
   title:"Hole #"+this.hOwner.Hole + " Shot #"+this.Shot+" "+ this.hOwner.Tee+" Tee -- Drag:Relocates, R-Click:Zooms, Click:Activates"
  });
 this.setMap(gmaps.map);
 if(this.hOwner._visible==false)
  this.setMap(null);
 this.fDrawCaptureMsg=function(aTxt,hlatlng,drawto,joiner)
 {
  try
  {
   var hHole=gmaps.hCourse.fHoleMarkers(this.hOwner.Hole);
   if(aTxt==null)
   {
    aTxt=new Array();
    if(drawto==null)
     drawto=fGD("spnCourseEditsMsg");  
   }
   aTxt.push("Hole :<b>"+this.hOwner.Hole+"</b>");
   aTxt.push("Par :<b>"+this.hOwner.Par+"</b>");
   aTxt.push("Yards :<b>"+this.hOwner.Yards+"</b>&nbsp;"+this.hOwner.Tee);
   aTxt.push("Capture :<b>Tee</b>&nbsp;-&nbsp;<b class='Tee-"+this.hOwner.Tee+"'>"+this.hOwner.Tee+"</b> Tee");
   if(drawto)
    drawto.innerHTML=aTxt.join(joiner||" ");  
  }catch(e){if(aTxt)aTxt.push(e.description);if(drawto)drawto.innerHTML=e.description;}
  return aTxt;
 }
 this.fOnClickMarker=function(ev)
 {
  if(gmaps.hCourse.fActiveTee()!=this.hOwner.Tee)
  {
   gmaps.hCourse.fActiveTee(this.hOwner.Tee);
   gmaps.hCourse.fReBuildPolylines();
  }
 }
 return this;
}
function clsFairwayCaptureMarker(gmaps,howner,shot)
{
 this.fCaptureMarkerSetup(gmaps,howner);
 this.Shot=shot; // Shots starts from the Tee(1)
 this.fLatLng=function(latlng)
 {
  var p=this.hOwner.Polyline[this.hOwner.Polyline.length-(this.Shot-1)];
  if(latlng)
  {
   p[0]=latlng.lat();
   p[1]=latlng.lng();
  }
  return {lat:p[0],lng:p[1]};
 }
 this.setOptions({
   position: new gmaps.LatLng(this.fLatLng().lat,this.fLatLng().lng),
   draggable: true,
   visible: gmaps.EditMode,
   icon: new gmaps.MarkerImage(hFlagImages.fMark(),null,null,new gmaps.Point(7,7)),
   cursor:"help",
   title:"Hole #"+this.hOwner.Hole + " Shot #"+this.Shot+" Fairway -- Drag:Relocates, R-Click:Zooms, Click:More..."
  });
 this.setMap(gmaps.map);
 if(this.hOwner._visible==false)
  this.setMap(null);
 this.fDrawCaptureMsg=function(aTxt,hlatlng,drawto,joiner)
 {
  try
  {
   var hTeeMarker=gmaps.hCourse.fHoleMarkers(this.hOwner.Hole).TeeMarker;
   if(aTxt==null)
   {
    aTxt=new Array();
    if(drawto==null)
     drawto=fGD("spnCourseEditsMsg");  
   }
   aTxt.push("Hole :<b>"+this.hOwner.Hole+"</b>");
   aTxt.push("Par :<b>"+this.hOwner.Par+"</b>");
   aTxt.push("Yards :<b>"+hTeeMarker.hOwner.Yards+"</b>&nbsp;<img src='"
   +hFlagImages.fTee(hTeeMarker.hOwner.Tee,hTeeMarker.hOwner.Position)
   +"' alt='"+hTeeMarker.hOwner.Tee+" Tee'>");
 //fDebug("Shot :"+this.Shot)
   aTxt.push("Capture :<b>Fairway</b>");
   if(this.Shot==2) // Back to the Tee
   {
    aTxt.push("Distance :<b>"+this.fDistance(hTeeMarker.fLatLng(),hlatlng)
    +"</b>&nbsp;from&nbsp;<b class='Tee-"+hTeeMarker.hOwner.Tee+"'>"+hTeeMarker.hOwner.Tee+"</b> Tee");
   }
   else
   {
    aTxt.push("Distance :<b>"+this.fDistance(this.hOwner._aShotMarkers[this.Shot-3].fLatLng(),hlatlng)
    +"</b>&nbsp;from&nbsp;<b>Previous Mark</b>");
   }
   if(this.distance>300)
    aTxt.push("<span class=warning>Too Long ?</span>");
   if(drawto)
    drawto.innerHTML=aTxt.join(joiner||" ");  
  }catch(e){if(aTxt)aTxt.push(e.description);if(drawto)drawto.innerHTML=e.description;}
  return aTxt;
 }
 return this;
}
function clsApproachCaptureMarker(gmaps,howner,shot)
{
 this.Shot=shot;// Shots starts from the Tee(1)
 this.fCaptureMarkerSetup(gmaps,howner);
 this.fLatLng=function(latlng)
 {
  var p=this.hOwner.Polyline[this.hOwner.Polyline.length-(this.Shot-1)];
  if(latlng)
  {
   p[0]=latlng.lat();
   p[1]=latlng.lng();
  }
  return {lat:p[0],lng:p[1]};
 }
 this.setOptions({
   position: new gmaps.LatLng(this.fLatLng().lat,this.fLatLng().lng),
   draggable: true,
   visible: gmaps.EditMode,
   icon: new gmaps.MarkerImage(hFlagImages.fMark(),null,null,new gmaps.Point(7,7)),
   cursor:"help",
   title:"Hole #"+this.hOwner.Hole + " Shot #"+this.Shot+" Approach -- Drag:Relocates, R-Click:Zooms, Click:More..."
  });
 this.setMap(gmaps.map);
 if(this.hOwner._visible==false)
  this.setMap(null);
 this.fDrawCaptureMsg=function(aTxt,hlatlng,drawto,joiner)
 {
  try
  {
   var hTeeMarker=gmaps.hCourse.fHoleMarkers(this.hOwner.Hole).TeeMarker;
   if(aTxt==null)
   {
    aTxt=new Array();
    if(drawto==null)
     drawto=fGD("spnCourseEditsMsg");  
   }
   aTxt.push("Hole :<b>"+this.hOwner.Hole+"</b>");
   aTxt.push("Par :<b>"+this.hOwner.Par+"</b>");
   aTxt.push("Yards :<b>"+hTeeMarker.hOwner.Yards+"</b>&nbsp;<img src='"
   +hFlagImages.fTee(hTeeMarker.hOwner.Tee,hTeeMarker.hOwner.Position)
   +"' alt='"+hTeeMarker.hOwner.Tee+" Tee'>");
   aTxt.push("Capture :<b>Approach</b>");
   if(this.hOwner.Par==4) // Back to the Tee
   {
    aTxt.push("Distance :<b>"+this.fDistance(hTeeMarker.hOwner._TeeMarker.fLatLng(),hlatlng)
    +"</b>&nbsp;from&nbsp;<b class='Tee-"+hTeeMarker.hOwner.Tee+"'>"
    +hTeeMarker.hOwner.Tee+"</b> Tee");
    if(this.distance>300)
     aTxt.push("<span class=warning>Too Long ?</span>");
   }
   else
   {
    aTxt.push("Distance :<b>"+this.fDistance(this.hOwner._aShotMarkers[this.Shot-3].fLatLng(),hlatlng)+"</b>&nbsp;from&nbsp;<b>Previous Mark</b>");
    if(this.distance>500)
     aTxt.push("<span class=warning>Too Long ?</span>");
   }
   if(drawto)
    drawto.innerHTML=aTxt.join(joiner||" ");  
  }catch(e){if(aTxt)aTxt.push(e.description);if(drawto)drawto.innerHTML=e.description;}
  return aTxt;
 }
 return this;
}
function clsGreenCaptureMarker(gmaps,howner,shot)
{
 this.Shot=shot;// Shots starts from the Tee(1)
 this.fCaptureMarkerSetup(gmaps,howner);

 // Assign the clsMarker.fOnDelete to _fOnDelete so we can call it after we are done.
 var _fOnDelete=this.fOnDelete;
 this.fOnDelete=function(gmaps)
 {
  if(gmaps==null)
   gmaps=USGMaps;
  if(this.fOnDelete==_fOnDelete)
  {
   fDebug("Cant Do _fOnDelete");
   return;
  }
  this._fOnDelete=_fOnDelete;
  if(this.PolylineOverlay)
  {
   this.PolylineOverlay.setMap(null);
   gmaps.event.clearInstanceListeners(this.PolylineOverlay);
  }
  this._fOnDelete(gmaps);
 }
 this.fLatLng=function(latlng)
 {
  if(latlng)
  {
   howner.Lat=latlng.lat();
   howner.Lng=latlng.lng();
  }
  return {lat:this.hOwner.Lat,lng:this.hOwner.Lng};
 }
 this.setOptions({
   position: new gmaps.LatLng(this.hOwner.Lat,this.hOwner.Lng),
   draggable: true,
   visible: true,
   icon: new gmaps.MarkerImage(hFlagImages.fPin(this.hOwner.Hole),null,null,new gmaps.Point(7,70)),
   cursor:"help",
   title:"Hole #"+this.hOwner.Hole + " Shot #"+this.Shot+" Green -- Drag:Relocates, R-Click:Zooms, Click:More..."
  });
 this.setMap(gmaps.map);
 if(this.hOwner._visible==false)
  this.setMap(null);
 this.fDrawCaptureMsg=function(aTxt,hlatlng,drawto,joiner)
 {
  try
  {
   var hTeeMarker=gmaps.hCourse.fHoleMarkers(this.hOwner.Hole).TeeMarker;
   if(aTxt==null)
   {
    aTxt=new Array();
    if(drawto==null)
     drawto=fGD("spnCourseEditsMsg");  
   }
   aTxt.push("Hole :<b>"+this.hOwner.Hole+"</b>");
   aTxt.push("Par :<b>"+this.hOwner.Par+"</b>");
   aTxt.push("Yards :<b>"+hTeeMarker.hOwner.Yards+"</b>&nbsp;<img src='"
   +hFlagImages.fTee(hTeeMarker.hOwner.Tee,hTeeMarker.hOwner.Position)+"' alt='"
   +hTeeMarker.hOwner.Tee+" Tee'>");
   aTxt.push("Capture :<b>Green</b>");
   if(this.hOwner.Par==3) // Back to the Tee
   {
    aTxt.push("Distance :<b>"+this.fDistance(hTeeMarker.fLatLng(),hlatlng)
    +"</b>&nbsp;from&nbsp;<b class='Tee-"+hTeeMarker.hOwner.Tee+"'>"+hTeeMarker.hOwner.Tee+"</b> Tee");
    if(this.distance >(parseInt(hTeeMarker.hOwner.Yards)+40))
     aTxt.push(" <span class=warning>Too Long ?</span>");
    if(this.distance <(hTeeMarker.hOwner.Yards-40))
     aTxt.push(" <span class=warning>Too Short ?</span>");
   }
   else if(this.hOwner.Par==4) // Back to the Approach
   {
    aTxt.push("Distance :<b>"+this.fDistance(this.hOwner._ApproachMarker.fLatLng(),hlatlng)
    +"</b>&nbsp;from&nbsp;<b>Previous Mark</b>");
    if(this.distance>(hTeeMarker.hOwner.Yards-this.hOwner._ApproachMarker.distance+40))
    {
     aTxt.push(" <span class=warning>Too Long ?</span>");
    }
    else if(this.distance<(hTeeMarker.hOwner.Yards-this.hOwner._ApproachMarker.distance-40))
    {
     aTxt.push(" <span class=warning>Too Short ?</span>");
    }
   }
   else  // Back to the Fairway/Approach
   {
    aTxt.push("Distance :<b>"+this.fDistance(this.hOwner._ApproachMarker.fLatLng(),hlatlng)
    +"</b>&nbsp;from&nbsp;<b>Previous Mark</b>");
    if(this.hOwner._aShotMarkers[this.Shot-this.hOwner.Par])
    {
     if(this.distance>(hTeeMarker.hOwner.Yards-this.hOwner._ApproachMarker.distance-this.hOwner._aShotMarkers[this.Shot-4].distance+40))
      aTxt.push(" <span class=warning>Too Long ?</span>");
     else if(this.distance<(hTeeMarker.hOwner.Yards-this.hOwner._ApproachMarker.distance-this.hOwner._aShotMarkers[this.Shot-4].distance-40))
      aTxt.push(" <span class=warning>Too Short ?</span>");
    }
   }
   if(drawto)
    drawto.innerHTML=aTxt.join(joiner||" ");  
  }catch(e){if(aTxt)aTxt.push(e.description);if(drawto)drawto.innerHTML=e.description;}
  return aTxt;
 }
 this.fBuildPolyline=function(options)
 {
  if(this.getMap()==null || this.fLatLng().lat==0 || this.fLatLng().lng==0)
   return;
  var hHole=gmaps.hCourse.fHoleMarkers(this.hOwner.Hole);
  if(this.PolylineOverlay==null)
  {
   this.PolylineOverlay=new gmaps.Polyline(csthTRACKLINEOPTIONS);
  }
  else if(options)
   this.PolylineOverlay.setOptions(options)

  try
  {
   if(csthTRACKLINEOPTIONS.strokeColor=="")
   {
    this.PolylineOverlay.setOptions({strokeColor:hFlagImages.fStroke(gmaps.hCourse.ActiveTee,hHole.TeeMarker.hOwner.Position)});
   }
  }
  catch(e){fDebug("UseTee FAILED TO SET POLYLINEOVERLAY["+this.hOwner.Hole+"] OPTIONS :"+e.description)}
  var po=this.PolylineOverlay;
  // po.setPath([]);
  if(po.getPath().length>0) 
  {
   path=po.getPath();
   path.setAt(0,new gmaps.LatLng(hHole.TeeMarker.fLatLng().lat,hHole.TeeMarker.fLatLng().lng));
   for(var s=0;hHole.aShotMarkers && s<hHole.aShotMarkers.length;s++)
   {
    path.setAt(s+1,new gmaps.LatLng(hHole.aShotMarkers[s].fLatLng().lat,hHole.aShotMarkers[s].fLatLng().lng));
   }
   if(hHole.ApproachMarker)
   {
    path.setAt(++s,new gmaps.LatLng(hHole.ApproachMarker.fLatLng().lat,hHole.ApproachMarker.fLatLng().lng));
   }
   path.setAt(++s,new gmaps.LatLng(this.fLatLng().lat,this.fLatLng().lng));
  }
  else if(this.hOwner._visible==true)
  {
   var path=po.getPath();
   path.push(new gmaps.LatLng(hHole.TeeMarker.fLatLng().lat,hHole.TeeMarker.fLatLng().lng));
   for(var s=0;hHole.aShotMarkers && s<hHole.aShotMarkers.length;s++)
   {
    path.push(new gmaps.LatLng(hHole.aShotMarkers[s].fLatLng().lat,hHole.aShotMarkers[s].fLatLng().lng));
   }
   if(hHole.ApproachMarker)
   {
    path.push(new gmaps.LatLng(hHole.ApproachMarker.fLatLng().lat,hHole.ApproachMarker.fLatLng().lng));
   }
   path.push(new gmaps.LatLng(this.fLatLng().lat,this.fLatLng().lng));
   po.setMap(gmaps.map);
  }
  else
   po.setMap(null);
 }
 this.fOnClickMarker=function()
 {
  var marker=this;
  var url="/include/USGQuery.asp?Options={Section:'Capture'}&CourseID="+USGMaps.hCourse.CourseID;
  fAjaxCall({async:true,url:url,fcallback:function(req)
   {
    try
    {
     if(req.status==200)
      USGMaps.HoleInfoWindow=new USGMaps.fHoleOptionsWindow({content:req.responseText}); 
     else
      USGMaps.HoleInfoWindow=new USGMaps.fHoleOptionsWindow({content:req.responseText}); 
    }
    catch(e)
    {
     fDebug("Load CaptureOptions Error :"+e.description);
    }
    fClientServerMsg();
   }
  });
 }
 return this;
}
function clsCourseMarker(gmaps,hsh)
{
 this.bUpdatePosition="checked";
 this.hCourse=hsh;
 this.hCourse._Marker=this; 
 var marker=this;
 this.fOnDelete=function()
 {
  return this.hCourse.fClose(gmaps);
 }
 this.OnMap=true;
 this.setOptions({
   position: new gmaps.LatLng(hsh.Latitude,hsh.Longitude),
   draggable: true,
   visible: true,
   icon: new gmaps.MarkerImage(hFlagImages[hsh.Classification+(hsh.Holes>9?(18+(hsh._Mapped>0?"_M":"")):9)],null,null,new gmaps.Point(7,70)),
   cursor:"help",
   zIndex:parseInt(hsh.Holes)+parseInt(hsh.Tees),
   title:(hsh._Mapped>0?"[Mapped]":"")+"["+hsh.Classification + "][Holes:"+hsh.Holes + "][Tees:"+hsh.Tees + "]["+hsh.Phone + "] " +hsh.Name
  });
 this.setMap(gmaps.map);
// this.setTitle("Position :"+this.getPosition());
 this.fTourStep=function(htour)
 {
  try
  {
   if(htour.Action=="Pause" || htour.Action=="Stop")
    return;
   var hactive;
   if(htour.Action=="Play")
   {
//    gmaps.map.setMapTypeId(gmaps.MapTypeId.SATELLITE);
//    gmaps.map.panTo(this.getPosition());
    hactive=this.hCourse.fActive();
    htour.Action="Next";
   }
   else if(htour.Action=="HoleBounds")
   {
    htour.Action="Next";
    return;
   }
   else if(htour.Action=="Prev")
   {
    if(this.hCourse.ActiveShot==1)
    {
     if(this.hCourse.ActiveHole=="1")
     {
      hactive=this.hCourse.fActive((this.hCourse.hHoleInfo[String(this.hCourse.Holes)].Par-1),{Hole:String(this.hCourse.Holes)});
      return;
     }
     hactive=this.hCourse.fActive((this.hCourse.hHoleInfo[String(parseInt(this.hCourse.ActiveHole)-1)].Par-1)
              ,{Hole:String(parseInt(this.hCourse.ActiveHole)-1)});
    }
    else 
    {
     hactive=this.hCourse.fActive(this.hCourse.ActiveShot-1);
    }
   }
   else if(htour.Action=="Next")
   {
    if((this.hCourse.ActiveShot+1)==this.hCourse.hHoleInfo[""+this.hCourse.ActiveHole].Par)
    {
     if(parseInt(this.hCourse.ActiveHole) >= this.hCourse.Holes)
     {
      hactive=this.hCourse.fActive(1,{Hole:String(1)});
      fDebug();
     }
     else 
      hactive=this.hCourse.fActive(1,{Hole:String(parseInt(this.hCourse.ActiveHole)+1)});
 //    htour.Action="HoleBounds";
    }
    else
    {
     hactive=this.hCourse.fActive(this.hCourse.ActiveShot+1);
    }
   }
   hactive.hMARKER.fDrawCaptureMsg();
   gmaps.map.panTo(hactive.hMARKER.getPosition());
   fDebug(htour.Action+":"+this.hCourse.ActiveHole+":"+this.hCourse.ActiveShot);
  }
  catch(e)
  {
   USGMaps.fMsg("Some courses do not have historic scorecard information. "
   +"While we have allowed these courses to be mapped, "
   +"they do not represent accurate hole information."
   +"\n\nAnd we are sorry to say they cannot be shown properly in the tour.");
   htour.Action="Stop";
  }
 }
 gmaps.event.addListener(marker, 'rightclick', function(ev)
 {
  gmaps.map.setZoom(Math.max(3,Math.floor(gmaps.map.getZoom()/8)));
  gmaps.map.panTo(new gmaps.LatLng(marker.hCourse.Latitude,marker.hCourse.Longitude));
 });
 gmaps.event.addListener(marker, 'dblclick', function(ev)
 {
  gmaps.map.setZoom(Math.min(16,gmaps.map.getZoom()*3));
  var latlng=new gmaps.LatLng(marker.hCourse.Latitude,marker.hCourse.Longitude);
  gmaps.map.panTo(latlng);
 });
 gmaps.event.addListener(marker, 'drag', function(ev)
 {
  if(gmaps.infoWindow.Marker==this)
     gmaps.infoWindow.setPosition(ev.latLng);
 });
 gmaps.event.addListener(marker, 'dragend', function(ev)
 {
  if(gmaps.infoWindow.Marker==this)
     gmaps.infoWindow.setPosition(ev.latLng);
  if(gmaps.hMember.fManager(marker.hCourse.CourseID))
  {
   var ans = window.confirm("Should we update the position for this course?");
   marker.bUpdatePosition="";
   if(ans)
    fAjaxCall({url:"/include/USGSave.asp?SaveCourseLL={CourseID:"+marker.hCourse.CourseID+",LL:["+marker.getPosition().lat()+","+marker.getPosition().lng()+"]}"});
  } 
 });
 gmaps.event.addListener(marker, 'click', function(ev)
 {
  var markr=this;
  var gmaps=USGMaps;
  gmaps.fOpenInfoWindow(this);
  var url="/include/USGQuery.asp?Section=Links&CourseID="+marker.hCourse.CourseID;
  fClientServerMsg("Loading "+marker.hCourse.Name);
  fAjaxCall({async:false,url:url,fcallback:function(req)
   {
    try
    {
     fGD("dvCourseTabs").innerHTML=req.responseText;
     window.setTimeout(function()
     {
      fClientServerMsg();
      gmaps.ActiveView.fCourseInfo("HomeCourse",markr.hCourse.CourseID,markr);
      fGD("aZoomToCourse").onclick=function(){gmaps.event.trigger(markr,"dblclick");};
     },2000);
    }
    catch(e)
    {
     USGMaps.fMsg("There was an error initially loading the course information. Please try again.");
    }
   }
  });
 });
 this.fLoadHoleTeeYards=function(gmaps)
 {
  var marker=this;
  var url="/include/USGQuery.asp?CourseGeo={CourseID:"+this.hCourse.CourseID+",Holes:"+this.hCourse.Holes+"}";
  if(marker.hCourse.hHoleTeeYards!=null)
  {
   if(!window.confirm("COURSE GEO INFORMATION IS ALREADY LOADED\n\nDo you want to re-load GEO information?"))
   {
//    fBuildCaptures(marker.hCourse);
    return;
   }
  }
  fClientServerMsg("Unloading Loading Hole Data");
  this.fUnLoadCapture(gmaps);
  fClientServerMsg("Loading Hole Data");

  fAjaxCall({async:false,url:url,fcallback:function(req)
   {
    try
    {
     var hcourse=marker.hCourse;
     var hTeesGeo={};
     if(gmaps.hCourse)
      gmaps.hCourse.fClose(gmaps,1);
     gmaps.hCourse=hcourse;
     gmaps.EditMode=(hcourse._Mapped==0 || gmaps.hMember.fManager(hcourse.CourseID));
     with(hcourse)
     {
      eval(req.responseText);
      fBuildMarkers(gmaps,hTeesGeo);
      fAnimate(gmaps);
      gmaps.infoWindow.close();
     }
    }
    catch(e)
    {
     gmaps.hCourse=null;
     USGMaps.fMsg("There was an error loading the course."
     +"\nIt may be due to transmission latency or it may be more serious."
     +"\nTry again and ... Please notify us if the problem persists."
     +"\nThanks :)"
     );
    }
    fClientServerMsg();
   }
  });
 }
 this.fInfoWindowClosing=function(gmaps)
 {
  if(gmaps.hCourse==null)
   gmaps.HoldEvents=false;
 }; 
 this.fUnLoadCapture=function(gmaps)
 {
  var coursemarker=this;
  this.hCourse.fClose(gmaps);
 }
 this.fCourseClosed=function(gmaps)
 {
  fDebug("fCourseClosed :"+this.hCourse.CourseID);
  fRunCaptures.fBreakDownAll();
  gmaps.HoldEvents=false;
  gmaps.hCourse=null;
 }
 return this;
}
function clsCountMarker(gmaps,hsh)
{
 this.fClearDelete();
 this.hCounts=hsh;
 var markerImage = new gmaps.MarkerImage(hFlagImages["USFlag"],
 null,
 null,new gmaps.Point(30,20),
 new gmaps.Size(Math.ceil(60*Math.min(1.8,hsh.Courses/25)),Math.ceil(40*Math.min(1.8,hsh.Courses/25)))
 );

 var latLng = new gmaps.LatLng(hsh.Latitude,hsh.Longitude);
 this.setOptions({
  position: latLng,
  visible: true,
  draggable: true,
  icon: markerImage,
  zIndex:1,
  title:hsh.Courses + " golf courses in this section."+(this.hCounts.Courses > 200?"":" Rt-Clk to list.")
 });
 this.setMap(gmaps.map);
 var marker=this;
 this.GridBounds=new gmaps.LatLngBounds(new gmaps.LatLng(hsh.hGridBounds.SW.lat,hsh.hGridBounds.SW.lng),new gmaps.LatLng(hsh.hGridBounds.NE.lat,hsh.hGridBounds.NE.lng))
 gmaps.event.addListener(marker, 'click', 
  function(ev)
  {
   gmaps.map.fitBounds(marker.GridBounds);
   gmaps.map.panTo(latLng);
  }
 );
 gmaps.event.addListener(marker, 'rightclick', function(ev)
 {
  view = gmaps.ActiveView;
  var url="/include/USGQuery.asp?InBounds={Grid:{Call:'fAddToList',SW:{y:"+this.hCounts.hGridBounds.SW.lat+",x:"+this.hCounts.hGridBounds.SW.lng+"},NE:{y:"+this.hCounts.hGridBounds.NE.lat+",x:"+this.hCounts.hGridBounds.NE.lng+"}}}";
  if(this.hCounts.Courses > 800)
  {
   USGMaps.fMsg(this.hCounts.Courses+" Courses! That's too many of courses.");
   return;
  }
  if(this.hCounts.Courses > 400)
  {
   if(!window.confirm("That's " +this.hCounts.Courses+" Courses!\nAre you sure?"))
   {
    return;
   }
  }
  fClientServerMsg("Loading "+this.hCounts.Courses+" Courses");

  fCourseList(view,url,marker);
 });
 return this;
} 
function clsHelperPanel(gmaps) 
{
 this._node = document.createElement('div');
 this._node.id = 'dvHelperPanel';
 this._node.index = 100;
 this._node.className="bdr op9 tiny";
 this._node.style.display="none";
 this._node.style.left="1px";
 this._node.style.top="1px";
 this._node.style.width="130px";
 
 this._node.setAttribute("Anchor","{Left:10,Top:-10}");
 gmaps.map.controls[gmaps.ControlPosition.TOP].push(this._node);
 this.setMap(gmaps.map);
 this.draw = function(){};
 this.onRemove=function()
 {
  gmaps.event.clearInstanceListeners(this);
  delete this._node;
 }
 this.aHelperListeners=[];
 this.fClose=function(gmaps)
 {
  for(var l=0;l<this.aHelperListeners.length;l++)
  {
   gmaps.event.removeListener(this.aHelperListeners[l]);
   this.aHelperListeners[l]=null;
  }
  this.aHelperListeners=[];
  this._node.style.display="none";
 }
 this.fAddListeners=function(gmaps,onmove)
 {
  var view=this;
  this.aHelperListeners.push(gmaps.event.addListener(gmaps.map, 'mouseover', function(ev) {view._node.style.display='';}));
  this.aHelperListeners.push(gmaps.event.addListener(gmaps.map, 'mouseout', function(ev) {view._node.style.display='none';}));
  this.aHelperListeners.push(gmaps.event.addListener(gmaps.map, 'mousemove', function(ev) 
  {
   fAnchorPosition(view._node,view.getProjection().fromLatLngToContainerPixel(ev.latLng));
   onmove(ev,view._node); 
  }));
 }
 return this;
}
try
{
 clsUSGMaps.prototype=google.maps;

 clsUSGView.prototype =new clsUSGMaps.prototype.OverlayView();
 clsHelperPanel.prototype = new clsUSGMaps.prototype.OverlayView();

 clsInfoWindow.prototype = new clsUSGMaps.prototype.InfoWindow();

 clsViewCourses.prototype=new clsUSGView()
 function clsViewCourse()//->clsUSGView
 {
 }
 clsViewCourse.prototype=new clsUSGView()
 function clsViewPlacements()//->clsUSGView
 {
 }
 clsViewPlacements.prototype=new clsUSGView()
 function clsViewPlacementsEdit()//->clsUSGView
 {
 }
 clsViewPlacementsEdit.prototype=new clsUSGView()
 function clsView3DPhoto()//->clsUSGView
 {
 }
 clsView3DPhoto.prototype=new clsUSGView()
 function clsView3DPhotoEdit()//->clsUSGView
 {
 }
 clsView3DPhotoEdit.prototype=new clsUSGView()

 clsMarker.prototype = new clsUSGMaps.prototype.Marker()

 clsCourseMarker.prototype = new clsMarker();
 clsCountMarker.prototype = new clsMarker();

 clsCaptureMarker.prototype = new clsMarker();
 clsTeeCaptureMarker.prototype = new clsCaptureMarker();
 clsGreenCaptureMarker.prototype = new clsCaptureMarker();
 clsFairwayCaptureMarker.prototype = new clsCaptureMarker();
 clsApproachCaptureMarker.prototype = new clsCaptureMarker();
 
 clsPolylineOverlay.prototype  = new clsUSGMaps.prototype.Polyline();
 clsPolygonOverlay.prototype  = new clsUSGMaps.prototype.Polygon();
 clsRectangleOverlay.prototype = new clsUSGMaps.prototype.Rectangle();
 clsCircleOverlay.prototype    = new clsUSGMaps.prototype.Circle();
 clsMapTileOverlay.prototype   = new clsUSGMaps.prototype.ImageMapType({});
 clsUSGMaps.prototype.fLoadGroundOverlays=function(cid)
 {
  if(this.ActiveView.hCourseMarkers[String(cid)]&& this.ActiveView.hCourseMarkers[String(cid)].hCourse)
   this.ActiveView.hCourseMarkers[String(cid)].hCourse.fLoadGroundOverlays(this);
  else
   alert("Course has not been loaded");
 }
}
catch(e)
{
 alert("Initialization failure :" + e.description); 
}

