// this variable gets set when "Cancel" is selected
var CancelClicked="";

// validate that a string is all numbers
function NumberValidation(string, msg) {
    var validnumbers = "0123456789";

    for (var i=0; i < string.length; i++) {
        if (validnumbers.indexOf(string.charAt(i)) == -1) {
		alert("Please enter only digits in the " + msg + ".");
		return (false);
	}
    }
}

// this gets called when the user submits the form
function FormValidation(theForm) {
var iCount, iCount2;

if (CancelClicked=="") {

var modules = new Array();

if (theForm.eepartnerother[0].checked==true && theForm.employee.selectedIndex==0) {
	alert("Please select a value in the \"ATSDR Employee\" drop down list.");
	theForm.employee.focus();
	return (false);
} else if (theForm.eepartnerother[1].checked==true && theForm.partner.selectedIndex==0) {
	alert("Please select a value in the \"ATSDR Partner\" drop down list.");
	theForm.partner.focus();
	return (false);
}    
  
if (theForm.eepartnerother[0].checked==false && theForm.eepartnerother[1].checked==false && theForm.eepartnerother[2].checked==false) {
	alert("Please select whether you are an ATSDR Employee, ATSDR Partner, or Other.");
	return (false);
}	  
  
if (theForm.discipline.selectedIndex==0) {
	alert("Please select a Work Discipline.");
	theForm.discipline.focus();  
	return (false);
} else if (theForm.discipline.selectedIndex == 10 && theForm.disciplineother.value=="") { // Other
	alert("Please enter the \"Other\" discipline.");
	theForm.disciplineother.focus();
	return(false);
}

if (theForm.phone1.value.length < 3 || theForm.phone2.value.length < 3 || theForm.phone3.value.length < 4) {
    alert("Please enter 10 digits in the phone number.");
    theForm.phone1.focus();
    return (false);
}

  // validate that phone is all digits
iRet = NumberValidation(theForm.phone1.value, "Phone Number");
if (iRet == false) {
	theForm.phone1.focus();
	return (false);
}
iRet = NumberValidation(theForm.phone2.value, "Phone Number");
if (iRet == false) {
	theForm.phone2.focus();
	return (false);
}
iRet = NumberValidation(theForm.phone3.value, "Phone Number");
if (iRet == false) {
	theForm.phone3.focus();
	return (false);
}
  
if (theForm.emailaddress.value.indexOf('@') < 1) {
	alert("Please enter a valid email address containing an '@'.");
	theForm.emailaddress.focus();
	return (false);
} 

// required fields for basic course only
// Commented 6/17/2003
//if (theForm.track[0].checked==false && theForm.track[1].checked==false) {
		//alert("Please select a track.");
		//return (false);
//} 

if (theForm.consultations[0].checked==false && theForm.consultations[1].checked==false && theForm.consultations[2].checked==false) {
	alert("Please indicate whether or not you will be preparing public health assessments for ATSDR.");
	theForm.consultations[0].focus();
	return (false);
}

if (theForm.us_citizen[0].checked==false && theForm.us_citizen[1].checked==false) {
	alert("Please indicate whether or not you are a US Citizen.");
	theForm.us_citizen[0].focus();
	return (false);
}

if (theForm.credits[0].checked==false && theForm.credits[1].checked==false && theForm.credits[2].checked==false && theForm.credits[3].checked==false && theForm.credits[4].checked==false) {
	alert("Please indicate whether or not you want Continuing Education Credits.");
	theForm.credits[0].focus();
	return (false);
}

if (theForm.emailaddress.value!=theForm.emailaddress2.value) {
	alert("Please check that you have typed your email address correctly.  The two values you have provided do not match.");
        theForm.emailaddress.focus();
	return (false);
}

if (theForm.sitedata.value=='') {
	alert("Please answer the questions in the comments box.");
        theForm.sitedata.focus();
	return (false);
}  
// These are for Net Web courses
/*
if (theForm.course_225_308.checked==true) {
  if (theForm.question_225_308_2[0].checked==false && theForm.question_225_308_2[1].checked==false) {
    alert("Please indicate whether or not you will be participating via on-site classroom at ATSDR.");
    theForm.question_225_308_2[0].focus();
    return (false);
  }

  if (theForm.question_225_308_1[0].checked==false && theForm.question_225_308_1[1].checked==false) {
    alert("Please indicate whether or not you need to reserve a portal.");
    theForm.question_225_308_1[0].focus();
    return (false);
  }

  if (theForm.question_225_308_1[0].checked==true && theForm.question_225_308_2[0].checked==true) {
    alert("If you are participating on-site at ATSDR no portal reservation is needed.");
    theForm.question_225_308_1[0].focus();
    return (false);
  }

  if (theForm.question_225_308_1[1].checked==true && theForm.question_225_308_2[1].checked==true && theForm.question_225_308_3.value.length < 5) {
    alert("If you are not participating on-site and do not need to reserve a portal, please provide the name of the person whose portal you will be using.");
    theForm.question_225_308_3.focus();
    return (false);
  }
}

if (theForm.course_226_309.checked==true) {
  if (theForm.question_226_309_2[0].checked==false && theForm.question_226_309_2[1].checked==false) {
    alert("Please indicate whether or not you will be participating via on-site classroom at ATSDR.");
    theForm.question_226_309_2[0].focus();
    return (false);
  }

  if (theForm.question_226_309_1[0].checked==false && theForm.question_226_309_1[1].checked==false) {
    alert("Please indicate whether or not you need to reserve a portal.");
    theForm.question_226_309_1[0].focus();
    return (false);
  }

  if (theForm.question_226_309_1[0].checked==true && theForm.question_226_309_2[0].checked==true) {
    alert("If you are participating on-site at ATSDR no portal reservation is needed.");
    theForm.question_226_309_1[0].focus();
    return (false);
  }

  if (theForm.question_226_309_1[1].checked==true && theForm.question_226_309_2[1].checked==true && theForm.question_226_309_3.value.length < 5) {
    alert("If you are not participating on-site and do not need to reserve a portal, please provide the name of the person whose portal you will be using.");
    theForm.question_226_309_3.focus();
    return (false);
  }
}

if (theForm.course_227_310.checked==true) {
  if (theForm.question_227_310_2[0].checked==false && theForm.question_227_310_2[1].checked==false) {
    alert("Please indicate whether or not you will be participating via on-site classroom at ATSDR.");
    theForm.question_227_310_2[0].focus();
    return (false);
  }

  if (theForm.question_227_310_1[0].checked==false && theForm.question_227_310_1[1].checked==false) {
    alert("Please indicate whether or not you need to reserve a portal.");
    theForm.question_227_310_1[0].focus();
    return (false);
  }

  if (theForm.question_227_310_1[0].checked==true && theForm.question_227_310_2[0].checked==true) {
    alert("If you are participating on-site at ATSDR no portal reservation is needed.");
    theForm.question_227_310_1[0].focus();
    return (false);
  }

  if (theForm.question_227_310_1[1].checked==true && theForm.question_227_310_2[1].checked==true && theForm.question_227_310_3.value.length < 5) {
    alert("If you are not participating on-site and do not need to reserve a portal, please provide the name of the person whose portal you will be using.");
    theForm.question_227_310_3.focus();
    return (false);
  }
}

if (theForm.course_228_311.checked==true) {
  if (theForm.question_228_311_2[0].checked==false && theForm.question_228_311_2[1].checked==false) {
    alert("Please indicate whether or not you will be participating via on-site classroom at ATSDR.");
    theForm.question_228_311_2[0].focus();
    return (false);
  }

  if (theForm.question_228_311_1[0].checked==false && theForm.question_228_311_1[1].checked==false) {
    alert("Please indicate whether or not you need to reserve a portal.");
    theForm.question_228_311_1[0].focus();
    return (false);
  }

  if (theForm.question_228_311_1[0].checked==true && theForm.question_228_311_2[0].checked==true) {
    alert("If you are participating on-site at ATSDR no portal reservation is needed.");
    theForm.question_228_311_1[0].focus();
    return (false);
  }

  if (theForm.question_228_311_1[1].checked==true && theForm.question_228_311_2[1].checked==true && theForm.question_228_311_3.value.length < 5) {
    alert("If you are not participating on-site and do not need to reserve a portal, please provide the name of the person whose portal you will be using.");
    theForm.question_228_311_3.focus();
    return (false);
  }
}

if (theForm.course_229_312.checked==true) {
  if (theForm.question_229_312_2[0].checked==false && theForm.question_229_312_2[1].checked==false) {
    alert("Please indicate whether or not you will be participating via on-site classroom at ATSDR.");
    theForm.question_229_312_2[0].focus();
    return (false);
  }

  if (theForm.question_229_312_1[0].checked==false && theForm.question_229_312_1[1].checked==false) {
    alert("Please indicate whether or not you need to reserve a portal.");
    theForm.question_229_312_1[0].focus();
    return (false);
  }

  if (theForm.question_229_312_1[0].checked==true && theForm.question_229_312_2[0].checked==true) {
    alert("If you are participating on-site at ATSDR no portal reservation is needed.");
    theForm.question_229_312_1[0].focus();
    return (false);
  }

  if (theForm.question_229_312_1[1].checked==true && theForm.question_229_312_2[1].checked==true && theForm.question_229_312_3.value.length < 5) {
    alert("If you are not participating on-site and do not need to reserve a portal, please provide the name of the person whose portal you will be using.");
    theForm.question_229_312_3.focus();
    return (false);
  }
}

if (theForm.course_230_313.checked==true) {
  if (theForm.question_230_313_2[0].checked==false && theForm.question_230_313_2[1].checked==false) {
    alert("Please indicate whether or not you will be participating via on-site classroom at ATSDR.");
    theForm.question_230_313_2[0].focus();
    return (false);
  }

  if (theForm.question_230_313_1[0].checked==false && theForm.question_230_313_1[1].checked==false) {
    alert("Please indicate whether or not you need to reserve a portal.");
    theForm.question_230_313_1[0].focus();
    return (false);
  }

  if (theForm.question_230_313_1[0].checked==true && theForm.question_230_313_2[0].checked==true) {
    alert("If you are participating on-site at ATSDR no portal reservation is needed.");
    theForm.question_230_313_1[0].focus();
    return (false);
  }

  if (theForm.question_230_313_1[1].checked==true && theForm.question_230_313_2[1].checked==true && theForm.question_230_313_3.value.length < 5) {
    alert("If you are not participating on-site and do not need to reserve a portal, please provide the name of the person whose portal you will be using.");
    theForm.question_230_313_3.focus();
    return (false);
  }
}

if (theForm.course_231_314.checked==true) {
  if (theForm.question_231_314_2[0].checked==false && theForm.question_231_314_2[1].checked==false) {
    alert("Please indicate whether or not you will be participating via on-site classroom at ATSDR.");
    theForm.question_231_314_2[0].focus();
    return (false);
  }

  if (theForm.question_231_314_1[0].checked==false && theForm.question_231_314_1[1].checked==false) {
    alert("Please indicate whether or not you need to reserve a portal.");
    theForm.question_231_314_1[0].focus();
    return (false);
  }

  if (theForm.question_231_314_1[0].checked==true && theForm.question_231_314_2[0].checked==true) {
    alert("If you are participating on-site at ATSDR no portal reservation is needed.");
    theForm.question_231_314_1[0].focus();
    return (false);
  }

  if (theForm.question_231_314_1[1].checked==true && theForm.question_231_314_2[1].checked==true && theForm.question_231_314_3.value.length < 5) {
    alert("If you are not participating on-site and do not need to reserve a portal, please provide the name of the person whose portal you will be using.");
    theForm.question_231_314_3.focus();
    return (false);
  }
}

if (theForm.course_232_315.checked==true) {
  if (theForm.question_232_315_2[0].checked==false && theForm.question_232_315_2[1].checked==false) {
    alert("Please indicate whether or not you will be participating via on-site classroom at ATSDR.");
    theForm.question_232_315_2[0].focus();
    return (false);
  }

  if (theForm.question_232_315_1[0].checked==false && theForm.question_232_315_1[1].checked==false) {
    alert("Please indicate whether or not you need to reserve a portal.");
    theForm.question_232_315_1[0].focus();
    return (false);
  }

  if (theForm.question_232_315_1[0].checked==true && theForm.question_232_315_2[0].checked==true) {
    alert("If you are participating on-site at ATSDR no portal reservation is needed.");
    theForm.question_232_315_1[0].focus();
    return (false);
  }

  if (theForm.question_232_315_1[1].checked==true && theForm.question_232_315_2[1].checked==true && theForm.question_232_315_3.value.length < 5) {
    alert("If you are not participating on-site and do not need to reserve a portal, please provide the name of the person whose portal you will be using.");
    theForm.question_232_315_3.focus();
    return (false);
  }
}

if (theForm.course_233_316.checked==true) {
  if (theForm.question_233_316_2[0].checked==false && theForm.question_233_316_2[1].checked==false) {
    alert("Please indicate whether or not you will be participating via on-site classroom at ATSDR.");
    theForm.question_233_316_2[0].focus();
    return (false);
  }

  if (theForm.question_233_316_1[0].checked==false && theForm.question_233_316_1[1].checked==false) {
    alert("Please indicate whether or not you need to reserve a portal.");
    theForm.question_233_316_1[0].focus();
    return (false);
  }

  if (theForm.question_233_316_1[0].checked==true && theForm.question_233_316_2[0].checked==true) {
    alert("If you are participating on-site at ATSDR no portal reservation is needed.");
    theForm.question_233_316_1[0].focus();
    return (false);
  }

  if (theForm.question_233_316_1[1].checked==true && theForm.question_233_316_2[1].checked==true && theForm.question_233_316_3.value.length < 5) {
    alert("If you are not participating on-site and do not need to reserve a portal, please provide the name of the person whose portal you will be using.");
    theForm.question_233_316_3.focus();
    return (false);
  }
}

if (theForm.course_234_317.checked==true) {
  if (theForm.question_234_317_2[0].checked==false && theForm.question_234_317_2[1].checked==false) {
    alert("Please indicate whether or not you will be participating via on-site classroom at ATSDR.");
    theForm.question_234_317_2[0].focus();
    return (false);
  }

  if (theForm.question_234_317_1[0].checked==false && theForm.question_234_317_1[1].checked==false) {
    alert("Please indicate whether or not you need to reserve a portal.");
    theForm.question_234_317_1[0].focus();
    return (false);
  }

  if (theForm.question_234_317_1[0].checked==true && theForm.question_234_317_2[0].checked==true) {
    alert("If you are participating on-site at ATSDR no portal reservation is needed.");
    theForm.question_234_317_1[0].focus();
    return (false);
  }

  if (theForm.question_234_317_1[1].checked==true && theForm.question_234_317_2[1].checked==true && theForm.question_234_317_3.value.length < 5) {
    alert("If you are not participating on-site and do not need to reserve a portal, please provide the name of the person whose portal you will be using.");
    theForm.question_234_317_3.focus();
    return (false);
  }
}

if (theForm.course_235_318.checked==true) {
  if (theForm.question_235_318_2[0].checked==false && theForm.question_235_318_2[1].checked==false) {
    alert("Please indicate whether or not you will be participating via on-site classroom at ATSDR.");
    theForm.question_235_318_2[0].focus();
    return (false);
  }

  if (theForm.question_235_318_1[0].checked==false && theForm.question_235_318_1[1].checked==false) {
    alert("Please indicate whether or not you need to reserve a portal.");
    theForm.question_235_318_1[0].focus();
    return (false);
  }

  if (theForm.question_235_318_1[0].checked==true && theForm.question_235_318_2[0].checked==true) {
    alert("If you are participating on-site at ATSDR no portal reservation is needed.");
    theForm.question_235_318_1[0].focus();
    return (false);
  }

  if (theForm.question_235_318_1[1].checked==true && theForm.question_235_318_2[1].checked==true && theForm.question_235_318_3.value.length < 5) {
    alert("If you are not participating on-site and do not need to reserve a portal, please provide the name of the person whose portal you will be using.");
    theForm.question_235_318_3.focus();
    return (false);
  }
}
*/
// End Net Web Specific course validation

  }

}
		  
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_validateForm() { //v3.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) {
		test=args[i+2];
		val=MM_findObj(args[i]);
		if (val) {
			nm=val.name;
			if ((val=val.value)!="") {
				if (test.indexOf('isEmail')!=-1) {
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
				} else if (test!='R') {
					num = parseFloat(val);
					if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('inRange') != -1) {
						p=test.indexOf(':');
						min=test.substring(8,p);
						max=test.substring(p+1);
						if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				}
			} else if (test.charAt(0) == 'R') {
				if (nm=='sitedata') {
					nm='Response in comment box';
				}
				errors += '- '+nm+' is required.\n';
			}
		}
	}
	if (errors) alert('The following error(s) occurred:\n'+errors);
	document.MM_returnValue = (errors == '');
}
