//  **********************************************
//  This function verifies that the required field has at least one
//    "non-space" character.
//  Changes the class value to "error" if no non-space characters exist.
//  **********************************************
//  Calls: trimString()
//  Called by:  [onchange attr of <input id="pers_name"]
// BEGIN ******* checkPersonalization FUNCTION *******************
function checkRequired(
			id, // id of the input field
			rqd // id of the span that follows the input field
			)
{
  var val = trimString(document.getElementById(id).value);
  document.getElementById(id).value = val;
  if(val != "")  {  // display "required" in gray
    document.getElementById(rqd).className = "required";
    document.getElementById(rqd).setAttribute("class", "required");
  }
  if(val == "")  {  // display "required" in red
    document.getElementById(rqd).className = "error";
    document.getElementById(rqd).setAttribute("class", "error");
  }
} // END ******* checkRequired FUNCTION *******************

function checkRequiredAll(
			)
{
  checkRequired('id_first','fn_rqd');
  checkRequired('id_last','ln_rqd');
  checkRequired('id_amt','amt_rqd');
} // END ******* checkRequiredAll FUNCTION *******************


//  **********************************************
//  Check user-input fields in the form prior to sending order to cart.
//  Upon detecting >= 1 error(s), display alert and stop form submittal.
//  **********************************************
// Calls: readForm(), calculate(), trimString()
// Called by: [document.fmBuy's Submit button]
// BEGIN ******* validateForm FUNCTION *******************
function validateForm()
{
  var valid = new Boolean(true);
  var err = "";
  // If a FIRST NAME has not been entered
  if (document.getElementById("fn_rqd").className == "error" ||
      document.getElementById("fn_rqd").getAttribute("class") == "error")
  {
    err = err + "    - First Name\n";
    valid = false;
  }
  // If a LAST NAME has not been entered
  if (document.getElementById("ln_rqd").className == "error" ||
      document.getElementById("ln_rqd").getAttribute("class") == "error")
  {
    err = err + "    - Last Name\n";
    valid = false;
  }
  // If an AMOUNT has not been entered
  if (document.getElementById("amt_rqd").className == "error" ||
      document.getElementById("amt_rqd").getAttribute("class") == "error")
  {
    err = err + "    - Amount\n";
    valid = false;
  }

  // If an AMOUNT is not a number
  if (isNaN(document.getElementById("id_amt").value))
  {
    err = err + "    - A Valid Number\n";
    valid = false;
  }
  if (valid) {
    // want to quickly go to a Beyond page that processes the data and redirects to the YL site
    return document.forms[0].submit();
	// return valid;
  }
  else { // form is  not valid
    alert("Please enter:                             \n" + err);
	return valid;
  }
} // END ******* validateForm FUNCTION *******************



//  **********************************************
//  This function removes leading and trailing spaces from a string
//  **********************************************
//  Calls: ----
//  Called by: readForm(), checkPersonalization(), validateDate()
// BEGIN ******* trimString FUNCTION *******************
// reference: http://www.pbdr.com/jscript/trimstr.htm
function trimString(
			str  // the string to be trimmed
			)
{
  str = str.replace( /^\s+/g, "" );// strip leading

  return str.replace( /\s+$/g, "" );// strip trailing
} // END ******* trimString FUNCTION *******************