function getSelectedRadio(buttonGroup,msg) {
	// returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   alert(msg);
   buttonGroup[0].focus();
   return -1;
} 

function ValidateForm(phase)
{   
		
	switch (phase) {
		case 0:
			if ( getSelectedRadio(document.formOption.radIntent,"Please confirm your selection.") < 0)  return false;
			break;
		case 10: /* update form initializer -- form: update0 */
			apptype = getSelectedRadio(document.update0.type,
								  "Please check whether you are a treatment counselor or a prevention professional.");
			if ( apptype  < 0)  return false;
			edtype = getSelectedRadio(document.update0.ed,
								  "Please check either certification training or higher education.");
			if ( edtype  < 0)  return false;
		
			if ( document.update0.ed[edtype].value == 1 && document.update0.type[apptype].value == 0) {
					alert ("Sorry. Higher education scholarships are not yet available to prevention professionals");
					return false;
			}
			break;	
		case 11: /* quick navigation form: quick */
			apptype = getSelectedRadio(document.quick.type,
								  "Please check whether you are a treatment counselor or a prevention professional.");
			if ( apptype  < 0)  return false;
			edtype = getSelectedRadio(document.quick.ed,
								  "Please check either certification training or higher education.");
			if ( edtype  < 0)  return false;
		
			if ( document.quick.ed[edtype].value == 1 && document.quick.type[apptype].value == 0) {
					alert ("Sorry. Higher education scholarships are not yet available to prevention professionals");
					return false;
			}
			if ( getSelectedRadio(document.quick.radWhat,
								  "Please tell us what you'd like to do at this site.") < 0 ) return false;
			break;
		
		case 1:
			/* check for contact info through SS# */
					for( i=1; i< 9 ; i++ ) {
					if (document.form1.elements[i].value == "" ) {
						alert ("Please enter Name through SS#: " );
						document.form1.elements[i].focus();
						return false;
					}				
					
			}
			if ( document.form1.txtPhoneH.value + document.form1.txtPhoneW.value + document.form1.txtPhoneF.value == "") {
				alert ("Please enter at least one phone number");
				document.form1.txtPhoneH.focus();
				return false;
			}
			
			if ( getSelectedRadio(document.form1.radSex,"Please indicate your sex") < 0)  return false;
			if ( getSelectedRadio(document.form1.radRE,"Please indicate your race/ethnicity") < 0)  return false;
			if ( getSelectedRadio(document.form1.radEd,"Please indicate your education") < 0)  return false;
			
			/* validate financial information when it is requested */
			
			if ( document.form1.txtHousehold ) {
				if ( ! checkString (document.form1.txtHousehold, 'your household size', false) ) return false;
				if ( getSelectedRadio(document.form1.radEmployed,"Please indicate whether you are employed") < 0)  return false;
				if ( getSelectedRadio(document.form1.radContinueWork,"Please indicate whether you will continue to work while in school") < 0)  return false;
			} 
					
			break;
	
	}

	return true;
}
function doSubmit (phase, validate)
{
	if ( validate ) {
		if ( ! ValidateForm(phase) ) return false;
	}
	switch (phase) {
		case 0:
			document.formOption.submit();
			break;
		case 1:
			document.form1.submit();
			break;
		case 2:
			document.phase2.submit();
			break;
		case 3:
			document.phase3.submit();
			break;
		case 10:
			document.update0.submit();
			break;
		case 11:
			document.quick.submit();
			break;
	}
	
}

function PropagateEmployer (formfield)
{
		if (document.form1.txtEmployerFin) {
			document.form1.txtEmployerFin.value = formfield.value;
			document.form1.radEmployed[0].checked = true;
		}
}