var Inversion = Class.create();
Inversion.prototype = {
	initialize: function (idDineroInvertido, idParticipacion,idValorLiquidativo,buscadorFondos, numberDinero, numberParticipaciones, numberValorLiquidativo) {
		this.dineroInvertidoField = $(idDineroInvertido);
		this.participacionesField = $(idParticipacion);
		this.valorLiquidativoField = $(idValorLiquidativo);
		this.fundSelected = null;	
		Event.observe(this.dineroInvertidoField,'blur', this.ondineroinvertido.bindAsEventListener(this));
		Event.observe(this.participacionesField,'blur', this.onparticipaciones.bindAsEventListener(this));
		buscadorFondos.addEventListener("selected",this.onfundselected.bindAsEventListener(this));
		this.numberDinero = numberDinero;
		this.numberParticipaciones = numberParticipaciones; 
		this.numberValorLiquidativo = numberValorLiquidativo;
	},
	
	onfundselected: function (fund) {
		this.fundSelected = fund;
		this.numberDinero.setValue(0.0);
		this.numberParticipaciones.setValue(0.0);
		this.numberValorLiquidativo.setValue(this.fundSelected.NetValueEuros);
		return;
	},
	ondineroinvertido: function () {
		try {
			this.numberDinero.onchange(0);
			if(this.numberValorLiquidativo.getValue() != 0.0)
				this.numberParticipaciones.setValue(this.numberDinero.getValue() / this.numberValorLiquidativo.getValue());
			else
				this.numberParticipaciones.setValue(0.0);
			
		} catch (ex){}
	},
	onparticipaciones: function () {
		try {
			this.numberParticipaciones.onchange(0);
			this.numberDinero.setValue(this.numberParticipaciones.getValue() * this.numberValorLiquidativo.getValue());
		} catch (ex){}
	},
	reset: function () {
		this.fundSelected = null;
		this.numberDinero.setValue(0.0);
		this.numberParticipaciones.setValue(0.0);
		this.numberValorLiquidativo.setValue(0);
	}	
};	
	
	
