<!-- Begin

// check for IE3
var isIE3 = (navigator.appVersion.indexOf('MSIE 3') != -1);


/***************************************************************
** define and instantiate validation objects
** the validation object accepts the following parameters:
**
**   realName: name used in the alerts (same as label on the page)
**
**   formEltName: this must be the name of the corresponding
**       HTML form element; make it the same as the object name
**
**   required: 'R' if the field is required to be present
**             null if the field is not required, but should be checked for valid data
**
**   eltType: element type (we have to create this since IE3
**       doesn't support the type property for for elements)
**     text
**     textarea
**     checkbox
**     radio
**     select
**
**   uptoSnuff: function call that's evaluated during validation check
**     isText(str)
**     isSelect(formObj)
**     isRadio(formObj)
**     isCheck(formObj, form, [index of first checkbox in group],
**         [number of checkboxes])
**     isEmail(str)
**     isState(str)
**     isZipCode(str)
**     isPhoneNum(str)
**     isDate(str)
**
**   format: text representation of required format;
**       pass 'null' if no required format;
**       used in alert as an aid to user
***************************************************************/

// object definition
function validation(realName, formEltName, required, eltType, upToSnuff, format) {
  this.realName = realName;
  this.formEltName = formEltName;
  this.required = required;
  this.eltType = eltType;
  this.upToSnuff = upToSnuff;
  this.format = format;
}

/***************************************************************
** create a new object for each form element you need to validate
** for example:
** var lastName = new validation('last name', 'lastName', 'text', 'isText(str)', null);
** var phoneNum = new validation('phone number', 'phoneNum', 'text', 'isPhoneNum(str)', 'xxx-xxx-xxxx');
** var reason = new validation('reason for reading this', 'reason', 'checkbox', 'isCheck(formObj, form, 14, 3)', null);
***************************************************************/
// create objects here:

// These objects are for the Student Registration Form
var firstName      = new validation('first name', 'firstname', 'R', 'text', 'isMultiName(str)', null);
var lastName       = new validation('last name', 'lastname', 'R', 'text', 'isMultiName(str)', null);
var streetAd       = new validation('street address', 'street', 'R', 'text', 'isText(str)', null);
var streetAd2      = new validation('street address second line', 'street2', null, 'text', 'isText(str)', null);
var streetAd3      = new validation('street address third line', 'street3', null, 'text', 'isText(str)', null);
var city           = new validation('city', 'city', 'R', 'text', 'isMultiName(str)', null);
var country        = new validation('country', 'country', 'R', 'select', 'isSelect(formObj)', null);
var province       = new validation('province or state', 'province', null, 'select', 'isSelect(formObj)', null);
var postalCode     = new validation('postal code or zip code', 'postalcode', 'R', 'text', "isPostal(str,'country')", null);
var email          = new validation('email address', 'email', null, 'text', 'isEmail(str)', null);
var phoneday       = new validation('daytime phone number', 'dayphone', null, 'text', 'isIPhoneNum(str)', null);
var phoneevening   = new validation('evening phone number', 'eveningphone', null, 'text', 'isIPhoneNum(str)', null);
var currency       = new validation('currency', 'currency', 'R', 'radio', 'isRadio(formObj)', null);
var matrixqty      = new validation('matrix quanity', 'matrixqty', null, 'select', 'isSelect(formObj)', null);
var matrixtotal    = new validation('matrix total', 'matrixtotal', null, 'text', 'isMultiName(str)', null);
var kitqty         = new validation('electrode kit quanity', 'kitqty', null, 'select', 'isSelect(formObj)', null);
var kittotal       = new validation('electrode kit total', 'kittotal', null, 'text', 'isMultiName(str)', null);
var shipping       = new validation('shipping', 'shipping', 'R', 'radio', 'isRadio(formObj)', null);
var instructions   = new validation('special instructions', 'instructions', null, 'textarea', 'isText(str)', null);

/***************************************************************
** Define the elts array:
** Add a new item to the array for each object you create above
** Make sure the value of the array element is the same as
** the name of the object, and that the array elements are listed
** in the same order the corresponding objects appear in the form
** (it's more clear to the user that way)
** for example:
** var elts = new Array(lastName, phoneNum, reason)
***************************************************************/
// Page 1 form array structure
var ifelts = new Array(
               firstName, lastName, streetAd, streetAd2, streetAd3, city, 
               country, province, 
               postalCode, email, phoneday, phoneevening, currency,
               matrixqty, matrixtotal, kitqty, kittotal, shipping,
               instructions				
			);

/***************************************************************
** The main function keeps track of which fields the user missed
** or filled in incorrectly, and alerts the user so they can go
** back and fix what's wrong.
** Set allAtOnce to true if you want this "validation help" to
** alert the user to all mistakes at once; set it to false if
** you want it to show one mistake at a time
***************************************************************/
var allAtOnce = true;


/***************************************************************
** change text for alerts here
** unspecified field (text): "Please include [field name]."
** unspecified field (other): "Please choose [field name]."
** invalid text field entries: "[field value] is an invalid [field name]!"
** help with format: "Use this format: "
***************************************************************/
var beginRequestAlertForText = "Please include ";
var beginRequestAlertGeneric = "Please choose ";
var endRequestAlert = ".";
var beginInvalidAlert = " is an invalid ";
var endInvalidAlert = "!";
var beginFormatAlert = "   ";


/***************************************************************
** these functions validate the string or form object passed in,
** and return true or false based on whether the test succeeds or fails
**
** validate existence of input
**   isText(str): verifies text input or textarea is not empty
**   isSelect(formObj): verifies item from a select menu is chosen
**   isRadio(formObj): verifies one of a group of radio buttons is chosen
**   isCheck(formObj, form, [begin], [num]): verifies at least one
**       of a group of checkboxes is checked
**     for [begin], fill in the index number in the elements array
**         of the first checkbox (remember to start counting from zero)
**     for [num], fill in the number of checkboxes in the group
**
** validate text in text input or textarea matches pattern
**   isEmail(str): verifies email address (contains "@" and ".")
**   isState(str): verifies U.S. State Code
**   isZipCode(str): verifies zip code of form xxxxx or xxxxx-xxxx
**   isPhoneNum(str): verifies phone number of form xxx-xxx-xxxx
**   isDate(str): verifies date of form mm/dd/yyyy
***************************************************************/

function isText(str) {
	var errors = "";
	if (str == "")
		return false;
	else if (!validvalue(str,"abcdefghijklmnopqrstuvwxyz0123456789 _-().,/!&:;#?",0)) errors ='Must contain only letters, number, puncutation, parenthesis or hyphens.';
   if (errors) {
	 elts[i].format = errors;
	 return false;
   } else
  	 return true;
}

function isName(str) {
	var errors = "";
   if (str.length < 2) errors = 'Must contain more than one letter and can only contain letters and hyphens.';
   else if (!validvalue(str,"abcdefghijklmnopqrstuvwxyz-",0)) errors ='Must contain only letters or hyphens.';
   if (errors) {
	 elts[i].format = errors;
	 return false;
   } else
  	 return true;
}

function isMultiName(str) {
	var errors = "";
	if (str.length < 2) 
		errors ='Must contain more than one letter and can only contain letters, hyphens, periods and spaces.';
	else if (!validvalue(str,"abcdefghijklmnopqrstuvwxyzéèàùâêîôûçëïü0123456789- '.",0)) 
		errors ='Must contain only letters, spaces, numbers, periods or hyphens.'
   if (errors) {
	 elts[i].format = errors;
	 return false;
   } else
  	 return true;
}

function isMultiNameN(str) {
	var errors = "";
	if (str.length < 2) 
		errors ='Must contain more than one letter and can only contain letters, hyphens, periods and spaces.';
	else if (!validvalue(str,"abcdefghijklmnopqrstuvwxyzéèàùâêîôûçëïü0123456789- '.",0)) 
		errors ='Must contain only letters, spaces, numbers, periods or hyphens.'
	else if (str.indexOf("None") != -1)
		errors ='Must contain only letters, spaces, numbers, periods or hyphens.'
   if (errors) {
	 elts[i].format = errors;
	 return false;
   } else
  	 return true;
}

function isMultiAlpha(str) {
	var errors = "";
	if (str.length < 2) 
		errors ='Must contain more than one letter and can only contain letters, hyphens, puncutation and spaces.';
	else if (!validvalue(str,"abcdefghijklmnopqrstuvwxyzéèàùâêîôûçëïü0123456789- '.()!?:;,\"",0)) 
		errors ='Must contain only letters, spaces, numbers, puncutation or hyphens.'
   if (errors) {
	 elts[i].format = errors;
	 return false;
   } else
  	 return true;
}

function isIPhoneNum(str) {
	var errors = "";
	if (str.length < 7) 
		errors ='Must contain full number including area code, only numbers, hyphens and () allowed.';
	else if (!validvalue(str,"0123456789-()",0)) 
		errors ='Must contain only numbers, hyphens and ()s.'
   if (errors) {
	 elts[i].format = errors;
	 return false;
   } else
  	 return true;
}

function isGrade(str) {
	var errors = "";
	if (!validvalue(str,"kK0123456789-",0))
		if (str.indexOf("None") == -1)
			errors ='Must contain only the leter K, the numbers 1 to 12, or a hyphen. Use format x-y.\n'
   if (errors) {
	 elts[i].format = errors;
	 return false;
   } else
  	 return true;
}

function isGradeN(str) {
	var errors = "";
	if (!validvalue(str,"k0123456789-",0))
		errors ='Must contain only the leter K, the numbers 1 to 12, or a hyphen.\nUse format x-y for a grade range.\n'
	else { /* Check if the numbers entered are valid */
		hyphenIndex = str.indexOf('-');
		if (hyphenIndex == -1) { /* Was a range entered? */
			if (!validGrade(str)) /* No, so check for K or number from 1-12 */
				errors ='Must contain only the leter K, the numbers 1 to 12, or a hyphen.\nUse format x-y for a grade range.\n'
		} else { /* Range was entered */
			if (hyphenIndex == 0)
				errors ='Must contain only the leter K, the numbers 1 to 12, or a hyphen.\nUse format x-y for a grade range.\n'				
			else
				if (!validGrade(str.substring(0,(hyphenIndex)))) /* First number valid */
					errors ='Must contain only the leter K, the numbers 1 to 12, or a hyphen.\nUse format x-y for a grade range.\n'
				else
					if (!validGrade(str.substring((hyphenIndex+1)))) /* Second number valid */			
						errors ='Must contain only the leter K, the numbers 1 to 12, or a hyphen.\nUse format x-y for a grade range.\n'
		}
	}
   if (errors) {
	 elts[i].format = errors;
	 return false;
   } else
  	 return true;
}

function validGrade(value) {
	if (value.toLowerCase() != 'k') { /* No, so check for K */
		num = parseFloat(value);
		if (value!=''+num)
			return false
		else
			if (num < 1 || num > 12)
				return false
			else
				return true
	} else {
		return true
	}
}

function isAlpha(str) {
	var errors = "";
   if (str.length < 2) errors = 'Must contain more than one character and can only contain letters, numbers, periods, hyphens, or underscores.';
   else if (!validvalue(str,"abcdefghijklmnopqrstuvwxyz1234567890.-_",0)) errors ='Must contain only letters, numbers, periods, hyphens, or underscores.';
   if (errors) {
	 elts[i].format = errors;
	 return false;
   } else
  	 return true;
}

function isURL(str) {
	var errors = "";
   if (!validvalue(str,"abcdefghijklmnopqrstuvwxyz1234567890.-_/:~",0)) errors ='Must contain a valid URL.';
   if (errors) {
	 elts[i].format = errors;
	 return false;
   } else
  	 return true;
}

function isSelect(formObj) {
  if (formObj.selectedIndex == -1) {
  	return false
  } else {
    if (formObj.options[formObj.selectedIndex].value == "0") {
		return false
	} else {
	  return true
	}
  }
}

function isRadio(formObj) {
  for (j=0; j<formObj.length; j++) {
    if (formObj[j].checked) {
      return true;
    }
  }
  return false;
}

function isCheck(formObj, form, begin, num) {
  for (j=begin; j<begin+num; j++) {
    if (form.elements[j].checked) {
      return true;
    }
  }
  return false;
}

function isNum(str) {
	var errors = "";
	num = parseFloat(str);
    if (str!=''+num) errors ='Must contain a number.';
    if (errors) {
		elts[i].format = errors;
		return false;
  	} else
  		return true;
}

function in4Range(str, lower, upper) {
	var errors = "";
	if (str.length < 4) errors ='Must contain a 4 digit number between '+lower+' and '+upper+'.';
	num = parseFloat(str);
    if (!validvalue(str,"1234567890",0)) errors ='Must contain a 4 digit number between '+lower+' and '+upper+'.';
	if (num<lower || upper<num) errors ='Must contain a 4 digit number between '+lower+' and '+upper+'.';
    if (errors) {
		elts[i].format = errors;
		return false;
  	} else
  		return true;
}

function inRange(str, lower, upper) {
	var errors = "";
	num = parseFloat(str);
    if (str!=''+num) errors ='Must contain a number between '+lower+' and '+upper+'.';
	else if (num<lower || upper<num) errors ='Must contain a number between '+lower+' and '+upper+'.';
    if (errors) {
		elts[i].format = errors;
		return false;
  	} else
  		return true;
}

function inLRange(str, lower, upper) { //Leading 0's are ok
	var errors = "";
	while (str.charAt(0) == "0") { // Strip off leading zeroes
		str = str.substring(1);
	}
	return inRange(str, lower, upper);
}

function isPassword(str) {
	var errors = "";
  errors = validatePswd(str);
  if (errors) {
	elts[i].format = errors;
	return false;
  } else
  	return true;
}
// Validate USA Zip Codes for the format 5 digits or 5 digits-4 digits
//
function validateZIP(field) {
	var valid = "0123456789-";
	var hyphencount = 0;
	var errors = "";

	if (field.length!=5 && field.length!=10)
		errors = "Please enter your 5 digit or 5 digit+4 digit zip code.";

	for (var i=0; i < field.length; i++) {
		temp = "" + field.substring(i, i+1);
		if (temp == "-") hyphencount++;
		if (valid.indexOf(temp) == "-1")
			errors = "Invalid characters in your zip code. Please enter your 5 digit or 5 digit+4 digit zip code.";
		if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-"))
			errors = "The hyphen character should be used with a properly formatted 5 digit+4 digit zip code, like '12345-6789'.";
	}
	return errors;
}

// Validate Canadian Postal code for the format A1A 1A1
//
// Parameters: postalCode is the postal code to be checked
//             reformats the postal code properly formatted & capitalized, if no errors
//
// Returns: null if there were no errors in the postal code
//			error string if an error was found
//
function ValidateCdnPostal(postalCode)
{
	var lnl = ""; // Initialize the letter number letter part of the postal code
	var nln = ""; // Initialize the number letter number part of the postal code
	var errors = ""; // Initialize the error string

	// Format must be Letter Number Letter (optional space) Number Letter Number
	if (postalCode.length == 6 || postalCode.length == 7) {
		lnl = postalCode.substring(0,3); // Take off the letter number letter part
		if (postalCode.indexOf(" ") == 3)
			nln = postalCode.substring(4,7) // Get the number letter number part, skipping the space
		else {
			nln = postalCode.substring(3,6); // Get the number letter number part, no space to skip
			postalCode = lnl + " " + nln; // Add the space to the postal code
		}
		letterStr = lnl.charAt(0) + lnl.charAt(2) + nln.charAt(1); // Make a new string of the letters
		numStr = lnl.charAt(1) + nln.charAt(0) + nln.charAt(2); // make a new string of the numbers
		if (!validvalue(letterStr,"abcdefghijklmnopqrstuvwxyz",0) || !validvalue(numStr, "0123456789", 0)) {
			errors = "Canadian postal code must be in the format A1A 1A1.";
		}
		else {
			postalCode = postalCode.toUpperCase(); // make sure the letters are in upper case
		}
	}
	else {
		errors = "Canadian postal code must be in the format A1A 1A1.";
	}
	return errors;
}

// Validates the Postal or Zip Code Field
//          properly formatted postal code if the postal code is ok
//          error string is stored in the format field of the array if an error is found
//
// Parameters: postalCode is the postal/zip code that the user entered
//             country is the country that the user entered
//
// Returns: true if there is no errors in the postal/zip code
//
function isPostal (postalCode, country)
{
	var errors = "";
	
  	switch (country) {
		case "US": {
			errors = validateZIP(postalCode); // check USA postal code format
			break;
		}
		case "CA": {
			errors = ValidateCdnPostal(postalCode); // check for valid Canadian Postal code format
			break;
		}
		default: {
			if (!validvalue(postalCode, "abcdefghijklmnopqrstuvwxyz1234567890- ", 0)) // Some other country, so check for only numbers & letters
				errors = "Only letters, numbers, hyphen and spaces are allowed for postal/zip codes.";
		}
	}
   if (errors) {
	 elts[i].format = errors;
	 return false;
   } else
  	 return true;
}

function isEmail(str) {
	var errors = "";
  errors = emailCheck(str);
  if (errors) {
	elts[i].format = errors;
	return false;
  } else
  	return true;
}

<!-- Changes:  Sandeep V. Tamhankar (stamhankar@hotmail.com)

/* 1.1.2: Fixed a bug where trailing . in e-mail address was passing
            (the bug is actually in the weak regexp engine of the browser; I
            simplified the regexps to make it work).
   1.1.1: Removed restriction that countries must be preceded by a domain,
            so abc@host.uk is now legal.  However, there's still the 
            restriction that an address must end in a two or three letter
            word.
     1.1: Rewrote most of the function to conform more closely to RFC 822.
     1.0: Original  */

<!-- This script and many more are available free online at
<!-- The JavaScript Source!! http://javascript.internet.com

<!-- Begin
function emailCheck (emailStr) {
	var errorStr = ""; //initialize the error string
	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
  		which case, there are no rules about which characters are allowed
   		and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   		is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
   		rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   		e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
   		non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
   		For example, in john.doe@somewhere.com, john and doe are words.
   		Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
		// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
   		domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	/* Finally, let's start trying to figure out if the supplied address is
   		valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
   		different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
 	 /* Too many/few @'s or something; basically, this address doesn't
     	even fit the general mould of a valid e-mail address. */
		return (errorStr += "Email address is incorrect (check @ and .'s).");
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
    	// user is not valid
    	return (errorStr += "The username doesn't seem to be valid.");
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
   		host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
    	// this is an IP address
	  	for (var i=1;i<=4;i++) {
	    	if (IPArray[i]>255) {
	        	return (errorStr += "Destination IP address is invalid!");
	    	}
    	}
    	return errorStr;
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null)
		return (errorStr += "The domain name doesn't seem to be valid.");

	/* domain name seems valid, but now make sure that it ends in a
   		three-letter word (like com, edu, gov) or a two-letter word,
   		representing country (uk, nl), and that there's a hostname preceding 
   		the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
   		it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
    	domArr[domArr.length-1].length>3) {
   		// the address must end in a two letter or three letter word.
   		return (errorStr += "The address must end in a three-letter domain, or two letter country.");
	}

	// Make sure there's a host name preceding the domain.
	if (len<2)
   		return (errorStr += "This address is missing a hostname!");

	// If we've gotten this far, everything's valid!
	return errorStr;
}

function isState(str) {
  str = str.toUpperCase();
  return ( (str == "AK") || (str == "AL") || (str == "AR") || (str == "AZ") || (str == "CA") || (str == "CO") || (str == "CT") || (str == "DC") || (str == "DE") || (str == "FL") || (str == "GA") || (str == "HI") || (str == "IA") || (str == "ID") || (str == "IL") || (str == "IN") || (str == "KS") || (str == "KY") || (str == "LA") || (str == "MA") || (str == "MD") || (str == "ME") || (str == "MI") || (str == "MN") || (str == "MO") || (str == "MS") || (str == "MT") || (str == "NB") || (str == "NC") || (str == "ND") || (str == "NH") || (str == "NJ") || (str == "NM") || (str == "NV") || (str == "NY") || (str == "OH") || (str == "OK") || (str == "OR") || (str == "PA") || (str == "RI") || (str == "SC") || (str == "SD") || (str == "TN") || (str == "TX") || (str == "UT") || (str == "VA") || (str == "VT") || (str == "WA") || (str == "WI") || (str == "WV") || (str == "WY") );
}


function isPhoneNum(str) {
  if (str.length != 12) { return false }
  for (j=0; j<str.length; j++) {
    if ((j == 3) || (j == 7)) {
      if (str.charAt(j) != "-") { return false }
    } else {
      if ((str.charAt(j) < "0") || (str.charAt(j) > "9")) { return false }
    }
  }
  return true;
}

function isDate(str) {
  if (str.length != 10) { return false }

  for (j=0; j<str.length; j++) {
    if ((j == 2) || (j == 5)) {
      if (str.charAt(j) != "/") { return false }
    } else {
      if ((str.charAt(j) < "0") || (str.charAt(j) > "9")) { return false }
    }
  }

  var month = str.charAt(0) == "0" ? parseInt(str.substring(1,2)) : parseInt(str.substring(0,2));
  var day = str.charAt(3) == "0" ? parseInt(str.substring(4,5)) : parseInt(str.substring(3,5));
  var begin = str.charAt(6) == "0" ? (str.charAt(7) == "0" ? (str.charAt(8) == "0" ? 9 : 8) : 7) : 6;
  var year = parseInt(str.substring(begin, 10));

  if (day == 0) { return false }
  if (month == 0 || month > 12) { return false }
  if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
    if (day > 31) { return false }
  } else {
    if (month == 4 || month == 6 || month == 9 || month == 11) {
      if (day > 30) { return false }
    } else {
      if (year%4 != 0) {
        if (day > 28) { return false }
      } else {
        if (day > 29) { return false }
      }
    }
  }
  return true;
}
/* ====================================================================
*/
/* Function to check that field value doesn't contain invalid characters
*/
/* ====================================================================
*/
/* Inputs are the string to be checked, the characters to be allowed and
flag value indicating */
/* if check on letters is to be case sensitive, where 1 inidcates it is
case sensitive */
/* Return code is true is field value is valid, false if not. */
function validvalue(value,validchars,casesensitive) {

        /* If not case sensitive then convert both value and valid */
        /* characters to upper case */
        if (casesensitive!=1) {
                value=value.toUpperCase();
                validchars=validchars.toUpperCase();
        }

        /* Go through each character in value until either end or hit an
invalid char */
        charposn=0;
        while
((charposn<value.length)&&(validchars.indexOf(value.charAt(charposn))!=-
1)) {
                charposn++;
        }

        /* Check if stop was due to end of input string or invalid char and set
return code */
        /* accordingly */
        if (charposn==value.length) {
                return(true);
        } else {
                return(false);
        }
}
// Checks for a valid password and returns and errorstring.
// errorstring is blank if the password is ok
//             otherwise it will have a message explaining what is wrong
function validatePswd(passwordstr)
{
	var invalid = " "; // Invalid character is a space
	var minLength = 4; // Minimum length
	var maxlength = 12; // Maximum length
	var errorstring = ""; //error return string
	// check for minimum length
	if (passwordstr.length < minLength || passwordstr.length > maxlength)
		return errorstring += "Valid passwords are 4 to 12 characters long.";
	// check for spaces
	if (passwordstr.indexOf(invalid) > -1)
	{
		errorstring += "Sorry, spaces are not allowed.\n";
		return errorstring += "Valid passwords are 4 to 12 characters long."
	}
	else if (!validvalue(passwordstr,"abcdefghijklmnopqrstuvwxyz1234567890.-_",0))
	{
		errorstring += "Sorry, only letters, numbers, periods, hyphens and underscores are allowed.\n";
		return errorstring += "Valid passwords are 4 to 12 characters long.";
	}
	else
		return errorstring;
}

function ifValidateForm(form) {
    var error;
	error = validateForm(form, "if");
    /* Check to make sure something was ordered */
    if ((form.matrixqty.options[form.matrixqty.selectedIndex].value == "0") &&
       (form.kitqty.options[form.kitqty.selectedIndex].value == "0")) {
        alert("You must order some products, please choose how many of each product you would like to order.");
        return false;
    }
    return error;
}

/***************************************************************
** The validateForm() function validates the form elements
** previously defined as validation objects and as members of
** the elts array. We loop through the elts array, testing each
** element in turn, and alerting the user when they've missed
** a required field
***************************************************************/

function validateForm(form, prefix) {
  var formEltName = "";
  var formObj = "";
  var str = "";
  var realName = "";
  var required = null;
  var alertText = "";
  var firstMissingElt = null;
  var hardReturn = "\r\n";
  
  elts = eval(prefix + "elts");

  for (i=0; i<elts.length; i++) {
    formEltName = elts[i].formEltName;
    formObj = eval("form." + formEltName);
    realName = elts[i].realName;
	required = elts[i].required;
    if ((elts[i].eltType == "text") || (elts[i].eltType == "password")
        || (elts[i].eltType == "textarea")) {
     str = formObj.value;

		if (elts[i].upToSnuff.indexOf(',') != -1) { // This function call has a 2nd argument, so need to set it up
			secName = elts[i].upToSnuff.substring(elts[i].upToSnuff.indexOf(',')+2,elts[i].upToSnuff.indexOf(')')-1);
			depformObj = eval("form." + secName);
			type = depformObj.options[depformObj.selectedIndex].value //Select type of field
			if (eval(elts[i].upToSnuff.substring(0,elts[i].upToSnuff.indexOf(',')) + ",\"" + type + "\")")) continue;
		} else if ((elts[i].upToSnuff.indexOf('inRange')!= -1) || (elts[i].upToSnuff.indexOf('inLRange') != -1)
					|| (elts[i].upToSnuff.indexOf('in4Range') != -1)) { // This is a range number test
			position = elts[i].upToSnuff.indexOf(':');
			endnumpos = elts[i].upToSnuff.indexOf('(');
          	lower=elts[i].upToSnuff.substring(7,position);
			upper=elts[i].upToSnuff.substring(position+1,endnumpos);
			if (elts[i].upToSnuff.indexOf('inRange')!= -1) {
          		lower=elts[i].upToSnuff.substring(7,position);
				if (inRange(str, lower, upper)) continue
			} else {
          		lower=elts[i].upToSnuff.substring(8,position);
				if (elts[i].upToSnuff.indexOf('inLRange')!= -1) {
					if (inLRange(str, lower, upper)) continue
				} else {
					if (in4Range(str, lower, upper)) continue	
				}
			}
		} else {
			if (eval(elts[i].upToSnuff)) continue;
		}

      if (str == "") {
	    if (required == 'R') {
        	if (allAtOnce) {
          		alertText += beginRequestAlertForText + realName + endRequestAlert + hardReturn;
          		if (firstMissingElt == null) {firstMissingElt = formObj};
        	} else {
          		alertText = beginRequestAlertForText + realName + endRequestAlert + hardReturn;
          		alert(alertText);
        	}
		}
      } else {
        if (allAtOnce) {
          alertText += str + beginInvalidAlert + realName + endInvalidAlert + hardReturn;
        } else {
          alertText = str + beginInvalidAlert + realName + endInvalidAlert + hardReturn;
        }
        if (elts[i].format != null) {
          alertText += beginFormatAlert + elts[i].format + hardReturn;
        }
        if (allAtOnce) {
          if (firstMissingElt == null) {firstMissingElt = formObj};
        } else {
          alert(alertText);
        }
      }
    } else { // not a text type field
      if (eval(elts[i].upToSnuff)) continue;
	  if (required == 'R') {
      	if (allAtOnce) {
        	alertText += beginRequestAlertGeneric + realName + endRequestAlert + hardReturn;
        	if (firstMissingElt == null) {firstMissingElt = formObj};
      	} else {
        	alertText = beginRequestAlertGeneric + realName + endRequestAlert + hardReturn;
        	alert(alertText);
      	}
	  }
    }
    if ((!isIE3) && (required == 'R')) {
      var goToObj = (allAtOnce) ? firstMissingElt : formObj;
      if (goToObj.select) goToObj.select();
      if (goToObj.focus) goToObj.focus();
    }
    if (!allAtOnce) {return false};
  }
  if (allAtOnce) {
    if (alertText != "") {
      alert(alertText);
      return false;
    }
  } 
  // alert("I am valid!"); //remove this line when you use the code
  return true; //change this to return true
}

function ifValidateField(form, fieldName) {
	return validateField(form, "if", fieldName);
}

function validateField(form, prefix, fieldName) {
  var formEltName = "";
  var formObj = "";
  var str = "";
  var realName = "";
  var required = null;
  var alertText = "";
  var firstMissingElt = null;
  var hardReturn = "\r\n";
  elts = eval(prefix + "elts");

  for (i=0; i<elts.length; i++) {
    formEltName = elts[i].formEltName;
	if (fieldName == formEltName) break;
  }
    formObj = eval("form." + formEltName);
    realName = elts[i].realName;
	required = elts[i].required;

    if ((elts[i].eltType == "text") || (elts[i].eltType == "password")
         || (elts[i].eltType == "textarea")) {
		str = formObj.value; // Set value of first argument
		if (elts[i].upToSnuff.indexOf(',') != -1) { // This function call has a 2nd argument, so need to set it up
			secName = elts[i].upToSnuff.substring(elts[i].upToSnuff.indexOf(',')+2,elts[i].upToSnuff.indexOf(')')-1);
			depformObj = eval("form." + secName);
			type = depformObj.options[depformObj.selectedIndex].value //Select type of field
			if (eval(elts[i].upToSnuff.substring(0,elts[i].upToSnuff.indexOf(',')) + ",\"" + type + "\")")) return true;
		} else if ((elts[i].upToSnuff.indexOf('inRange')!= -1) || (elts[i].upToSnuff.indexOf('inLRange') != -1)
					|| (elts[i].upToSnuff.indexOf('in4Range') != -1)) { // This is a range number test
			position = elts[i].upToSnuff.indexOf(':');
			endnumpos = elts[i].upToSnuff.indexOf('(');
			upper=elts[i].upToSnuff.substring(position+1,endnumpos);
			if (elts[i].upToSnuff.indexOf('inRange')!= -1) {
          		lower=elts[i].upToSnuff.substring(7,position);
				if (inRange(str, lower, upper)) return true
			} else {
          		lower=elts[i].upToSnuff.substring(8,position);
				if (elts[i].upToSnuff.indexOf('inLRange')!= -1) {
					if (inLRange(str, lower, upper)) return true
				} else {
					if (in4Range(str, lower, upper)) return true
				}
			}
		} else {
			if (eval(elts[i].upToSnuff)) return true;
		}
		if (str == "") {
			if (required == 'R') {
          		alertText = beginRequestAlertForText + realName + endRequestAlert + hardReturn;
  			}
		} else {
          alertText = str + beginInvalidAlert + realName + endInvalidAlert + hardReturn;
		}
        if (elts[i].format != null) {
			alertText += beginFormatAlert + elts[i].format + hardReturn;
        }
       alert(alertText);
	   formObj.focus();
	   formObj.select();
	   return false;
	} else {
		if (eval(elts[i].upToSnuff)) return true;
		
		if (required == 'R') {
        	alertText = beginRequestAlertGeneric + realName + endRequestAlert + hardReturn;
        	alert(alertText);
			formObj.focus();
			formObj.select();
			return false;
      	}
	}
//  alert("I am valid!"); //remove this line when you use the code
  return true; //change this to return true
}


// End -->
