var OwnMemory = new Class({
	Implements: [Events],
	
	data: null,
	
	initialize: function(checkbox) {
		checkbox.addEvent(Browser.Engine.trident ? 'click' : 'change', this.send.bind(this));
	},
	
	send: function(e) {
		if(!e.target.checked) {
			this.populate(true);
		} else {
			if(this.data == null) {
				new Request.JSON({
					url: '/ajax/memory/2/ownMemory',
					method: 'get',
					onSuccess: function(data) {
						this.data = data;
						this.populate(false);
					}.bind(this)
				}).send();
			} else {
				this.populate(false);
			}
		}
	},
	
	populate: function(empty) {
		$('message.memories.person.firstName').set('value', empty ? '' : this.data.firstName);
		$('message.memories.person.lastName').set('value', empty ? '' : this.data.lastName);
		$('message.memories.person.maidenName').set('value', empty ? '' : this.data.maiden);
		$(this.data.sex).set('checked', empty ? '' : 'checked');
		if(!empty && this.data.sex == 'female')
			document.getElement('.maidenName').show();
		var inputBirth = document.getElement('input[name=memory.person.birthDate]');
		inputBirth.set('value', empty ? $time() : this.data.birth);
		inputBirth.getNext().set('value', empty ? new Date().format('%d/%m/%Y') : new Date().parse(this.data.birth).format('%d/%m/%Y'));
		$('message.memories.personal.birthplace').set('value', empty ? '' : this.data.town);
	}
});