function  validate ($form) {
	
	var $nodes = $form.elements;
	var $i, $j, $tag, $type, $name, $node, $optional, $optionals, $parts;
	
	for ($i = 0; $i < $nodes.length; ++$i) {
		
		$node = $nodes [$i];
		$name = $node.name;
		$tag = $node.nodeName.toLowerCase (); // normalize type to lowercase
		
		if ($tag != 'fieldset') {
			if ($tag == 'input') {
				$type = $node.type;
				
				if ($type != 'hidden') {
					if ($name.indexOf ('req_') >= 0) {
						
						if ($node.value == '') {
							alert ('This field is required');
							$node.focus ();
							return false;
						}
						
						$parts = $name.split ('__');
						
						if ($parts.length > 1) {
							
							$optionals = $parts [0].split ('_');
							
							for ($j = 0; $j < $optionals.length; ++$j) {
								$optional = $optionals [$j];
								
								switch ($optional) {
									case 'phone':
										if ((!validPhone ($node.value))) {
											alert ('This is not a valid U.S. Phone Format');
											$node.focus ();
											return false;
										} else break;
									case 'email':
										if ((!validEmail ($node.value))) {
											alert ('This is not a valid Email Address Format');
											$node.focus ();
											return false;
										} else break;
									case 'max':
										if (($node.value.length != $node.maxLength)) {
											alert ('This captcha text requires ' + $node.maxLength + ' characters');
											$node.focus ();
											return false;
										} else break;
									case 'captcha': break; // not implemented at this time
									default: alert ('The option "' + $optional + '" is not a valid entry'); return false;
								}
							}
						}
					}
				}
			}
		}
	}
	
	return true;
}

function validPhone ($phone) {
	$phoneRegExp = new RegExp ('^(1\\s*[-\/\.]?)?(\\((\\d{3})\\)|(\\d{3}))\\s*[-\/\.]?\\s*(\\d{3})\\s*[-\/\.]?\\s*(\\d{4})\\s*(([xX]|[eE][xX][tT])\\.?\\s*(\\d+))*$', 'g');
	
	return $phoneRegExp.test ($phone);
}

function validEmail ($email) {
	
	$emailRegExp = new RegExp ('\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*([,;]\\s*\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*)*', 'g');
	
	return $emailRegExp.test ($email);
}