<!--

//**********************************************************************************
// "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 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;
}

function FrontPage_Form2_Validator(theForm)
{
	//Validate Student_ID
  var StudId = removeSpaces(theForm.Student_Id.value);
  if (StudId == "")
  {
    alert("Please enter a value for the \"User ID\" field.");
	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);
  }
  
  //Validate Last Name
  var thisNameValue = removeSpaces(theForm.Student_Name_Last.value);
  if (thisNameValue == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    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);
  }

	//Validate First Name
  thisNameValue = removeSpaces(theForm.Student_Name_First.value);
  if (thisNameValue == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    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 > 50)
  {
    alert("Please enter at most 50 characters in the \"First Name\" field.");
    theForm.Student_Name_First.focus();
    return (false);
  }
  
  //Validate Title  
  if (theForm.Title.value == "")
  {
    alert("Please enter a value for the \"Title\" field.");
    theForm.Title.focus();
    return (false);
  }

	//Validate Student_Phone
  if (theForm.Student_Phone.value == "")
  {
    alert("Please enter a value for the \"Phone Number\" field.");
    theForm.Student_Phone.focus();
    return (false);
  }

  //Validate Student_Email
  var thisValue = removeSpaces(theForm.Student_Email.value);
  if (thisValue == "")
  {
    alert("Please enter a value for the \"E-Mail\" field.");
    theForm.Student_Email.value = thisValue;
    theForm.Student_Email.focus();
    return (false);
  } 

	//Validate Address1
  if (theForm.Address1.value == "")
  {
    alert("Please enter a value for the \"Address Line 1\" field.");
    theForm.Address1.focus();
    return (false);
  }

  //Validate City  
  thisValue = removeSpaces(theForm.City.value);
  if (thisValue == "")
  {
    alert("Please enter a value for the \"City\" field.");
    theForm.City.value = thisValue;
    theForm.City.focus();
    return (false);
  }  
  
  //Validate State
  thisValue = removeSpaces(theForm.State.value);
  if (thisValue == "")
  {
    alert("Please enter a value for the \"State\" field. It cannot be all spaces.");
    theForm.State.value = thisValue;
    theForm.State.focus();
    return (false);
  }

	//Validate Zip
	//Turned off 10/11/2006 to allow international users to register
	/*thisValue = removeSpaces(theForm.Zip.value);
	if (thisValue.length !=5)
	{
		alert("Enter a valid 5-digit Zip Code");
		theForm.Zip.value = thisValue;
		theForm.Zip.focus();
		return (false);
	} else {
		digits = "0123456789";
		for(i=0; i<5; i++)
		{
			if (digits.indexOf(thisValue.charAt(i))<0)
			{
				alert("Zip Code must be numeric");
				theForm.Zip.value = thisValue;
				theForm.Zip.focus();
				return (false);
			}
		}
	}  */
	
	
	//Validate Shipping Address info
	if (theForm.sameshipping.checked == false)
	{
		//alert("validating shipping");
		
		  if (theForm.Ship_Name.value == "")
		  {
		    alert("Please enter a value for the \"Shipping Name\" field.");
		    theForm.Address1.focus();
		    return (false);
		  }	
			
			
		  if (theForm.Ship_Address1.value == "")
		  {
		    alert("Please enter a value for the \"Shipping Address Line 1\" field.");
		    theForm.Address1.focus();
		    return (false);
		  }

		  //Validate City  
		  thisValue = removeSpaces(theForm.Ship_City.value);
		  if (thisValue == "")
		  {
		    alert("Please enter a value for the \"Shipping City\" field.");
		    theForm.City.value = thisValue;
		    theForm.City.focus();
		    return (false);
		  }  
		  
		  //Validate State
		  thisValue = removeSpaces(theForm.Ship_State.value);
		  if (thisValue == "")
		  {
		    alert("Please enter a value for the \"Shipping State\" field. It cannot be all spaces.");
		    theForm.State.value = thisValue;
		    theForm.State.focus();
		    return (false);
		  }	
			
	}
	

	
	

	//Validate Password
  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.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);
  }	
  

	//End Validation  
	return(true);

}


//-->