

// 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] = "Title";
		description[1] = "First Name";
		description[2] = "Surname";
		description[3] = "Date of birth (Day)";		
		description[4] = "Date of birth (Month)";	
		description[5] = "Date of birth (Year)";				
		description[6] = "House Address";
		description[8] = "Post Code";
		description[9] = "Town/City";		
		description[11] = "E-mail address";
		description[12] = "Home Tel";		
		description[18] = "Date of incident (Day)";		
		description[19] = "Date of incident (Month)";	
		description[20] = "Date of incident (Year)";					
		description[21] = "Incident location";
		description[22] = "Person responsible for the incident";
		description[23] = "Information about the incident";
		description[24] = "Information about your injuries";				
	var msg;
	var empty_fields = "";
	var errors = "";

// set numeric fields
f.homephone.numeric = true; 
f.workphone.numeric = true; 
f.mobilephone.numeric = true; 
f.fax.numeric = true; 
f.dobday.numeric = true; 
f.dobmonth.numeric = true; 
f.dobyear.numeric = true; 
f.incidentday.numeric = true; 
f.incidentmonth.numeric = true; 
f.incidentyear.numeric = true; 

// set optional fields

f.address2.optional = true; 
f.county.optional = true; 
f.workphone.optional = true; 
f.mobilephone.optional = true; 
f.fax.optional = true; 
f.preferrednumber.optional = true;
f.preferredmethod.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 += "- The field email doesn't seem a valid email address";
		errors += ".\n";
	}
	}



	
if (!empty_fields && !errors) return true;

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 += "- The following required field(s) are empty:"
			+ empty_fields + "\n";
		if (errors) msg += "\n";
	}
	msg += errors;
	alert(msg);
	
return false;

//if ( f.iagree.checked==false )  
//	{
//		alert ("We can only process your loan application if you agree to the terms and conditions.\n Please select the box 'I Agree' to continue with this submission");

	
//}	
}	
		
	