// JavaScript Document
function Pret() {

	this.inputRef = null;
	this.totalRef = null;
	this.mentenantaRef = null;

	this.value = 0;
	this.mentenanta = 0;
	this.minMentenanta = 0;
	this.total = 0;
	
	this.modificaPret = function(cb,value) {
		
		if(cb == null) {
			this.value = value;
		} else {
			this.value = cb.checked ? this.value + value : (this.value >= value) ? this.value - value : 0;
		}
		
		this.calculeazaMentenanta();	
	}
	
	this.calculeazaMentenanta = function() {		
		
		if(this.mentenantaRef.checked) {	
			var pret = Math.floor(this.value * 0.2/12);			
			this.mentenanta = (pret > this.minMentenanta) ? pret : this.minMentenanta;		
		} else {
			this.mentenanta = 0;
		}

		this.calculeazaTotal(true);
	} 
	
	this.displayTotal = function() {	
		this.totalRef.innerHTML = this.total;
		this.inputRef.value = this.total;
	}
	
	this.calculeazaTotal = function(boolDisplayTotal) {
			
		this.total = this.value + this.mentenanta;
		if(boolDisplayTotal)	this.displayTotal();
	}
	
}
