/***********************************************
 * Function	setFocus
 * Purpose	Simple helper routine that sets the focus
 *  			on a particuarl field.
 * Parms obForm  - The Form we are working with
 *       fldName - The name of the field we are working with.
 *************************************************/
 function setFocus(obForm, fldName)
 {
	sEvalString= "obForm." + fldName + ".focus();";
	eval(sEvalString);
	sEvalString= "obForm." + fldName + ".value = '';";
 	eval(sEvalString);
  
 }


/*****************************************
 * Function 	checkForEmpties
 * Purpose		This routine will ensure that the specified form
 *					entries do have some value in them.  This is usually
 *					used to ensure that a minimum # of fields have been 
 *					filled out.  This function returns true if there
 *					are no empties, false otherwise.
 * Parms			obForm - The Form To check
 * 				aValues	- An array of field names to check.
 ******************************************/
 function checkForEmpties(obForm, aFldNames)
 {
  	sIfStatement = "bIfValue = sVal=='';";
  	sError="All fields must be filled in!";
  	return genericCheckRoutine(obForm,aFldNames,sIfStatement,sError,null);
  	
 }
 
 /**************************************************************
  * Function 	checkForNumbers
  * Purpose		This method is designed to ensure that the given
  *				fields actually have numeric values within them.
  *				It will return a false value if any of the fields
  *				contain NaNs and additionally pop up a alert box to
  *				indicate this fact.
  * Parms		obForm		The Reference to the form we are working with
  *				aFldList    The array of field names we are to check.
  **************************************************************/
  function checkForNumbers(obForm, aFldList)
  {
	 
  		sIfStatement = "bIfValue = isNaN(sVal);";
		
  		sErrorStm = "Indicated field did not contain a Valid Number";
		
  		return genericCheckRoutine(obForm, aFldList,sIfStatement,sErrorStm, null);
  
  }
  
  
/**************************************************************
 Function	checkForPhoneNumbers
 Purpose		This routine, given a list of fields, will attempt to
 				ensure that all the fields contain representations of 
 				valid Phone Numbers.
 Parms		obForm   Current form we are working with
 				aFldList List of fields to check to ensure that Phone
 				numbers are contained there-in.
 *************************************************************/
 
 function checkForPhoneNumbers(obForm,aField)
 {
 
 	myRegExp = /\(\d{3}\)\d{3}-\d{4}$|^\d{3}-?\d{4}$|^\d{10}$/;
 	sIfStatement = "bIfValue = !myRegExp.test(sVal);";
 	sErrorStm = "Indicated Field is not a phone number";
 	
 	return genericCheckRoutineSingle(obForm, aField,sIfStatement,sErrorStm, myRegExp);
 
 }
 
 
 /**************************************************************
 Function	checkPassword
 Purpose		This routine will check the 2 password and see if they match
 Parms		obForm   Current form we are working with
 				aFldList List of fields to check to ensure that Phone
 				numbers are contained there-in.
 *************************************************************/
 
 function checkPassword(obForm,aField1,aField2)
 {
	sExp = "sVal = obForm." + aField1 + ".value;";
	sExp1 = "sVal1 = obForm." + aField2 + ".value;";
	
	eval(sExp);
	eval(sExp1);
	
	if (sVal != sVal1)
	{
		alert("Passwords do not match!");
		setFocus(obForm,aField1);
		return false;
	}
	
	return true; 
 }
 	
 	
/**************************************************************
 * Function 	checkFor ValidEmailAddress
 * Purpose		This routine will check to ensure that a valid
 *					Email Address is supplied for the indicated fields.
 *	Parms			obForm	- The Form we are currently woriking with
 * 				aFldList - The array of names to check
 ************************************************************/
 function checkForValidEMail(obForm,aField)
 {
 
 	myRegExp = /^[a-zA-Z][\w\.-]*@[\w-]+\.([\w-]+\.)*[\w-]+$/;
 	sIfStatement = "bIfValue = !myRegExp.test(sVal);";
 	sErrorStm = " The E-Mail address you entered is not valid!";
 	return genericCheckRoutineSingle(obForm, aField,sIfStatement,sErrorStm, myRegExp);
  }
 	
 
 /**********************************************************
  * Function	genericCheckRoutine
  * Purpose		all the check routines that we are using have a
  *				similar makeup in their structure.  In an effort
  *				to reduce the # of lines of Code and the chances of
  *			   error creep, this function blends some of the commonality
  *				between the checks.
  *				This should almost be a class. We note that the
  *				sIfExp is to set a value bIfValue that will be used
  *				as the basis for our statement.
  *
  * Parms		obForm   - This is the form we are checking
  *				aFldList - This is the list of fields to check
  *				sIfExp   - The If expression to evaluate.
  * 				sError   - The error Message to evaluate.
  *				myRegExp - A potential Regular expression we are checking.
  ***********************************************************/
  function genericCheckRoutine(obForm,aFldList,sIfExp,sError,myRegExp)
  {
  		for(i=0; i<aFldList.length; i++)
 		{
 			sExp = "sVal = obForm." + aFldList[i] + ".value;";
 			eval(sExp);
 			
 			eval(sIfExp);
 			
 			if (bIfValue)
 			{
 				alert(sError);
 				setFocus(obForm,aFldList[i]);
 				return false;
 			}
 		}
 		return true;
 }

  /**********************************************************
  * Function	genericCheckRoutineSingle
  * Purpose		all the check routines that we are using have a
  *				similar makeup in their structure.  In an effort
  *				to reduce the # of lines of Code and the chances of
  *			   error creep, this function blends some of the commonality
  *				between the checks.
  *				This should almost be a class. We note that the
  *				sIfExp is to set a value bIfValue that will be used
  *				as the basis for our statement.
  *
  * Parms		obForm   - This is the form we are checking
  *				aFldList - This is the list of fields to check
  *				sIfExp   - The If expression to evaluate.
  * 				sError   - The error Message to evaluate.
  *				myRegExp - A potential Regular expression we are checking.
  ***********************************************************/
  function genericCheckRoutineSingle(obForm,aField,sIfExp,sError,myRegExp)
  {
	sExp = "sVal = obForm." + aField + ".value;";
	eval(sExp);

	eval(sIfExp);

	if (bIfValue)
	{
		alert(sError);
		setFocus(obForm,aField);
		return false;
	}
	return true;
 }
