// Questionnaire Validation

// STANDARD REQUIRED FIELD

function Required(formField,fieldLabel)

{

	var result = true;

	if (formField.value == "" || formField.value == "--" || formField.value == "£")

	{

		alert('Please complete the "' + fieldLabel +'" field.');

		formField.focus();

		result = false;

	}

	return result;

}

// CHECK INTEGRITY OF EMAIL ADDRESS

function isEmailAddr(app1_email)

{

  var result = false;

  var theStr = new String(app1_email);

  var index = theStr.indexOf("@");

  if (index > 0)

  {

    var pindex = theStr.indexOf(".",index);

    if ((pindex > index+1) && (theStr.length > pindex+1))

	result = true;

  }

  return result;

}

// VALID EMAIL

function validEmail(formField,fieldLabel,required)

{

	var result = true;

	if (required && !validRequired(formField,fieldLabel))

		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )

	{

		alert("Please enter a complete email address in the form: yourname@yourdomain.com");

		formField.focus();

		result = false;

	}

  return result;

}

// FIELDS REQUIRED AND MESSAGES

function validateForm(theForm)

{

<!-- start of Applicant 1 detail -->


	if (!Required(theForm.app1_title,"Applicant 1 title"))

		return false;

	if (!Required(theForm.app1_firstname,"Applicant 1 firstname"))

		return false;
		
	if (!Required(theForm.app1_surname,"Applicant 1 surname"))

		return false;
		
	if (!Required(theForm.app1_dob,"Applicant 1 date of birth"))

		return false;

	if (!Required(theForm.app1_smoker,"Applicant 1 smoker"))

		return false;

	if (!validEmail(theForm.app1_email,"Applicant 1 email address"))

		return false;

	if (!Required(theForm.app1_phone,"Applicant 1 phone number"))

		return false;


<!-- end of Applicant 1 detail -->


<!-- start of Home detail -->

	
	if (!Required(theForm.yearsinsurance,"Number of Years Insurance held"))

		return false;

	if (!Required(theForm.refusedinsurance,"Have you ever been refused insurance of this kind"))

		return false;
		
	if (!Required(theForm.claims,"Number of Home Insurance claims in last 5 years"))

		return false;

	if (!Required(theForm.housetype,"Type of House"))

		return false;

	if (!Required(theForm.houseno_name,"House No or Name"))

		return false;

	if (!Required(theForm.road,"Road Name"))

		return false;
		
	if (!Required(theForm.town,"Town"))

		return false;

	if (!Required(theForm.county,"County"))

		return false;

	if (!Required(theForm.postcode,"Post Code"))

		return false;

	if (!Required(theForm.bedrooms,"Number of bedrooms"))

		return false;

	if (!Required(theForm.yearbuilt,"Year property was built"))

		return false;

	if (!Required(theForm.rebuildingcosts,"Estimated rebuilding costs"))

		return false;

	if (!Required(theForm.suminsured,"Sum Insured"))

		return false;
		
	if (!Required(theForm.itmesover1000,"Individual items over £1000"))

		return false;
		
	if (!Required(theForm.personalpossesionsawayfromhome,"Personal possesions away from home"))

		return false;
		
	if (!Required(theForm.amountrequired,"Amount required"))

		return false;


<!-- end of Home detail -->



<!-- start of Property detail -->
	

	if (!Required(theForm.standardconstruction,"Standard Construction"))

		return false;

	if (!Required(theForm.soundstateofrepair,"Sound State of Repair"))

		return false;

	if (!Required(theForm.freefromflooding,"Free from flooding"))

		return false;

	if (!Required(theForm.underpinned,"Underpinned"))

		return false;

	if (!Required(theForm.occupiedduringday,"Occupied during the day"))

		return false;

	if (!Required(theForm.locksonwindows,"Locks on windows"))

		return false;

	if (!Required(theForm.buglaralarm,"Buglar alarm"))

		return false;

	if (!Required(theForm.neighbourhoodwatch,"Neighbourhood watch area"))

		return false;
		
	if (!Required(theForm.smokealarm,"Fitted with a smoke alarm"))

		return false;


<!-- end of Property detail -->		



<!-- start of Cover detail -->

	
	if (!Required(theForm.moreinfodetails,"More Information Details"))

		return false;


<!-- end of Cover detail -->	

		
	return true;

}
