// form fields description structure
var a_fields = {
	'formtop': {
		'l': 'Title',  // label
		'r': false,    // required
		'f': 'alpha',  // format (see below)
		't': 't_title',// id of the element to highlight if input not validated
		
		'm': null,     // must match specified form field
		'mn': 2,       // minimum length
		'mx': 10       // maximum length
	},
	'title':{'l':'Title','r':false,'t':'t_title'},
	'firstname':{'l':'Applicant first name','r':true,'f':'alpha','t':'t_firstname'},
	'middlename':{'l':'Applicant middle name','r':false,'f':'alpha','t':'t_middlename'},
	'lastname':{'l':'Applicant last name','r':true,'f':'alpha','t':'t_lastname'},
	'suffix':{'l':'Suffix','r':false,'f':'alpha','t':'t_suffix'},
	'email':{'l':'Applicant email address','r':true,'f':'email','t':'t_email'},
	'email2':{'l':'Applicant re-enter email address','r':true,'f':'email','m':'email','t':'t_email2'},
	'gender':{'l':'Applicant gender','r':true,'t':'t_gender'},
	'street1':{'l':'Applicant street address','r':true,'t':'t_street1'},
	'street2':{'l':'Applicant street address, line 2','r':false,'t':'t_street2'},
	'city':{'l':'Applicant city','r':true,'f':'alpha','t':'t_city'},
	'island':{'l':'Applicant island','r':true,'t':'t_island'},
	'phone':{'l':'Applicant phone','r':true,'f':'phone','t':'t_phone'},
	'id':{'l':'Applicant National Insurance number','r':true,'f':'integer','t':'t_id','mn':'8','mx':'8'},
	'citizenship':{'l':'Applicant country of citizenship','r':true,'f':'alpha','t':'t_citizenship'},
	'dob_m':{'l':'Applicant birth month','r':true,'t':'t_dob_m'},
	'dob_d':{'l':'Applicant birth day','r':true,'t':'t_dob_d'},
	'dob_y':{'l':'Applicant birth year','r':true,'t':'t_dob_y','mn':'4','mx':'4'},
	'ownership':{'l':'Applicant home ownership','r':true,'t':'t_ownership'},
	'residence_year':{'l':'Applicant year of residency','r':true,'t':'t_residence_year','mn':'4','mx':'4'},
	'prev_address':{'l':'Applicant previous address','r':false,'f':'alphanum','t':'t_prev_address'},
	'marital':{'l':'Applicant marital status','r':true,'t':'t_marital'},
	'dependents':{'l':'Applicant dependents','r':false,'f':'integer','t':'t_dependents','mn':'0','mx':'15'},
	'employer':{'l':'Applicant employer','r':true,'t':'t_employer'},
	'hiredate_m':{'l':'Applicant month hired','r':true,'t':'t_hiredate_m'},
	'hiredate_y':{'l':'Applicant year hired','r':true,'f':'integer','t':'t_hiredate_y','mn':'4','mx':'4'},
	'emp_address':{'l':'Applicant employer address','r':true,'t':'t_emp_address'},
	'emp_phone':{'l':'Applicant employer phone','r':true,'f':'phone','t':'t_emp_phone'},
	'occupation':{'l':'Applicant occupation','r':true,'t':'t_occupation'},
	'emp_type':{'l':'Applicant employment type','r':true,'t':'t_emp_type'},
	'emp_title':{'l':'Applicant employment title','r':true,'t':'t_emp_title'},
	'salary_gross':{'l':'Applicant gross salary','r':true,'f':'integer','t':'t_salary_gross'},
	'salary_net':{'l':'Applicant net salary','r':true,'f':'integer','t':'t_salary_net'},
	'pay_period':{'l':'Applicant pay period','r':true,'t':'t_pay_period'},
	'repayment':{'l':'Applicant loan repayment','r':true,'t':'t_repayment'},
	'previous_credit':{'l':'Applicant previous credit','r':true,'t':'t_previous_credit'},
// co-applicant validation for format
	'co_title':{'l':'Co-applicant title','r':false,'t':'t_title'},
	'co_firstname':{'l':'Co-applicant first name','r':false,'f':'alpha','t':'t_co_firstname'},
	'co_middlename':{'l':'Co-applicant middle name','r':false,'f':'alpha','t':'t_co_middlename'},
	'co_lastname':{'l':'Co-applicant last name','r':false,'f':'alpha','t':'t_co_lastname'},
	'co_suffix':{'l':'Co-applicant suffix','r':false,'f':'alpha','t':'t_co_suffix'},
	'co_email':{'l':'Co-applicant email address','r':false,'f':'email','t':'t_co_email'},
	'co_email2':{'l':'Co-applicant re-enter email address','r':false,'f':'email','m':'co_email','t':'t_co_email2'},
	'co_gender':{'l':'Co-applicant gender','r':false,'t':'t_co_gender'},
	'co_street1':{'l':'Co-applicant street address','r':false,'t':'t_co_street1'},
	'co_street2':{'l':'Co-applicant street address, line 2','r':false,'t':'t_co_street2'},
	'co_city':{'l':'Co-applicant city','r':false,'f':'alpha','t':'t_co_city'},
	'co_island':{'l':'Co-applicant island','r':false,'t':'t_co_island'},
	'co_phone':{'l':'Co-applicant phone','r':false,'f':'phone','t':'t_co_phone'},
//  For some reason this triggers an error even though it is set to "false" so I had to disable it
//	'co_id':{'l':'Co-applicant National Insurance number','r':false,'f':'integer','t':'t_co_id','mn':'8','mx':'8'},
	'co_citizenship':{'l':'Co-applicant country of citizenship','r':false,'f':'alpha','t':'t_co_citizenship'},
	'co_dob_m':{'l':'Co-applicant birth month','r':false,'t':'t_co_dob_m'},
	'co_dob_d':{'l':'Co-applicant birth day','r':false,'t':'t_co_dob_d'},
	'co_dob_y':{'l':'Co-applicant birth year','r':false,'t':'t_co_dob_y','mn':'4','mx':'4'},
	'co_ownership':{'l':'Co-applicant home ownership','r':false,'t':'t_co_ownership'},
	'co_residence_year':{'l':'Co-applicant year of residency','r':false,'t':'t_co_residence_year','mn':'4','mx':'4'},
	'co_prev_address':{'l':'Co-applicant previous address','r':false,'f':'alphanum','t':'t_co_prev_address'},
	'co_marital':{'l':'Co-applicant marital status','r':false,'t':'t_co_marital'},
	'co_dependents':{'l':'Co-applicant dependents','r':false,'f':'integer','t':'t_co_dependents','mn':'0','mx':'15'},
	'co_hiredate_m':{'l':'Co-applicant month hired','r':false,'t':'t_co_hiredate_m'},
	'co_hiredate_y':{'l':'Co-applicant year hired','r':false,'f':'integer','t':'t_co_hiredate_y','mn':'4','mx':'4'},
	'co_emp_address':{'l':'Co-applicant employer address','r':false,'t':'t_co_emp_address'},
	'co_emp_phone':{'l':'Co-applicant employer phone','r':false,'f':'phone','t':'t_co_emp_phone'},
	'co_occupation':{'l':'Co-applicant occupation','r':false,'t':'t_co_occupation'},
	'co_emp_type':{'l':'Co-applicant employment type','r':false,'t':'t_co_emp_type'},
	'co_emp_title':{'l':'Co-applicant employment title','r':false,'t':'t_co_emp_title'},
	'co_salary_gross':{'l':'Co-applicant gross salary','r':false,'f':'integer','t':'t_co_salary_gross'},
	'co_salary_net':{'l':'Co-applicant net salary','r':false,'f':'integer','t':'t_co_salary_net'},
	'co_pay_period':{'l':'Applicant pay period','r':false,'t':'t_co_pay_period'},
	'co_repayment':{'l':'Applicant loan repayment','r':false,'t':'t_co_repayment'},
	'co_previous_credit':{'l':'Co-applicant previous credit','r':false,'t':'t_co_previous_credit'},	
// references
	'ref1_name':{'l':'Name of 1st reference','r':true,'t':'t_ref1_name'},
	'ref1_relationship':{'l':'Relationship to 1st reference','r':true,'t':'t_ref1_relationship'},
	'ref1_address':{'l':'Address for 1st reference','r':true,'t':'t_ref1_address'},
	'ref1_phone':{'l':'Phone for 1st reference','r':true,'f':'phone','t':'t_ref1_phone'},
	'ref2_name':{'l':'Name of 2nd reference','r':true,'t':'t_ref2_name'},
	'ref2_relationship':{'l':'Relationship to 2nd reference','r':true,'t':'t_ref2_relationship'},
	'ref2_address':{'l':'Address for 2nd reference','r':true,'t':'t_ref2_address'},
	'ref2_phone':{'l':'Phone for 2nd reference','r':true,'f':'phone','t':'t_ref2_phone'},
	'ref3_name':{'l':'Name of 3rd reference','r':true,'t':'t_ref3_name'},
	'ref3_relationship':{'l':'Relationship to 3rd reference','r':true,'t':'t_ref3_relationship'},
	'ref3_address':{'l':'Address for 3rd reference','r':true,'t':'t_ref3_address'},
	'ref3_phone':{'l':'Phone for 3rd reference','r':true,'f':'phone','t':'t_ref3_phone'},
	'ref4_name':{'l':'Name of 4th reference','r':true,'t':'t_ref4_name'},
	'ref4_relationship':{'l':'Relationship to 4th reference','r':true,'t':'t_ref4_relationship'},
	'ref4_address':{'l':'Address for 4th reference','r':true,'t':'t_ref4_address'},
	'ref4_phone':{'l':'Phone for 4th reference','r':true,'f':'phone','t':'t_ref4_phone'}

		
//alpha  	A string of characters of Latin alphabet, a dot (.) and a hyphen (-)
//alphanum 	Alphanumeric characters and an underline (_)
//unsigned 	Unsigned integer number
//integer 	An integer number
//real 	A number with a decimal point
//email 	E-mail address format
//phone 	Phone number consisting of digits, spaces ( ), dots (.) and hyphens (-)
//date 	Date value formatted as DD-MM-YYYY
//time 	Time value formatted as HH:MM:SS


},

o_config = {
	'to_disable' : ['Submit', 'Reset'],
	// 1 - fill error dialog,
	// 2 - fill error HTML box,
	// 4 - debug alert,
	// 8 - submit ok HTML box
	// 16 - submit confirmation dialog,
	// function - custom function(array of messages)
	'alert' : 2 + 4 + 8,
	'alert_class' : ['inputHighlighted', 'inputNormal']
}

// validator constructor call
var v = new validator('CreditApp', a_fields, o_config)

/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
                
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}