<!--
//**********************************************************************************
// "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 checkInvalidOneChar(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;
}

// check if string contains a specific character
function checkForChar(mainStr,findstr) {
   // will return 1 if found; 0 if not
   var foundFlag=1   // 
   foundOffset = mainStr.indexOf(findstr)
   if (foundOffset == -1) {
      // not found  
     foundFlag = 0
   }
  return foundFlag;
}

function FrontPage_Form2_Validator(theForm)
{

  if (theForm.Student_Id.value == "")
  {
    alert("Please enter a value for the \"User ID\" field.");
    theForm.Student_Id.focus();
    return (false);
  }
  var StudId = removeSpaces(theForm.Student_Id.value);
  if (StudId == "")
  {
    alert("Please enter a value for the \"User ID\" field. It cannot be all spaces.");
    theForm.Student_Id.value = StudId;
    theForm.Student_Id.focus();
    return (false);
  }
  var errFlag = checkInvalidChars(theForm.Student_Id.value);
  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);
  }

  if (theForm.Student_Name_Last.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.Student_Name_Last.focus();
    return (false);
  }
  var thisNameValue = trimSpaces(theForm.Student_Name_Last.value);
  theForm.Student_Name_Last.value = thisNameValue;
  if (thisNameValue == "")
  {
    alert("Please enter a value for the \"Last Name\" field. It cannot be all spaces.");
    theForm.Student_Name_Last.value = thisNameValue;
    theForm.Student_Name_Last.focus();
    return (false);
  }
  errFlag = checkInvalidOneChar(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);
  }

  if (theForm.Student_Name_First.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    theForm.Student_Name_First.focus();
    return (false);
  }
  thisNameValue = trimSpaces(theForm.Student_Name_First.value);
  theForm.Student_Name_First.value = thisNameValue;
  if (thisNameValue == "")
  {
    alert("Please enter a value for the \"First Name\" field. It cannot be all spaces.");
    theForm.Student_Name_First.value = thisNameValue;
    theForm.Student_Name_First.focus();
    return (false);
  }
  errFlag = checkInvalidOneChar(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 > 40)
  {
    alert("Please enter at most 50 characters in the \"First Name\" field.");
    theForm.Student_Name_First.focus();
    return (false);
  }

  if (theForm.Student_Phone.value == "")
  {
    alert("Please enter a value for the \"Phone Number\" field.");
    theForm.Student_Phone.focus();
    return (false);
  }

  if (theForm.Student_Email.value == "")
  {
    alert("Please enter a value for the \"Email Address\" field.");
    theForm.Student_Email.focus();
    return (false);
  }
  thisValue = trimSpaces(theForm.Student_Email.value);
  theForm.Student_Email.value = thisValue;
  if (thisValue == "")
  {
    alert("Please enter a value for the \"Email Address\" field. It cannot be all spaces.");
    theForm.Student_Email.value = thisValue;
    theForm.Student_Email.focus();
    return (false);
  }

  if ((theForm.Student_Email.value.length > 50) || (theForm.Student_Email.value.length < 5))
  {
    alert("Please enter a valid value in the \"Email Address\" field.");
    theForm.Student_Email.focus();
    return (false);
  }

  errFlag = checkInvalidChars(theForm.Student_Email.value);
  if (errFlag > 0)
  {
    alert("The \"Email Address\" field contains an invalid character, spaces and apostrophes are not allowed.");
    theForm.Student_Email.focus();
    return (false);
  }
  foundFlag = checkForChar(thisValue,"@");
  if ((foundFlag == 0) || (checkForChar(thisValue,".") == 0))
  {
    alert("Please enter a valid \"Email Address\".");
    theForm.Student_Email.focus();
    return (false);
  }

  var thisPassword = removeSpaces(theForm.Student_Password.value);
  if (thisPassword == "")
  {
    alert("Please enter a value for the \"Password\" field. It cannot be all spaces.");
    theForm.Student_Password.value = thisPassword;
    theForm.Student_Password.focus();
    return (false);
  }
  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.Password_Id.focus();
    return (false);
  }

  if (theForm.Student_Password.value.length > 15)
  {
    alert("Please enter at most 15 characters in the \"Password\" field.");
    theForm.Password_Id.focus();
    return (false);
  }

  return (true);
}


//-->
