// JavaScript Validation for Contact Form
//Check the enquiry form is filled in correctly
function CheckForm () { 

	//Initialise variables
	var errorMsg = "";

	//Check for a Title
	if (document.frmEnquiry.strtitle.value == ""){
		errorMsg += "\n\tTitle \t\t\t\t- Enter your Title";	
	}
	//Check for a first name
	if (document.frmEnquiry.strfname.value == ""){
		errorMsg += "\n\tFirst Name \t\t- Enter your First Name";	
	}
		
	//Check for a last name
	if (document.frmEnquiry.strsname.value == ""){
		errorMsg += "\n\tLast Name \t\t- Enter your Last Name";
	}
	
	//Check for 
	if (document.frmEnquiry.straddr1.value == ""){
		errorMsg += "\n\tAddress \t\t\t- Enter your Last Name";
	}	
	
	//Check for 
	if (document.frmEnquiry.strtown.value == ""){
		errorMsg += "\n\tTown \t\t\t- Enter your Town/City";
	}	
	
	//Check for 
	if (document.frmEnquiry.strcounty.value == ""){
		errorMsg += "\n\tCounty \t\t\t- Enter your County";
	}	
	
	//Check for 
	if (document.frmEnquiry.strpcode.value == ""){
		errorMsg += "\n\tPost Code \t\t- Enter your Post Code";
	}	
	
	
	
	
	
	//Check for a adversecredit
	if (document.frmEnquiry.adversecredit.value == ""){
		errorMsg += "\n\tAdverse Credit \t- Enter any Adverse Credit information";
	}
	
	//Check for a strdob
	if (document.frmEnquiry.strdob.value == ""){
		errorMsg += "\n\tDate Of Birth \t\t- Enter your Date Of Birth";
	}
	
	//Check for a strtype
	if (document.frmEnquiry.strtype.value == ""){
		errorMsg += "\n\tMortgage Type \t- Enter the Type of Mortgage you want";
	}
	
	//Check for a strprice
	if (document.frmEnquiry.strprice.value == ""){
		errorMsg += "\n\tPurchase Price \t- Enter the Purchase Price of the property";
	}
	
	//Check for a strloan
	if (document.frmEnquiry.strloan.value == ""){
		errorMsg += "\n\tLoan Amount \t\t- Enter the Amount you want to borrow";
	}	
	
	
	//Check for a Telephone Number
	if (document.frmEnquiry.strtel.value == ""){
		errorMsg += "\n\tTelephone Number \t- Enter your Telephone Number";
	}
	 	
	//Check for an e-mail address and that it is valid
	if ((document.frmEnquiry.stremail.value == "") || (document.frmEnquiry.stremail.value.length > 0 && (document.frmEnquiry.stremail.value.indexOf("@",0) == - 1 || document.frmEnquiry.stremail.value.indexOf(".",0) == - 1))) { 
		errorMsg += "\n\tE-mail Address \t- Enter your valid e-mail address";
	}
			
	//Check for Comments
	if (document.frmEnquiry.strcomments.value == "") { 
 		errorMsg += "\n\tAsk a Question \t- Ask a Question/Any Other Info";
	}
		
	//If there is a problem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your enquiry has not been sent because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
