function EstateWeb_Objects_CIPManager(){
	this.applicant = new EstateWeb_Objects_CIPManager_Applicant(this);
	this.saveRecordResponseTypes = new EstateWeb_Objects_CIPManager_SaveRecordResponseTypes();
}

function EstateWeb_Objects_CIPManager_Applicant(o){
	this.parent = o;
	this.details = new EstateWeb_Objects_CIPManager_Applicant_Details();
	this.create = EstateWeb_Objects_CIPManager_Applicant_Create;
	this.retrieve = EstateWeb_Objects_CIPManager_Applicant_Retrieve;
}

function EstateWeb_Objects_CIPManager_Applicant_Details(){
	this.id = -1;
	this.title = "";
	this.firstName = "";
	this.lastName = "";
	this.emailAddress = "";
	this.mobileNumber = "";
	this.isLoggedIn = false;
	this.minimumPrice = -1;
	this.maximumPrice = -1;
	this.minimumBedrooms = -1;
	this.listingType = 5;
	this.areas = [];
	this.areaIDs = [];
	this.hasProfile = false;
}

function EstateWeb_Objects_CIPManager_Applicant_Create(){
	var oresponse = CIPManager.CreateApplicantClientSide(this.details.title,
																				  this.details.firstName,
																				  this.details.lastName,
																				  "",
																				  "",
																				  "",
																				  "",
																				  "",
																				  "",
																				  "",
																				  "",
																				  "",
																				  this.details.mobileNumber,
																				  "",
																				  "",
																				  this.details.emailAddress,
																				  this.details.areas,
																				  this.details.minimumPrice,
																				  this.details.maximumPrice,
																				  this.details.minimumBedrooms,
																				  -1,
																				  -1,
																				  this.details.listingType, 
																				  this.details.areaIDs);
																				  
	return this.parent.saveRecordResponseTypes.match( oresponse.value.ResponseType );
}

function EstateWeb_Objects_CIPManager_Applicant_Retrieve(){
	var oresponse = CIPManager.Profile();
	if (oresponse.value){
		with ( oresponse.value ){
			this.details.title = Title;
			this.details.firstname = FirstName;
			this.details.lastname = LastName;
			this.details.emailaddress = EmailAddress;
			this.details.isLoggedIn = IsLoggedIn;
			this.details.hasProfile = true;
		}
	}
}

function EstateWeb_Objects_CIPManager_SaveRecordResponseTypes(){
	this.success = 0;
	this.alreadyExists = 1;
	this.failure = 2;
	this.match = EstateWeb_Objects_CIPManager_SaveRecordResponseTypes_Match;
}

function EstateWeb_Objects_CIPManager_SaveRecordResponseTypes_Match(val){
	switch (val.toLowerCase()){
		case "success":
			return this.success;
			break;
		case "alreadyexists":
			return this.alreadyExists;
			break;
		case "failure":
			return this.failure;
			break;
	}
}
