function Validate()
{
	var initialMsg = "The following fields must be filled in to submit your Cover Page:\n";

	if (RequiredFields(initialMsg))
	{
		  document.ApplicationCover.submit();
		  return true;
	}
		else
	{
		return false;		
	}
}

function chkNAN(char2chk)
{
   var validNum = "0123456789";
   if (validNum.indexOf(char2chk) == "-1")
      return(confirm("You have entered a non-numeric character.\nDo you want to turn off non-numeric character checking?"));
}

function maskIt(fld)
{
   fldVal = fld.value;

   var tmpStr = "(";
   keyCount = fldVal.length;
   keyEntered =fldVal.substring(keyCount-1,keyCount);

   if (keyCount < 2)   isNamedFone = false;
   if (!isNamedFone)   isNamedFone = chkNAN(keyEntered);

   keyCount++;
   with (document.ChurchAd2)
   {
      switch (keyCount)
      {
         case 2:
            tmpStr +=  fldVal;
            fld.value = tmpStr;
            break;
         case 5:
            fld.value +=  ") ";
            break;
          case 10:
            fld.value += "-"; 
            break;
      }
   }
}

function RequiredFields(errorMsg)
{
	var isError = false;

	// Check for Project Leader
	if (document.ApplicationCover.project_leader.value == "")
	{
		errorMsg = errorMsg + "\t-->Project Leader Missing\n";
		if (!isError) // if this is first error, set focus
		{
		  SetFocus('project_leader');
		}
		isError = true;
	}

	// Check for Position
	if (document.ApplicationCover.position.value == "")
	{
		errorMsg = errorMsg + "\t-->Position Missing\n";
		if (!isError) // if this is first error, set focus
		{
		  SetFocus('position');
		}
		isError = true;
	}
	
	// Check for Grade Level
	if (document.ApplicationCover.grade.value == "")
	{
		errorMsg = errorMsg + "\t-->Grade Level Missing\n";
		if (!isError) // if this is first error, set focus
		{
		  SetFocus('grade');
		}
		isError = true;
	}
	
	// Check for Home Address
	if (document.ApplicationCover.home_address.value == "")
	{
		errorMsg = errorMsg + "\t-->Home Address Missing\n";
		if (!isError) // if this is first error, set focus
		{
		  SetFocus('home_address');
		}
		isError = true;
	}
	
	// Check for Home Telephone
	if (document.ApplicationCover.home_phone.value == "")
	{
		errorMsg = errorMsg + "\t-->Home Telephone Missing\n";
		if (!isError) // if this is first error, set focus
		{
		  SetFocus('home_phone');
		}
		isError = true;
	}

	// Check for School Telephone
	if (document.ApplicationCover.school_phone.value == "")
	{
		errorMsg = errorMsg + "\t-->School Telephone Missing\n";
		if (!isError) // if this is first error, set focus
		{
		  SetFocus('school_phone');
		}
		isError = true;
	}
	
	// Check for Grant Project Title
	if (document.ApplicationCover.project_title.value == "")
	{
		errorMsg = errorMsg + "\t-->Grant Project Title Missing\n";
		if (!isError) // if this is first error, set focus
		{
		  SetFocus('project_title');
		}
		isError = true;
	}
	
	// Check for Principal's Email Address Title
	if (document.ApplicationCover.principals_email.value == "")
	{
		errorMsg = errorMsg + "\t-->Principal Email Address Missing\n";
		if (!isError) // if this is first error, set focus
		{
		  SetFocus('principals_email');
		}
		isError = true;
	}
		
	if (isError)
	{
		alert(errorMsg);
		return false;
	}
	else
	{
		return true;
	}
}

function SetFocus(field) 
{
  //set focus to field passed in (great for error correcting)
  eval ("document.ApplicationCover." + field + ".focus();");
}

function ClearFocus(field) 
{
  //this clears the field and sets focus to field passed in
  field.value = "";
  field.focus();
}




