
// this function returns true if sthe string is blank

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
}

// this function performs form verification

function verify(f)
{
	var description = new Array();
		description[0] = "First Name";
		description[1] = "Surname";
		description[2] = "E-mail address";
		description[3] = "Company Name";		
		description[4] = "Address";
		description[5] = "City/Town";
		description[6] = "County";
		description[7] = "Country";
		description[8] = "Post Code/Zip";
		description[9] = "Phone Number";
		description[10] = "Comment";
				
	var msg;
	var empty_fields = "";
	var errors = "";
	
// set numeric fieldsf.phone.numeric = true; 

// set optional fields
f.district.optional = true; 
	
for(var i = 0; i < f.length; i++) {
	var e = f.elements[i];
	if ((e.type == "text") && !e.optional) {
// check if the field is empty
	if ((e.value == null) || (e.value == "") || isblank(e.value)) {
		empty_fields += "\n          " + description[i];
		continue;
	}

// check for numeric fields

	if (e.numeric) {
	var v = parseFloat(e.value);
	if (isNaN(v)) {
		errors += "- The " + description[i] + " must be a number";
		errors += ".\n";
	}
	}
	
}
}	

// check email address

if (f.email.value!="")
{if (f.email.value.indexOf("@")==-1 || f.email.value.indexOf(".")==-1 || f.email.value.indexOf(" ")!=-1 || f.email.value.length<6) {
		errors += "- E-mail doesn't seem a valid email address";
		errors += ".\n";
	}
	}


	
if (!empty_fields && !errors) return true;

msg  = "\n"
//msg  = "_________________________________________\n\n"
//msg += "The form was not submitted because of the following error(s).\n";
//msg += "Please correct these error(s) and re-submit.\n";	
//msg += "_________________________________________\n\n"	

if (empty_fields) {
	msg += "- Please  fill in the following field(s):"
			+ empty_fields + "\n";
		if (errors) msg += "\n";
	}
	msg += errors;
	alert(msg);
	return false;
}	
		
	