/*
Note: V2 - is it possible to have a generic constructor function that adds an object to an Array object
           maybe passing the parent Array object in: this. + 'ArrayObject' + .push(inputObject) ??
*/

//----------------------------------------------------------------------		
//Application Object constructor
function Application(strRef, dtmReturnDate, numEOICount){
	this.Ref = (strRef != '') ? strRef : '';
	this.ReturnDate = new Date();
	//this.ReturnDate = (dtmReturnDate != null || dtmReturnDate != '') ? new Date(dtmReturnDate) : null;
	this.EOICount = (numEOICount != null) ? numEOICount : null;								
	this.Applicants = new Array(); //V2 will try to move Applicants to seperate object constructor				
	this.NotSetReason = null;
}

//Application addApplicant constructor
function Application_addApplicant(strTitle, strFirstName, strLastName, dtmDOB){
	var objApplicant = new Applicant(strTitle, strFirstName, strLastName, dtmDOB);		
	var arrLengthPlusOne = this.Applicants.length;		

	this.Applicants[arrLengthPlusOne] = objApplicant;
	//TODO: this.Applicants.push(objApplicant) //Adds Applicant to internal Applicants Array of Application	

	return objApplicant
}
Application.prototype.addApplicant = Application_addApplicant;
			
//----------------------------------------------------------------------
//Applicant object constructor
function Applicant(strTitle, strFirstName, strLastName, dtmDOB){
	this.Title = strTitle;
	this.FirstName = strFirstName;
	this.LastName = strLastName;
	this.DOB = new Date(dtmDOB);
	this.Addresses = new Array();
	this.Phones = new Array();
}

//----------------------------------------------------------------------
//Address constructor
function Address(strHouseNumber, strStreet, strTown, strLocality, strPostCode){
	this.HouseNumber = strHouseNumber;
	this.Street = strStreet;
	this.Town = strTown;
	this.Locality = strLocality;
	this.PostCode = strPostCode;
}

//addAddress method
function Applicant_addAddress(strHouseNumber, strStreet, strTown, strLocality, strPostCode){
	var objAddress = new Address(strHouseNumber, strStreet, strTown, strLocality, strPostCode);		
	var arrLengthPlusOne = this.Addresses.length;
	
	this.Addresses[arrLengthPlusOne] = objAddress;
	// TODO: this.Addresses.push(objAddress);	
	
	return objAddress;
}
Applicant.prototype.addAddress = Applicant_addAddress //add function as method of applicant object
//----------------------------------------------------------------------
//Phone constructor
function Phone(strType, numNumber){
	this.Type = strType;
	this.Number = numNumber;
}
			
//Applicant addPhone method
function Applicant_addPhone(strType, numNumber){
	var objPhone = new Phone(strType, numNumber);
	var arrLengthPlusOne = this.Phones.length;
	
	this.Phones[arrLengthPlusOne] = objPhone;
	//TODO: this.Phones.push(objPhone);
	return objPhone;
}
Applicant.prototype.addPhone = Applicant_addPhone; //add function as method of applicant object
