
function getElementsByClassName(clsName) {
       var i, matches=new Array();
       var els=document.getElementsByTagName('*');

       for(i=0; i<els.length; i++) {
          if(els.item(i).className==clsName) {
             matches.push(els.item(i));
          }
       }
       return matches;
    }

/*    function toggleCompanions(yayOrNay) {
      var companionInputs = getElementsByClassName('companionInput');

      for(i=0; i < companionInputs.length; i++) 
      {
        if (yayOrNay == 0) 
        {
          companionInputs[i].checked = "";
          companionInputs[i].disabled = "disabled";
        }
        if (yayOrNay == 1) 
        {
          companionInputs[i].disabled = "";
        }

      }
    }
*/
    function toggleCompanionTour() {
      var companionTour = document.getElementsByName('companion_bee_orchard_glass')[0];
      var companionWedLunch = document.getElementsByName('wednesday_lunch_companion')[0];
	  if (companionTour.checked)
        {
          companionWedLunch.disabled = "true";
        }
	  else
        {
          companionWedLunch.disabled = "";
        }
	  if (companionWedLunch.checked)
        {
          companionTour.disabled = "true";
        }
	  else
        {
          companionTour.disabled = "";
        }

      var companionTour = document.getElementsByName('companion_spa')[0];
      var companionWedLunch = document.getElementsByName('thursday_lunch_companion')[0];
	  if (companionTour.checked)
        {
          companionWedLunch.disabled = "true";
        }
	  else
        {
          companionWedLunch.disabled = "";
        }
	  if (companionWedLunch.checked)
        {
          companionTour.disabled = "true";
        }
	  else
        {
          companionTour.disabled = "";
        }
    }
    
    function toggleGolfTour() {
      var delegateGolf = document.getElementsByName('delegate_activity_golf')[0];
      var companionGolf = document.getElementsByName('companion_activity_golf')[0];
      var delegateTour = document.getElementsByName('delegate_activity_tour')[0];
      var companionTour = document.getElementsByName('companion_activity_tour')[0];
      var companionTourLunch = document.getElementsByName('companion_tour_lunch');
      var delegateTourLunch = document.getElementsByName('delegate_tour_lunch');
	  var has_companion =  document.getElementsByName('has_companion')[0];
	  if (delegateGolf.checked)
        {
          delegateTour.disabled = "true";
          delegateTourLunch[0].disabled = "true";
          delegateTourLunch[1].disabled = "true";
          delegateTourLunch[2].disabled = "true";
          delegateTourLunch[3].disabled = "true";
          delegateTourLunch[0].checked = "";
          delegateTourLunch[1].checked = "";
          delegateTourLunch[2].checked = "";
          delegateTourLunch[3].checked = "";
        }
	  else
        {
          delegateTour.disabled = "";
        }
	  if (delegateTour.checked)
        {
          delegateGolf.disabled = "true";
          delegateTourLunch[0].disabled = "";
          delegateTourLunch[1].disabled = "";
          delegateTourLunch[2].disabled = "";
          delegateTourLunch[3].disabled = "";
		  
        }
	  else
        {
          delegateGolf.disabled = "";
          delegateTourLunch[0].disabled = "true";
          delegateTourLunch[1].disabled = "true";
          delegateTourLunch[2].disabled = "true";
          delegateTourLunch[3].disabled = "true";
        }
		
		if (has_companion.checked) {
			if (companionGolf.checked)
				{
				companionTour.disabled = "true";
				companionTourLunch[0].disabled = "true";
				companionTourLunch[1].disabled = "true";
				companionTourLunch[2].disabled = "true";
				companionTourLunch[3].disabled = "true";
				companionTourLunch[0].checked = "";
				companionTourLunch[1].checked = "";
				companionTourLunch[2].checked = "";
				companionTourLunch[3].checked = "";
				}
			else {
				companionTour.disabled = "";
			}
			if (companionTour.checked)
				{
				companionGolf.disabled = "true";
				companionTourLunch[0].disabled = "";
				companionTourLunch[1].disabled = "";
				companionTourLunch[2].disabled = "";
				companionTourLunch[3].disabled = "";
				}
			else
				{
				companionGolf.disabled = "";
				companionTourLunch[0].disabled = "true";
				companionTourLunch[1].disabled = "true";
				companionTourLunch[2].disabled = "true";
				companionTourLunch[3].disabled = "true";
				}
		}
    }

    function toggleRides() {
      var tour = document.getElementsByName('transportation_tour');
      var golf = document.getElementsByName('transportation_golf');
		
   if (tour[2].checked && golf[2].checked)
      {
			alert ("Please ensure transportation is arranged for the appropriate attendees and events. Currently there are rides arranged for both attendees to both events. Transportation settings have been reset for both events.");
			golf[0].checked="checked";
			tour[0].checked="checked";
      }
   if (tour[2].checked && golf[1].checked)
      {
			alert ("Please ensure transportation is arranged for the appropriate attendees and events. Currently there are two rides arranged for the tour and one ride for golf. Golf transportation settings have been reset.");
			golf[0].checked="checked";
      }
   if (tour[1].checked && golf[2].checked)
      {
			alert ("Please ensure transportation is arranged for the appropriate attendees and events. Currently there are two rides arranged for golf and one ride for the tour. Tour transportation settings have been reset.");
			tour[0].checked="checked";
      }
    }

    function toggleCompanions(yayOrNay) {
	  var companionInputs = getElementsByClassName('companionInput');
      var companionFirstName = document.getElementById('companion_firstname');
      var companionLastName = document.getElementById('companion_lastname');
      for(i=0; i < companionInputs.length; i++) 
      {
        if (yayOrNay == 0) 
        {
          companionInputs[i].checked = "";
          companionInputs[i].disabled = "disabled";
          companionFirstName.value = '';
          companionLastName.value = '';
          companionFirstName.disabled = "disabled";
          companionLastName.disabled = "disabled";
		  disableCompanionLunchOptions();
        }
        if (yayOrNay == 1) 
        {
          companionInputs[i].disabled = "";
          companionFirstName.disabled = "";
          companionLastName.disabled = "";
        }

      }
    }
	function disableCompanionLunchOptions() {
      var companionTourLunch = document.getElementsByName('companion_tour_lunch');
		companionTourLunch[0].disabled = "true";
		companionTourLunch[1].disabled = "true";
		companionTourLunch[2].disabled = "true";
		companionTourLunch[3].disabled = "true";
//		companionTourLunch[0].checked = "";
//		companionTourLunch[1].checked = "";
//		companionTourLunch[2].checked = "";
//		companionTourLunch[3].checked = "";
	}

	function disableDelegateLunchOptions() {
      var delegateTourLunch = document.getElementsByName('delegate_tour_lunch');
        delegateTourLunch[0].disabled = "true";
        delegateTourLunch[1].disabled = "true";
        delegateTourLunch[2].disabled = "true";
        delegateTourLunch[3].disabled = "true";

	}
    

	function prestate() {
/*      var delegateTour = document.getElementsByName('delegate_activity_tour');
	  //alert(delegateTour[0].checked);
	  if (delegateTour[0].checked) {
		var delegateTourLunch = document.getElementsByName('delegate_tour_lunch');
		delegateTourLunch[0].disabled = "";
		delegateTourLunch[1].disabled = "";
		delegateTourLunch[2].disabled = "";
		delegateTourLunch[3].disabled = "";
		}
*/
		toggleGolfTour();
		toggleCompanionTour();
	}


    // 2009 Conference handling //
    $(document).ready(function() {
    
		toggleCompanions(0);
		disableCompanionLunchOptions();
		disableDelegateLunchOptions();
		prestate();
//		Logic();
		


});