	
	
	function switchInputType(elem){
		// is there a corresponding div with the same ID as the selected value?
		var myDiv			= document.getElementById(elem.value);
		var optionsLength	= elem.length;

		for( var i=0; i<optionsLength; i++ ){
			//alert(elem.options[i].value);
			toggleDiv(elem.options[i].value, 2);
		}
		toggleDiv(elem.value, 1);
	}







	function switchHowHeards(elem){

		// is there a corresponding div with the same ID as the selected value?
		var num		= elem.id.split("_")[1];

		var myDiv			= document.getElementById(elem.value + '_' + num);
		var optionsLength	= elem.length;

		for( var i=0; i<optionsLength; i++ ){
			//alert(elem.options[i].value + '_' + num);
			toggleDiv(elem.options[i].value + '_' + num, 2);
		}
		toggleDiv(elem.value + '_' + num, 1);
	}







	function switchRegType(elemid){
		// is there a corresponding div with the same ID as the selected value?
		var elem			= document.getElementById(elemid);
		var value			= elem.value;
		var optionsLength	= elem.length;
		if( value == 2 ){
			toggleDiv('family', 1);
		}else{
			toggleDiv('family', 2);
		}
	}







	function switchAcknowledgement(value)
	{
		if( value == 1 )
		{
			toggleDiv('AckYes', 1);
		}else if( value == 0 )
		{
			toggleDiv('AckYes', 2);
		}
	}







	function showBikeClubMembers(num){
		for( var i=1; i<=6; i++ ){
			if( i <= num ){
				toggleDiv('member'+i, 1);
			}else{
				toggleDiv('member'+i, 2);
			}
		}
	}





	function auto_fill_kids(elem){
		var srcname = elem.name;
		var tgtname = srcname.substring(6);

		for( var i=0; i<=5; i++ ){
			var target = tgtname + '[' + i + ']';
			if( elem.type == 'select-one' ){
				document.registration_form.elements[target].selectedIndex = elem.selectedIndex;
			}else if( elem.type == 'text' ){
				document.registration_form.elements[target].value = elem.value;
			}
		}
	}





	function check_receipt_eligible(elem, elemid){
		var amount = document.getElementById(elemid).value;
		var value = elem.value;
		if( amount < 15 && value == 'y'){
			alert('Only donations of $25 or more will receive a tax receipt.');
			elem.checked='';
		}
	}




	function numbers_only(val){
		if( val )
		{
			val = strip_dollar(val);
			val = parseInt(val,10);
			if( isNaN(val) )
			{
				val = '';
			}
		}
		return val
	}




	function strip_dollar(val){
		val = val.replace("$",'');
		return val
	}





	function select_option(target,value)
	{
		var elem	= document.getElementById(target);
		var length	= elem.options.length;
alert(length);
/*
		for( var i=0; i<=5; i++ ){
			var target = tgtname + '[' + i + ']';
			if( elem.type == 'select-one' ){
				document.registration_form.elements[target].selectedIndex = elem.selectedIndex;
			}else if( elem.type == 'text' ){
				document.registration_form.elements[target].value = elem.value;
			}
		}
*/
	}





	function toggleDiv(id, type){
		var x = null;
		if (document.getElementById){
			x = document.getElementById(id);
		}else if (document.all){
			x = document.all[id];
		}else if (document.layers){
			x = document.layers[id];
		}
		if (x){
			if (type == 0){
				if (x.style){
					if (x.style.display == 'none'){
						x.style.display = '';
					}else{
						x.style.display = 'none';
					}
				}else{
					x.visibility = 'show';
				}
			}else{
				if (type == 1){
					if (x.style){
						x.style.display = '';
					}else{
						x.visibility = 'show';
					}
				}
				if (type == 2){
					if (x.style){
						x.style.display = 'none';
					}else{
						x.visibility = '';
					}
				}
			}
		}
	}









	function checkSpinningAgeRestriction(ageid, rideselid)
	{
		var age		= document.getElementById(ageid).value;
		var ridesel	= document.getElementById(rideselid).value;
		var bits	= rideselid.split("_");
		var ind		= bits[1];

		if( ridesel != 5 || age >= 14 )
		{
			return true;
		}
		document.getElementById(rideselid).selectedIndex="0";
		toggleDiv('bike_slots_'+ind, 2);

		alert('All riders must be at least 14 years of age to participate in the spinning selection.');
		return false;
	}









	function countBikeSlots(slot)
	{
		var count = 0;
		var container = document.getElementById('bike_slots_'+slot);

		var inputs = container.getElementsByTagName("input"); 
		for(var i = 0; i < inputs.length; i++)
		{ 
			if( inputs[i].type == 'checkbox')
			{
				if( inputs[i].checked == true )
				{
					count++;
				}
			}

		}
		return count;
	}








	function calculateMinDonation(RegType, Adults){
		var MinDonations	= document.getElementById('MinDonation');
		var MinDonValue		= 0;

		// single rider
		if (RegType == '1') {
			var RideSel	= document.getElementById('RideSelectionID');
			var age		= document.getElementById('Age').value;

			if( RideSel.value != 5 )
				toggleDiv('bike_slots_0', 2);

			if( RideSel.value != 6 )
				//toggleDiv('sidekick_info', 2);

			if( RideSel.value == 0 ){
				MinDonValue = 50;
			}else if( RideSel.value == 1 ){
				MinDonValue = 125;
			}else if( RideSel.value == 2 ){
				MinDonValue = 250;
			}else if( RideSel.value == 3 ){
				MinDonValue = 500;
			}else if( RideSel.value == 4 ){
				MinDonValue = 1500;
			}else if( RideSel.value == 5 ){
				// how many hours @ $50 / hour
				toggleDiv('bike_slots_0', 1);
				var slots = countBikeSlots(0);
				MinDonValue = slots*50;
			}
			// if 17 or under override the pledge level with $25
			if( age <= 17 && age != '' )
			{
				MinDonValue = 25;
			}
			if( RideSel.value == 6 )
			{
				MinDonValue = 0;
			}

		// family rider
		}else if(RegType == '2'){
			var ridercount = document.getElementById('RiderCount').value;

			if( ridercount > 0 ){
				Adults = 1;
				for( var i=0; i < ridercount; i++ ){
					var ridesel = document.getElementById('RideSelectionID_' + i).value;
					var age		= document.getElementById('Age_' + i).value;

					if( ridesel == 6 )
					{
						MinDonValue += 0;
					}
					else
					{
						if( ! age ){
							age = 18;
						}
						if( age >= 18 ){
							if( ridesel != 5 ){
								toggleDiv('bike_slots_'+i, 2);
							}
							if( ridesel == 0 ){
								MinDonValue += 50;
							}else if( ridesel == 1 ){
								MinDonValue += 125;
							}else if( ridesel == 2 ){
								MinDonValue += 250;
							}else if( ridesel == 3 ){
								MinDonValue += 500;
							}else if( ridesel == 4 ){
								MinDonValue += 1500;
							}
						}
						else
						{
							MinDonValue += 25;
						}
						if( ridesel == 5 && age >= 14 ){
							// how many hours @ $50 / hour
							var slots = countBikeSlots(i);
							MinDonValue += slots*50;
							toggleDiv('bike_slots_'+i, 1);
						}
					}
				}
			}

		// team rider
		}else if(RegType == '3'){
			var RideSel	= document.getElementById('RideSelectionID');
			var age		= document.getElementById('Age').value;

			if( RideSel.value != 5 ){
				toggleDiv('bike_slots_0', 2);
			}
			if( RideSel.value == 0 ){
				MinDonValue = Adults * 50;
			}else if( RideSel.value == 1 ){
				MinDonValue = Adults * 125;
			}else if( RideSel.value == 2 ){
				MinDonValue = Adults * 250;
			}else if( RideSel.value == 3 ){
				MinDonValue = Adults * 500;
			}else if( RideSel.value == 4 ){
				MinDonValue = Adults * 1500;
			}else if( RideSel.value == 5 ){
				// how many hours @ $50 / hour
				toggleDiv('bike_slots_0', 1);
				var slots = countBikeSlots(0);
				MinDonValue = slots*50;
			}
			// if 17 or under override the pledge level with $25
			if( age <= 17 && age != '' )
			{
				MinDonValue = 25;
			}
			if( RideSel.value == 6 )
			{
				MinDonValue = 0;
			}
		}
		MinDonations.value = MinDonValue;
		return true;
	}






	function calculateTeamRegistrationTotal(){
		// default registration amount for 1 rider
		var Total				= 50;
		// registration total element
		var RegistrationTotal	= document.getElementById('RegistrationTotal');
		var RideSelection		= document.getElementById('RideSelectionID').selectedIndex;

		// is 'captain pays for team' checked?
		for (i=0;i<document.registration_form.TeamPay.length;i++) {
			if (document.registration_form.TeamPay[i].checked) {
				var teamPay = document.registration_form.TeamPay[i].value;
			}
		}
		var teamRiderCount	= document.getElementById('TeamRiderCount').value;

		// is captain paying for team jerseys?
		for (i=0;i<document.registration_form.TeamJerseyPay.length;i++) {
			if (document.registration_form.TeamJerseyPay[i].checked) {
				var teamJerseyPay = document.registration_form.TeamJerseyPay[i].value;
			}
		}
		var teamJerseyCount		= document.getElementById('TeamJerseyCount').value;

		// captain pays
		if( teamPay == 1 ){
			Total = teamRiderCount * 50;
			// captain is paying for some jerseys
			if( teamJerseyPay == 1 )
				Total += teamJerseyCount * 35;
		}
		// if captain is a 'sidekick', registration is $25 not 50 for captain
		if( RideSelection == 6 )
			Total -= 25;
		//alert('calculate team reg\n'+'riders='+teamRiderCount+'\n'+'jerseys='+teamJerseyCount+'\n'+'ride selected='+RideSelection);
		RegistrationTotal.value = Total;
		return true;
	}
