 

isEmptyArray = new Array(
"Forename",
"Surname",
"Occupation",
"Email",
"Address",
"Title",
"Source of Funds",
"Country of Residence",
"Citizenship",
"Income"
);
isNumeric = new Array(
"Day",
"Month",
"Year"
);
isQuestion = new Array(
"Mothers Maiden Name",
"Place Of Birth"
)
isOwnQuestion = new Array(
"Secret Question",
"Answer"
)
telephoneArr = new Array(
"TelephoneH",
"TelephoneW",
"TelephoneM"
)
otherArr = new Array(
"Title",
"Source of Funds"
)

var isEmptyStr = new String(isEmptyArray.join());
var isNumericStr = new String(isNumeric.join());

var isQuestionStr = new String(isQuestion.join());
var isOwnQuestionStr = new String(isOwnQuestion.join());

var telephoneStr = new String(telephoneArr.join());

var otherStr = new String(otherArr.join());

function checkApplication(){


var str='The following fields must be completed:\n\n';
var titleError = 'You must enter a Title';
var fundsError = 'You must enter a source of funds';

var isQuestionInt = -2;
var isOwnQuestionInt = -2;
var isDateOfBirthInt = 0;
var isTitleInt = 0;
var isFundsInt = 0;
var isResidenceInt = 0;
var isCitizenshipKaneInt = 0;
var telephoneInt = 0;
var isOtherInt =0;



	for(var i=0; i < document.applicationForm.elements.length; i++){

	     var e = document.applicationForm.elements[i];
	     var eStr = e.name;
	     var eValue = e.value;
	     if(isEmptyStr.search(eStr) != -1){
	          if(eValue == ''){
	               str=str+eStr+'\n';
	          }
	     }
	     if(isNumericStr.search(eStr) != -1){
	     
	     	  if (isNaN(eValue) || eValue == '') {

		       isDateOfBirthInt++;

	          }
	     }else if(isQuestionStr.search(eStr) != -1){
	          if(eValue != ''){
		       //alert(eValue);
		       isQuestionInt++;
		  }
	     }else if(isOwnQuestionStr.search(eStr) != -1){
	          if(eValue != ''){
		       //alert(eValue);
		       isOwnQuestionInt++;
		  }
	     }else if(telephoneStr.search(eStr) != -1){
	          if(eValue != ''){

		       telephoneInt++;

		  }
	     }else if(otherStr.search(eStr) != -1){
	          if(eValue == 'Other'){

		       if(eStr == 'Title' && document.applicationForm.elements[4].value == ''){
		            isOtherInt++;
			    //return false;
		       }

		       if(eStr == 'Source of Funds' && document.applicationForm.elements[24].value == ''){
		            isFundsInt++;
			    //return false;
		       }

		  }
	     }
	}


	if(str!='The following fields must be completed:\n\n'){
		alert(str);
		return false;
	}
	else if(document.applicationForm.elements[0].checked == false && 
		    document.applicationForm.elements[1].checked == false) {
	     str='';
	     str += 'You must tick one of the boxes to indicate whether you are an existing Goodbody client or not.\n';
	     alert(str);
	     return false;
    }		    

	else if(!(telephoneInt)){
	     str='';
	     str += 'You must enter at least one phone number\n';
	     alert(str);
	     return false;
	
	}else if(isDateOfBirthInt != 0){
	
	     str='';
	     str += 'The date of birth value is incorrect\n';
	     alert(str);
	     return false;

	}else if(isTitleInt != 0){
	     str='';
	     str += titleError;
	     alert(str);
	     return false;

	}else if(isFundsInt != 0){
	     str='';
	     str += fundsError;
	     alert(str);
	     return false;

	}else if(isOtherInt != 0){
	     str='';
	     str += 'Please enter your other title';
	     alert(str);
	     return false;

   }

 

	//if((isQuestionInt) && (isOwnQuestionInt)){
	  //   str='';
	    // str += '\nThe Verification Questions have not been filled in correctly\n';
	    // alert(str);
	    // return false;
//	}else{ 
	//     if(isOwnQuestionInt){
	          // This is when the two provided questions have been filled in.
		  // So we ignore the secret question.
	  //   }else{
	          // This is when the secret question has been filled in.
	    // }
	     //alert("The entrys are valid."); return true; 
//	}  

	return true; 
	
 
}

function validate(myValue){
        if(myValue != "Other"){
	return false;
	}else{ 
	document.applicationform.elements[2].enabled;
	}

 } 
 
