﻿// JScript File
var sailingClubs = new clubs();

function club(objectName,regattaName,radioButtonID,imageFileName,fleetNumber,latitude,longitude,clubName,streetAddress,
					cityStateZip,url,contact,phone,email,weatherCode) 
{
	this.objectName = objectName;
	this.regattaName = regattaName;
	this.imageLocation = "images/Page_Regatta/"+imageFileName;
	this.radioButtonID = "ctl00_MainContentPlaceHolder_"+radioButtonID;
	this.latitude = latitude;
	this.longitude = longitude;
	this.clubName = clubName;
	this.fleetNumber = fleetNumber;
	this.streetAddress = streetAddress;
	this.cityStateZip = cityStateZip;
	this.url = url;
	this.contact = contact;
	this.phone = phone;
	this.email = email;
	this.weatherChannelLink = 'http://www.weather.com/weather/local/'+weatherCode;
	this.yahooWeatherLink = 'http://weather.yahoo.com/forecast/'+weatherCode+'.html';
}

function clubs()
{
	this.AtlantaYachtClub = new club("sailingClubs.AtlantaYachtClub","Atlanta Invitational Regatta and Beers Regatta","radioButtonAtlantaYachtClub",
		"markerA.png",1,34.1502,-84.6675,"Atlanta Yacht Club","7120 Yacht Club Dr","Acworth, GA 30102","http://www.atlantayachtclub.org","Carlin Hodges",
		"478-836-9130","sailingvet@aol.com","USGA0028");
	
	this.BloomingtonYachtClub = new club("sailingClubs.BloomingtonYachtClub","Lake Lemon Regatta","radioButtonBloomingtonYachtClub",
		"markerB.png",13,39.2518,-86.3949,"Bloomington Yacht Club","8933 E South Shore Dr","Unionville, IN 47468","http://www.bloomingtonyachtclub.org/","Doug Kinzer",
		"812-876-3531","evenkeely@juno.com","USIN0046");

	this.CarlyleSailingAssociation = new club("sailingClubs.CarlyleSailingAssociation","Beer & Boats Regatta and Whale of a Sail","radioButtonCarlyleSailingAssociation",
		"markerC.png",56,38.6598,-89.2969,"Carlyle Sailing Association","","Carlyle Lake, IL","http://www.csa-sailing.org/","Jack Klug",
		"314-838-9309","jackklub@sbcglobal.net","USIL0188");
	
	this.CharlestonYachtClub = new club("sailingClubs.CharlestonYachtClub","","radioButtonCharlestonYachtClub",
		"markerD.png",10,32.7781,-79.9497,"Charleston Yacht Club","17 Lockwood Dr","Charleston, SC  29401","http://www.charlestonyachtclub.com/","Bill Hanckel",
		"843-766-2469","whanckel@aol.com","USSC0051");
	
	this.ChippewaYachtClub = new club("sailingClubs.ChippewaYachtClub","Midsummer Madness Regatta","radioButtonChippewaYachtClub",
		"markerE.png",4,41.0665,-81.9106,"Chippewa Yacht Club","105 Euclid Ave","Chippewa Lake, OH 44215","",
		"Ivan Baker","330-722-3600","ibaker@neo.rr.com","USOH0582");
	
	this.ClintonLake = new club("sailingClubs.ClintonLake","","radioButtonClintonLake",
		"markerF.png",19,38.9167,-95.3806,"Clinton Lake","","Lawrence, KS 66049-9048","","Ed Bigus",
		"913-856-9953","biguslaw@aol.com","USKS0298");
	
	this.ColumbiaSailingClub = new club("sailingClubs.ColumbiaSailingClub","","radioButtonColumbiaSailingClub",
		"markerG.png",16,34.0697,-81.3661,"Columbia Sailing Club","","Lake Murray, Columbia, SC","http://www.columbiasailingclub.org/","Johnny Dotterer",
		"803 254-7942","rdotterer@sc.rr.com","USSC0065");
	
	this.CorinthianSailingClub = new club("sailingClubs.CorinthianSailingClub","Texas State Fair Regatta","radioButtonCorinthianSailingClub",
		"markerH.png",24,32.8352,-96.7188,"Corinthian Sailing Club","441 E. Lawther Drive","Dallas, Texas  75218","http://www.cscsailing.org/","Ralph Capen",
		"972-669-0010","recapen@earthlink.net","USTX0327");
		
	this.CreveCoeurSailingAssociation = new club("sailingClubs.CreveCoeurSailingAssociation","","radioButtonCreveCoeurSailingAssociation",
		"markerI.png",59,38.7174,-90.4889,"Creve Coeur Sailing Association","14700 Whitebrook Dr","Chesterfield, MO 63017-2400","http://www.co.st-louis.mo.us/parks/creve.html",
		"Jeff Adkins","636-939-6379","ljadkins@hotmail.com","USMO0170");
	
	this.GrandMaumelleSailingClub = new club("sailingClubs.GrandMaumelleSailingClub","Hawg Wild Regatta","radioButtonGrandMaumelle",
		"markerJ.png",30,34.8826,-92.5543,"Grand Maumelle Sailing Club","","Lake Maumelle, AR","http://www.gmsc.org","Drew Daugherty",
		"501-224-8951","adaugherty224@comcast.net","USAR0336");
		
	this.HuestonSailingAssociation = new club("sailingClubs.HuestonSailingAssociation","Redskin Regatta","radioButtonHuestonSailingAssociation",
		"markerK.png",25,39.5784,-84.7520,"Hueston Sailing Association","","Acton Lake, OH","http://members.aol.com/hsasailing/hsa/","Jerry Callahan",
		"513-988-6747 (Winter-941-758-7816)","aftermath2@juno.com","USOH0744");
	
	this.IndianapolisSailingClub = new club("sailingClubs.IndianapolisSailingClub","Indy-Outty Regatta","radioButtonIndianapolisSailingClub",
		"markerL.png",8,39.9224,-85.9570,"Indianapolis Sailing Club","11325 Fall Creek Rd","Indianapolis, IN 46256","http://www.indianapolissailing.org/yflyer.shtml","Howard Roeschlein",
		"317-826-3955","roeschleinh@hurco.com","USIN0305");
	
	this.LakeLashawaySailingClub = new club("sailingClubs.LakeLashawaySailingClub","Kenyon Cup Regatta","radioButtonLakeLashawaySailingClub",
		"markerM.png",53,42.2372,-72.0449,"Lake Lashaway Sailing Club","Shore Road","North Brookfield, MA 01535","http://webpages.charter.net/cathysailsyflyers/index.html",
		"Jack Nash","508-867-7670","","USMA0287");
	
	this.LakeMattoonSailingAssociation = new club("sailingClubs.LakeMattoonSailingAssociation","Riviera Regatta and Bed & Breakfast Regatta","radioButtonLakeMattoonSailingAssociation",
		"markerN.png",39,39.3630,-88.4640,"Lake Mattoon Sailing Association","RR 1 Box 226C","Neoga, IL 62447-9615","","David Irons",
		"217-895-2458","dirons@mcleodusa.net","USIL0835");
	
	this.LakeNormanYachtClub = new club("sailingClubs.LakeNormanYachtClub","Midwinter Championships","radioButtonLakeNormanYachtClub",
		"markerO.png",21,35.5456,-80.9335,"Lake Norman Yacht Club","","Mooresville, NC 28117 ","http://www.lakenormanyachtclub.com/","Merrill Callen",
		"704-664-2770","mbcallen@msn.com","USNC0121");
	
	this.LouisvilleSailingClub = new club("sailingClubs.LouisvilleSailingClub","","radioButtonLouisvilleSailingClub",
		"markerP.png",12,38.3543,-85.6314,"Louisville Sailing Club","7300 Beechland Beach Rd","Prospect, KY  40059","http://saillouisville.org/lsc/","Pat Passafume",
		"502-671-7982","jibsaill@bellsouth.net","USKY1096");
	
	this.SudburyYachtClub = new club("sailingClubs.SudburyYachtClub","","radioButtonSudburyYachtClub",
		"markerQ.png",12,46.4723,-80.9925,"Sudbury Yacht Club","","Sudbury ON P3E 4N5","http://syclub.com","",
		"705-522-2666","commodore@syclub.com","CAXX0482");
		
	this.HarborIslandYachtClub = new club("sailingClubs.HarborIslandYachtClub","Tennesean Regatta","radioButtonHarborIslandYachtClub",
		"markerR.png",12,36.2541,-86.5674,"Harbor Island Yacht Club","272 Harbor Drive","Old Hickory, Tennessee, 37138","http://www.hiyc.org","Marian Maxwell",
		"615-754-9116","newmember@hiyc.org","USTN0376");
  
}

//<![CDATA[
function InitializeRegattaClubsPage() 
{
	pictureTimer();
	
	if (GBrowserIsCompatible()) 
	{
		var map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new GLatLng(40,-95), 4);
		
		//show up|down|left|right  Zoom in|zoom out
		map.addControl(new GSmallMapControl());  	 
		
		//shows types  Map|Satellite|Hybrid
      //map.addControl(new GMapTypeControl());   
      
		map.addOverlay(newMarker(map,sailingClubs.GrandMaumelleSailingClub));
		map.addOverlay(newMarker(map,sailingClubs.AtlantaYachtClub));
		map.addOverlay(newMarker(map,sailingClubs.CarlyleSailingAssociation));
		map.addOverlay(newMarker(map,sailingClubs.LakeMattoonSailingAssociation));
		map.addOverlay(newMarker(map,sailingClubs.BloomingtonYachtClub));
		map.addOverlay(newMarker(map,sailingClubs.IndianapolisSailingClub));
		map.addOverlay(newMarker(map,sailingClubs.ClintonLake));
		map.addOverlay(newMarker(map,sailingClubs.LouisvilleSailingClub));
		map.addOverlay(newMarker(map,sailingClubs.LakeLashawaySailingClub));
		map.addOverlay(newMarker(map,sailingClubs.CreveCoeurSailingAssociation));
		map.addOverlay(newMarker(map,sailingClubs.ChippewaYachtClub));
		map.addOverlay(newMarker(map,sailingClubs.HuestonSailingAssociation));
		map.addOverlay(newMarker(map,sailingClubs.LakeNormanYachtClub));
		map.addOverlay(newMarker(map,sailingClubs.CharlestonYachtClub));
		map.addOverlay(newMarker(map,sailingClubs.ColumbiaSailingClub));
		map.addOverlay(newMarker(map,sailingClubs.CorinthianSailingClub));
		map.addOverlay(newMarker(map,sailingClubs.SudburyYachtClub));
		map.addOverlay(newMarker(map,sailingClubs.HarborIslandYachtClub));
  }
	var cell = document.getElementById('tdClubDetail').innerHTML = '';
	
}

function newMarker(map,sailingClub)
{
	var newIcon = new GIcon(G_DEFAULT_ICON);
   newIcon.image = sailingClub.imageLocation; //file location of image
	
	//create latitude/longitude instance
	var latlong = new GLatLng(sailingClub.latitude,sailingClub.longitude);
   
   //create marker options that hold the icon
	markerOptions = {title:sailingClub.clubName, icon:newIcon };
	//create new marker with latitude/longitude and icon
	var marker = new GMarker(latlong,markerOptions);

	//add click event to marker that will popup a window
  GEvent.addListener(marker,"click", function(){zoomToClub(sailingClub,11);});
	
	return marker;
}

function zoomToClub(club,zoomLevel)
{
	if (GBrowserIsCompatible()) 
	{
		var map = new GMap2(document.getElementById("map_canvas"));

		//show up|down|left|right  Zoom in|zoom out
		map.addControl(new GSmallMapControl());  	 

		if (club != null)
		{
			var radioButton = document.getElementById(club.radioButtonID);
			if (radioButton != null)
				radioButton.checked = true;

			var latlong = new GLatLng(club.latitude,club.longitude)
			map.setCenter(latlong, zoomLevel);
			map.addOverlay(newMarker(map,club));
			//map.openInfoWindowHtml(latlong, club.divHtml);
			
			//club address, fleet number and url
			var html = createClubInfoDiv(club,true);
			var cell = document.getElementById('tdClubDetail');
			cell.innerHTML = html;
		}
	}
}

function createClubInfoDiv(club,createDirectionsTable)
{
	var address = club.streetAddress;
	if (address != '')
		address += '<br/>';
	address += club.cityStateZip;
	
	var toAddress = club.streetAddress;
	if (toAddress.length > 0)
		toAddress += ', ';
	toAddress += club.cityStateZip;
	
	var widthPercent = "99%";
	
	var cellPrint = '&nbsp;';
	if (!createDirectionsTable)
	{
		cellPrint = '<A class="Function" id="aPrintDocument" title="Print Candidate" href="javascript:window.print();" style="color:Blue" runat="server">'+
				'<IMG src="images/print_icon_small.gif" border="0"><u style="font-size:small"> Print Document </u>'+
				'</A><br/><font size="2pt">(Under the terms and conditions of using the google map API on our site, ' + 
				'the map portion of the direction will not print.  For you to be able '+
				'to print the map, you have to go to <a href="#" onclick="window.open(\'http://maps.google.com/maps\');">'+
				'www.google.com/maps</a>';
		widthPercent = "50%";
	}

	var html = '<div style=" background-color:#FFEEDD; border-style:groove; border-width:1px;padding-left:5px;"><br />'+
						'<table width="100%">'+
						'	<tr>'+
						'		<td width="'+widthPercent+'"><b>'+club.clubName+'</b><br />'+
								address+'<br /><br />'+
								'Regatta: <font color="maroon">'+club.regattaName+'</font><br />'+
								'Fleet #: <font color="maroon">'+club.fleetNumber+'</font><br />'+
								'Contact: <font color="maroon">'+club.contact+'</font><br />'+
								'Phone: <font color="maroon">'+club.phone+'</font><br />'+
								'Email: <a href="mailto:'+club.email+'">'+club.email+'</a><br />'+
								'URL: <a href="#" onclick="window.open(\''+club.url+'\')\">'+club.url+'</a><br /><br />'+
								'Weather Links:   <a href="#" onclick="window.open(\''+club.weatherChannelLink+'\')\">Weather Channel</a>&nbsp;'+
								'						<a href="#" onclick="window.open(\''+club.yahooWeatherLink+'\')\">Yahoo Weather</a>'+
								'</td>'+
								'<td valign="top" align="left">'+cellPrint+'</td>'+
							'</tr>'+
						'</table>';
								
	//show 'from' and 'to' textboxes
	if (createDirectionsTable)
	{
		html +=	'<br /><br />'+
						'<table id="tableDirections" width="100%">'+
						'<tr>'+
						'<td align="center" colspan="2" style="background-color:Scrollbar;color:Maroon; font-weight:bold;">Directions</td>'+
						'</tr>'+
						'<tr>'+
						'<td align="right" style="width:10%;">From:</td>'+
						'<td><input type="text" id="textBoxFrom" maxlength="75" size="50" /></td>'+
						'</tr>'+
						'<tr>'+
						'<td align="right" >To:</td>'+
						'<td><input type="text" id="textBoxTo" maxlength="75" size="50" value="'+toAddress+'"/></td>'+
						'</tr>'+
						'<tr>'+
						'<td align="center" colspan="2"><input type="button" onclick="showDirectionPage('+club.objectName+
							',document.getElementById(\'textBoxFrom\').value,document.getElementById(\'textBoxTo\').value)" value="Get Directions" /></td>'+
						'</tr>'+
						'</table>';
	}
	html += '</div>';
							
	return html;
}

function showDirectionPage(club,fromAddress,toAddress)
{
	window.open('RegattaSchedule_ClubDirections.aspx?p1='+club.objectName+'&p2='+fromAddress+'&p3='+toAddress);
}

//used for RegattaSchedule_ClubDirections page
function getDirections(club,fromAddress,toAddress)
{		
	if (GBrowserIsCompatible()) 
	{
		var map = new GMap2(document.getElementById("divMapCanvas"));
		//show up|down|left|right  Zoom in|zoom out
		map.addControl(new GSmallMapControl());  	 
		
    gdir = new GDirections(map, document.getElementById("divDirections"));
    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", handleErrors);
		gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": "en_US"});
		
		document.getElementById("divClubInfo").innerHTML = createClubInfoDiv(club,false);
  }
}

function onGDirectionsLoad()
{ 
	// Use this function to access information about the latest load()
  // results.

  // e.g.
  // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	// and yada yada yada...
}

    
function handleErrors()
{
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
   
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
     
   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
    
   else alert("An unknown error occurred.");
}


//]]>
