  //generally good code, mess with this as little as possible
//date object initialized with today's date and time  
  var date = new Date();
//this is set by the various onloads for each page
var sailType = 0;
//snorkeling=1, high speed = 3, sunset = 5, hs.htm = 2
  var weekday = new Array(7);
  weekday[0]="Sunday";
  weekday[1]="Monday";
  weekday[2]="Tuesday";
  weekday[3]="Wednesday";
  weekday[4]="Thursday";
  weekday[5]="Friday";
  weekday[6]="Saturday";
  var times = new Array(6);
  times[0] = new Array ("8am", "10:00am", "11am", "1pm", "3pm", "5 or 5:30pm"); //"Any"
  times[1] = new Array("8am");													//"Snorkel TRSSu"
  times[2] = new Array("10:00am");												//"Snorkel MWF"
  times[3] = new Array("11am");													//"High Speed 11AM"
  times[4] = new Array("1pm", "3pm");											//"High Speed 1, 3"
  times[5] = new Array("5 or 5:30pm");											//"Sunset"
  var sailNames = new Array("Any", "Snorkel (Tues. Thurs. Sat. Sun. 8am)", "Snorkel (Monday, Wednesday, Friday 10:00am)", "High Speed (Tues. Thurs. Sat. Sun. 11am)", "High Speed (Every Day 1pm, 3pm)", 		"Sunset (everyday 5 or 5:30pm)");
  var prices = new Array("", "49.21", "49.21", "31.41", "31.41", "40.84");

//runs in onLoad() on highspeed page
  function setup()
  {
	  try
		{
    document.forms[0].month.selectedIndex = date.getMonth();
    //document.forms[0].year.selectedIndex = date.getYear() - 2003;
    document.forms[0].year.selectedIndex = date.getYear() - 2010;
		}
		catch(e) {}
    update();
  }
  
  function updateMonth(month)
  {
    date.setMonth(month-1);
    update();
  }
  function updateYear(year)
  {
    date.setYear(year);
    update();
  }
	
  function updateDate(d)
  {
    date.setDate(d);
    update();
  }
	
	function updateTime(time)
	{
	  update();
	}
//sets a number here in onLoad(), 3 for highspeed sail @ 11, 4 for hs at 1,3
// 1 for snorkle TRS, 2 for snorkle MWF,  5 for sunset, 0 for all sails
	function updateSailType(type)
	{
	  sailType = type;
	  update();
	}
	
	//called when checkSubmit() is run for the final submit, also any time anything changes
  function update()
  {
	  updateSails();
	updateDates();
    updateTimes();
    updateCost();
  }
  
  function updateSails()
  {
    var o = document.forms[0].sailType;
    o.length = 0;
    for(var i = 0; i < sailNames.length; i++)
    {
      o.options[i] = new Option(sailNames[i], i);
    }
	  o.selectedIndex = sailType;
	  document.forms[0].sailName.value = sailNames[o.value];
  }
	
//only ever called by the update() function - designed to arrange a nice ordered list
//containing only the values desired in date/dayofweek pairs
function updateDates()
  {
	//new Date object initialized filling in vars using global var 'date', which changes
	var date2 = new Date(date.getFullYear(), date.getMonth(), date.getDate());
    //get # of days in month, store as integer, this seems to work OK
	var daysInMonth = 32 - new Date(date.getYear(), date.getMonth(), 32).getDate();
	
    //grab form element
	var o = document.forms[0].dateInfo;
	  //grab currently selected form position
	  var x = o.selectedIndex;
	 // alert("o.selectedIndex="+o.selectedIndex);
	//select the first element if nothing has been selected
	  if(x == -1) x = 0;
	//set the length of the list to 0 SUSPECT!!!
    o.length = 0;
    //for each day of the month, do this loop
	for(var i = 1; i <= daysInMonth; i++)
    {
      //set the day of the month of the date object we are using to the day we are working with
	  date2.setDate(i);
		//thisSailType = sailType;
		
//if sail is snorkle
//sets a number here in onLoad() and updateSailType(), 3 for highspeed sail @ 11, 4 for hs at 1,3
// 1 for snorkle TRS, 2 for snorkle MWF,  5 for sunset, 0 for all sails
//alert ("check!");
if(sailType == 1 && date2.getDay() % 2 != 0) continue;
	  //if(sailType == 1 && (date2.getDay() == 0 || date2.getDay() % 2 != 0)) continue;
	  //don't write a option if : sailType is a TRS Snorkel AND (day is Sunday OR day != 1,3,5), seems correct
	 // if(sailType == 2 && (date2.getDay() == 0 || date2.getDay() % 2 == 0)) continue;
	  if(sailType == 2 && date2.getDay() % 2 == 0) continue;
	  //dont write an option if: sailType is a MWF snorkel AND (day is STRS)
	  if(sailType == 3 && date2.getDay() % 2 != 0) continue;
	  //dont write an option if: sailtype is a high speed 11AM AND day is not 1,3,5
	  //ANY EVEN # mod 2 will return 0, so 0, 2, 4, 6 or Sun, Tues, Thur, Sat % 2 == 0, MWF % 2 != 0
	
      var value = i + " " + weekday[date2.getDay()];
      //var value = i + " " + date2.getDay(); //return # instead
      o.options[o.length] = new Option(value, date2.getDate());
    }
	    o.selectedIndex = x;
  
  }
  
  function updateTimes()
  {
    var o = document.forms[0].time;
	  var x = o.selectedIndex;
	  if(x == -1) x = 0;
    o.length = 0;
    for(var i = 0; i < times[sailType].length; i++)
    {
      o.options[i] = new Option(times[sailType][i], times[sailType][i]);
    }
	  o.selectedIndex = x;
  }
	
  function updateCost()
  {
    var qty = document.forms[0].qty;
    var cost = document.forms[0].cost;
    cost.value = qty.value * prices[sailType];
  }
  
//called when page is submitted by hitting the "Next" key
function checkSubmit()
	{
	  update();
    	var cost = document.forms[0].cost;
	  if(cost.value <= 0)
	  {
	    alert("Choose a sail and quantity first");
	    return(false);
	  }	
	  else return(true);
	}
