var bValidForm = true;

function IsNumeric(sText)

{
	var anum=/\d/;
   	return anum.test($(sText).value);
}


function checkNumField(sID)
{	
	if( !IsNumeric(sID) && ($(sID).value != ' ') && ($(sID).value != '') )
	{
		setElementClass( $(sID), 'alertInput' );
		bValidForm = false;
	}
	else
	{
		removeElementClass( $(sID), 'alertInput' );
	}
	
}


function checkForm()
{
	bValidForm = true;
	
	// #########################################################################
	// PHASE 1 - Check basic information.
	// #########################################################################
	if( ($("URegistrantType").value != 'teacher') && ($("URegistrantType").value != 'student') )
	{
		setElementClass( $('URegistrantTypeLabel'), 'alertLabel' );
		bValidForm = false;
	}
	else
	{
		removeElementClass( $('URegistrantTypeLabel'), 'alertLabel' );
	}
	
	if( $('UFirstName').value == '' )
	{
		setElementClass( $('UFirstName'), 'alertInput' );
		bValidForm = false;
	}
	else
	{
		removeElementClass( $('UFirstName'), 'alertInput' );
	}
	
	if( $('ULastName').value == '' )
	{
		setElementClass( $('ULastName'), 'alertInput' );
		bValidForm = false;
	}
	else
	{
		removeElementClass( $('ULastName'), 'alertInput' );
	}
	
	if( $('USchool').value == '' )
	{
		setElementClass( $('USchool'), 'alertInput' );
		bValidForm = false;
	}
	else
	{
		removeElementClass( $('USchool'), 'alertInput' );
	}
	
	if( $('UEmail').value == '' )
	{
		setElementClass( $('UEmail'), 'alertInput' );
		bValidForm = false;
	}
	else
	{
		removeElementClass( $('UEmail'), 'alertInput' );
	}
	
	if( ($("URegistrantType").value == 'student') && ($('UEmergencyPhone').value == ''))
	{
		setElementClass( $('UEmergencyPhone'), 'alertInput' );
		bValidForm = false;
	}
	else
	{
		removeElementClass( $('UEmergencyPhone'), 'alertInput' );
	}
	
	if( ($("URegistrantType").value == 'student') && ($('UScienceTeacher').value == ''))
	{
		setElementClass( $('UScienceTeacher'), 'alertInput' );
		bValidForm = false;
	}
	else
	{
		removeElementClass( $('UScienceTeacher'), 'alertInput' );
	}
	
	if( ($("UHeardAboutBRR").value == '-- Select One --') )
	{
		setElementClass( $('UHeardAboutBRRLabel'), 'alertLabel' );
		bValidForm = false;
	}
	else
	{
		removeElementClass( $('UHeardAboutBRRLabel'), 'alertLabel' );
	}
	
	if( !$("UCameToBRRYes").checked && !$("UCameToBRRNo").checked )
	{
		setElementClass( $('UCameToBRRLabel'), 'alertLabel' );
		bValidForm = false;
	}
	else
	{
		removeElementClass( $('UCameToBRRLabel'), 'alertLabel' );
	}
	
	
	// #########################################################################
	// PHASE 2 - Check number inputs.
	// #########################################################################
	
	checkNumField('SouthGen_LogBook');
	checkNumField('SouthGen_Tips');
	checkNumField('SouthGen_Research');
	checkNumField('SouthGen_Stats');
	checkNumField('SouthGen_FairWay');
	checkNumField('SouthGen_Inquiry');
	
	checkNumField('SouthSub_AnimalSciences');
	checkNumField('SouthSub_EarthSciences');
	checkNumField('SouthSub_Microbiology');
	checkNumField('SouthSub_Behavioral');
	checkNumField('SouthSub_Engineering');
	checkNumField('SouthSub_Physics');
	checkNumField('SouthSub_Biochemistry');
	checkNumField('SouthSub_Env');
	checkNumField('SouthSub_Plants');
	checkNumField('SouthSub_Chemistry');
	checkNumField('SouthSub_Computers');
	checkNumField('SouthSub_Medicine');
	
	
	// #########################################################################
	// PHASE 2 - Check number inputs.
	// #########################################################################
	/*
	if( !$('USite1').checked && !$('USite2').checked )
	{
		setElementClass( $('USite1Label'), 'alertLabel' );
		setElementClass( $('USite2Label'), 'alertLabel' );
		bValidForm = false;
	}
	else
	{
		removeElementClass( $('USite1Label'), 'alertLabel' );
		removeElementClass( $('USite2Label'), 'alertLabel' );
	}
	*/

	// #########################################################################
	// PHASE 4 - Return results.
	// #########################################################################

	// If the form is not valid jump the user to the top and alert them.
	if( !bValidForm )
	{
		// Jump to the top of the page.
		location.hash = "Top";
		// Alert the user to the errors.
		alert("Please fill in/check the following fields (highlighted in red).");
	}
	
	// Return the result of the test.
	return bValidForm;
}

function teacherCheck()
{
	if( $("URegistrantType").value == 'teacher' )
	{
		window.alert("TEACHERS: Under the 'General Category' section below, please choose only TWO...numbered 1 (favorite) and 2 (almost as good).  You will be scheduled for one 'General Category' session and the special teacher session 'Everything you need to know about science fair paperwork (but were afraid to ask)'.");
	}
}

/**
 *	MAIN
 *	###############################################################################################
 *	This function actually kick-starts the setup and processing for this page.
 */
function main()
{	
	connect( "URegistrantType", "onchange", teacherCheck );
}


/**
 *	RUN TIME 
 *	###############################################################################################
 *	The actions below setup default actions (bootstraps) functionality implmented by this file.
 */

	addLoadEvent(main);
