
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 = "";
        }

      }
    }
    
	
	Logic = function()
	{
		// Delegate attending Rail Tour (Click/Unclick)
		if ($("input[name='delegate_activity_rails']").attr("checked"))
		{
			$("input[name='delegate_activity_golf']").attr("checked", "");
			$("input[name='transportation_golf_delegate']").attr("checked", "");
		}
		else
		{
			$("input[name='transportation_rails_delegate']").attr("checked", "");
		}

		// Companion attending Rail Tour (Click/Unclick)
		if ($("input[name='companion_activity_rails']").attr("checked"))
		{
			$("input[name='companion_activity_golf']").attr("checked", "");
			$("input[name='transportation_golf_companion']").attr("checked", "");
		}
		else
		{
			$("input[name='transportation_rails_companion']").attr("checked", "");
		}

		// No transportation required - Rail Tour (Click)
		if ($("input[name='transportation_rails_none']").attr("checked"))
		{
			$("input[name='transportation_rail_tour_delegate']").attr("checked", "");
			$("input[name='transportation_rail_tour_companion']").attr("checked", "");
		}

	}

    Rail_Attending_Delegate_Click = function()
	{
		$("input[name='both_activity_rails']").attr("checked", "");

		$("input[name='delegate_activity_golf']").attr("checked", "");
		$("input[name='transportation_golf_delegate']").attr("checked", "");
		$("input[name='transportation_rail_tour_delegate']").attr("checked", "");
	}

	Rail_Attending_Delegate_Unclick = function()
	{
		$("input[name='transportation_rail_tour_delegate']").attr("checked", "");
	}

	Rail_Attending_Companion_Click = function()
	{
		$("input[name='both_activity_rails']").attr("checked", "");

		$("input[name='companion_activity_golf']").attr("checked", "");
		$("input[name='transportation_golf_companion']").attr("checked", "");
	}

	Rail_Attending_Companion_Unclick = function()
	{
		$("input[name='transportation_rail_tour_companion']").attr("checked", "");
	}

	No_Rails_Click = function()
	{
		$("input[name='delegate_activity_rails']").attr("checked", "");
		$("input[name='companion_activity_rails']").attr("checked", "");

		$("input[name='transportation_rail_tour_none']").attr("checked", "true");
		$("input[name='transportation_rail_tour_delegate']").attr("checked", "");
		$("input[name='transportation_rail_tour_companion']").attr("checked", "");
	}

	// Transportation: Rails
	Transportation_Rails_None_Clicked = function()
	{
		$("input[name='transportation_rail_tour_delegate']").attr("checked", "");
		$("input[name='transportation_rail_tour_companion']").attr("checked", "");
	}

	Transportation_Rails_Delegate_Clicked = function()
	{
		if ($("input[name='transportation_rail_tour_delegate']").attr("checked"))
		{
			$("input[name='transportation_rail_tour_none']").attr("checked", "");
			$("input[name='transportation_golf_delegate']").attr("checked", "");
			$("input[name='delegate_activity_rails']").attr("checked", "true");
			$("input[name='delegate_activity_golf']").attr("checked", "");
			$("input[name='both_activity_rails']").attr("checked", "");
		}
	}

	Transportation_Rails_Companion_Clicked = function()
	{
		if ($("input[name='transportation_rail_tour_companion']").attr("checked"))
		{
			$("input[name='transportation_rail_tour_none']").attr("checked", "");
			$("input[name='transportation_golf_companion']").attr("checked", "");
			$("input[name='companion_activity_rails']").attr("checked", "true");
			$("input[name='companion_activity_golf']").attr("checked", "");
			$("input[name='both_activity_rails']").attr("checked", "");
		}
	}



	






	Golf_Attending_Delegate_Click = function()
	{
		$("input[name='both_activity_golf']").attr("checked", "");

		$("input[name='delegate_activity_rails']").attr("checked", "");
		$("input[name='transportation_rail_tour_delegate']").attr("checked", "");
	}

	Golf_Attending_Delegate_Unclick = function()
	{
		$("input[name='transportation_golf_delegate']").attr("checked", "");
	}

	Golf_Attending_Companion_Click = function()
	{
		$("input[name='both_activity_golf']").attr("checked", "");

		$("input[name='companion_activity_rails']").attr("checked", "");
		$("input[name='transportation_rail_tour_companion']").attr("checked", "");
	}

	Golf_Attending_Companion_Unclick = function()
	{
		$("input[name='transportation_golf_companion']").attr("checked", "");
	}

	No_Golf_Click = function()
	{
		$("input[name='delegate_activity_golf']").attr("checked", "");
		$("input[name='companion_activity_golf']").attr("checked", "");

		$("input[name='transportation_golf_none']").attr("checked", "true");
		$("input[name='transportation_golf_delegate']").attr("checked", "");
		$("input[name='transportation_golf_companion']").attr("checked", "");
	}

	// Transportation: Rails
	Transportation_Golf_None_Clicked = function()
	{
		$("input[name='transportation_golf_delegate']").attr("checked", "");
		$("input[name='transportation_golf_companion']").attr("checked", "");
	}

	Transportation_Golf_Delegate_Clicked = function()
	{
		if ($("input[name='transportation_golf_delegate']").attr("checked"))
		{
			$("input[name='transportation_golf_none']").attr("checked", "");
			$("input[name='transportation_rail_tour_delegate']").attr("checked", "");
			$("input[name='delegate_activity_golf']").attr("checked", "true");
			$("input[name='delegate_activity_rails']").attr("checked", "");
			$("input[name='both_activity_golf']").attr("checked", "");
		}
	}

	Transportation_Golf_Companion_Clicked = function()
	{
		if ($("input[name='transportation_golf_companion']").attr("checked"))
		{
			$("input[name='transportation_golf_none']").attr("checked", "");
			$("input[name='transportation_rail_tour_companion']").attr("checked", "");
			$("input[name='companion_activity_golf']").attr("checked", "true");
			$("input[name='companion_activity_rails']").attr("checked", "");
			$("input[name='both_activity_golf']").attr("checked", "");
		}
	}



















    // 2009 Conference handling //
    $(document).ready(function() {
    
		toggleCompanions(1);
		Logic();
		

		$("input[name='delegate_activity_rails']").click(function()
		{
			if ($(this).attr("checked"))
				Rail_Attending_Delegate_Click();
			else
				Rail_Attending_Delegate_Unclick();
		});
		$("input[name='companion_activity_rails']").click(function()
		{
			if ($(this).attr("checked"))
				Rail_Attending_Companion_Click();
			else
				Rail_Attending_Companion_Unclick();
		});	
		$("input[name='both_activity_rails']").click(function()
		{
			if ($(this).attr("checked"))
				No_Rails_Click();
		});
			
		// Golf transportation
		$("input[name='transportation_golf_none']").click(function()
		{
			Transportation_Golf_None_Clicked();
		});

		$("input[name='transportation_golf_delegate']").click(function()
		{
			Transportation_Golf_Delegate_Clicked();
		});

		$("input[name='transportation_golf_companion']").click(function()
		{
			Transportation_Golf_Companion_Clicked();
		});

		


		$("input[name='delegate_activity_golf']").click(function()
		{
			if ($(this).attr("checked"))
				Golf_Attending_Delegate_Click();
			else
				Golf_Attending_Delegate_Unclick();
		});
		$("input[name='companion_activity_golf']").click(function()
		{
			if ($(this).attr("checked"))
				Golf_Attending_Companion_Click();
			else
				Golf_Attending_Companion_Unclick();
		});
		$("input[name='both_activity_golf']").click(function()
		{
			if ($(this).attr("checked"))
				No_Golf_Click();
		});


		// Rail Tour transportation
		$("input[name='transportation_rail_tour_none']").click(function()
		{
			Transportation_Rails_None_Clicked();
		});

		$("input[name='transportation_rail_tour_delegate']").click(function()
		{

			Transportation_Rails_Delegate_Clicked();
		});

		$("input[name='transportation_rail_tour_companion']").click(function()
		{
			Transportation_Rails_Companion_Clicked();
		});

		













		
		// Selecting the Hacienda activity for a companion will cancel their conference lunch
		$("input[name='companion_hacienda']").click(function() {
			if ($(this).attr("checked"))
			{

				if ($("input[name='wednesday_lunch_companion']").attr("checked"))
				{
					alert("Lunch is provided at this event in the form of local cheeses and wine. " +
							"Your companion's conference lunch for wednesday has been unselected.");
				}
				
				$("input[name='wednesday_lunch_companion']").attr("checked", "");
				$("input[name='wednesday_lunch_companion']").attr("disabled", "disabled");
			
			
			}
			else
			{
				$("input[name='wednesday_lunch_companion']").attr("disabled", "");
			}
		});
    
		$("input[name='companion_sun_peaks']").click(function() {
			if ($(this).attr("checked"))
			{
				if ($("input[name='thursday_lunch_companion']").attr("checked"))
				{
					alert("Lunch at a local restaurant is included with this event . " +
							"Your companion's conference lunch for thursday has been unselected.");
				}
							
				$("input[name='thursday_lunch_companion']").attr("checked", "");	
				$("input[name='thursday_lunch_companion']").attr("disabled", "disabled");
			}
			else
			{
				$("input[name='thursday_lunch_companion']").attr("disabled", "");
			}
		});
});