function CheckForAlpha(theField) 
{ 
  var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
  var checkStr = theField; 
  var allValid = true; 
  for (i = 0;  i < checkStr.length;  i++) 
  { 
    ch = checkStr.charAt(i); 
    for (j = 0;  j < checkOK.length;  j++) 
      if (ch == checkOK.charAt(j)) 
        break; 
    if (j == checkOK.length) 
    { 
      allValid = false; 
      break; 
    } 
  } 
  return(allValid);
} 

function CheckForCaps(theField) 
{ 
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
  var checkStr = theField; 
  var allValid = true; 
  for (i = 0;  i < checkStr.length;  i++) 
  { 
    ch = checkStr.charAt(i); 
    for (j = 0;  j < checkOK.length;  j++) 
      if (ch == checkOK.charAt(j)) 
        break; 
    if (j == checkOK.length) 
    { 
      allValid = false; 
      break; 
    } 
  } 
  return(allValid); 
} 

function CheckForNumerics(theField) 
{ 
  var checkOK = "0123456789-.,"; 
  var checkStr = theField; 
  var allValid = true; 
  var decPoints = 0; 
  var allNum = ""; 
  for (i = 0;  i < checkStr.length;  i++) 
  { 
    ch = checkStr.charAt(i); 
    for (j = 0;  j < checkOK.length;  j++) 
      if (ch == checkOK.charAt(j)) 
        break; 
    if (j == checkOK.length) 
    { 
      allValid = false; 
      break; 
    } 
    if (ch == ".") 
    { 
      allNum += "."; 
      decPoints++; 
    } 
    else if (ch != ",") 
      allNum += ch; 
  } 
  if (decPoints > 1) 
    { 
      allValid = false; 
    } 
        
        return(allValid); 
} 

function ContainsAlpha(theField) 
{ 
  var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
  var checkStr = theField;
  var allValid = false; 
  for (i = 0;  i < checkStr.length;  i++) 
  { 
    ch = checkStr.charAt(i); 
    for (j = 0;  j < checkOK.length;  j++) 
      if (ch == checkOK.charAt(j)) 
		return true;
        break; 
    if (j == checkOK.length) 
    { 
      allValid = false; 
      break; 
    } 
  } 
  return(allValid); 
} 

function ContainsNumeric(theField) 
{ 
  var checkOK = "0123456789"; 
  var checkStr = theField;
  var allValid = false; 
  for (i = 0;  i < checkStr.length;  i++) 
  { 
    ch = checkStr.charAt(i); 
    for (j = 0;  j < checkOK.length;  j++) 
      if (ch == checkOK.charAt(j)) 
		return true;
        break; 
    if (j == checkOK.length) 
    { 
      allValid = false; 
      break; 
    } 
  } 
  return(allValid); 
} 

function isEmailAddress(addr)
{
	var atPos;
	var allvalid = true;
	if (addr.length == 0)
		return true;
	atPos = addr.indexOf("@");
	if (atPos == -1)
		return false;
	if (	(addr.indexOf(" ") != -1) ||
		(addr.indexOf("/") != -1) ||
		(addr.indexOf(";") != -1) ||
		(addr.indexOf(":") != -1) ||
		(addr.indexOf(",") != -1) ||
		(addr.indexOf("<") != -1) ||
		(addr.indexOf(">") != -1) )
		return false;
	else
		if ((addr.indexOf("@", atPos+1) != -1) || (addr.indexOf(".",atPos) == atPos+1) || (addr.indexOf(".",atPos) == -1))
			return false;
	return (true); 
}

function isPhoneNumber(theField)
{ 
	var CleanedString=""; 
	var index = 0; 
	var ch;
	var checkOK = "0123456789"; 

	if (theField.length == 0)
		return true;

//	Walk through the input string and collect only number characters, appending them to CleanedString
	while (index <= theField.length)
		{
	    ch = theField.charAt(index);
		for (j = 0;  j < checkOK.length;  j++)
			{
			if (ch == checkOK.charAt(j))
				{
				CleanedString = CleanedString + ch;
		        break;
		        }
			}
			index = index + 1;
		}

//	If CleanedString is exactly 10 digits long, then format it and allow form submission
	if (CleanedString.length == 10)
		{
		return "(" + CleanedString.substring(0,3) + ") " + CleanedString.substring(3,6) + "-" + CleanedString.substring(6,10);
		}
 
//	If CleanedString is not 10 digits longs, show an alert and cancel form submission
	else
		return false;
} 


function ContainsSpecial(theField) 
{ 
  var checkOK = "!@#$%^&*(){}[];:<>,./?\|"; 
  var checkStr = theField;
  var allValid = false; 
  for (i = 0;  i < checkStr.length;  i++) 
  { 
    ch = checkStr.charAt(i); 
    for (j = 0;  j < checkOK.length;  j++) 
      if (ch == checkOK.charAt(j)) 
		return true;
        break; 
    if (j == checkOK.length) 
    { 
      allValid = false; 
      break; 
    } 
  } 
  return(allValid); 
} 

function _validate(theelement) {
	if (theelement.required == 'yes')
		{
		if (theelement.value.length == 0)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' is required');
			else
				alert(theelement.name + ' is required');
     		theelement.focus();
			return false;
			}
		}
	if (theelement.minlength > 0)
		{
		if (theelement.value.length < theelement.minlength)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' min length is ' + theelement.minlength);
			else
				alert(theelement.name + ' min length is ' + theelement.minlength);
     		theelement.focus();
			return false;
			}
		}
	if (theelement.maxlength > 0)
		{
		if (theelement.value.length > theelement.maxlength)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' max length is ' + theelement.maxlength);
			else
				alert(theelement.name + ' max length is ' + theelement.maxlength);
     		theelement.focus();
			return false;
			}
		}

	if (theelement.minvalue != '')
		{
		if (theelement.value < theelement.minvalue)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' min value is ' + theelement.minvalue);
			else
				alert(theelement.name + ' min value is ' + theelement.minvalue);
     		theelement.focus();
			return false;
			}
		}

	if (theelement.phone == 'yes')
		{
		var PhoneNumber;
		PhoneNumber = isPhoneNumber(theelement.value);
		if (PhoneNumber == false)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' must be a valid phone number (area code + exchange + ext)');
			else
				alert(theelement.name + ' must be a valid phone number (area code + exchange + ext)');
     			theelement.focus();
			return false;
			}
		else
			if (PhoneNumber.length == 14)
				theelement.value = PhoneNumber;
		}

	if (theelement.email == 'yes')
		{
		if (isEmailAddress(theelement.value) == false)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' must be a valid email address');
			else
				alert(theelement.name + ' must be a valid email address');
     			theelement.focus();
			return false;
			}
		}

	if (theelement.maxvalue != '')
		{
		if (theelement.value > theelement.maxvalue)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' max value is ' + theelement.maxvalue);
			else
				alert(theelement.name + ' max value is ' + theelement.maxvalue);
	     		theelement.focus();
			return false;
			}
		}

	if (theelement.alpha == "yes")
		{
		if (CheckForAlpha(theelement.value) == false)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' must be all alpha');
			else
				alert(theelement.name + ' must be all alpha');
	     		theelement.focus();
			return false;
			}
		}

	if (theelement.containsnumeric == "yes")
		{
		if (ContainsNumeric(theelement.value) == false)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' must contain at least one numeric digit');
			else
				alert(theelement.name + ' must contain at least one numeric digit');
	     		theelement.focus();
			return false;
			}
		}

	if (theelement.containsspecial == "yes")
		{
		if (ContainsSpecial(theelement.value) == false)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' must contain at least one of the following special characters: !@#$%^&*(){}[];:<>,./?\|');
			else
				alert(theelement.name + ' must contain at least one of the following special characters: !@#$%^&*(){}[];:<>,./?\|');
	     		theelement.focus();
			return false;
			}
		}

	if (theelement.containsalpha == "yes")
		{
		if (ContainsAlpha(theelement.value) == false)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' must contain at least one alpha character');
			else
				alert(theelement.name + ' must contain at least one alpha character');
	     		theelement.focus();
			return false;
			}
		}

	if (theelement.caps == "yes")
		{
		if (CheckForCaps(theelement.value) == false)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' must be all caps');
			else
				alert(theelement.name + ' must be all caps');
	     		theelement.focus();
			return false;
			}
		}
	if (theelement.numeric == "yes")
		{
		if (CheckForNumerics(theelement.value) == false)
			{
			if (theelement.caption != 'undefined')
				alert(theelement.caption + ' must be all numeric');
			else
				alert(theelement.name + ' must be all numeric');
     		theelement.focus();
			return false;
			}
		}
     	return true;
}

function checkinfo() {

if (_validateuserdata() == false)
	return false;
var i = 0;
for (i=0;i<document.forms.form1.elements.length;i++) 
	{
	if (_validate(document.forms.form1.elements[i]) == false)
		return false;
	}
   	return true;
}