// JavaScript Document


function verifyFields(){
	
	var strSalutation = document.getElementById("salutation").value;
	var strFName = document.getElementById("fname").value;
	var strLName = document.getElementById("lname").value;
	var strDate = document.getElementById("date").value;
	var strMonth = document.getElementById("month").value;
	var strYear	= document.getElementById("year").value;
	var strEmailAddress = document.getElementById("email").value;
	var strIncome = document.getElementById("aincome").value;
	var strHomeTel = document.getElementById("htel").value;
	var strOffTel = document.getElementById("otel").value;
	var strMobile = document.getElementById("mtel").value;
	var strHouseNo = document.getElementById("hno").value;
	var strPostcode = document.getElementById("pcode").value;
	var strAmount = document.getElementById("oamount").value;
	var strCreditors = document.getElementById("creditors").value;
	
// declaring and initializing variables
	
	var strErrorArray=[];
	var strErrorMsg="Please correct the following";
	strErrorMsg+="\n---------------------------------------------------\n---------------------------------------------------\n";
	
// checking values

	if(strSalutation==""){
		strErrorArray.push("Please select Salutation");
	}
	if(strFName==""){
		strErrorArray.push("Please fill in First Name");
	}
	if(strLName==""){
		strErrorArray.push("Please fill in Last Name");
	}
	if(strDate == "" || strMonth == "" || strYear == ""){
		strErrorArray.push("Please select your Date of Birth");
	}
	if(strEmailAddress == ""){
		strErrorArray.push("Please enter your email address");
	}else if(!isValidEmailAddress(strEmailAddress)){
		strErrorArray.push("Please enter valid email address");
	}
	if(strIncome==""){
		strErrorArray.push("Please fill in Annual Income");
	}else if(isNaN(strIncome)){
		strErrorArray.push("Please fill in valid Annual Income");
	}
	if(strHomeTel=="" && strOffTel=="" && strMobile==""){
		strErrorArray.push("Please specify atleast one Contact Number");
	}
	if(strHomeTel!=""){
		if(isNaN(strHomeTel)){
			strErrorArray.push("Please fill in valid Home Telephone Number");
		}
	}
	if(strOffTel!=""){
		if(isNaN(strOffTel)){
			strErrorArray.push("Please fill in valid Office Telephone Number");
		}
	}
	if(strMobile!=""){
		if(isNaN(strMobile)){
			strErrorArray.push("Please fill in valid Mobile Number");
		}
	}
	if(strHouseNo==""){
		strErrorArray.push("Please fill in House Name/No");
	}
	if(strPostcode==""){
		strErrorArray.push("Please fill in Postcode");
	}
	if(strAmount==""){
		strErrorArray.push("Please fill in Amount of Unsecured Debt");
	}else if(isNaN(strAmount)){
		strErrorArray.push("Please fill in valid Amount of Unsecured Debt");
	}
	if(strCreditors==""){
		strErrorArray.push("Please select Number of Creditors");
	}
	
// on error(s) dispalying them
	
	if(strErrorArray.length==0){
		return true;
	}else{
		for(var i=0;i<strErrorArray.length;i++){
			strErrorMsg+=(i+1)+". "+strErrorArray[i]+"\n";
		}
		alert(strErrorMsg);
		return false;
	}
	
}

function isValidEmailAddress(email){
 	var regex=/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return regex.test(email);
 }
