var input_types = new Array(); 
input_types["email_address"] = /^(\w|\.|\-)+\@((\w|\-)+\.)+\w+$/;
input_types["area_code"] = /^\d{3}$/;
input_types["phone_number10"] =  /^\s*\D?\d{3}\D{0,2}\d{3}\D?\d{4}\s*$/;  // works
input_types["phone_number7"] =  /^\s*\d{3}\D?\d{4}\s*$/;  // works
input_types["b_month"] = /^\d{1,2}$/; 
input_types["b_day"] = /^\d{1,2}$/; 
input_types["b_year"] = /^\d{4}$/; 
input_types["zip_code5"] = /^\d{5}$/;
input_types["zip_code4"] = /^\d{4}$/;
  

function checkFields ( theForm ) 
{ 
//     alert("hello"); 
	for(i = 0; i < inputs.length; i++) 
	{ 
		this_input = theForm.elements[(""+inputs[i][0]+"")]; 
		if(inputs[i][1] == "text") 
		{
// uncomment for debugging
//			var match_val = this_input.value.match(input_types[inputs[i][3]]);
//			alert("match_val = " + match_val + "\nthis_input.value = " + this_input.value + "\ninput_types[inputs[i][3]] = " + input_types[inputs[i][3]] + "\nthis_input.value.match(input_types[inputs[i][3]]) = " + this_input.value.match(input_types[inputs[i][3]]));
			if(inputs[i][3])
			{
				var bool_to_check = ( this_input.value == null || this_input.value == "" || this_input.value.match(input_types[inputs[i][3]]) == null || this_input.value.match(input_types[inputs[i][3]]) == "");
			}
			else
			{
				var bool_to_check = ( this_input.value == null || this_input.value == "");
			}
		}
		else if(inputs[i][1] == "select") 
			var bool_to_check = ( this_input.selectedIndex == 0 ); 
		else if(inputs[i][1] == "checkbox")
			if (this_input.length > 1)
			{
				var tmp_bool = true; 
				for(j = 0; j < this_input.length; j++) 
				{ 
					if(this_input[j].checked) 
						tmp_bool = false; 
				} 
				var bool_to_check = tmp_bool;
			} else {
				var bool_to_check = ( !this_input.checked ); 
			}
		else if(inputs[i][1] == "radio") 
		{ 
			var tmp_bool = true; 
			for(j = 0; j < this_input.length; j++) 
			{ 
				if(this_input[j].checked) 
					tmp_bool = false; 
			} 
			var bool_to_check = tmp_bool; 
		} 
		if(bool_to_check) 
		{ 
			alert(inputs[i][2]); 
			if(inputs[i][1] != "radio" && inputs[i][1] != "checkbox") 
				this_input.focus(); 
			return false; 
		} 
	} 
	return true; 
}
