
function Sponsor(name,street,city,state,zip,phone,lat,lng,distance,link,logo,onMap)
{this.name=name;this.lat=lat;this.lng=lng;this.distance=distance;this.onMap=onMap;this.link=link;this.street=street;this.city=city;this.state=state;this.zip=zip;this.phone=phone;this.logo=logo;}
function findSponsors()
{sponsorOn.length=0;var dist;for(var i=0;i<numSponsors;i++)
{lat1=sponsorList[i].lat;lng1=sponsorList[i].lng;lat2=BaseLocation.lat();lng2=BaseLocation.lng();dist=LatLngDist(lat1,lng1,lat2,lng2);if(dist<sponsorList[i].distance)
{sponsorList[i].onMap=true;var useSponsor=new sponsorOnType(i,dist);sponsorOn.push(useSponsor);}}}
function displaySponsors()
{for(var i=0;i<sponsorMarkers.length;i++){sponsorMarkers[i].setMap(null);}
var pin=0;var sponsorText=new String();for(var j=0;j<sponsorOn.length;j++)
{var i=sponsorOn[j].index;if(sponsorList[i].onMap)
{var markerPosition=new google.maps.LatLng(sponsorList[i].lat,sponsorList[i].lng);pin++;var marker=new google.maps.Marker({position:markerPosition,map:map,draggable:true,icon:sponsorList[i].logo});var flagText=new String();flagText="<a href=\""+sponsorList[i].link+"\" target=\"_blank\">"+sponsorList[i].name+"</a>";flagText+="<br>";flagText+=sponsorList[i].street;flagText+="<br>";flagText+=sponsorList[i].city;flagText+=", ";flagText+=sponsorList[i].state;flagText+=" ";flagText+=sponsorList[i].zip;flagText+="<br>";flagText+=sponsorList[i].phone;flagText+="<br>";attachInstructionText(marker,flagText);sponsorMarkers[pin-1]=marker;if(pin==1)sponsorText+="<h2>RouteLoops Sponsors:</h2>";sponsorText+="<img src='RLimages/iconb"+pin+".png'>";sponsorText+="&nbsp;&nbsp;";sponsorText+="<a href=\"javascript:centerMap(";sponsorText+=markerPosition.lat()+","+markerPosition.lng();sponsorText+=")\">";if(document.getElementById("unitSystem").value==0)
{var d=sponsorOn[j].distance*1000*100/2.54/12/5280;var u="mi";}
else
{var d=sponsorOn[j].distance;var u="km";}
sponsorText+="<img src='"+sponsorList[i].logo+"'>"+"<br>"+sponsorList[i].name;sponsorText+="</a>"+" ("+d.toFixed(1)+u+")"+"<p>";}}
if(sponsorOn.length==0)
{sponsorText+="<h2>RouteLoops Sponsors:</h2>";sponsorText+="<br><br>";sponsorText+="<a href=\"mailto:info@routeloops.com?subject=We would like to sponsor RouteLoops\">";sponsorText+="<h3>";sponsorText+="Click here to <i>become</i> a RouteLoops sponsor for this area.";sponsorText+="</h2>";sponsorText+="</a>";sponsorText+="<p>";sponsorText+="<a href=\"mailto:info@routeloops.com?subject=Suggestion for a RouteLoops sponsor\">";sponsorText+="<h3>";sponsorText+="Click here to <i>suggest</i> a RouteLoops sponsor for this area.";sponsorText+="</h2>";sponsorText+="</a>";sponsorText+="<br>";}}
function sponsorOnType(index,distance)
{this.index=index;this.distance=distance;}
function orderSponsors()
{var holdIndex;var holdDistance;for(var i=0;i<sponsorOn.length;i++)
{for(var j=i+1;j<sponsorOn.length;j++)
{if(sponsorOn[j].distance<sponsorOn[i].distance)
{holdIndex=sponsorOn[i].index;holdDistance=sponsorOn[i].distance;sponsorOn[i].index=sponsorOn[j].index;sponsorOn[i].distance=sponsorOn[j].distance;sponsorOn[j].index=holdIndex;sponsorOn[j].distance=holdDistance;}}}}
function handleSponsors()
{loadSponsors();findSponsors();orderSponsors();displaySponsors();}
