// JavaScript Document

function format(valeur,decimal) {
	separateur=" " ;
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

 
function calcul()
{
	var facade = document.getElementById("facade").value;
	var cote = document.getElementById("cote").value;
	
	var cotear = parseFloat(document.getElementById("cotearec").value);
	var cotebr = parseFloat(document.getElementById("cotebrec").value);
	
	var cotea = parseFloat(document.getElementById("cotea").value);
	var coteb = parseFloat(document.getElementById("coteb").value);
	var cotec = parseFloat(document.getElementById("cotec").value);
	var coted = parseFloat(document.getElementById("coted").value);
	
	
	var tcotea = parseFloat(document.getElementById("tcotea").value);
	var tcoteb = parseFloat(document.getElementById("tcoteb").value);
	var tcotec = parseFloat(document.getElementById("tcotec").value);
	
	var vtcotea = parseFloat(document.getElementById("vtcotea").value);
	var vtcoteb = parseFloat(document.getElementById("vtcoteb").value);
	var vtcotec = parseFloat(document.getElementById("vtcotec").value);
	
	var vstcotea = parseFloat(document.getElementById("vstcotea").value);
	var vstcoteb = parseFloat(document.getElementById("vstcoteb").value);
	var vstcotec = parseFloat(document.getElementById("vstcotec").value);
	 
 surface=(Math.sqrt(((cote*cote)/2)));
 versant=surface;
 surface=surface.toFixed(2)*facade*2 ;
 surface=surface.toFixed(2);
 document.getElementById("tuiles").value = format((surface* 30),0) +' €';
 document.getElementById("ardoisesA").value = format((surface*65),0) +' €';
 document.getElementById("ardoisesN").value = format((surface*75),0) +' €';
 document.getElementById("tuilesPetites").value = format((surface*80),0) +' €';
 document.getElementById("tuilesBeton").value = format((surface*25),0) +' €';
 document.getElementById("surface").value = surface +' M2';
 document.getElementById("versant").value = format((versant),2) +' ML';
 

 surfacerec=((cotear*cotebr))
 surfacerec= surfacerec.toFixed(2);
 perimetrerec=((cotear+cotebr)*2)
 perimetrerec=  perimetrerec.toFixed(2);
 document.getElementById("surfacerec").value = format((surfacerec),2) +' M2';
 document.getElementById("perimetrerec").value = format((perimetrerec),2) +' ML';
 

 surfacetrapeze=((cotea+coteb)/2)*((cotec+coted)/2);
 surfacetrapeze= surfacetrapeze.toFixed(2);
 perimetretrapeze=((cotea+coteb))+((cotec+coted));
 perimetretrapeze=  perimetretrapeze.toFixed(2);
 document.getElementById("surfacetrapeze").value = format((surfacetrapeze),2) +' M2';
 document.getElementById("perimetretrapeze").value = format((perimetretrapeze),2) +' ML';
 

 angletriangle=(Math.acos(((tcotec*tcotec)+(tcotea*tcotea)-(tcoteb*tcoteb))/(2*tcotea*tcotec))); 
 angletriangle= angletriangle/(Math.PI/180);
 angletriangle= angletriangle.toFixed(2);
 document.getElementById("angletriangle").value = angletriangle +' degres';
 
 versantsimple=(Math.sqrt(((vtcotec*vtcotec)+((vtcoteb-vtcotea)*(vtcoteb-vtcotea)))));
 //versantsimple=(vtcotec*vtcotec);
  versantsimple= versantsimple.toFixed(2);
 document.getElementById("versantsimple").value = versantsimple +' Ml';

 vstcotec=vstcotec/2;
 versantdouble=(Math.sqrt(((vstcotec*vstcotec)+((vstcoteb-vstcotea)*(vstcoteb-vstcotea)))));
 versantdouble= versantdouble.toFixed(2);
 document.getElementById("versantdouble").value = versantdouble+' Ml';

 
}
 

