<!--

//java script to validate the add/edit form information for a student for a regular administrator
//(i.e. the add/edit available to a regular administrator)

//**********************************************************************************
// "Internal" function to remove all spaces ensures user input values correctly
//**********************************************************************************
function removeSpaces(s) {
 var tempVal=""
 for(var i=0;i<s.length;++i) {
  var c=s.charAt(i)
  if(c!=" ") tempVal += c
 }
 return tempVal
}



//**********************************************************************************
// "Internal" function to trim leading and trailing spaces
//**********************************************************************************
function trimSpaces(s) {
  var tempVal1 = "";
  var trimDone = false;
  var c;
  // pass through string left to right removing leading spaces (trim on left)
  for(var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if ((trimDone == true) || (c != " ")) {
      tempVal1 += c;
      trimDone = true
    }
  }
  // pass through string right to left removing trailing spaces (trim on right)
  var tempVal2 = "";
  trimDone = false;
  for (var i = tempVal1.length; i > 0; i--) {
    var c = tempVal1.charAt(i - 1)
    if ((trimDone == true) || (c != " ")) {
      tempVal2 = c + tempVal2;
      trimDone = true
    }
  }
  return tempVal2;
}



//**********************************************************************************
// "Internal" function to help ensure user input processed correctly
//**********************************************************************************
function checkInvalidChars(s) {
  var errFlag=0
  var firstChar=s.charAt(0);
  for(var i=0;i<s.length;++i) {
	var thisChar=s.charAt(i);
	if((thisChar=="'") || (thisChar==" ")){
	  errFlag = 1
	}
  }
  return errFlag;
}


function checkForApostrophes(s) {
  var errFlag=0
  var firstChar=s.charAt(0);
  for(var i=0;i<s.length;++i) {
	var thisChar=s.charAt(i);
	if(thisChar=="'"){
	  errFlag = 1
	}
  }
  return errFlag;
}


function checkForAtSymbol(s) {
  var errFlag=1
  var firstChar=s.charAt(0);
  for(var i=0;i<s.length;++i) {
	var thisChar=s.charAt(i);
	if(thisChar=="@"){
	  errFlag = 0
	}
  }
  return errFlag;
}


function LocationSelected(theForm)
 //this function checks to see if a location was selected and if so puts the location into
 //the location field from the drop down box
 {
  var selected_location = theForm.LocationList.value
  if (selected_location != "Select An Existing Location")
   {
    theForm.Location.value = selected_location
    theForm.Location.focus()
    theForm.LocationList.value = "Select An Existing Location"
   }
 }


function FrontPage_Form2_Validator(theForm)
 {
  var StudId = trimSpaces(theForm.Student_Id.value);
  theForm.Student_Id.value = StudId;
  if (StudId == "")
  {
    alert("Please enter a value for the \"User Id\" field. Spaces and apostrophes are not allowed.");
    theForm.Student_Id.focus();
    return (false);
  }

  var errFlag = checkInvalidChars(StudId);
  if (errFlag > 0)
  {
    alert("The \"User Id\" field contains an invalid character. Spaces and apostrophes are not allowed.");
    theForm.Student_Id.focus();
    return (false);
  }

  if (theForm.Student_Id.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"User ID\" field.");
    theForm.Student_Id.focus();
    return (false);
  }

  if (theForm.Student_Id.value.length > 15)
  {
    alert("Please enter at most 15 characters in the \"User ID\" field.");
    theForm.Student_Id.focus();
    return (false);
  }

  var LastName = trimSpaces(theForm.Student_Name_Last.value);
  theForm.Student_Name_Last.value = LastName;
  if (theForm.Student_Name_Last.value == "")
  {
   	 alert("Please enter a value for the \"Last Name\" field.");
    theForm.Student_Name_Last.focus();
    return (false);
  }

  var errFlag = checkForApostrophes(theForm.Student_Name_Last.value);
  if (errFlag > 0)
  {
    alert("The \"Last Name\" field contains an invalid character.  Apostrophes are not allowed.");
    theForm.Student_Name_Last.focus();
    return (false);
  }

  if (theForm.Student_Name_Last.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Last Name\" field.");
    theForm.Student_Name_Last.focus();
    return (false);
  }

  var FirstName = trimSpaces(theForm.Student_Name_First.value);
  theForm.Student_Name_First.value = FirstName;
  if (theForm.Student_Name_First.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.Student_Name_First.focus();
    return (false);
  }

  var errFlag = checkForApostrophes(theForm.Student_Name_First.value);
  if (errFlag > 0)
  {
    alert("The \"First Name\" field contains an invalid character.  Apostrophes are not allowed.");
    theForm.Student_Name_First.focus();
    return (false);
  }

  if (theForm.Student_Name_First.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"First Name\" field.");
    theForm.Student_Name_First.focus();
    return (false);
  }

  var MiddleInitial = trimSpaces(theForm.Student_Name_MI.value);
  theForm.Student_Name_MI.value = MiddleInitial;
  //no checking of middle initial for minimum size, it's not required

  var errFlag = checkForApostrophes(theForm.Student_Name_MI.value);
  if (errFlag > 0)
  {
    alert("The \"Middle Initial\" field contains an invalid character.  Apostrophes are not allowed.");
    theForm.Student_Name_MI.focus();
    return (false);
  }

  if (theForm.Student_Name_MI.value.length > 1)
  {
    alert("Please enter at most 1 character in the \"Middle Initial\" field.");
    theForm.Middle_Initial.focus();
    return (false);
  }


  var LicenseNumber = trimSpaces(theForm.Student_License_Number.value);
  theForm.Student_License_Number.value = LicenseNumber;
  if (theForm.Student_License_Number.value == "")
  {
    alert("Please enter a value for the \"License Number\" field.");
    theForm.Student_License_Number.focus();
    return (false);
  }

  var errFlag = checkForApostrophes(theForm.Student_License_Number.value);
  if (errFlag > 0)
  {
    alert("The \"License Number\" field contains an invalid character.  Apostrophes are not allowed.");
    theForm.Student_License_Number.focus();
    return (false);
  }

  if (theForm.Student_License_Number.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"License Number\" field.");
    theForm.Student_License_Number.focus();
    return (false);
  }


  var location = trimSpaces(theForm.Student_Location.value);
  theForm.Student_Location.value = location;


  if (theForm.Student_Location.value == "")
  {
    alert("Please enter a value for the \"Employer\" field.");
    theForm.Student_Location.focus();
    return (false);
  }


  var errFlag = checkForApostrophes(location);
  if (errFlag > 0)
  {
    alert("The \"Location\" field contains an invalid character.  Apostrophes are not allowed.");
    theForm.Student_Location.focus();
    return (false);
  }

  if (theForm.Student_Location.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Location\" field.");
    theForm.Student_Location.focus();
    return (false);
  }


  var Phone = trimSpaces(theForm.Student_Phone.value);
  theForm.Student_Phone.value = Phone;
  if (Phone == "")
  {
    alert("Please enter a value for the \"Phone Number\" field. (area code and phone number, separators like dashes or periods are optional)");
    theForm.Student_Phone.focus();
    return (false);
  }

  var errFlag = checkForApostrophes(theForm.Student_Phone.value);
  if (errFlag > 0)
  {
    alert("The \"Phone\" field contains an invalid character.  Apostrophes are not allowed.");
    theForm.Student_Phone.focus();
    return (false);
  } 

  if (theForm.Student_Phone.value.length < 10)
  {
    alert("Please enter at least 10 characters in the \"Phone Number\" field. (area code and phone number, separators like dashes or periods are optional)");
    theForm.Student_Phone.focus();
    return (false);
  }

  if (theForm.Student_Phone.value.length > 20)
  {
    alert("Please enter at most 20 characters in the \"Phone Number\" field.");
    theForm.Student_Phone.focus();
    return (false);
  }


  var Email = trimSpaces(theForm.Student_Email.value);
  theForm.Student_Email.value = Email;
  if (Email == "")
  {
    alert("Please enter a value for the \"EMail\" field.");
    theForm.Student_Email.focus();
    return (false);
  }

  var errFlag = checkInvalidChars(theForm.Student_Email.value);
  if (errFlag > 0)
  {
    alert("The \"Email\" field contains an invalid character. Spaces and apostrophes are not allowed.");
    theForm.Student_Email.focus();
    return (false);
  }

  var errFlag = checkForAtSymbol(theForm.Student_Email.value);
  if (errFlag > 0)
  {
    alert("The \"Email\" field does not contain a valid email address.  A valid email address contains an \"@\" symbol.");
    theForm.Student_Email.focus();
    return (false);
  }

  if (theForm.Student_Email.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Email\" field.");
    theForm.Student_Email.focus();
    return (false);
  }

  if (theForm.Student_Email.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Email\" field.");
    theForm.Student_Email.focus();
    return (false);
  }


  var Address1 = trimSpaces(theForm.Address1.value);
  theForm.Address1.value = Address1;
  if (theForm.Address1.value == "")
  {
   alert("Please enter a value for the \"Address Line 1\" field.");
    theForm.Address1.focus();
   return (false);
  }

  var errFlag = checkForApostrophes(theForm.Address1.value);
  if (errFlag > 0)
  {
    alert("The \"Address Line 1\" field contains an invalid character.  Apostrophes are not allowed.");
    theForm.Address1.focus();
    return (false);
  }

  if (theForm.Address1.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"Address Line 1\" field.");
    theForm.Address1.focus();
    return (false);
  }

  if (theForm.Address1.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Address Line 1\" field.");
    theForm.Address1.focus();
    return (false);
  }

  // Address2 is checked only to not be greater than 50 and no apostrophes (there is no minimum requirement)

  var Address2 = trimSpaces(theForm.Address2.value);
  theForm.Address2.value = Address2;

  var errFlag = checkForApostrophes(theForm.Address2.value);
  if (errFlag > 0)
  {
    alert("The \"Address Line 2\" field contains an invalid character.  Apostrophes are not allowed.");
    theForm.Address2.focus();
    return (false);
  }

  if (theForm.Address2.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Address Line 2\" field.");
    theForm.Address2.focus();
    return (false);
  }


  var City = trimSpaces(theForm.City.value);
  theForm.City.value = City;

  if (theForm.City.value == "")
  {
   alert("Please enter a value for the \"City\" field.");
    theForm.City.focus();
    return (false);
  }

  var errFlag = checkForApostrophes(theForm.City.value);
  if (errFlag > 0)
  {
    alert("The \"City\" field contains an invalid character.  Apostrophes are not allowed.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.City.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"City\" field.");
   theForm.City.focus();
    return (false);
  }

  // For the state check that there is something entered (at least 2 characters) and not more 
  //than 50 characters, no apostrophes
  var State = trimSpaces(theForm.State.value);
  theForm.State.value = State;

  if (theForm.State.value == "")
  {
    alert("Please enter a value for the \"State\" field.");
    theForm.State.focus();
    return (false);
  }

  var errFlag = checkForApostrophes(theForm.State.value);
  if (errFlag > 0)
  {
    alert("The \"State\" field contains an invalid character.  Apostrophes are not allowed.");
    theForm.State.focus();
    return (false);
  }

  if (theForm.State.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"State\" field. (state abbreviation)");
    theForm.State.focus();
    return (false);
  }

  // whatever they put in for a state don't let it go over the limit of 50

  if (theForm.State.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"State\" field.");
   theForm.State.focus();
    return (false);
  }

  var Zip = trimSpaces(theForm.Zip.value);
  theForm.Zip.value = Zip;
  if (theForm.Zip.value == "")
 {
    alert("Please enter a value for the \"Zip Code\" field.");
    theForm.Zip.focus();
    return (false);
  }

  var errFlag = checkInvalidChars(theForm.Zip.value);
  if (errFlag > 0)
 {
    alert("The \"Zip Code\" field contains an invalid character.  Spaces and apostrophes are not allowed.");
    theForm.Zip.focus();
    return (false);
  } 

  if (theForm.Zip.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"Zip Code\" field.");
    theForm.Zip.focus();
    return (false);
  }

  // whatever they put in for a zip code don't let it go over the limit of 15

  if (theForm.Zip.value.length > 15)
 {
    alert("Please enter at most 15 characters in the \"Zip Code\" field.");
    theForm.Zip.focus();
    return (false);
  }


  var Password = trimSpaces(theForm.Student_Password.value);
  theForm.Student_Password.value = Password;
  if (theForm.Student_Password.value == "")
  {
    alert("Please enter a value for the \"Password\" field. Spaces and apostrophes are not allowed.");
    theForm.Student_Password.focus();
    return (false);
  }

  var errFlag = checkInvalidChars(theForm.Student_Password.value);
  if (errFlag > 0)
  {
    alert("The \"Password\" field contains an invalid character. Spaces and apostrophes are not allowed.");
    theForm.Student_Password.focus();
    return (false);
  }

  if (theForm.Student_Password.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"Password\" field.");
    theForm.Student_Password.focus();
    return (false);
  }

  if (theForm.Student_Password.value.length > 15)
  {
    alert("Please enter at most 15 characters in the \"Password\" field.");
    theForm.Student_Password.focus();
    return (false);
  }

  //all seems okay
  return (true);
}


//-->