/*
Purpose: Check for blank required fields in Timebus quote form

Original author:  Unknown

Changes:

EP 2006-01-10:
added code to check for a dropdown (vehicle)
made a separate .js file

EP 2008-01-12:
new field 'organization' option, field telephone_number_2 deleted, other changes to go with new form field names

*/

function isblank(s)
{
	for (var i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function quotefields(form)
{
	form.organization.optional = true; // set optional text or textarea fields here
	var empty_fields = "";
	for (var i = 0; i < form.length; i++)
	{
		var description = "";
		var e = form.elements[i];
		if (e.name == "vehicles::::")
		{
			// alert(e.selectedIndex)
			if ((e.selectedIndex == 0) || (e.selectedIndex == -1))
			{
				// no 'vehicle' dropdown selected
				description = "'Type of Vehicle'"
			}
		}
		if (((e.type == "text") || (e.type == "textarea")) && !e.optional)
		{
			if ((e.value == null) || isblank(e.value))
			{
				// empty text or textarea field detected
				switch (e.name)
				{
					// ensure all text or textarea fields have nice descriptions below (whether required fields or not)
					case "name_fore":
						description = "'Forename'"
						break;
					case "realname":
						description = "'Surname'"
						break;
					case "email":
						description = "'Email address'"
						break;
					case "telephone_no":
						description = "'Telephone number'"
						break;
					case "hire_dates::":
						description = "'Prospective hire date(s)'"
						break;
					case "hire_details":
						description = "'Details of hire'"
						break;
				}
			}
		}
		if (description)
		{
			if (empty_fields) { empty_fields += " and " + description; }
			else { empty_fields += description; }
		}
	}
	if (empty_fields)
	{
		alert("Please fill in the following field(s): " + empty_fields + " before you send the form... thank you");
		return false;
	}
	return true;
}