/*-----------------------------------------------
author:   Roland Carney
modified:  27.06.2008
desc: validates secured application form
copyright my-ma.co.uk - the content in this page is not for replication
-----------------------------------------------*/

function validateIntroducer() {
	//checks required fields
	if(checkEmpty(document.introducerApply.Contact_Name, 'Please enter your Name')==false ||
		 checkEmpty(document.introducerApply.Company_Name, 'Please enter your Company Name')==false ||
		 checkEmpty(document.introducerApply.Company_Address1, 'Please enter your Address')==false ||
		 checkEmpty(document.introducerApply.Company_Town, 'Please enter your Town')==false ||
		 checkEmpty(document.introducerApply.Company_Postcode, 'Please enter your Postcode')==false ||
		 checkEmpty(document.introducerApply.Telephone_Number, 'Please enter your Telephone Number')==false ||
		 checkEmpty(document.introducerApply.Introducer_Email, 'Please enter your Email Address')==false ||
		 checkEmail(document.introducerApply.Introducer_Email, 'The email address is not valid')==false || 
		 checkEmpty(document.introducerApply.FSA_Number, 'Please enter your FSA Number')==false ||
		 checkEmpty(document.introducerApply.CCL_Number, 'Please enter your CCL Number')==false ||
		 checkEmpty(document.introducerApply.Hear_About_Us, 'Please tell us where you heard about us')==false) {
		 return false;
	}
	else {
		return true;
	}
}

function validateCommercial() {
	//checks required fields
	if(checkEmpty(document.commercialApply.Introducer_Title, 'Please choose your Title')==false ||
		checkEmpty(document.commercialApply.Introducer_First, 'Please enter your First Name')==false ||
		checkEmpty(document.commercialApply.Introducer_Surname, 'Please enter your Surname')==false ||
		checkEmpty(document.commercialApply.Introducer_Email, 'Please enter your Email Address')==false ||
		checkEmail(document.commercialApply.Introducer_Email, 'The email address is not valid')==false || 
		checkEmpty(document.commercialApply.Introducer_Phone, 'Please enter your Phone Number')==false || 
		checkEmpty(document.commercialApply.Introducer_Address1, 'Please enter your Address')==false ||
		checkEmpty(document.commercialApply.Introducer_Town, 'Please enter your Town')==false ||
		checkEmpty(document.commercialApply.Introducer_Postcode, 'Please enter your Postcode')==false ||
		checkEmpty(document.commercialApply.Title, 'Please choose client Title')==false ||
		checkEmpty(document.commercialApply.First_Name, 'Please enter client First Name')==false ||
		checkEmpty(document.commercialApply.Surname, 'Please enter client Surname')==false ||
		checkEmpty(document.commercialApply.Client_Type, 'Please choose Client Type')==false ||
		checkEmpty(document.commercialApply.Address1, 'Please enter client Address')==false ||
		checkEmpty(document.commercialApply.Town, 'Please enter client Town')==false ||
		checkEmpty(document.commercialApply.Postcode, 'Please enter client Postcode')==false || 
		checkEmpty(document.commercialApply.Loan_Amount, 'Please enter Loan Amount')==false || 
		checkEmpty(document.commercialApply.Loan_Term, 'Please enter Loan Term')==false ||
		checkEmpty(document.commercialApply.Case_Type, 'Please enter Case Type')==false ||
		checkEmpty(document.commercialApply.Property_Value, 'Please enter Property Value')==false ||
		checkEmpty(document.commercialApply.Property_Type, 'Please enter Property Type')==false ||
		checkEmpty(document.commercialApply.Case_Address1, 'Please enter property Address')==false ||
		checkEmpty(document.commercialApply.Case_Town, 'Please enter property Town')==false ||
		checkEmpty(document.commercialApply.Case_Postcode, 'Please enter property Postcode')==false) {
		return false;
	}
	else {
		return true;
	}
}

function validateSecured() {
	//checks required fields
	if(checkEmpty(document.securedApply.Introducer_Title, 'Please choose your Title')==false ||
		checkEmpty(document.securedApply.Introducer_First, 'Please enter your First Name')==false ||
		checkEmpty(document.securedApply.Introducer_Surname, 'Please enter your Surname')==false ||
		checkEmpty(document.securedApply.Introducer_Email, 'Please enter your Email Address')==false ||
		checkEmail(document.securedApply.Introducer_Email, 'The email address is not valid')==false || 
		checkEmpty(document.securedApply.Introducer_Phone, 'Please enter your Phone Number')==false || 
		checkEmpty(document.securedApply.Introducer_Address1, 'Please enter your Address')==false ||
		checkEmpty(document.securedApply.Introducer_Town, 'Please enter your Town')==false ||
		checkEmpty(document.securedApply.Introducer_Postcode, 'Please enter your Postcode')==false ||
		checkEmpty(document.securedApply.Address1, 'Please enter client Address')==false ||
		checkEmpty(document.securedApply.Town, 'Please enter client Town')==false ||
		checkEmpty(document.securedApply.Postcode, 'Please enter client Postcode')==false ||
		checkEmpty(document.securedApply.Title, 'Please choose client Title')==false ||
		checkEmpty(document.securedApply.First_Name, 'Please client your First Name')==false ||
		checkEmpty(document.securedApply.Surname, 'Please enter client Surname')==false ||
		checkEmpty(document.securedApply.Birth_Day, 'Please enter client Date of Birth')==false ||
		checkEmpty(document.securedApply.Birth_Month, 'Please enter client Date of Birth')==false ||
		checkEmpty(document.securedApply.Birth_Year, 'Please enter client Date of Birth')==false ||
		checkEmpty(document.securedApply.Gross_Income, 'Please enter Total Gross Income/Annum')==false ||
		checkEmpty(document.securedApply.Employment_Type, 'Please choose Employment Type')==false ||
		checkEmpty(document.securedApply.Income_Verification, 'Please choose Income Verification')==false ||
		checkEmpty(document.securedApply.Income_Evidence, 'Please choose Income evidence available')==false ||
		checkEmpty(document.securedApply.Income_Evidence_Type, 'Please choose Income evidence type')==false ||
		checkEmpty(document.securedApply.Time_Employed, 'Please enter Time Employed/Self-Employed')==false ||
		checkEmpty(document.securedApply.Amount_Required, 'Please enter Amount Required')==false ||
		checkEmpty(document.securedApply.Broker_Fee_Required, 'Please enter Broker Fee Required')==false ||
		checkEmpty(document.securedApply.Term_of_Loan, 'Please enter Term of Loan')==false ||
		checkEmpty(document.securedApply.Purpose_of_Loan, 'Please enter Purpose of Loan')==false ||
		checkEmpty(document.securedApply.Repayment_Method, 'Please enter Repayment Method')==false ||
		checkEmpty(document.securedApply.Present_Mortgage_Balance, 'Please enter Present Mortgage Balance')==false ||
		checkEmpty(document.securedApply.Current_Lender, 'Please enter Current Lender')==false ||
		checkEmpty(document.securedApply.Years_With_Current_Lender, 'Please enter Years with Current Lender')==false ||
		checkEmpty(document.securedApply.Months_With_Current_Lender, 'Please enter Months with Current Lender')==false ||
		checkEmpty(document.securedApply.Monthly_Payment, 'Please enter Monthly Payment')==false ||
		checkEmpty(document.securedApply.Repayments_missed, 'Please enter Repayments Missed')==false ||
		checkEmpty(document.securedApply.Bankrupt, 'Please choose Bankruptcy option')==false ||
		checkEmpty(document.securedApply.Purchase_Price, 'Please enter Purchase Price')==false ||
		checkEmpty(document.securedApply.Current_Valuation, 'Please enter Current Valuation')==false ||
		checkEmpty(document.securedApply.Property_Location, 'Please enter Current Location')==false ||
		checkEmpty(document.securedApply.Property_Use, 'Please enter Property Use')==false ||
		checkEmpty(document.securedApply.Property_Type, 'Please enter Property Type')==false ||
		checkEmpty(document.securedApply.Property_Construction, 'Please choose Property Construction')==false ||
		checkEmpty(document.securedApply.Property_ExCouncil, 'Please tell us if Property is Ex-council')==false ||
		checkEmpty(document.securedApply.Security_Address1, 'Please enter Security Property Address')==false ||
		checkEmpty(document.securedApply.Security_AddressTown, 'Please enter Security Property Town')==false ||
		checkEmpty(document.securedApply.Security_AddressPostcode, 'Please enter Security Property Postcode')==false) {
		return false;
	}
	else {
		return true;
	}
}

function validateBridging() {
	//checks required fields
	if(checkEmpty(document.bridgingApply.Introducer_Title, 'Please choose your Title')==false ||
		checkEmpty(document.bridgingApply.Introducer_First, 'Please enter your First Name')==false ||
		checkEmpty(document.bridgingApply.Introducer_Surname, 'Please enter your Surname')==false ||
		checkEmpty(document.bridgingApply.Introducer_Email, 'Please enter your Email Address')==false ||
		checkEmail(document.bridgingApply.Introducer_Email, 'The email address is not valid')==false || 
		checkEmpty(document.bridgingApply.Introducer_Phone, 'Please enter your Phone Number')==false ||
		checkEmpty(document.bridgingApply.Introducer_Address1, 'Please enter your Address')==false ||
		checkEmpty(document.bridgingApply.Introducer_Town, 'Please enter your Town')==false ||
		checkEmpty(document.bridgingApply.Introducer_Postcode, 'Please enter your Postcode')==false ||
		checkEmpty(document.bridgingApply.Address1, 'Please enter client Address')==false ||
		checkEmpty(document.bridgingApply.Town, 'Please enter client Town')==false ||
		checkEmpty(document.bridgingApply.Postcode, 'Please enter client Postcode')==false ||
		checkEmpty(document.bridgingApply.Title, 'Please choose client Title')==false ||
		checkEmpty(document.bridgingApply.First_Name, 'Please enter client First Name')==false ||
		checkEmpty(document.bridgingApply.Surname, 'Please enter client Surname')==false ||
		checkEmpty(document.bridgingApply.Birth_Day, 'Please enter client Date of Birth')==false ||
		checkEmpty(document.bridgingApply.Birth_Month, 'Please enter client Date of Birth')==false ||
		checkEmpty(document.bridgingApply.Birth_Year, 'Please enter client Date of Birth')==false ||
		checkEmpty(document.bridgingApply.Limited_Company, 'Please tell us if Applicant is a Limited Company')==false ||
		checkEmpty(document.bridgingApply.Loan_Amount, 'Please enter Loan Amount')==false ||
		checkEmpty(document.bridgingApply.Broker_Fee_Amount, 'Please enter Broker Fee Amount')==false ||
		checkEmpty(document.bridgingApply.Loan_Term, 'Please enter Loan Term')==false ||
		checkEmpty(document.bridgingApply.Bridging_Reason, 'Please enter Bridging Reason')==false ||
		checkEmpty(document.bridgingApply.Property_Type, 'Please enter Property Type')==false ||
		checkEmpty(document.bridgingApply.Regulated_Mortgage_Contract, 'Please enter Regulated Mortgage Contract')==false ||
		checkEmpty(document.bridgingApply.Bridging_Method, 'Please tell us how will bridge be redeemed')==false ||
		checkEmpty(document.bridgingApply.Valuation_Instructed, 'Please choose Valuation option')==false ||
		checkEmpty(document.bridgingApply.Valuation, 'Please choose Valuation option')==false ||
		checkEmpty(document.bridgingApply.Payment_Option, 'Please choose Payment Option')==false) {
		return false;
	}
	else {
		return true;
	}
}

function checkEmpty(field, message) {
	var value = field.value;
	if(value =='' || value =='null') {
		field.focus();
		alert(message);
		return false;
	}
}

function checkEmail(field, message) {
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	var value = field.value;
	if(!(emailPattern.test(value))) {
		field.focus();
		alert(message);
		return false;
	}
}

function clearForm() {
	document.securedApply.PastAddresses1.value = "";
}
