/*
	Javascript stuff custom for Striders content
*/

function newsletters_doYearChange( theSelect )
{
	for( x=0; x<theSelect.length; x++ )
	{
		var tgtObj = eval( 'document.getElementById("' + theSelect[x].value + '")' );

		if( theSelect.selectedIndex == x )
			tgtObj.style.display = "block";
		else
			tgtObj.style.display = "none";
	}

}

function contact_doFormChange( theSelect )
{
	if( theSelect.selectedIndex == 0 )
	{
		for( x=1; x<theSelect.length; x++ )
		{
			var tgtObj = eval( 'document.getElementById("' + theSelect[x].value + '")' );
			tgtObj.style.display = "none";
		}
		
		return;
	}

	for( x=1; x<theSelect.length; x++ )
	{
		var tgtObj = eval( 'document.getElementById("' + theSelect[x].value + '")' );

		if( theSelect.selectedIndex == x )
			tgtObj.style.display = "block";
		else
			tgtObj.style.display = "none";
	}

}

function checkStriderForm( tf )
{
	var formID = tf.formID.value;
	if( formID == 'resource_request' )
	{
		var allRequired = document.getElementsByClassName( 'required' );
		var allLabels   = document.getElementsByTagName( 'label' );
		for( x=0; x<allRequired.length; x++ )
		{
			if( allRequired[x].value == "" )
			{
				var elementName = "[NOLABEL]";
				for( y=0; y<allLabels.length; y++ )
				{
					if( allLabels[y].htmlFor == allRequired[x].id )
					{
						elementName = allLabels[y].innerHTML;
						break;
					}
				}
				
				alert( elementName + ' is a required field' );
				allRequired[x].focus();
				
				return( false );
			}
		}
		
		if( tf.orgPurposeAndMission.value == "" )
		{
			alert( 'Please tell us a bit about your organization and its purpose/mission' );
			tf.orgPurposeAndMission.focus();
			
			return( false );
		}

		if( tf.resourceRequest.value == "" )
		{
			alert( 'Please provide details about your specific request' );
			tf.resourceRequest.focus();
			
			return( false );
		}
		
		if( tf.reqForSpecificEvent.checked )
		{
			if( tf.specificEventDetails.value == "" )
			{
				alert( 'Please detail the date, time, place and purpose of the event' );
				tf.specificEventDetails.focus();
				
				return( false );
			}
		}

		return( true );
	}

	if( formID == 'track_availability' )
	{
		var allRequired = document.getElementsByClassName( 'ta_required' );
		var allLabels   = document.getElementsByTagName( 'label' );
		for( x=0; x<allRequired.length; x++ )
		{
			if( allRequired[x].value == "" )
			{
				var elementName = "[NOLABEL]";
				for( y=0; y<allLabels.length; y++ )
				{
					if( allLabels[y].htmlFor == allRequired[x].id )
					{
						elementName = allLabels[y].innerHTML;
						break;
					}
				}
				
				alert( elementName + ' is a required field' );
				allRequired[x].focus();
				
				return( false );
			}
		}

		var answered_haveATrack = false;
		var hasATrack;

		for( x=0; x<tf.haveATrack.length; x++ )
		{
			if( tf.haveATrack[x].checked )
			{
				answered_haveATrack = true;
				hasATrack = tf.haveATrack[x].value;
				
				break;
			}
		}
		
		if( answered_haveATrack == false )
		{
			alert( 'Please answer the question "Do you have a track?"' );
			return( false );
		}
		
		if( hasATrack == "yes" )
		{
			var answered_openToPublic = false;
			var openToPublic;
	
			for( x=0; x<tf.openToPublic.length; x++ )
			{
				if( tf.openToPublic[x].checked )
				{
					answered_openToPublic = true;
					openToPublic = tf.openToPublic[x].value;
					
					break;
				}
			}
			
			if( answered_openToPublic == false )
			{
				alert( 'Please answer the question "Is the track open to the plubic?"' );
				return( false );
			}
		
			if( openToPublic == "yes" )
			{
				if( tf.trackHours.value == "" )
				{
					alert( 'Please detail what hours your track is available' );
					tf.trackHours.focus();
					
					return( false );
				}
				
				if( tf.specialRules.value == "" )
				{
					alert( 'Please detail what rules you would like followed on your track' );
					tf.specialRules.focus();
					
					return( false );
				}
				
				if( tf.trackAddress.value == "" )
				{
					alert( 'Please provide an address for your track' );
					tf.trackAddress.focus();
					
					return( false );
				}
			}
		}
		
		return( true );
	}
	
	return( false );
}
