        var defaultEmptyOK = true
        var dUSPhone = "10 digit U.S. phone number (like 415 555 1212)."
        var eUSPhone = "10 digit U.S. phone number (like 415 555 1212)."
        var pEmail = "valid email address (like jsmith@somewhere.com)."
        var pEntryPrompt = "Please enter a "
        // non-digit characters which are allowed in phone numbers
        var phoneNumberDelimiters = "()- ";
        var digitsInUSPhoneNumber = 10;
        var iUSPhone = "This field must be a 10 digit U.S. phone number (like 415 555 1212). Please reenter it now."
        var iEmail = "This field must be a valid email address (like jsmith@somewhere.com). Please reenter it now."
        // whitespace characters
        var whitespace = " \t\n\r";

        function validateUSPersonalInfo()
        {   return (
              checkUSPhone(document.contactSeller.elements["Phone"])
                        );
                }
		function checkUSPhone (theField, emptyOK) {
				if (checkUSPhone.arguments.length == 1) {
						emptyOK = defaultEmptyOK;
				}
				if ((emptyOK == true) && (isEmpty(theField.value))) {
						return true;
				} else {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
				   if (!isUSPhoneNumber(normalizedPhone, false)) {
                  return warnInvalid (theField, iUSPhone);
               } else {  // if you don't want to reformat as (123) 456-789, comment next line out
                  theField.value = reformatUSPhone(normalizedPhone);
                  return true;
               }
            }
        }

        // Check whether string s is empty.
        function isEmpty(s)
        {   return ((s == null) || (s.length == 0))
        }

        // Removes all characters which appear in string bag from string s.
        function stripCharsInBag (s, bag)
        {   var i;
            var returnString = "";

            // Search through string's characters one by one.
            // If character is not in bag, append to returnString.

            for (i = 0; i < s.length; i++)
            {
                // Check that current character isn't whitespace.
                var c = s.charAt(i);
                if (bag.indexOf(c) == -1) returnString += c;
            }

            return returnString;
        }

        function isUSPhoneNumber (s)
        {   if (isEmpty(s))
               if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
               else return (isUSPhoneNumber.arguments[1] == true);
            return (isInteger(s) && s.length == digitsInUSPhoneNumber)
        }

        // Notify user that contents of field theField are invalid.
        // String s describes expected contents of theField.value.
        // Put select theField, pu focus in it, and return false.
        function warnInvalid (theField, s)
        {   theField.focus()
            theField.select()
            alert(s)
            return false
        }

        // takes USPhone, a string of 10 digits
        // and reformats as (123) 456-789
        function reformatUSPhone (USPhone)
        {   return (reformat (USPhone, "(", 3, ") ", 3, "-", 4))
        }

        // Display data entry prompt string s in status bar.
        function promptEntry (s)
        {   window.status = pEntryPrompt + s
        }

        function checkEmail (theField, emptyOK)
        {   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
            if ((emptyOK == true) && (isEmpty(theField.value))) return true;
            else if (!isEmail(theField.value, false))
               return warnInvalid (theField, iEmail);
            else return true;
        }

        function isEmail (s)
        {   if (isEmpty(s))
                if (isEmail.arguments.length == 1) {
                    return defaultEmptyOK;
                } else {
                    return (isEmail.arguments[1] == true);
                }
                // is s whitespace?
                if (isWhitespace(s)) {
                    return false;
                }
                // there must be >= 1 character before @, so we
                // start looking at character position 1
                // (i.e. second character)
                var i = 1;
                var sLength = s.length;

                // look for @
                while ((i < sLength) && (s.charAt(i) != "@")) { 
                    i++
                }
                if ((i >= sLength) || (s.charAt(i) != "@")) {
                    return false;
                } else {
                    i += 2;
                }
                // look for .
                while ((i < sLength) && (s.charAt(i) != ".")) { 
                    i++
                }

                // there must be at least one character after the .
                if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
                    return false;
                } else {
                    return true;
                }
        }

        function isInteger (s)
        {   var i;

            if (isEmpty(s))
               if (isInteger.arguments.length == 1) return defaultEmptyOK;
               else return (isInteger.arguments[1] == true);

            // Search through string's characters one by one
            // until we find a non-numeric character.
            // When we do, return false; if we don't, return true.

            for (i = 0; i < s.length; i++)
            {
                // Check that current character is number.
                var c = s.charAt(i);

                if (!isDigit(c)) return false;
            }

            // All characters are numbers.
            return true;
        }

        // Returns true if character c is a digit
        // (0 .. 9).

        function isDigit (c)
        {   return ((c >= "0") && (c <= "9"))
        }

        function isUSPhoneNumber (s)
        {   if (isEmpty(s))
               if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
               else return (isUSPhoneNumber.arguments[1] == true);
            return (isInteger(s) && s.length == digitsInUSPhoneNumber)
        }

        function reformat (s)

        {   var arg;
            var sPos = 0;
            var resultString = "";

            for (var i = 1; i < reformat.arguments.length; i++) {
               arg = reformat.arguments[i];
               if (i % 2 == 1) resultString += arg;
               else {
                   resultString += s.substring(sPos, sPos + arg);
                   sPos += arg;
               }
            }
            return resultString;
        }

        // Returns true if string s is empty or
        // whitespace characters only.

        function isWhitespace (s)

        {   var i;

            // Is s empty?
            if (isEmpty(s)) return true;

            // Search through string's characters one by one
            // until we find a non-whitespace character.
            // When we do, return false; if we don't, return true.

            for (i = 0; i < s.length; i++)
            {
                // Check that current character isn't whitespace.
                var c = s.charAt(i);

                if (whitespace.indexOf(c) == -1) return false;
            }

            // All characters are whitespace.
            return true;
        }


        //limit character entry in the comments field
        function textCounter(field, maxlimit) {
            if (field.value.length > maxlimit) {
                field.value = field.value.substring(0, maxlimit);
                alert('Comments must be no more than 250 characters.');
            }
        }
        
        function validateNumericField(fieldValue) {
    if (!fieldValue) return false;
    var validChars = "0123456789";
    for (var i = 0; i < fieldValue.length; i++) {
        if (validChars.indexOf(fieldValue.charAt(i)) == -1) {
            return false;
        }
    }
    return true;
}

