function check_format(field_value,field_type)
	{
	inv_format = false;
	
	if (field_type == "email")	{reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;}
	if (field_type == "phone")	{reg_exp = /^\d\d\d\-\d\d\d-\d\d\d\d$/;}
	if (field_type == "state")	{reg_exp = /^([a-zA-Z]{2})$/;}
	if (field_type == "zip")	{reg_exp = /^\d\d\d\d\d$/;}
	if (field_type == "qty")	{reg_exp = /^([0-9]{1,3})$/;}
	if (field_type == "price")	{reg_exp = /^([0-9]{1,2})\.([0-9]{2})$/;}

	if (! field_value.match(reg_exp))	{inv_format = true;}

	if (inv_format == false) {return true;} else {return false;}
	}

function Validate(form_name)
	{
	//alert(form_name);
	found_errors = false;

	if (form_name=="new_acct_form")
		{
		user_id = document.new_acct_form.user_id.value;
		password = document.new_acct_form.password.value;
		confirm_pw = document.new_acct_form.confirm_pw.value;
		contact = document.new_acct_form.contact.value;
		email = document.new_acct_form.email.value;
		phone1 = document.new_acct_form.phone1.value;
		phone2 = document.new_acct_form.phone2.value;
		st_address = document.new_acct_form.st_address.value;
		city = document.new_acct_form.city.value;
		state = document.new_acct_form.state.value;
		zip = document.new_acct_form.zip.value;
		
		blank_fields = "";

		if (user_id == "")		{blank_fields += "Username\n";}
		if (password == "")		{blank_fields += "Password\n";}
		if (confirm_pw == "")	{blank_fields += "Confirm Password\n";}
		if (contact == "")		{blank_fields += "Contact Name\n";}
		if (email == "")		{blank_fields += "Email Address\n";}
		if (phone1 == "")		{blank_fields += "Phone Number\n";}
		if (st_address == "")	{blank_fields += "Street Address\n";}
		if (city == "")			{blank_fields += "City\n";}
		if (state == "")		{blank_fields += "State\n";}
		if (zip == "")			{blank_fields += "Zip Code\n";}
		
		error_msg = "";

		if (blank_fields != "")
			{
			error_msg += "The following fields can not be blank: \n\n"+blank_fields;
			}
		else
			{
			inv_fields = "";
			
			if (check_format(email,"email") == false)	{inv_fields += "Email Address\n";}
			if (check_format(phone1,"phone") == false)	{inv_fields += "Phone Number\n";}
			if ((check_format(phone2,"phone") == false) && (phone2 != "")) 
				{
				inv_fields += "Alternate Phone Number\n";
				}
			if (check_format(state,"state") == false)	{inv_fields += "State\n";}
			if (check_format(zip,"zip") == false)		{inv_fields += "Zip Code\n";}
			
			if (inv_fields != "")
				{
				error_msg +="The following fields were found to have invalid entries: \n\n"+inv_fields;
				}
			else
				{
				if ((user_id.length<4) || (password.length<4))
					{
					error_msg += "The username and password must be between 4 and 20 characters\n";
					}
				if (password != confirm_pw)
					{
					error_msg += "The password and confirm password fields do not match\n";
					}
				}

			}
		if (error_msg != "")
			{
			alert(error_msg);
			found_errors = true;
			}
		}
	
	if (form_name=="edit_acct_form")
		{
		contact = document.edit_acct_form.contact.value;
		email = document.edit_acct_form.email.value;
		phone1 = document.edit_acct_form.phone1.value;
		phone2 = document.edit_acct_form.phone2.value;
		st_address = document.edit_acct_form.st_address.value;
		city = document.edit_acct_form.city.value;
		state = document.edit_acct_form.state.value;
		zip = document.edit_acct_form.zip.value;
		
		blank_fields = "";

		if (contact == "")		{blank_fields += "Contact Name\n";}
		if (email == "")		{blank_fields += "Email Address\n";}
		if (phone1 == "")		{blank_fields += "Phone Number\n";}
		if (st_address == "")	{blank_fields += "Street Address\n";}
		if (city == "")			{blank_fields += "City\n";}
		if (state == "")		{blank_fields += "State\n";}
		if (zip == "")			{blank_fields += "Zip Code\n";}
		
		error_msg = "";

		if (blank_fields != "")
			{
			error_msg += "The following fields can not be blank: \n\n"+blank_fields;
			}
		else
			{
			inv_fields = "";
			
			if (check_format(email,"email") == false)	{inv_fields += "Email Address\n";}
			if (check_format(phone1,"phone") == false)	{inv_fields += "Phone Number\n";}
			if ((check_format(phone2,"phone") == false) && (phone2 != "")) 
				{
				inv_fields += "Alternate Phone Number\n";
				}
			if (check_format(state,"state") == false)	{inv_fields += "State\n";}
			if (check_format(zip,"zip") == false)		{inv_fields += "Zip Code\n";}
			
			if (inv_fields != "")
				{
				error_msg +="The following fields were found to have invalid entries: \n\n"+inv_fields;
				}
			}
		if (error_msg != "")
			{
			alert(error_msg);
			found_errors = true;
			}
		}
	
	if (form_name == "new_order_form")
		{
		count = 0;
		blank_fields = false;
		while (count<document.new_order_form.length-3)
			{
			qty = document.new_order_form[count].value;
			if (qty == "") {blank_fields = true;}
			count++;
			}
			
		error_msg = "";

		if (blank_fields == true)
			{
			error_msg = "None of the fields can be blank!";
			}
		else
			{
			
			count=1;
			zeros_qty=0;
			field_qty=0;
			all_qty_zero = false;
			while (count<document.new_order_form.length-2)
				{
				if (document.new_order_form[count].value == 0)
					{
					zeros_qty++;
					}
				count = count+2;
				field_qty++;
				}
				
			if (zeros_qty==field_qty)
				{
				all_qty_zero = true;
				}
			
			if (all_qty_zero == true)
				{
				error_msg = "At least one quantity must be greater than 0.";
				}
			else
				{
				count = 0;
				inv_fields = false;
				while (count<document.new_order_form.length-3)
					{
					field_value = document.new_order_form[count].value;
					if (count/2 == Math.round(count/2))
						{
						if (check_format(field_value,"price") == false)	{inv_fields = true;}
						}
					else
						{
						if (check_format(field_value,"qty") == false)	{inv_fields = true;}
						}
	
					count++;
					}
			
				if (inv_fields == true)
					{
					error_msg = "One of the fields has invalid content!";
					}
				}
			}

		if (error_msg != "")
			{
			alert(error_msg);
			found_errors = true;
			}
		}
	
	if (found_errors == false) 
		{
		return true;
		}
	else
		{
		return false;
		}
	}
