<!--
//**********************************************************************************
// "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=""
  var firstChar=s.charAt(0);
  for(var i=0;i<s.length;++i) {
	var thisChar=s.charAt(i);
	// check if it contains an invalid character
	if (thisChar=="'") errFlag += thisChar;
	if (thisChar==" ") errFlag += thisChar;
	if((thisChar=="'") || (thisChar==" ")){
	  errFlag += thisChar
	}
  }
  return errFlag;
}

//**********************************************************************************
// "Internal" function to help ensure user input processed correctly; no apostrophes
//**********************************************************************************
function checkforApostrophes(s) {
  var errFlag=""
  var firstChar=s.charAt(0);
  for(var i=0;i<s.length;++i) {
	var thisChar=s.charAt(i);
	// check if it contains an invalid character
	if (thisChar=="'") errFlag += thisChar;
  }
  return errFlag;
}

function FrontPage_Form1_Validator(theForm)
{
  var StudId = removeSpaces(theForm.Student_Id.value);
  theForm.Student_Id.value = StudId;
  if (StudId == "")
  {
    alert("Please enter a value for the \"User Name\" field.");
    theForm.Student_Id.focus();
    return (false);
  }
 var errFlag = checkInvalidChars(StudId);
  if (errFlag.length > 0)
  {
    alert("The \"User Name\" field contains an invalid character, spaces and apostrophes are not allowed.");
    theForm.Student_Id.focus();
    return (false);
  }

  var thisPassword = removeSpaces(theForm.Password.value);
  theForm.Password.value = thisPassword;
  if (thisPassword == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    theForm.Password.focus();
    return (false);
  }

  errFlag = checkInvalidChars(thisPassword);
  if (errFlag.length > 0)
  {
    alert("The \"Password\" field contains an invalid character, spaces and apostrophes are not allowed.");
    theForm.Password.focus();
    return (false);
  }
// County field is only required for a new person
  if (theForm.County.value.length > 0)
  {
    var thisCounty = trimSpaces(theForm.County.value);
    theForm.County.value = thisCounty;
    errFlag = checkforApostrophes(thisCounty);
    if (errFlag.length > 0)
    {
      alert("The \"County\" field contains an invalid character, spaces and apostrophes are not allowed.");
      theForm.County.focus();
      return (false);
    }
  }


  return (true);
}

//-->
