function checkVals(value, after, hearus)
{
	var test = document.getElementById("gradeText");
	if(value=="Parent")
	{
		if(after)
			test.innerHTML = '<font class="gentext">Child\'s Grade Level*:</font>';
		else
			test.innerHTML = '<font color="red">*</font><font class="gentext">Child\'s Grade Level:</font>';
	  	document.forms['regForm'].gradeLvl.options[9] = new Option('Special Education','SpecEd');
	}
	else
	  document.forms['regForm'].gradeLvl.options[9] = null;
	if(value=="Teacher" || value=="MathCoord")
	{
		if(after)
			test.innerHTML = '<font class="gentext">Grade Taught*:</font>';	  
		else
			test.innerHTML = '<font color="red">*</font><font class="gentext">Grade Taught:</font>';	
	}

	if(value=="SPED")
	{
		if(after)
	    	test.innerHTML = '<font class="gentext">School Level*:</font>';		  
		else
			test.innerHTML = '<font color="red">*</font><font class="gentext">School Level:</font>';		  
	}	
	
	if(value=='Teacher' || value=="Parent")
		document.getElementById('TeacherGrades').style.display = '';
	if(value=="SPED")
		document.getElementById('SchoolLvl').style.display = '';
	if(value=="MathCoord")
		document.getElementById('CoordGrades').style.display = '';
	if (value=="Other")
		document.getElementById('OtherTitle').style.display = '';	
	if (value=="University")
		document.getElementById('Univ').style.display = '';
		

	if(hearus=='OTH')
		document.getElementById('SpecHear').style.display = '';

}

function popupWindow (width, height, url)
{
	var name="ViewEdit";
	ViewEdit=window.open (url,name,"dependent=yes,height="+height+",resizable=yes,scrollbars=yes,status=no,width="+width+",top=0,left=0" );
	//ViewEdit.focus();
}
function ShowHear(value)
{
	
	if(value=="OTH")
		document.getElementById('SpecHear').style.display = '';
	else
		document.getElementById('SpecHear').style.display = 'none';	
}
// This function shows or hides the appropriate pull downs for grade lvls based on what the user chose for a title.
function ShowHide(value, after)
{ 

	var test = document.getElementById("gradeText");

	if(value=="Parent")
	{
		if(after)
			test.innerHTML = '<font class="gentext">Child\'s Grade Level*:</font>';
		else
			test.innerHTML = '<font color="red">*</font><font class="gentext">Child\'s Grade Level:</font>';
	  	document.forms['regForm'].gradeLvl.options[9] = new Option('Special Education','SpecEd');
	}
	else
	  document.forms['regForm'].gradeLvl.options[9] = null;
	if(value=="Teacher" || value=="MathCoord")
	{
		if(after)
			test.innerHTML = '<font class="gentext">Grade Taught*:</font>';	  
		else
			test.innerHTML = '<font color="red">*</font><font class="gentext">Grade Taught:</font>';	
	}

	if(value=="SPED")
	{
		if(after)
	    	test.innerHTML = '<font class="gentext">School Level*:</font>';		  
		else
			test.innerHTML = '<font color="red">*</font><font class="gentext">School Level:</font>';		  
	}
	  
	if(value=="Teacher" || value=="Parent")
	{
		document.getElementById('TeacherGrades').style.display = '';
		document.getElementById('SchoolLvl').style.display = 'none';
		document.getElementById('OtherTitle').style.display = 'none';
		document.getElementById('Univ').style.display = 'none';
		document.getElementById('CoordGrades').style.display = 'none';
	}
	
	else if(value=="SPED")
	{
		document.getElementById('TeacherGrades').style.display = 'none';
		document.getElementById('SchoolLvl').style.display = '';	 
		document.getElementById('OtherTitle').style.display = 'none';
		document.getElementById('Univ').style.display = 'none';
		document.getElementById('CoordGrades').style.display = 'none';
	}
	else if(value=="MathCoord")
	{
		document.getElementById('TeacherGrades').style.display = 'none';
		document.getElementById('SchoolLvl').style.display = 'none';	 
		document.getElementById('OtherTitle').style.display = 'none';
		document.getElementById('Univ').style.display = 'none';
		document.getElementById('CoordGrades').style.display = '';
	}	
	else if (value=="Other")
	{
		document.getElementById('TeacherGrades').style.display = 'none';
		document.getElementById('SchoolLvl').style.display = 'none';
		document.getElementById('OtherTitle').style.display = '';		
		document.getElementById('Univ').style.display = 'none';
		document.getElementById('CoordGrades').style.display = 'none';
	}
	else if (value=="University")
	{
		document.getElementById('TeacherGrades').style.display = 'none';
		document.getElementById('SchoolLvl').style.display = 'none';
		document.getElementById('OtherTitle').style.display = 'none';
		document.getElementById('Univ').style.display = '';
		document.getElementById('CoordGrades').style.display = 'none';
	}	
	else  
	{
		document.getElementById('TeacherGrades').style.display = 'none';
		document.getElementById('SchoolLvl').style.display = 'none';	 
		document.getElementById('OtherTitle').style.display = 'none';
		document.getElementById('Univ').style.display = 'none';
		document.getElementById('CoordGrades').style.display = 'none';
	}	

}

//validate the function, if it's the registration form, then make sure the password is valid, and it matches
function nowvalidate(theForm, checkPass) {


	// check if first field is blank
	if (theForm.vchFName.value == "")
	{
	alert("Please enter a value for the \"First Name\".");
	theForm.vchFName.focus();
	return (false);
	}
	
	// check if last name field is blank
	if (theForm.vchLName.value == "")
	{
	alert("Please enter a value for the \"Last Name\".");
	theForm.vchLName.focus();
	return (false);
	}
	// check if vchTitle field is blank
	if (theForm.vchTitle.value == "")
	{
	alert("Please enter a value for the \"Title\".");
	theForm.vchTitle.focus();
	return (false);
	}
		
	if(theForm.vchTitle.value=="Teacher")
	{
	  if(theForm.gradeLvl.value=="")
	  {
	  	alert("Please enter a value for the \"Grade Taught\".");
		theForm.gradeLvl.focus();
		return false;
	  }
	}
	
	if(theForm.vchTitle.value=="MathCoord")
	{
	  if(theForm.CoordGradeLvl.value=="")
	  {
	  	alert("Please enter a value for the \"Grade Taught\".");
		theForm.CoordGradeLvl.focus();
		return false;
	  }
	}	
	
	if(theForm.vchTitle.value=="Parent" )
	{
	  if(theForm.gradeLvl.value=="")
	  {
	  	alert("Please enter a value for your child's \"Grade\".");
		theForm.gradeLvl.focus();
		return false;
	  }
	}	
	
	if(theForm.vchTitle.value=="SPED")
	{
	  if(theForm.sLvl.value=="")
	  {
	  	alert("Please enter a value for the \"Grade Level\".");
		theForm.sLvl.focus();
		return false;
	  }
	}
	
	if(theForm.vchTitle.value=="University")
	{
	  if(theForm.uLvl.value=="")
	  {
	  	alert("Please enter a value for the \"Position\".");
		theForm.uLvl.focus();
		return false;
	  }
	}	 
	
	if(theForm.vchTitle.value=="Other")
	{
	  if(theForm.OTitle.value=="")
	  {
	  	alert("Please specify your \"Title\".");
		theForm.OTitle.focus();
		return false;
	  }
	}		
		
	// check if email field is blank
	if (theForm.vchEMail.value == "")
	{
	alert("Please enter a value for the \"Email Address\" field.");
	theForm.vchEMail.focus();
	return (false);
	}
	
	// test if valid email address, must have @ and .
	var checkEmail = "@.";
	var checkStr = theForm.vchEMail.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (k = 0;  k < checkStr.length;  k++)
	{
	ch = checkStr.charAt(k);
	for (j = 0;  j < checkEmail.length;  j++)
	{
	if (ch == checkEmail.charAt(j) && ch == "@")
	EmailAt = true;
	if (ch == checkEmail.charAt(j) && ch == ".")
	EmailPeriod = true;
		  if (EmailAt && EmailPeriod)
			break;
		  if (j == checkEmail.length)
			break;
		}
		// if both the @ and . were in the string
	if (EmailAt && EmailPeriod)
	{
			EmailValid = true
			break;
		}
	}
	if (!EmailValid)
	{
	alert("The \"email\" field must contain an \"@\" and a \".\".");
	theForm.vchEMail.focus();
	return (false);
	}
	
	// check if vchPhone field is blank
	if (theForm.vchPhone.value == "")
	{
	alert("Please enter a value for the \"Phone Number\".");
	theForm.vchPhone.focus();
	return (false);
	}

	if(checkPass == 1)
	{
			if(theForm.vchPassword.value == '' || theForm.vchPasswordConf.value == '' || theForm.vchPassword.value.length < 6 ){
				alert('Please fill out both Password and Password Confirmation fields and make sure the password length is at least 6 characters long.');
				return (false);
			}
			if(theForm.vchPassword.value != theForm.vchPasswordConf.value){
				alert('Password mismatch.');
				return (false)
			}
	}
	
	if(checkPass==1 || checkPass == 2) //NOTE: this means we are on the main Reg page, so we also need to check the "Hear about us" stuff
	{

		// check if the How Hear about us is blank
		if (theForm.HearAbout.value == "")
		{
			alert("Please tell us how you heard about us.");
			theForm.HearAbout.focus();
			return (false);
		}	
		if (theForm.HearAbout.value == "Other")
		{
			if(theForm.SpecificHear.value == "")
			{
				alert("Please specify how you heard about us.");
			    theForm.SpecificHear.focus();
				return (false);
			}
		}	
		if(checkPass == 2) //coming from videorequest page
		{
			if(theForm.format.value == "")
			{
				alert("Please specify what format you would like.");
			    theForm.format.focus();
				return (false);
			}
			if(theForm.vidAttend.value == "" || !IsNumeric(theForm.vidAttend.value))
			{
				alert("Please specify the number fo people viewing the video.");
			    theForm.vidAttend.focus();
				return (false);
			}
		}//end checkPass == 2
	}
	
	if(checkPass==3) //Coming from the Playcore page - use MD5 to verify the code they entered
	{		
		if(hex_md5(theForm.passCode.value.toLowerCase()) != "2af15cded3bda9fb4ff7f8bcaafbd0aa")
		{
			alert("Invalid code. Please check your Playcore manual for the correct code.")
			theForm.passCode.focus();
			return (false);
		}
	}
	
	// check if PhoneType field is blank
	if (theForm.atype.value == "")
	{
	alert("Please select the type of \"Address\".");
	theForm.atype.focus();
	return (false);
	}
	
	// check if vchAddress1 field is blank
	if (theForm.vchAddress1.value == "")
	{
	alert("Please enter a value for the \"Address\".");
	theForm.vchAddress1.focus();
	return (false);
	}
	// check if vchCity field is blank
	if (theForm.vchCity.value == "")
	{
	alert("Please enter a value for the \"City\".");
	theForm.vchCity.focus();
	return (false);
	}
	// check if no drop down or first drop down is selected, if so, invalid selection
	if ((theForm.vchCountry.selectedIndex==1 || theForm.vchCountry.selectedIndex==9 || theForm.vchCountry.selectedIndex==65) && theForm.iStateID.selectedIndex <= 0)
	{
	alert("Please select a state or province.");
	theForm.iStateID.focus();
	return (false);
	}
	// check if vchZip field is blank
	if (theForm.vchZip.value == "" || theForm.vchZip.value.length < 4)
	{
	alert("Please enter a valid \"Zip Code\".");
	theForm.vchZip.focus();
	return (false);
	}
	theForm.vchZip.value = theForm.vchZip.value.toUpperCase();
	// check if no drop down or first drop down is selected, if so, invalid selection
	if (theForm.vchCountry.selectedIndex <= 0)
	{
	alert("Please select a country.");
	theForm.vchCountry.focus();
	return (false);
	}
	
	if(theForm.TC_check.value == 1)
	{
		if(theForm.TC_Accept.checked == false){
			alert("You must accept the EULA.");
			theForm.TC_Accept.focus();
			return (false);
		}
	}


	return (true);
}

//function that tests whether or not string passed is an INTEGER value. Floats are not permitted.
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
