// JavaScript Document

//Les constantes
var DEP = 21.58;
var PINSTAL = 25.896;
var TXFINAL = 34;
var ELEC = 3.196;
var ABO_ELEC = 353;
var ENTRETIEN_ELEC = 0;
var PROP = 4.114;
var ABO_PROP = 104;
var ENTRETIEN_PROP =178 ;
var FUEL = 2.38;
var ABO_FUEL = 104;
var ENTRETIEN_FUEL = 234;
var GAZ = 2.312;
var ABO_GAZ = 229;
var ENTRETIEN_GAZ = 178;
var GEO = 0.918;
var ABO_GEO = 187;
var ENTRETIEN_GEO = 105 ;


function estimer(e){
	//stop la propagation
	Event.stop(e);
	//Recuperation du volume rentré
	var volumeChauffe = parseInt($('volumeChauffe').value,10);
	
	if (isNaN(volumeChauffe)){
		alert("Vous n'avez pas renseigné le volume chauffé. Merci de l'indiquer, puis de cliquer sur \"calculer\"");
	}else{
		
		//deperdition totale
		Element.update('depTotal', Math.round(100*(volumeChauffe * DEP))/100);
		
		//puissance à installer
		Element.update('puisInstal', Math.round(100*(volumeChauffe * PINSTAL))/100);
		
		//energie necessaire
		Element.update('nrjNecess', Math.round(100*(volumeChauffe * TXFINAL))/100);
		
		//calcul electricité
		var consoElec = Math.round(100*(volumeChauffe * ELEC))/100;
		Element.update('consoElec', consoElec);
		Element.update('totalElec', Math.round(100*(consoElec + ENTRETIEN_ELEC + ABO_ELEC))/100);
		Element.update('totalElec15',Math.round(100*(consoElec + ENTRETIEN_ELEC + ABO_ELEC)*15)/100);
		
		//calcul propane
		var consoProp = Math.round(100*(volumeChauffe * PROP))/100;
		Element.update('consoProp', consoProp);
		Element.update('totalProp', Math.round(100*(consoProp + ENTRETIEN_PROP + ABO_PROP))/100);
		Element.update('totalProp15', Math.round(100*(consoProp + ENTRETIEN_PROP + ABO_PROP)*15)/100);
		
		//calcul fuel
		var consoFuel = Math.round(100*(volumeChauffe * FUEL))/100;
		Element.update('consoFuel', consoFuel);
		Element.update('totalFuel', Math.round(100*(consoFuel + ENTRETIEN_FUEL + ABO_FUEL))/100);
		Element.update('totalFuel15', Math.round(100*(consoFuel + ENTRETIEN_FUEL + ABO_FUEL)*15)/100);
		
		//calcul Gaz nat
		var consoGaz = Math.round(100*(volumeChauffe * GAZ))/100;
		Element.update('consoGaz', consoGaz);
		Element.update('totalGaz', Math.round(100*(consoGaz + ENTRETIEN_GAZ + ABO_GAZ))/100);
		Element.update('totalGaz15', Math.round(100*(consoGaz + ENTRETIEN_GAZ + ABO_GAZ)*15)/100);
		
		//calcul Geo
		var consoGeo = Math.round(100*(volumeChauffe * GEO))/100;
		Element.update('consoGeo', consoGeo);
		Element.update('totalGeo', Math.round(100*(consoGeo + ENTRETIEN_GEO + ABO_GEO))/100);
		Element.update('totalGeo15', Math.round(100*(consoGeo + ENTRETIEN_GEO + ABO_GEO)*15)/100);
	}
}

function initCalcul(){
	
	Event.observe('estimation', 'click', estimer, false);
	
	Element.update('aboElec', ABO_ELEC);
	Element.update('entretienElec', ENTRETIEN_ELEC);
	
	Element.update('aboProp', ABO_PROP);
	Element.update('entretienProp', ENTRETIEN_PROP);
	
	Element.update('aboFuel', ABO_FUEL);
	Element.update('entretienFuel', ENTRETIEN_FUEL);
	
	Element.update('aboGaz', ABO_GAZ);
	Element.update('entretienGaz', ENTRETIEN_GAZ);
	
	Element.update('aboGeo', ABO_GEO);
	Element.update('entretienGeo', ENTRETIEN_GEO);
}




Event.observe(window, 'load', initCalcul, false);

